From 72170b891ef224779a42622be5a619fc20e8e276 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 15 Nov 2016 20:47:11 +0100 Subject: [PATCH] SONAR-6912 add response example to api/users/deactivate --- .../org/sonar/server/user/ws/DeactivateAction.java | 1 + .../sonar/server/user/ws/example-deactivate.json | 10 ++++++++++ .../sonar/server/user/ws/DeactivateActionTest.java | 14 +++++++++----- .../ws/DeactivateActionTest/deactivate_user.json | 9 --------- 4 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 server/sonar-server/src/main/resources/org/sonar/server/user/ws/example-deactivate.json delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/user/ws/DeactivateActionTest/deactivate_user.json diff --git a/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java b/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java index 121da89409e..6c840abca92 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/user/ws/DeactivateAction.java @@ -69,6 +69,7 @@ public class DeactivateAction implements UsersWsAction { .setDescription("Deactivate a user. Requires Administer System permission") .setSince("3.7") .setPost(true) + .setResponseExample(getClass().getResource("example-deactivate.json")) .setHandler(this); action.createParam("login") diff --git a/server/sonar-server/src/main/resources/org/sonar/server/user/ws/example-deactivate.json b/server/sonar-server/src/main/resources/org/sonar/server/user/ws/example-deactivate.json new file mode 100644 index 00000000000..e45bb206694 --- /dev/null +++ b/server/sonar-server/src/main/resources/org/sonar/server/user/ws/example-deactivate.json @@ -0,0 +1,10 @@ +{ + "user": { + "login": "ada.lovelace", + "name": "Ada Lovelace", + "active": false, + "local": true, + "groups": [], + "scmAccounts": [] + } +} diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java index 7cd0b79fd36..6c4d8828714 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/ws/DeactivateActionTest.java @@ -96,15 +96,17 @@ public class DeactivateActionTest { @Test public void deactivate_user_and_delete_his_related_data() throws Exception { - UserDto user = insertUser(newUserDto().setEmail("john@email.com") - .setLogin("john") - .setName("John") - .setScmAccounts(singletonList("jn"))); + UserDto user = insertUser(newUserDto() + .setLogin("ada.lovelace") + .setEmail("ada.lovelace@noteg.com") + .setName("Ada Lovelace") + .setScmAccounts(singletonList("al"))); loginAsAdmin(); String json = deactivate(user.getLogin()).getInput(); - assertJson(json).isSimilarTo(getClass().getResource("DeactivateActionTest/deactivate_user.json")); + // scm accounts, groups and email are deleted + assertJson(json).isSimilarTo(ws.getDef().responseExampleAsString()); assertThat(index.getNullableByLogin(user.getLogin()).active()).isFalse(); verifyThatUserIsDeactivated(user.getLogin()); @@ -246,5 +248,7 @@ public class DeactivateActionTest { Optional user = db.users().selectUserByLogin(login); assertThat(user).isPresent(); assertThat(user.get().isActive()).isFalse(); + assertThat(user.get().getEmail()).isNull(); + assertThat(user.get().getScmAccountsAsList()).isEmpty(); } } diff --git a/server/sonar-server/src/test/resources/org/sonar/server/user/ws/DeactivateActionTest/deactivate_user.json b/server/sonar-server/src/test/resources/org/sonar/server/user/ws/DeactivateActionTest/deactivate_user.json deleted file mode 100644 index f5e9eac1f29..00000000000 --- a/server/sonar-server/src/test/resources/org/sonar/server/user/ws/DeactivateActionTest/deactivate_user.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "user": { - "login": "john", - "name": "John", - "scmAccounts": [], - "active": false, - "local": true - } -} -- 2.39.5