Commit 8d4d256e authored by Martin Lowe's avatar Martin Lowe 🇨🇦 Committed by Martin Lowe
Browse files

Add unit testing, fix issues with formatting on copyright


Signed-off-by: Martin Lowe's avatarMartin Lowe <martin.lowe@eclipse-foundation.org>
parent 633802d2
/**
* ***************************************************************************** Copyright (C) 2020
* Eclipse Foundation
* Copyright (C) 2020 Eclipse Foundation
*
* <p>This program and the accompanying materials are made available under the terms of the Eclipse
* This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/
*
* <p>SPDX-License-Identifier: EPL-2.0
* ****************************************************************************
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.git.eca.service.impl;
......
......@@ -41,9 +41,17 @@ public class MockProjectsAPI implements ProjectsAPI {
Repo r2 = new Repo();
r2.setUrl("http://www.github.com/eclipsefdn/test");
Repo r3 = new Repo();
r3.setUrl("http://www.github.com/eclipsefdn/prototype");
r3.setUrl("http://www.github.com/eclipsefdn/prototype.git");
Repo r4 = new Repo();
r4.setUrl("http://www.github.com/eclipsefdn/tck-proto");
Repo r5 = new Repo();
r5.setUrl("/gitroot/sample/gerrit.project.git");
Repo r6 = new Repo();
r6.setUrl("/gitroot/sample/gerrit.other-project");
Repo r7 = new Repo();
r7.setUrl("https://gitlab.eclipse.org/eclipse/dash/dash.git");
Repo r8 = new Repo();
r8.setUrl("https://gitlab.eclipse.org/eclipse/dash/dash.handbook.test");
// sample users, correlates to users in Mock projects API
User u1 = new User();
......@@ -60,6 +68,7 @@ public class MockProjectsAPI implements ProjectsAPI {
p1.setProjectId("sample.proj");
p1.setSpecWorkingGroup(null);
p1.setGithubRepos(Arrays.asList(r1, r2));
p1.setGerritRepos(Arrays.asList(r5));
p1.setCommitters(Arrays.asList(u1, u2));
src.add(p1);
......@@ -68,6 +77,8 @@ public class MockProjectsAPI implements ProjectsAPI {
p2.setProjectId("sample.proto");
p2.setSpecWorkingGroup(null);
p2.setGithubRepos(Arrays.asList(r3));
p1.setGerritRepos(Arrays.asList(r6));
p1.setGitlabRepos(Arrays.asList(r8));
p2.setCommitters(Arrays.asList(u2));
src.add(p2);
......@@ -76,6 +87,7 @@ public class MockProjectsAPI implements ProjectsAPI {
p3.setProjectId("spec.proj");
p3.setSpecWorkingGroup("proj1");
p3.setGithubRepos(Arrays.asList(r4));
p1.setGitlabRepos(Arrays.asList(r7));
p3.setCommitters(Arrays.asList(u1, u2));
src.add(p3);
}
......@@ -84,5 +96,4 @@ public class MockProjectsAPI implements ProjectsAPI {
public List<Project> getProject(int page, int pageSize) {
return page == 1 ? new ArrayList<>(src) : Collections.emptyList();
}
}
......@@ -212,7 +212,7 @@ class ValidationResourceTest {
ValidationRequest vr = new ValidationRequest();
vr.setProvider(ProviderType.GITHUB);
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/prototype"));
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/prototype.git"));
vr.setCommits(commits);
// test output w/ assertions
......@@ -253,7 +253,7 @@ class ValidationResourceTest {
ValidationRequest vr = new ValidationRequest();
vr.setProvider(ProviderType.GITHUB);
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/prototype"));
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/prototype.git"));
vr.setCommits(commits);
// test output w/ assertions
......@@ -482,7 +482,7 @@ class ValidationResourceTest {
ValidationRequest vr = new ValidationRequest();
vr.setProvider(ProviderType.GITHUB);
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/tck-proto"));
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/tck-proto.git"));
vr.setCommits(commits);
// test output w/ assertions
......@@ -510,7 +510,7 @@ class ValidationResourceTest {
vr = new ValidationRequest();
vr.setProvider(ProviderType.GITHUB);
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/prototype"));
vr.setRepoUrl(new URI("http://www.github.com/eclipsefdn/prototype.git"));
vr.setCommits(commits);
// test output w/ assertions
......
/**
* Copyright (C) 2020 Eclipse Foundation
*
* This program and the accompanying materials are made available under the terms of the Eclipse
* Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipsefoundation.git.eca.service.impl;
import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.eclipsefoundation.git.eca.model.Project;
import org.eclipsefoundation.git.eca.model.Project.Repo;
import org.eclipsefoundation.git.eca.service.ProjectsService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import io.quarkus.test.junit.QuarkusTest;
@QuarkusTest
class PaginationProjectsServiceTest {
// get the projects service
@Inject ProjectsService ps;
@Test
void validateGerritUrlScrubbed() {
// get all projects
List<Project> projectsAll = ps.getProjects();
// get projects that have gerrit repos
List<Project> projs =
projectsAll
.stream()
.filter(p -> !p.getGerritRepos().isEmpty())
.collect(Collectors.toList());
// for all repos, check that none end with .git (this doesn't account for .git.git, but I assume
// that would be an entry error)
for (Project p : projs) {
for (Repo r : p.getGerritRepos()) {
Assertions.assertFalse(r.getUrl().endsWith(".git"), "Expected no URLs to end with '.git'");
}
}
}
@Test
void validateGithubUrlNotScrubbed() {
// get all projects
List<Project> projectsAll = ps.getProjects();
// get projects that have github repos
List<Project> projs =
projectsAll
.stream()
.filter(p -> !p.getGithubRepos().isEmpty())
.collect(Collectors.toList());
// for all repos, check that at least one ends with .git
boolean foundGitSuffix = false;
for (Project p : projs) {
for (Repo r : p.getGithubRepos()) {
if (r.getUrl().endsWith(".git")) {
foundGitSuffix = true;
}
}
}
Assertions.assertTrue(foundGitSuffix, "Expected a URL to end with '.git'");
}
@Test
void validateGitlabUrlNotScrubbed() {
// get all projects
List<Project> projectsAll = ps.getProjects();
// get projects that have gitlab repos
List<Project> projs =
projectsAll
.stream()
.filter(p -> !p.getGitlabRepos().isEmpty())
.collect(Collectors.toList());
// for all repos, check that at least one ends with .git
boolean foundGitSuffix = false;
for (Project p : projs) {
for (Repo r : p.getGitlabRepos()) {
if (r.getUrl().endsWith(".git")) {
foundGitSuffix = true;
}
}
}
Assertions.assertTrue(foundGitSuffix, "Expected a URL to end with '.git'");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment