]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR_8951 moved rules/show medium test to dedicated test class
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Wed, 5 Apr 2017 15:08:11 +0000 (17:08 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Fri, 14 Apr 2017 06:57:18 +0000 (08:57 +0200)
server/sonar-server/src/test/java/org/sonar/server/rule/ws/RulesWsMediumTest.java
server/sonar-server/src/test/java/org/sonar/server/rule/ws/SearchActionMediumTest.java
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/get_tags_filtered.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/get_tags_limited.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/show_rule_active.json [deleted file]
server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/show_rule_no_active.json [deleted file]

index a75bf25c85cb5324f67de69741b1071a3880907a..fe1498b312404ec50e3577986ac63380b2891424 100644 (file)
@@ -27,22 +27,8 @@ import org.junit.Test;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
-import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.qualityprofile.ActiveRuleDao;
-import org.sonar.db.qualityprofile.ActiveRuleDto;
-import org.sonar.db.qualityprofile.QualityProfileDao;
-import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.db.rule.RuleDao;
-import org.sonar.db.rule.RuleDto;
-import org.sonar.db.rule.RuleTesting;
-import org.sonar.server.organization.DefaultOrganization;
-import org.sonar.server.organization.DefaultOrganizationProvider;
-import org.sonar.server.qualityprofile.QProfileTesting;
-import org.sonar.server.qualityprofile.index.ActiveRuleIndexer;
-import org.sonar.server.rule.index.RuleIndexer;
 import org.sonar.server.tester.ServerTester;
 import org.sonar.server.tester.UserSessionRule;
-import org.sonar.server.ws.WsTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -58,25 +44,14 @@ public class RulesWsMediumTest {
   private static final String API_SHOW_METHOD = "show";
   private static final String API_TAGS_METHOD = "tags";
 
-  private DbClient db;
   private RulesWs ws;
-  private RuleDao ruleDao;
   private DbSession session;
-  private RuleIndexer ruleIndexer;
-  private ActiveRuleIndexer activeRuleIndexer;
-  private OrganizationDto defaultOrganization;
 
   @Before
   public void setUp() {
     tester.clearDbAndIndexes();
-    db = tester.get(DbClient.class);
-    ruleDao = tester.get(RuleDao.class);
     ws = tester.get(RulesWs.class);
     session = tester.get(DbClient.class).openSession(false);
-    ruleIndexer = tester.get(RuleIndexer.class);
-    activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
-    DefaultOrganization defaultOrganization = tester.get(DefaultOrganizationProvider.class).get();
-    this.defaultOrganization = db.organizationDao().selectByUuid(session, defaultOrganization.getUuid()).get();
   }
 
   @After
@@ -102,34 +77,4 @@ public class RulesWsMediumTest {
     assertThat(controller.action("repositories")).isNotNull();
     assertThat(controller.action("app")).isNotNull();
   }
-
-  @Test
-  public void show_rule() throws Exception {
-    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
-    tester.get(QualityProfileDao.class).insert(session, profile);
-
-    RuleDto rule = RuleTesting.newXooX1(defaultOrganization);
-    ruleDao.insert(session, rule.getDefinition());
-    ruleDao.insertOrUpdate(session, rule.getMetadata().setRuleId(rule.getId()));
-
-    ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(profile, rule.getDefinition()).setSeverity("BLOCKER");
-    tester.get(ActiveRuleDao.class).insert(session, activeRuleDto);
-
-    session.commit();
-    ruleIndexer.indexRuleDefinition(rule.getDefinition().getKey());
-    activeRuleIndexer.index();
-
-    // 1. With Activation
-    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SHOW_METHOD);
-    request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
-    request.setParam(ShowAction.PARAM_ACTIVES, "true");
-    WsTester.Result result = request.execute();
-    result.assertJson(this.getClass(), "show_rule_active.json");
-
-    // 1. Default Activation (defaults to false)
-    request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SHOW_METHOD);
-    request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
-    result = request.execute();
-    result.assertJson(this.getClass(), "show_rule_no_active.json");
-  }
 }
index 582c732a964f122805dd50d04d7cd2f454a95dad..d9cb7d9bdd2c6a602d17476eddc5ab2d2fec13e7 100644 (file)
@@ -100,6 +100,82 @@ public class SearchActionMediumTest {
     dbSession.close();
   }
 
+  @Test
+  public void show_rule() throws Exception {
+    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
+    tester.get(QualityProfileDao.class).insert(dbSession, profile);
+
+    RuleDto rule = RuleTesting.newXooX1(defaultOrganizationDto);
+    ruleDao.insert(dbSession, rule.getDefinition());
+    ruleDao.insertOrUpdate(dbSession, rule.getMetadata().setRuleId(rule.getId()));
+
+    ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(profile, rule.getDefinition()).setSeverity("BLOCKER");
+    tester.get(ActiveRuleDao.class).insert(dbSession, activeRuleDto);
+
+    dbSession.commit();
+    ruleIndexer.indexRuleDefinition(rule.getDefinition().getKey());
+    activeRuleIndexer.index();
+
+    // 1. With Activation
+    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, "show");
+    request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
+    request.setParam(ShowAction.PARAM_ACTIVES, "true");
+    WsTester.Result result = request.execute();
+    result.assertJson("{\n" +
+      "  \"rule\": {\n" +
+      "    \"key\": \"xoo:x1\",\n" +
+      "    \"repo\": \"xoo\",\n" +
+      "    \"name\": \"Rule x1\",\n" +
+      "    \"htmlDesc\": \"Description x1\",\n" +
+      "    \"severity\": \"INFO\",\n" +
+      "    \"status\": \"READY\",\n" +
+      "    \"internalKey\": \"InternalKeyx1\",\n" +
+      "    \"isTemplate\": false,\n" +
+      "    \"tags\": [\n" +
+      "      \"tag1\",\n" +
+      "      \"tag2\"\n" +
+      "    ],\n" +
+      "    \"sysTags\": [\n" +
+      "      \"systag1\",\n" +
+      "      \"systag2\"\n" +
+      "    ],\n" +
+      "    \"debtRemFnType\": \"LINEAR\",\n" +
+      "    \"debtRemFnCoeff\": \"1h\",\n" +
+      "    \"lang\": \"xoo\",\n" +
+      "    \"params\": []\n" +
+      "  },\n" +
+      "  \"actives\": [\n" +
+      "    {\n" +
+      "      \"qProfile\": \"XOO_P1\",\n" +
+      "      \"inherit\": \"NONE\",\n" +
+      "      \"severity\": \"BLOCKER\",\n" +
+      "      \"params\": []\n" +
+      "    }\n" +
+      "  ]\n" +
+      "}\n");
+
+    // 1. Default Activation (defaults to false)
+    request = tester.wsTester().newGetRequest(API_ENDPOINT, "show");
+    request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
+    result = request.execute();
+    result.assertJson("{\"rule\": {\n" +
+      "  \"key\": \"xoo:x1\",\n" +
+      "  \"repo\": \"xoo\",\n" +
+      "  \"name\": \"Rule x1\",\n" +
+      "  \"htmlDesc\": \"Description x1\",\n" +
+      "  \"severity\": \"INFO\",\n" +
+      "  \"status\": \"READY\",\n" +
+      "  \"internalKey\": \"InternalKeyx1\",\n" +
+      "  \"isTemplate\": false,\n" +
+      "  \"tags\": [\"tag1\", \"tag2\"],\n" +
+      "  \"sysTags\": [\"systag1\", \"systag2\"],\n" +
+      "  \"debtRemFnType\": \"LINEAR\",\n" +
+      "  \"debtRemFnCoeff\": \"1h\",\n" +
+      "  \"lang\": \"xoo\",\n" +
+      "  \"params\": []\n" +
+      "}}\n");
+  }
+
   @Test
   public void search_no_rules() throws Exception {
     WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/get_tags_filtered.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/get_tags_filtered.json
deleted file mode 100644 (file)
index 0ce4ec6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"tags": ["hello"]}
\ No newline at end of file
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/get_tags_limited.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/get_tags_limited.json
deleted file mode 100644 (file)
index 0ce4ec6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"tags": ["hello"]}
\ No newline at end of file
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/show_rule_active.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/show_rule_active.json
deleted file mode 100644 (file)
index 2e936ca..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-{
-  "rule": {
-    "key": "xoo:x1",
-    "repo": "xoo",
-    "name": "Rule x1",
-    "htmlDesc": "Description x1",
-    "severity": "INFO",
-    "status": "READY",
-    "internalKey": "InternalKeyx1",
-    "isTemplate": false,
-    "tags": [
-      "tag1",
-      "tag2"
-    ],
-    "sysTags": [
-      "systag1",
-      "systag2"
-    ],
-    "debtRemFnType": "LINEAR",
-    "debtRemFnCoeff": "1h",
-    "lang": "xoo",
-    "params": []
-  },
-  "actives": [
-    {
-      "qProfile": "XOO_P1",
-      "inherit": "NONE",
-      "severity": "BLOCKER",
-      "params": []
-    }
-  ]
-}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/show_rule_no_active.json b/server/sonar-server/src/test/resources/org/sonar/server/rule/ws/RulesWsMediumTest/show_rule_no_active.json
deleted file mode 100644 (file)
index d511ffa..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-{"rule": {
-  "key": "xoo:x1",
-  "repo": "xoo",
-  "name": "Rule x1",
-  "htmlDesc": "Description x1",
-  "severity": "INFO",
-  "status": "READY",
-  "internalKey": "InternalKeyx1",
-  "isTemplate": false,
-  "tags": ["tag1", "tag2"],
-  "sysTags": ["systag1", "systag2"],
-  "debtRemFnType": "LINEAR",
-  "debtRemFnCoeff": "1h",
-  "lang": "xoo",
-  "params": []
-}}