diff options
author | Daniel Schwarz <daniel.schwarz@sonarsource.com> | 2017-03-22 11:41:13 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-03-23 17:38:34 +0100 |
commit | 86eb92e9dfae0e390201f0c0b19e049f25589b8a (patch) | |
tree | 99a5ca7e53bcbad9236b83a95b8420c8e17e3d63 /it | |
parent | 6dc1afaf6ef40ac4834864afb3c6ce394889791f (diff) | |
download | sonarqube-86eb92e9dfae0e390201f0c0b19e049f25589b8a.tar.gz sonarqube-86eb92e9dfae0e390201f0c0b19e049f25589b8a.zip |
SONAR-8857 add /restore and /activate_rule to sonar-ws, refactor tests
Diffstat (limited to 'it')
-rw-r--r-- | it/it-tests/src/test/java/it/organization/IssueAssignTest.java | 61 | ||||
-rw-r--r-- | it/it-tests/src/test/java/util/ItUtils.java | 7 |
2 files changed, 50 insertions, 18 deletions
diff --git a/it/it-tests/src/test/java/it/organization/IssueAssignTest.java b/it/it-tests/src/test/java/it/organization/IssueAssignTest.java index c9e5c4234f0..005660a7bde 100644 --- a/it/it-tests/src/test/java/it/organization/IssueAssignTest.java +++ b/it/it-tests/src/test/java/it/organization/IssueAssignTest.java @@ -21,8 +21,8 @@ package it.organization; import com.sonar.orchestrator.Orchestrator; -import com.sonar.orchestrator.locator.FileLocation; import it.Category3Suite; +import java.net.URISyntaxException; import java.util.List; import java.util.stream.Collectors; import org.junit.After; @@ -34,12 +34,15 @@ import org.junit.rules.ExpectedException; import org.sonarqube.ws.Issues; import org.sonarqube.ws.Issues.Issue; import org.sonarqube.ws.client.HttpException; -import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.issue.AssignRequest; import org.sonarqube.ws.client.issue.BulkChangeRequest; import org.sonarqube.ws.client.issue.SearchWsRequest; import org.sonarqube.ws.client.organization.CreateWsRequest; +import org.sonarqube.ws.client.project.CreateRequest; +import org.sonarqube.ws.client.qualityprofile.AddProjectRequest; +import org.sonarqube.ws.client.qualityprofile.RestoreWsRequest; +import util.ItUtils; import util.issue.IssueRule; import util.user.UserRule; @@ -53,9 +56,21 @@ import static util.ItUtils.setServerProperty; public class IssueAssignTest { + @Test + public void auto_assign_issues_to_user_if_default_assignee_is_member_of_project_organization() throws Exception { + userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); + adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); + provisionProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); + setServerProperty(orchestrator, "sample", "sonar.issues.defaultAssigneeLogin", ASSIGNEE_LOGIN); + + analyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); + + assertThat(issueRule.getRandomIssue().getAssignee()).isEqualTo(ASSIGNEE_LOGIN); + } private final static String SAMPLE_PROJECT_KEY = "sample"; private final static String ORGANIZATION_KEY = "organization-key"; private final static String OTHER_ORGANIZATION_KEY = "other-organization-key"; + private static final String ASSIGNEE_LOGIN = "bob"; @Rule @@ -79,8 +94,7 @@ public class IssueAssignTest { orchestrator.getServer().post("api/organizations/enable_support", emptyMap()); createOrganization(ORGANIZATION_KEY); - - orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/organization/IssueAssignTest/one-issue-per-file-profile.xml")); + restoreProfile(ORGANIZATION_KEY); } @After @@ -91,18 +105,6 @@ public class IssueAssignTest { } @Test - public void auto_assign_issues_to_user_if_default_assignee_is_member_of_project_organization() throws Exception { - userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); - adminClient.organizations().addMember(ORGANIZATION_KEY, ASSIGNEE_LOGIN); - provisionProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); - setServerProperty(orchestrator, "sample", "sonar.issues.defaultAssigneeLogin", ASSIGNEE_LOGIN); - - analyseProject(SAMPLE_PROJECT_KEY, ORGANIZATION_KEY); - - assertThat(issueRule.getRandomIssue().getAssignee()).isEqualTo(ASSIGNEE_LOGIN); - } - - @Test public void does_not_auto_assign_issues_to_user_if_default_assignee_is_not_member_of_project_organization() throws Exception { createOrganization(OTHER_ORGANIZATION_KEY); userRule.createUser(ASSIGNEE_LOGIN, ASSIGNEE_LOGIN); @@ -162,18 +164,41 @@ public class IssueAssignTest { adminClient.organizations().create(new CreateWsRequest.Builder().setKey(organizationKey).setName(organizationKey).build()).getOrganization(); } + private void restoreProfile(String organization) throws URISyntaxException { + adminClient.qualityProfiles().restoreProfile( + RestoreWsRequest.builder() + .setBackup(ItUtils.findFileInClasspath("/organization/IssueAssignTest/one-issue-per-file-profile.xml")) + .setOrganization(organization) + .build()); + } + private void provisionAndAnalyseProject(String projectKey, String organization) { provisionProject(projectKey, organization); analyseProject(projectKey, organization); } private void provisionProject(String projectKey, String organization) { - adminClient.wsConnector().call(new PostRequest("/api/projects/create").setParam("key", projectKey).setParam("name", projectKey).setParam("organization", organization)); + adminClient.projects().create( + CreateRequest.builder() + .setKey(projectKey) + .setName(projectKey) + .setOrganization(organization) + .build()); } private void analyseProject(String projectKey, String organization) { - orchestrator.getServer().associateProjectToQualityProfile(projectKey, "xoo", "one-issue-per-file-profile"); + addQualityProfileToProject(organization, projectKey); runProjectAnalysis(orchestrator, "issue/xoo-with-scm", "sonar.projectKey", projectKey, "sonar.organization", organization, "sonar.login", "admin", "sonar.password", "admin", "sonar.scm.disabled", "false", "sonar.scm.provider", "xoo"); } + + private void addQualityProfileToProject(String organization, String projectKey) { + adminClient.qualityProfiles().addProject( + AddProjectRequest.builder() + .setProjectKey(projectKey) + .setOrganization(organization) + .setLanguage("xoo") + .setProfileName("one-issue-per-file-profile") + .build()); + } } diff --git a/it/it-tests/src/test/java/util/ItUtils.java b/it/it-tests/src/test/java/util/ItUtils.java index 4e4d192c0cc..a40009ad88f 100644 --- a/it/it-tests/src/test/java/util/ItUtils.java +++ b/it/it-tests/src/test/java/util/ItUtils.java @@ -29,9 +29,11 @@ import com.sonar.orchestrator.build.BuildResult; import com.sonar.orchestrator.build.SonarRunner; import com.sonar.orchestrator.container.Server; import com.sonar.orchestrator.locator.FileLocation; +import com.sonar.orchestrator.locator.ResourceLocation; import java.io.File; import java.io.IOException; import java.lang.reflect.Type; +import java.net.URISyntaxException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; @@ -336,6 +338,11 @@ public class ItUtils { return ComponentNavigation.parse(content); } + public static File findFileInClasspath(String classpathRelativeFilename) throws URISyntaxException { + ResourceLocation location = FileLocation.ofClasspath("/organization/IssueAssignTest/one-issue-per-file-profile.xml"); + return new File(ItUtils.class.getResource(location.getPath()).toURI()); + } + public static class ComponentNavigation { private String version; private String snapshotDate; |