aboutsummaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-04-27 18:31:04 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-05-03 19:49:09 +0200
commitb6c626d517f2a9783688b80a8dac0d5ba8a1f794 (patch)
tree81dea057e93bd27701c12f19904532ccaf62e580 /it
parentbe31eae8b4497281b32cb609d05590c590b83af0 (diff)
downloadsonarqube-b6c626d517f2a9783688b80a8dac0d5ba8a1f794.tar.gz
sonarqube-b6c626d517f2a9783688b80a8dac0d5ba8a1f794.zip
SONAR-8865 remove old documents from rules/extension index when updating
Diffstat (limited to 'it')
-rw-r--r--it/it-tests/src/test/java/it/rule/RulesPerOrganizationTest.java124
-rw-r--r--it/it-tests/src/test/java/it/rule/ToDoTest.java23
2 files changed, 124 insertions, 23 deletions
diff --git a/it/it-tests/src/test/java/it/rule/RulesPerOrganizationTest.java b/it/it-tests/src/test/java/it/rule/RulesPerOrganizationTest.java
new file mode 100644
index 00000000000..f405fc0d181
--- /dev/null
+++ b/it/it-tests/src/test/java/it/rule/RulesPerOrganizationTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.rule;
+
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.http.HttpMethod;
+import it.Category6Suite;
+import java.util.List;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.sonarqube.ws.client.WsClient;
+import org.sonarqube.ws.client.organization.CreateWsRequest;
+import util.ItUtils;
+
+import static it.Category6Suite.enableOrganizationsSupport;
+import static org.assertj.core.api.Assertions.assertThat;
+import static util.ItUtils.deleteOrganizationsIfExists;
+import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.newWsClient;
+
+public class RulesPerOrganizationTest {
+
+ private static WsClient adminWsClient;
+ private static final String ORGANIZATION_FOO = "foo-org";
+ private static final String ORGANIZATION_BAR = "bar-org";
+
+ @ClassRule
+ public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
+
+ @BeforeClass
+ public static void setUp() {
+ adminWsClient = newAdminWsClient(orchestrator);
+ enableOrganizationsSupport();
+ createOrganization(ORGANIZATION_FOO);
+ createOrganization(ORGANIZATION_BAR);
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ deleteOrganizationsIfExists(orchestrator, ORGANIZATION_FOO);
+ deleteOrganizationsIfExists(orchestrator, ORGANIZATION_BAR);
+ }
+
+ private static void createOrganization(String organization) {
+ adminWsClient.organizations().create(new CreateWsRequest.Builder().setKey(organization).setName(organization).build());
+ }
+
+ @Test
+ public void should_not_show_tags_of_other_org() {
+ updateTag("foo-tag", ORGANIZATION_FOO);
+ updateTag("bar-tag", ORGANIZATION_BAR);
+ assertThat(showRuleTags(ORGANIZATION_FOO)).containsExactly("foo-tag");
+ assertThat(showRuleTags(ORGANIZATION_BAR)).containsExactly("bar-tag");
+ }
+
+ @Test
+ public void should_not_list_tags_of_other_org() {
+ updateTag("foo-tag", ORGANIZATION_FOO);
+ updateTag("bar-tag", ORGANIZATION_BAR);
+ assertThat(listTags(ORGANIZATION_FOO))
+ .contains("foo-tag")
+ .doesNotContain("bar-tag");
+ }
+
+ @Test
+ public void should_not_show_removed_tags() {
+ updateTag("foo-tag", ORGANIZATION_FOO);
+ assertThat(showRuleTags(ORGANIZATION_FOO)).contains("foo-tag");
+
+ updateTag("", ORGANIZATION_FOO);
+ assertThat(showRuleTags(ORGANIZATION_FOO)).isEmpty();
+ }
+
+ @Test
+ public void should_not_list_removed_tags() {
+ updateTag("foo-tag", ORGANIZATION_FOO);
+ assertThat(listTags(ORGANIZATION_FOO)).contains("foo-tag");
+
+ updateTag("", ORGANIZATION_FOO);
+ assertThat(listTags(ORGANIZATION_FOO)).doesNotContain("foo-tag");
+ }
+
+ private List<String> listTags(String organization) {
+ String json = orchestrator.getServer().newHttpCall("/api/rules/tags")
+ .setParam("organization", organization)
+ .execute()
+ .getBodyAsString();
+ return (List<String>) ItUtils.jsonToMap(json).get("tags");
+ }
+
+ private List<String> showRuleTags(String organization) {
+ return newWsClient(orchestrator).rules().show(organization, "xoo:OneIssuePerFile")
+ .getRule().getTags().getTagsList();
+ }
+
+ private void updateTag(String tag, String organization) {
+ orchestrator.getServer().newHttpCall("/api/rules/update")
+ .setMethod(HttpMethod.POST)
+ .setAdminCredentials()
+ .setParam("organization", organization)
+ .setParam("key", "xoo:OneIssuePerFile")
+ .setParam("tags", tag)
+ .execute();
+ }
+}
diff --git a/it/it-tests/src/test/java/it/rule/ToDoTest.java b/it/it-tests/src/test/java/it/rule/ToDoTest.java
deleted file mode 100644
index 1314ebbb4bb..00000000000
--- a/it/it-tests/src/test/java/it/rule/ToDoTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.rule;
-
-public class ToDoTest {
-}