import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.sonar.api.issue.Issue;
import org.sonar.api.rule.RuleStatus;
import org.sonar.api.security.DefaultGroups;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.server.issue.ws.IssuesWs.API_ENDPOINT;
+import static org.sonar.server.issue.ws.SearchAction.SEARCH_ACTION;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.ADDITIONAL_FIELDS;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.COMPONENTS;
+import static org.sonarqube.ws.client.issue.IssueFilterParameters.CREATED_AFTER;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.DEPRECATED_FACET_MODE_DEBT;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.FACET_MODE_EFFORT;
import static org.sonarqube.ws.client.issue.IssueFilterParameters.HIDE_COMMENTS;
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester);
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
DbClient db;
DbSession session;
@Test
public void empty_search() throws Exception {
- WsTester.TestRequest request = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION);
+ WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION);
WsTester.Result result = request.execute();
assertThat(result).isNotNull();
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION).execute();
result.assertJson(this.getClass(), "response_contains_all_fields_except_additional_fields.json");
}
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("additionalFields", "comments,users")
.execute();
result.assertJson(this.getClass(), "issue_with_comments.json");
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).setParam(HIDE_COMMENTS, "true").execute();
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION).setParam(HIDE_COMMENTS, "true").execute();
result.assertJson(this.getClass(), "issue_with_comment_hidden.json");
assertThat(result.outputAsString()).doesNotContain("fabrice");
}
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("additionalFields", "_all").execute();
result.assertJson(this.getClass(), "load_additional_fields.json");
}
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.execute();
result.assertJson(this.getClass(), "issue_on_removed_file.json");
}
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).execute();
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION).execute();
assertThat(result.outputAsString()).contains("\"componentId\":" + file.getId() + ",");
}
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).setParam(COMPONENTS, file.getKey()).execute();
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION).setParam(COMPONENTS, file.getKey()).execute();
result.assertJson(this.getClass(), "apply_paging_with_one_component.json");
}
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION).setParam(ADDITIONAL_FIELDS, "_all").execute();
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION).setParam(ADDITIONAL_FIELDS, "_all").execute();
result.assertJson(this.getClass(), "components_contains_sub_projects.json");
}
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("resolved", "false")
.setParam(WebService.Param.FACETS, "statuses,severities,resolutions,projectUuids,rules,fileUuids,assignees,languages,actionPlans,types")
.execute();
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("resolved", "false")
.setParam(WebService.Param.FACETS, "statuses,severities,resolutions,projectUuids,rules,fileUuids,assignees,languages,actionPlans")
.setParam("facetMode", FACET_MODE_EFFORT)
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("resolved", "false")
.setParam("severities", "MAJOR,MINOR")
.setParam("languages", "xoo,polop,palap")
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("resolved", "false")
.setParam("assignees", "__me__")
.setParam(WebService.Param.FACETS, "assignees,assigned_to_me")
session.commit();
tester.get(IssueIndexer.class).indexAll();
- wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("resolved", "false")
.setParam("assignees", "__me__")
.execute()
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john-bob.polop");
- wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("resolved", "false")
.setParam("assignees", "alice")
.setParam(WebService.Param.FACETS, "assignees,assigned_to_me")
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("sort", IssueQuery.SORT_BY_UPDATE_DATE)
.setParam("asc", "false")
.execute();
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.TestRequest request = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION);
+ WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION);
request.setParam(WebService.Param.PAGE, "2");
request.setParam(WebService.Param.PAGE_SIZE, "9");
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.TestRequest request = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION);
+ WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION);
request.setParam(WebService.Param.PAGE, "1");
request.setParam(WebService.Param.PAGE_SIZE, "-1");
session.commit();
tester.get(IssueIndexer.class).indexAll();
- WsTester.TestRequest request = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION);
+ WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION);
request.setParam(PAGE_INDEX, "2");
request.setParam(PAGE_SIZE, "9");
@Test
public void default_page_size_is_100() throws Exception {
- WsTester.TestRequest request = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION);
+ WsTester.TestRequest request = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION);
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "default_page_size_is_100.json");
tester.get(IssueIndexer.class).indexAll();
userSessionRule.login("john");
- WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ WsTester.Result result = wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
.setParam("resolved", "false")
.setParam(WebService.Param.FACETS, "severities")
.setParam("facetMode", DEPRECATED_FACET_MODE_DEBT)
result.assertJson(this.getClass(), "display_deprecated_debt_fields.json");
}
+ @Test
+ public void fail_when_invalid_format() throws Exception {
+ expectedException.expect(IllegalArgumentException.class);
+ expectedException.expectMessage("Date 'wrong-date-input' cannot be parsed as either a date or date+time");
+
+ wsTester.newGetRequest(API_ENDPOINT, SEARCH_ACTION)
+ .setParam(CREATED_AFTER, "wrong-date-input")
+ .execute();
+ }
+
private RuleDto newRule() {
RuleDto rule = RuleTesting.newXooX1()
.setName("Rule name")