.setBooleanPossibleValues()
.setRequired(false);
- // FIXME add response example and test it
- // action.setResponseExample()
+ action.setResponseExample(getClass().getResource("search-example.json"));
}
@Override
.types(singleton(RuleType.SECURITY_HOTSPOT.name()))
.sort(IssueQuery.SORT_HOTSPOTS)
.asc(true)
- .statuses(wsRequest.getStatus().map(Collections::singletonList).orElse(STATUSES));;
+ .statuses(wsRequest.getStatus().map(Collections::singletonList).orElse(STATUSES));
project.ifPresent(p -> {
builder.organizationUuid(p.getOrganizationUuid());
--- /dev/null
+{
+ "paging": {
+ "pageIndex": 1,
+ "pageSize": 100,
+ "total": 3
+ },
+ "hotspots": [
+ {
+ "key": "hotspot-0",
+ "component": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java",
+ "project": "com.sonarsource:test-project",
+ "securityCategory": "others",
+ "vulnerabilityProbability": "LOW",
+ "status": "TO_REVIEW",
+ "line": 10,
+ "message": "message-0",
+ "assignee": "assignee-uuid",
+ "author": "joe",
+ "creationDate": "2020-01-02T15:43:10+0100",
+ "updateDate": "2020-01-02T15:43:10+0100"
+ },
+ {
+ "key": "hotspot-1",
+ "component": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java",
+ "project": "com.sonarsource:test-project",
+ "securityCategory": "others",
+ "vulnerabilityProbability": "LOW",
+ "status": "TO_REVIEW",
+ "line": 11,
+ "message": "message-1",
+ "assignee": "assignee-uuid",
+ "author": "joe",
+ "creationDate": "2020-01-02T15:43:10+0100",
+ "updateDate": "2020-01-02T15:43:10+0100"
+ },
+ {
+ "key": "hotspot-2",
+ "component": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java",
+ "project": "com.sonarsource:test-project",
+ "securityCategory": "others",
+ "vulnerabilityProbability": "LOW",
+ "status": "TO_REVIEW",
+ "line": 12,
+ "message": "message-2",
+ "assignee": "assignee-uuid",
+ "author": "joe",
+ "creationDate": "2020-01-02T15:43:10+0100",
+ "updateDate": "2020-01-02T15:43:10+0100"
+ }
+ ],
+ "components": [
+ {
+ "organization": "default-organization",
+ "key": "com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java",
+ "qualifier": "FIL",
+ "name": "FourthClass.java",
+ "longName": "src/main/java/com/sonarsource/FourthClass.java",
+ "path": "src/main/java/com/sonarsource/FourthClass.java"
+ },
+ {
+ "organization": "default-organization",
+ "key": "com.sonarsource:test-project",
+ "qualifier": "TRK",
+ "name": "test-project",
+ "longName": "test-project"
+ }
+ ]
+}
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Ordering;
+import com.google.common.collect.Sets;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleTesting;
import org.sonar.server.es.EsTester;
.toArray(String[]::new));
}
+ @Test
+ public void verify_response_example() {
+ ComponentDto project = dbTester.components().insertPublicProject(componentDto -> componentDto
+ .setName("test-project")
+ .setLongName("test-project")
+ .setDbKey("com.sonarsource:test-project")
+ );
+ userSessionRule.registerComponents(project);
+ indexPermissions();
+ ComponentDto fileWithHotspot = dbTester.components().insertComponent(newFileDto(project)
+ .setDbKey("com.sonarsource:test-project:src/main/java/com/sonarsource/FourthClass.java")
+ .setName("FourthClass.java")
+ .setLongName("src/main/java/com/sonarsource/FourthClass.java")
+ .setPath("src/main/java/com/sonarsource/FourthClass.java")
+ );
+
+ long time = 1577976190000L;
+
+ IssueDto[] hotspots = IntStream.range(0, 3)
+ .mapToObj(i -> {
+ RuleDefinitionDto rule = newRule(SECURITY_HOTSPOT)
+ .setSecurityStandards(Sets.newHashSet(SQCategory.WEAK_CRYPTOGRAPHY.getKey()));
+ return insertHotspot(rule, project, fileWithHotspot, issueDto -> issueDto.setKee("hotspot-" + i)
+ .setAssigneeUuid("assignee-uuid")
+ .setAuthorLogin("joe")
+ .setMessage("message-" +i)
+ .setLine(10 + i)
+ .setIssueCreationTime(time)
+ .setIssueUpdateTime(time)
+ );
+ })
+ .toArray(IssueDto[]::new);
+ indexIssues();
+
+ newRequest(project)
+ .execute()
+ .assertJson(actionTester.getDef().responseExampleAsString()
+ .replaceAll("default-organization", dbTester.getDefaultOrganization().getKey()));
+ }
+
private IssueDto insertHotspot(ComponentDto project, ComponentDto file, RuleDefinitionDto rule) {
return insertHotspot(rule, project, file, t -> {
});