]> source.dussan.org Git - sonarqube.git/commitdiff
Add response example to api/qualityprofiles/copy
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Mon, 4 Dec 2017 17:21:31 +0000 (18:21 +0100)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 6 Dec 2017 13:40:17 +0000 (14:40 +0100)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java
server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/copy-example.json [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java

index fecbbcdb8f7e3a19220396fe56d361b7c04e9d6c..a9261e390070cb000af6b839be97a27f106f9b67 100644 (file)
@@ -63,6 +63,7 @@ public class CopyAction implements QProfileWsAction {
       .setSince("5.2")
       .setDescription("Copy a quality profile.<br> " +
         "Requires to be logged in and the 'Administer Quality Profiles' permission.")
+      .setResponseExample(getClass().getResource("copy-example.json"))
       .setPost(true)
       .setHandler(this);
 
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/copy-example.json b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/copy-example.json
new file mode 100644 (file)
index 0000000..72b96f9
--- /dev/null
@@ -0,0 +1,8 @@
+{
+  "key" : "AU-TpxcA-iU5OvuD2FL1",
+  "name" : "My New Profile",
+  "language" : "Java",
+  "isDefault" : false,
+  "isInherited" : true,
+  "parentKey" : "AU-TpxcA-iU5OvuD2FL2"
+}
index 73faa831fa51213ddfef2192da7028cfa0ca30fd..7465bd73d2f9d74b6f6e2e3e7283bdc45b270e5b 100644 (file)
@@ -84,6 +84,7 @@ public class CopyActionTest {
 
     assertThat(definition.key()).isEqualTo("copy");
     assertThat(definition.isInternal()).isFalse();
+    assertThat(definition.responseExampleAsString()).isNotEmpty();
     assertThat(definition.since()).isEqualTo("5.2");
     assertThat(definition.isPost()).isTrue();
 
@@ -92,6 +93,26 @@ public class CopyActionTest {
     assertThat(definition.param("toName").isRequired()).isTrue();
   }
 
+  @Test
+  public void example() {
+    OrganizationDto organization = db.organizations().insert();
+    logInAsQProfileAdministrator(organization);
+    QProfileDto parent = db.qualityProfiles().insert(organization, p -> p.setKee("AU-TpxcA-iU5OvuD2FL2"));
+    QProfileDto profile = db.qualityProfiles().insert(organization, p -> p.setKee("old")
+      .setLanguage("Java")
+      .setParentKee(parent.getKee()));
+    String profileUuid = profile.getRulesProfileUuid();
+
+    String response = tester.newRequest()
+      .setMethod("POST")
+      .setParam("fromKey", profile.getKee())
+      .setParam("toName", "My New Profile")
+      .execute()
+      .getInput();
+
+    assertJson(response).ignoreFields("key").isSimilarTo(getClass().getResource("copy-example.json"));
+  }
+
   @Test
   public void create_profile_with_specified_name_and_copy_rules_from_source_profile() throws Exception {
     OrganizationDto organization = db.organizations().insert();
@@ -113,8 +134,7 @@ public class CopyActionTest {
       "  \"isDefault\": false," +
       "  \"isInherited\": false" +
       "}");
-    QProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(db.getSession(), organization, "target-name", sourceProfile.getLanguage()
-    );
+    QProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(db.getSession(), organization, "target-name", sourceProfile.getLanguage());
     assertThat(loadedProfile.getKee()).isEqualTo(generatedUuid);
     assertThat(loadedProfile.getParentKee()).isNull();
 
@@ -177,8 +197,7 @@ public class CopyActionTest {
       "  \"isDefault\": false," +
       "  \"isInherited\": true" +
       "}");
-    QProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(db.getSession(), organization, "target-name", sourceProfile.getLanguage()
-    );
+    QProfileDto loadedProfile = db.getDbClient().qualityProfileDao().selectByNameAndLanguage(db.getSession(), organization, "target-name", sourceProfile.getLanguage());
     assertThat(loadedProfile.getKee()).isEqualTo(generatedUuid);
     assertThat(loadedProfile.getParentKee()).isEqualTo(parentProfile.getKee());