From ad745fb92a0450298d89f01c21d1d6a439c3d19c Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Mon, 4 Dec 2017 18:21:31 +0100 Subject: [PATCH] Add response example to api/qualityprofiles/copy --- .../server/qualityprofile/ws/CopyAction.java | 1 + .../qualityprofile/ws/copy-example.json | 8 ++++++ .../qualityprofile/ws/CopyActionTest.java | 27 ++++++++++++++++--- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/copy-example.json diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java index fecbbcdb8f7..a9261e39007 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/CopyAction.java @@ -63,6 +63,7 @@ public class CopyAction implements QProfileWsAction { .setSince("5.2") .setDescription("Copy a quality profile.
" + "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 index 00000000000..72b96f9aac9 --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/qualityprofile/ws/copy-example.json @@ -0,0 +1,8 @@ +{ + "key" : "AU-TpxcA-iU5OvuD2FL1", + "name" : "My New Profile", + "language" : "Java", + "isDefault" : false, + "isInherited" : true, + "parentKey" : "AU-TpxcA-iU5OvuD2FL2" +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java index 73faa831fa5..7465bd73d2f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/CopyActionTest.java @@ -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()); -- 2.39.5