import static org.sonar.api.utils.DateUtils.parseEndingDateOrDateTime;
import static org.sonar.api.utils.DateUtils.parseStartingDateOrDateTime;
import static org.sonar.server.es.SearchOptions.MAX_LIMIT;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SINCE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO;
public class ChangelogAction implements QProfileWsAction {
- static final String PARAM_SINCE = "since";
- static final String PARAM_TO = "to";
-
private final ChangelogLoader changelogLoader;
private final QProfileWsSupport wsSupport;
private final Languages languages;
.setDescription("Get the history of changes on a quality profile: rule activation/deactivation, change in parameters/severity. " +
"Events are ordered by date in descending order (most recent first).")
.setHandler(this)
- .setResponseExample(getClass().getResource("example-changelog.json"));
+ .setResponseExample(getClass().getResource("changelog-example.json"));
QProfileWsSupport.createOrganizationParam(wsAction)
.setSince("6.4");
}
}
- private void writeResponse(JsonWriter json, int page, int pageSize, ChangelogLoader.Changelog changelog) {
+ private static void writeResponse(JsonWriter json, int page, int pageSize, ChangelogLoader.Changelog changelog) {
json.beginObject();
json.prop("total", changelog.getTotal());
json.prop(Param.PAGE, page);
--- /dev/null
+{
+ "total": 3,
+ "ps": 10,
+ "p": 1,
+ "events": [
+ {
+ "date" : "2015-02-23T17:58:39+0100",
+ "action" : "ACTIVATED",
+ "authorLogin" : "anakin.skywalker",
+ "authorName" : "Anakin Skywalker",
+ "ruleKey" : "squid:S2438",
+ "ruleName" : "\"Threads\" should not be used where \"Runnables\" are expected",
+ "params" : {
+ "severity" : "CRITICAL"
+ }
+ },
+ {
+ "date" : "2015-02-23T17:58:18+0100",
+ "action" : "DEACTIVATED",
+ "authorLogin" : "padme.amidala",
+ "authorName" : "Padme Amidala",
+ "ruleKey" : "squid:S2162",
+ "ruleName" : "\"equals\" methods should be symmetric and work for subclasses"
+ },
+ {
+ "action" : "ACTIVATED",
+ "authorLogin" : "obiwan.kenobi",
+ "authorName" : "Obiwan Kenobi",
+ "ruleKey" : "squid:S00101",
+ "ruleName" : "Class names should comply with a naming convention",
+ "date" : "2014-09-12T15:20:46+0200",
+ "params" : {
+ "severity" : "MAJOR",
+ "format" : "^[A-Z][a-zA-Z0-9]*$"
+ }
+ }
+ ]
+}
+++ /dev/null
-{
- "total": 3,
- "ps": 10,
- "p": 1,
- "events": [
- {
- "date" : "2015-02-23T17:58:39+0100",
- "action" : "ACTIVATED",
- "authorLogin" : "anakin.skywalker",
- "authorName" : "Anakin Skywalker",
- "ruleKey" : "squid:S2438",
- "ruleName" : "\"Threads\" should not be used where \"Runnables\" are expected",
- "params" : {
- "severity" : "CRITICAL"
- }
- },
- {
- "date" : "2015-02-23T17:58:18+0100",
- "action" : "DEACTIVATED",
- "authorLogin" : "padme.amidala",
- "authorName" : "Padme Amidala",
- "ruleKey" : "squid:S2162",
- "ruleName" : "\"equals\" methods should be symmetric and work for subclasses"
- },
- {
- "action" : "ACTIVATED",
- "authorLogin" : "obiwan.kenobi",
- "authorName" : "Obiwan Kenobi",
- "ruleKey" : "squid:S00101",
- "ruleName" : "Class names should comply with a naming convention",
- "date" : "2014-09-12T15:20:46+0200",
- "params" : {
- "severity" : "MAJOR",
- "format" : "^[A-Z][a-zA-Z0-9]*$"
- }
- }
- ]
-}
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.resources.Languages;
+import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_LANGUAGE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_ORGANIZATION;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_NAME;
public class ChangelogActionDatabaseTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private WsActionTester wsTester;
+ private WsActionTester ws;
private ChangelogLoader changelogLoader;
private QProfileWsSupport wsSupport;
private OrganizationDto organization;
defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
wsSupport = new QProfileWsSupport(dbTester.getDbClient(), userSession, defaultOrganizationProvider);
changelogLoader = new ChangelogLoader(dbTester.getDbClient());
- wsTester = new WsActionTester(
+ ws = new WsActionTester(
new ChangelogAction(changelogLoader, wsSupport, new Languages(), dbTester.getDbClient()));
organization = dbTester.organizations().insert();
}
+ @Test
+ public void definition() {
+ WebService.Action definition = ws.getDef();
+
+ assertThat(definition.responseExampleAsString()).isNotEmpty();
+ assertThat(definition.params()).extracting(WebService.Param::key)
+ .containsExactlyInAnyOrder("profile", "profileName", "language", "organization", "since", "to", "p", "ps");
+ WebService.Param profile = definition.param("profile");
+ assertThat(profile.deprecatedKey()).isEqualTo("profileKey");
+ WebService.Param profileName = definition.param("profileName");
+ assertThat(profileName.deprecatedSince()).isEqualTo("6.5");
+ WebService.Param language = definition.param("language");
+ assertThat(language.deprecatedSince()).isEqualTo("6.5");
+ }
+
@Test
public void find_changelog_by_profile_key() throws Exception {
QProfileDto profile = dbTester.qualityProfiles().insert(organization);
- String response = wsTester.newRequest()
+ String response = ws.newRequest()
.setMethod("GET")
- .setParam("profileKey", profile.getKee())
+ .setParam(PARAM_PROFILE, profile.getKee())
.execute()
.getInput();
public void find_changelog_by_language_and_name() throws Exception {
QProfileDto qualityProfile = dbTester.qualityProfiles().insert(dbTester.getDefaultOrganization());
- String response = wsTester.newRequest()
+ String response = ws.newRequest()
.setMethod("GET")
- .setParam("language", qualityProfile.getLanguage())
- .setParam("profileName", qualityProfile.getName())
+ .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
+ .setParam(PARAM_PROFILE_NAME, qualityProfile.getName())
.execute()
.getInput();
public void find_changelog_by_organization_and_language_and_name() throws Exception {
QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
- String response = wsTester.newRequest()
+ String response = ws.newRequest()
.setMethod("GET")
- .setParam("language", qualityProfile.getLanguage())
- .setParam("profileName", qualityProfile.getName())
- .setParam("organization", organization.getKey())
+ .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
+ .setParam(PARAM_PROFILE_NAME, qualityProfile.getName())
+ .setParam(PARAM_ORGANIZATION, organization.getKey())
.execute()
.getInput();
QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization1);
- TestRequest request = wsTester.newRequest()
+ TestRequest request = ws.newRequest()
.setMethod("GET")
- .setParam("language", qualityProfile.getLanguage())
- .setParam("profileName", qualityProfile.getName())
- .setParam("organization", organization2.getKey());
+ .setParam(PARAM_LANGUAGE, qualityProfile.getLanguage())
+ .setParam(PARAM_PROFILE_NAME, qualityProfile.getName())
+ .setParam(PARAM_ORGANIZATION, organization2.getKey());
thrown.expect(NotFoundException.class);
public void changelog_empty() throws Exception {
QProfileDto qualityProfile = dbTester.qualityProfiles().insert(organization);
- String response = wsTester.newRequest()
+ String response = ws.newRequest()
.setMethod("GET")
- .setParam("profileKey", qualityProfile.getKee())
+ .setParam(PARAM_PROFILE, qualityProfile.getKee())
.execute()
.getInput();
dbTester.getDbClient().qProfileChangeDao().insert(session, change);
session.commit();
- String response = wsTester.newRequest()
+ String response = ws.newRequest()
.setMethod("GET")
- .setParam("profileKey", qualityProfile.getKee())
+ .setParam(PARAM_PROFILE, qualityProfile.getKee())
.execute()
.getInput();
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.api.resources.Languages;
-import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.organization.OrganizationDto;
import static org.mockito.Mockito.when;
import static org.sonar.api.utils.DateUtils.parseDate;
import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P1_KEY;
-import static org.sonar.server.qualityprofile.ws.ChangelogAction.PARAM_SINCE;
-import static org.sonar.server.qualityprofile.ws.ChangelogAction.PARAM_TO;
-import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE_KEY;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_PROFILE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_SINCE;
+import static org.sonarqube.ws.client.qualityprofile.QualityProfileWsParameters.PARAM_TO;
public class ChangelogActionMockTest {
private static final long A_DATE = 1_500_000_000_000L;
@Rule
- public DbTester dbTester = DbTester.create(System2.INSTANCE);
+ public DbTester db = DbTester.create();
- private WsTester wsTester;
+ private WsTester ws;
private ChangelogLoader changelogLoader = mock(ChangelogLoader.class);
private QProfileWsSupport wsSupport = mock(QProfileWsSupport.class);
private OrganizationDto organization;
@Before
public void before() {
- wsTester = new WsTester(new QProfilesWs(mock(ActivateRulesAction.class),
- new ChangelogAction(changelogLoader, wsSupport, new Languages(), dbTester.getDbClient())));
- organization = dbTester.organizations().insert();
+ ws = new WsTester(new QProfilesWs(mock(ActivateRulesAction.class),
+ new ChangelogAction(changelogLoader, wsSupport, new Languages(), db.getDbClient())));
+ organization = db.organizations().insert();
}
@Test
when(wsSupport.getProfile(any(DbSession.class), eq(QProfileReference.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1(organization));
when(changelogLoader.load(any(DbSession.class), any(QProfileChangeQuery.class))).thenReturn(new ChangelogLoader.Changelog(0, Collections.emptyList()));
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE_KEY, XOO_P1_KEY)
+ ws.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE, XOO_P1_KEY)
.execute().assertJson(getClass(), "changelog_empty.json");
}
List<ChangelogLoader.Change> changes = asList(change1, change2);
when(changelogLoader.load(any(DbSession.class), any(QProfileChangeQuery.class))).thenReturn(new ChangelogLoader.Changelog(10, changes));
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE_KEY, XOO_P1_KEY)
+ ws.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE, XOO_P1_KEY)
.execute().assertJson(getClass(), "changelog_nominal.json");
}
List<ChangelogLoader.Change> changes = asList(change1);
when(changelogLoader.load(any(DbSession.class), any(QProfileChangeQuery.class))).thenReturn(new ChangelogLoader.Changelog(10, changes));
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE_KEY, XOO_P1_KEY)
+ ws.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE, XOO_P1_KEY)
.execute().assertJson(getClass(), "changelog_full.json");
}
when(wsSupport.getProfile(any(DbSession.class), eq(QProfileReference.fromKey(XOO_P1_KEY)))).thenReturn(QProfileTesting.newXooP1(organization));
when(changelogLoader.load(any(DbSession.class), any(QProfileChangeQuery.class))).thenReturn(new ChangelogLoader.Changelog(0, Collections.emptyList()));
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog")
- .setParam(PARAM_PROFILE_KEY, XOO_P1_KEY)
+ ws.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog")
+ .setParam(PARAM_PROFILE, XOO_P1_KEY)
.setParam(PARAM_SINCE, "2016-09-01")
.setParam(PARAM_TO, "2016-09-01")
.execute();
public void fail_on_unknown_profile() throws Exception {
when(wsSupport.getProfile(any(DbSession.class), eq(QProfileReference.fromKey(XOO_P1_KEY)))).thenThrow(new NotFoundException("Profile not found"));
- wsTester.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE_KEY, XOO_P1_KEY).execute();
+ ws.newGetRequest(QProfilesWs.API_ENDPOINT, "changelog").setParam(PARAM_PROFILE, XOO_P1_KEY).execute();
}
}
public static final String PARAM_RESET = "reset";
public static final String PARAM_RULE = "rule";
public static final String PARAM_SEVERITY = "severity";
+ public static final String PARAM_SINCE = "since";
public static final String PARAM_TARGET_PROFILE = "targetProfile";
public static final String PARAM_TARGET_SEVERITY = "targetSeverity";
+ public static final String PARAM_TO = "to";
public static final String PARAM_TO_NAME = "toName";
private QualityProfileWsParameters() {