diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-26 10:56:00 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-04-26 16:34:31 +0200 |
commit | 439d0750b2ec547f6829cbeadcb9fed995c6eb05 (patch) | |
tree | ee21937c819fdbe34c5039a399ad80097c9867cf /it/it-tests/src/test/java | |
parent | 4d9cbe9276073d6b026cbaf8510743aa0b62c4fb (diff) | |
download | sonarqube-439d0750b2ec547f6829cbeadcb9fed995c6eb05.tar.gz sonarqube-439d0750b2ec547f6829cbeadcb9fed995c6eb05.zip |
SONAR-9126 Add ITs
Diffstat (limited to 'it/it-tests/src/test/java')
-rw-r--r-- | it/it-tests/src/test/java/it/Category6Suite.java | 3 | ||||
-rw-r--r-- | it/it-tests/src/test/java/it/organization/BillingTest.java | 109 |
2 files changed, 112 insertions, 0 deletions
diff --git a/it/it-tests/src/test/java/it/Category6Suite.java b/it/it-tests/src/test/java/it/Category6Suite.java index 9e627ae9bf5..65a39793a75 100644 --- a/it/it-tests/src/test/java/it/Category6Suite.java +++ b/it/it-tests/src/test/java/it/Category6Suite.java @@ -21,6 +21,7 @@ package it; import com.sonar.orchestrator.Orchestrator; import it.issue.OrganizationIssueAssignTest; +import it.organization.BillingTest; import it.organization.OrganizationMembershipTest; import it.organization.OrganizationTest; import it.qualityProfile.OrganizationQualityProfilesPageTest; @@ -46,6 +47,7 @@ import static util.ItUtils.xooPlugin; OrganizationQualityProfilesPageTest.class, OrganizationTest.class, OrganizationUiExtensionsTest.class, + BillingTest.class }) public class Category6Suite { @@ -54,6 +56,7 @@ public class Category6Suite { .addPlugin(xooPlugin()) .addPlugin(pluginArtifact("base-auth-plugin")) .addPlugin(pluginArtifact("ui-extensions-plugin")) + .addPlugin(pluginArtifact("billing-plugin")) .build(); @BeforeClass diff --git a/it/it-tests/src/test/java/it/organization/BillingTest.java b/it/it-tests/src/test/java/it/organization/BillingTest.java new file mode 100644 index 00000000000..10a623dbe61 --- /dev/null +++ b/it/it-tests/src/test/java/it/organization/BillingTest.java @@ -0,0 +1,109 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package it.organization; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.BuildResult; +import com.sonar.orchestrator.build.SonarScanner; +import it.Category6Suite; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonarqube.ws.client.WsClient; +import org.sonarqube.ws.client.organization.CreateWsRequest; +import util.ItUtils; +import util.user.UserRule; + +import static it.Category6Suite.enableOrganizationsSupport; +import static java.lang.String.format; +import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.sonarqube.ws.WsCe.TaskResponse; +import static util.ItUtils.newAdminWsClient; +import static util.ItUtils.newOrganizationKey; +import static util.ItUtils.newProjectKey; +import static util.ItUtils.projectDir; +import static util.ItUtils.resetSettings; +import static util.ItUtils.setServerProperty; + +public class BillingTest { + @ClassRule + public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + + @ClassRule + public static UserRule userRule = UserRule.from(orchestrator); + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private static WsClient adminClient; + + @BeforeClass + public static void setUp() throws Exception { + adminClient = newAdminWsClient(orchestrator); + enableOrganizationsSupport(); + resetSettings(orchestrator, "sonar.billing.preventProjectAnalysis"); + } + + @AfterClass + public static void tearDown() throws Exception { + resetSettings(orchestrator, "sonar.billing.preventProjectAnalysis"); + } + + @Test + public void execute_successfully_ce_analysis_on_organization() { + String organizationKey = createOrganization(); + setServerProperty(orchestrator, "sonar.billing.preventProjectAnalysis", "false"); + + String taskUuid = executeAnalysis(organizationKey); + + TaskResponse taskResponse = adminClient.ce().task(taskUuid); + assertThat(taskResponse.getTask().hasErrorMessage()).isFalse(); + } + + @Test + public void fail_to_execute_ce_analysis_on_organization() { + String organizationKey = createOrganization(); + setServerProperty(orchestrator, "sonar.billing.preventProjectAnalysis", "true"); + + String taskUuid = executeAnalysis(organizationKey); + + TaskResponse taskResponse = adminClient.ce().task(taskUuid); + assertThat(taskResponse.getTask().hasErrorMessage()).isTrue(); + assertThat(taskResponse.getTask().getErrorMessage()).contains(format("Organization %s cannot perform analysis", organizationKey)); + } + + private static String createOrganization() { + String key = newOrganizationKey(); + adminClient.organizations().create(new CreateWsRequest.Builder().setKey(key).setName(key).build()).getOrganization(); + return key; + } + + private static String executeAnalysis(String organizationKey) { + BuildResult buildResult = orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"), + "sonar.organization", organizationKey, + "sonar.projectKey", newProjectKey(), + "sonar.login", "admin", + "sonar.password", "admin")); + return ItUtils.extractCeTaskId(buildResult); + } +} |