From bd314784e17f2b0573a9e6a25e6a7b8a231c5ed1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lievremont Date: Mon, 13 Apr 2015 15:30:36 +0200 Subject: [PATCH] SONAR-6308 Add edge test cases --- .../ws/QProfileChangelogActionTest.java | 33 ++++++++++++++++--- .../changelog_no_login.json | 15 +++++++++ .../changelog_no_param.json | 17 ++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_login.json create mode 100644 server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_param.json diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest.java index 5e9b7659533..232fe5f0352 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest.java @@ -30,7 +30,6 @@ import org.sonar.api.rule.Severity; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.api.utils.internal.Uuids; -import org.sonar.core.permission.GlobalPermissions; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.DbTester; import org.sonar.core.qualityprofile.db.ActiveRuleKey; @@ -51,7 +50,6 @@ import org.sonar.server.qualityprofile.QProfileFactory; import org.sonar.server.qualityprofile.QProfileTesting; import org.sonar.server.rule.RuleTesting; import org.sonar.server.rule.db.RuleDao; -import org.sonar.server.user.MockUserSession; import org.sonar.server.user.db.UserDao; import org.sonar.server.ws.WsTester; @@ -107,21 +105,41 @@ public class QProfileChangelogActionTest { dbSession.close(); } + @Test + public void changelog_empty() throws Exception { + wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY) + .execute().assertJson(getClass(), "changelog_empty.json"); + } + @Test public void changelog_nominal() throws Exception { - MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN).setLogin(login); createActivity(login, ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MAJOR, "max", "10"); wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY) .execute().assertJson(getClass(), "changelog_nominal.json"); } + @Test + public void changelog_no_param() throws Exception { + createActivity(login, ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MAJOR); + + wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY) + .execute().assertJson(getClass(), "changelog_no_param.json"); + } + + @Test + public void changelog_system_user() throws Exception { + createActivity(null, ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MAJOR); + + wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY) + .execute().assertJson(getClass(), "changelog_no_login.json"); + } + @Test public void changelog_with_dates() throws Exception { Date yesterday = DateTime.now().minusDays(1).toDate(); Date tomorrow = DateTime.now().plusDays(1).toDate(); - MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN).setLogin("david"); createActivity(login, ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MAJOR, "max", "10"); // Tests with "since" @@ -139,11 +157,16 @@ public class QProfileChangelogActionTest { wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY).setParam("to", DateUtils.formatDateTime(tomorrow)) .execute().assertJson(getClass(), "changelog_nominal.json"); + + // Test with both bounds set + wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam("profileKey", XOO_P1_KEY) + .setParam("since", DateUtils.formatDateTime(yesterday)) + .setParam("to", DateUtils.formatDateTime(tomorrow)) + .execute().assertJson(getClass(), "changelog_nominal.json"); } @Test public void changelog_with_pagination() throws Exception { - MockUserSession.set().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN).setLogin("david"); createActivity(login, ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.MAJOR, "max", "10"); createActivity(login, ActiveRuleChange.Type.ACTIVATED, ActiveRuleKey.of(XOO_P1_KEY, RuleTesting.XOO_X1), Severity.CRITICAL, "max", "20"); diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_login.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_login.json new file mode 100644 index 00000000000..eb0fe995d92 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_login.json @@ -0,0 +1,15 @@ +{ + "total": 1, + "p": 1, + "ps": 50, + "events": [ + { + "action" : "ACTIVATED", + "ruleKey" : "xoo:x1", + "ruleName" : "Rule x1", + "params" : { + "severity" : "MAJOR" + } + } + ] +} \ No newline at end of file diff --git a/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_param.json b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_param.json new file mode 100644 index 00000000000..9ad8c7cd405 --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/qualityprofile/ws/QProfileChangelogActionTest/changelog_no_param.json @@ -0,0 +1,17 @@ +{ + "total": 1, + "p": 1, + "ps": 50, + "events": [ + { + "action" : "ACTIVATED", + "authorLogin" : "david", + "authorName" : "David", + "ruleKey" : "xoo:x1", + "ruleName" : "Rule x1", + "params" : { + "severity" : "MAJOR" + } + } + ] +} \ No newline at end of file -- 2.39.5