Skip to content

Commit

Permalink
[testsuite] Aligned building blocks to new validations
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Tundo <alessandrotundo94@gmail.com>
  • Loading branch information
aletundo committed Jul 15, 2018
1 parent a56584d commit f9d2dcd
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,40 @@ public void path3() throws IOException, InterruptedException {
}


// @Test
// public void dummy() throws Exception {
//
// //analysisConfigurationService.createValidConfiguration();
// //analysisConfigurationService.createInvalidConfiguration();
@Test
public void dummy() throws Exception {
ResponseEntity<String> response = projectService.createValidProject();
JsonNode body = objectMapper.readTree(response.getBody());
String projectId = body.get("id").textValue();
response = projectService.createValidProjectVersion(projectId);
body = objectMapper.readTree(response.getBody());
String versionId = body.at("/versions").get(0).get("id").textValue();
response = analysisConfigurationService.createValidConfiguration(projectId, versionId);
body = objectMapper.readTree(response.getBody());
String configurationId = body.get("id").textValue();
analysisConfigurationService.createInvalidConfiguration();
projectService.uploadValidArtefactsZip(projectId, versionId);
response = analysisService.createStartNowAnalysisWithValidConfig(configurationId);
body = objectMapper.readTree(response.getBody());
String analysisId = body.get("id").textValue();

final Set<String> statusesToCheck = newLinkedHashSet(AnalysisStatus.CREATED.name(), AnalysisStatus.SCHEDULED.name(),
AnalysisStatus.RUNNING.name(), AnalysisStatus.COMPLETED.name());

analysisService.verifyAnalysesMessages(1, statusesToCheck);

await().atMost(10, SECONDS).untilAsserted(() -> {
notificationService.verifyAnalysisCreatedStatusNotification(analysisId);
notificationService.verifyAnalysisScheduledStatusNotification(analysisId);
notificationService.verifyAnalysisRunningStatusNotification(analysisId);
notificationService.verifyAnalysisCompletedStatusNotification(analysisId);
});

await().atMost(10, SECONDS).untilAsserted(() -> analysisService.verifyAnalysisResultsCreated(analysisId));
await().atMost(10, SECONDS).untilAsserted(() -> reportService.verifyReportGenerated(analysisId));
reportService.verifyReportGeneratedMessage(ReportStatus.GENERATED);
await().atMost(10, SECONDS).untilAsserted(() -> notificationService.verifyReportGeneratedNotification(analysisId));

// ResponseEntity<String> response = projectService.createValidProject();
// JsonNode body = objectMapper.readTree(response.getBody());
// String projectId = body.get("id").textValue();
Expand Down Expand Up @@ -113,8 +142,8 @@ public void path3() throws IOException, InterruptedException {
// await().atMost(10, SECONDS).untilAsserted(() -> reportService.verifyReportGenerated(analysisId));
// reportService.verifyReportGeneratedMessage(ReportStatus.GENERATED);
// await().atMost(10, SECONDS).untilAsserted(() -> notificationService.verifyReportGeneratedNotification(analysisId));
//
// //projectService.uploadValidEmptyArtefactsZip(projectId, versionId);
// //projectService.uploadInvalidArtefactsZip(projectId, versionId);
// }

//projectService.uploadValidEmptyArtefactsZip(projectId, versionId);
//projectService.uploadInvalidArtefactsZip(projectId, versionId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AnalysisConfigurationService {
@Autowired
private ObjectMapper objectMapper;

public void createValidConfiguration(String projectId, String versionId) throws RestClientException, IOException, InterruptedException {
public ResponseEntity<String> createValidConfiguration(String projectId, String versionId) throws RestClientException, IOException, InterruptedException {
ObjectNode jsonObject = objectMapper.getNodeFactory().objectNode()
.put("projectId", projectId)
.put("versionId", versionId);
Expand All @@ -55,6 +55,8 @@ public void createValidConfiguration(String projectId, String versionId) throws
analysisConfigurationConsumer.getLatch().await(1, TimeUnit.MINUTES);
assertThat(analysisConfigurationConsumer.getLatch().getCount()).isEqualTo(0);
assertThat(analysisConfigurationConsumer.getMessages().get(0).getProjectId()).isEqualTo(projectId);

return response;
}

public void createInvalidConfiguration() throws RestClientException, IOException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,8 @@ public AnalysisService() {
this.dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
}

public ResponseEntity<String> createStartNowAnalysisWithValidConfig(String projectId, String versionId,
Map<String, String> arcanParameters) throws IOException, InterruptedException {
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("projectId", projectId)
.put("versionId", versionId);

ObjectNode parametersObject = objectMapper.getNodeFactory().objectNode();

for (String key : arcanParameters.keySet()) {
parametersObject.put(key, arcanParameters.get(key));
}
configurationObject.set("arcanParameters", parametersObject);
public ResponseEntity<String> createStartNowAnalysisWithValidConfig(String configurationId) throws IOException, InterruptedException {
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("id", configurationId);

ObjectNode jsonObject = objectMapper.getNodeFactory().objectNode();

Expand All @@ -74,23 +65,16 @@ public ResponseEntity<String> createStartNowAnalysisWithValidConfig(String proje

assertThat(status).isEqualTo(HttpStatus.CREATED);
assertThat(headers.getLocation()).isNotNull();
assertThat(body.at("/id").isMissingNode()).isEqualTo(false);
assertThat(body.at("/_links/self").isMissingNode()).isEqualTo(false);
assertThat(body.at("/_links/self").isNull()).isEqualTo(false);

return response;
}

public void createStartNowAnalysisWithInvalidConfig(String projectId, String versionId,
Map<String, String> arcanParameters) throws JsonProcessingException {
public void createStartNowAnalysisWithInvalidConfig() throws JsonProcessingException {

ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("projectId", projectId);

ObjectNode parametersObject = objectMapper.getNodeFactory().objectNode();

for (String key : arcanParameters.keySet()) {
parametersObject.put(key, arcanParameters.get(key));
}
configurationObject.set("arcanParameters", parametersObject);
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("configurationId", "");

ObjectNode jsonObject = objectMapper.getNodeFactory().objectNode();

Expand All @@ -104,18 +88,9 @@ public void createStartNowAnalysisWithInvalidConfig(String projectId, String ver
assertThat(status).isEqualTo(HttpStatus.BAD_REQUEST);
}

public ResponseEntity<String> createScheduledAnalysisWithValidConfigAndValidStartTime(String projectId,
String versionId, Map<String, String> arcanParameters) throws IOException, InterruptedException {

ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("projectId", projectId)
.put("versionId", versionId);
public ResponseEntity<String> createScheduledAnalysisWithValidConfigAndValidStartTime(String configurationId) throws IOException, InterruptedException {

ObjectNode parametersObject = objectMapper.getNodeFactory().objectNode();

for (String key : arcanParameters.keySet()) {
parametersObject.put(key, arcanParameters.get(key));
}
configurationObject.set("arcanParameters", parametersObject);
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("id", configurationId);

ObjectNode jsonObject = objectMapper.getNodeFactory().objectNode();

Expand All @@ -136,16 +111,8 @@ public ResponseEntity<String> createScheduledAnalysisWithValidConfigAndValidStar
return response;
}

public void createScheduledAnalysisWithInvalidConfigAndValidStartTime(String projectId, String versionId,
Map<String, String> arcanParameters) throws JsonProcessingException {
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("projectId", projectId);

ObjectNode parametersObject = objectMapper.getNodeFactory().objectNode();

for (String key : arcanParameters.keySet()) {
parametersObject.put(key, arcanParameters.get(key));
}
configurationObject.set("arcanParameters", parametersObject);
public void createScheduledAnalysisWithInvalidConfigAndValidStartTime() throws JsonProcessingException {
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("configurationId", "");

ObjectNode jsonObject = objectMapper.getNodeFactory().objectNode();

Expand All @@ -160,17 +127,9 @@ public void createScheduledAnalysisWithInvalidConfigAndValidStartTime(String pro
assertThat(status).isEqualTo(HttpStatus.BAD_REQUEST);
}

public void createScheduledAnalysisWithValidConfigAndInvalidStartTime(String projectId, String versionId,
Map<String, String> arcanParameters) throws JsonProcessingException {
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("projectId", projectId)
.put("versionId", versionId);

ObjectNode parametersObject = objectMapper.getNodeFactory().objectNode();
public void createScheduledAnalysisWithValidConfigAndInvalidStartTime(String configurationId) throws JsonProcessingException {

for (String key : arcanParameters.keySet()) {
parametersObject.put(key, arcanParameters.get(key));
}
configurationObject.set("arcanParameters", parametersObject);
ObjectNode configurationObject = objectMapper.getNodeFactory().objectNode().put("id", configurationId);

ObjectNode jsonObject = objectMapper.getNodeFactory().objectNode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void verifyReportGeneratedNotification(String analysisId) throws IOExcept
JsonNode body = objectMapper.readTree(response.getBody());
HttpStatus status = response.getStatusCode();
assertThat(status).isEqualTo(HttpStatus.OK);
assertThat(body.at("/_embedded/report-notifications").isArray()).isEqualTo(true);
assertThat(body.at("/_embedded/report-notifications/0/reportStatus").textValue()).isEqualTo("GENERATED");
assertThat(body.at("/_embedded/report-notifications/0/analysisId").textValue()).isEqualTo(analysisId);
}
Expand All @@ -112,6 +113,7 @@ public void verifyReportFailedNotification(String analysisId) throws IOException
JsonNode body = objectMapper.readTree(response.getBody());
HttpStatus status = response.getStatusCode();
assertThat(status).isEqualTo(HttpStatus.OK);
assertThat(body.at("/_embedded/report-notifications").isArray()).isEqualTo(true);
assertThat(body.at("/_embedded/report-notifications/0/reportStatus").textValue()).isEqualTo("FAILED");
assertThat(body.at("/_embedded/report-notifications/0/analysisId").textValue()).isEqualTo(analysisId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public ResponseEntity<String> createValidProjectVersion(String projectId) throws
assertThat(status).isEqualTo(HttpStatus.OK);
assertThat(body.at("/versions").isArray()).isEqualTo(true);
assertThat(body.at("/versions").size()).isEqualTo(1);
assertThat(body.at("/versions").get(0).at("/name").asText()).isEqualTo("TestVersion");
assertThat(body.at("/versions/0/name").asText()).isEqualTo("TestVersion");
assertThat(body.at("/versions/0/description").asText()).isEqualTo("A beautiful version description");

return response;
}
Expand Down Expand Up @@ -108,7 +109,8 @@ public ResponseEntity<String> uploadValidArtefactsZip(String projectId, String v
JsonNode body = objectMapper.readTree(response.getBody());
HttpStatus status = response.getStatusCode();
assertThat(status).isEqualTo(HttpStatus.OK);
assertThat(body.at("/versions").get(0).at("/artefactsPath").isMissingNode()).isEqualTo(false);
assertThat(body.at("/versions/0/artefactsPath").isMissingNode()).isEqualTo(false);
assertThat(body.at("/versions/0/artefactsPath").textValue()).isEqualTo("/data/artefacts/" + projectId + "/" + versionId + "/validZip.zip");
return response;
}

Expand All @@ -118,7 +120,8 @@ public ResponseEntity<String> uploadValidEmptyArtefactsZip(String projectId, Str
JsonNode body = objectMapper.readTree(response.getBody());
HttpStatus status = response.getStatusCode();
assertThat(status).isEqualTo(HttpStatus.OK);
assertThat(body.at("/versions").get(0).at("/artefactsPath").isMissingNode()).isEqualTo(false);
assertThat(body.at("/versions/0/artefactsPath").isMissingNode()).isEqualTo(false);
assertThat(body.at("/versions/0/artefactsPath").textValue()).isEqualTo("/data/artefacts/" + projectId + "/" + versionId + "/emptyZip.zip");
return response;
}

Expand Down

0 comments on commit f9d2dcd

Please sign in to comment.