Skip to content

Commit

Permalink
[testsuite] Added awaitility to perform async tests. Improved message…
Browse files Browse the repository at this point in the history
…s building block tests

Signed-off-by: Alessandro Tundo <alessandrotundo94@gmail.com>
  • Loading branch information
aletundo committed Jul 13, 2018
1 parent 45dcc1a commit 02a8ccf
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 84 deletions.
18 changes: 15 additions & 3 deletions testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,22 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility-proxy</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<!-- <scope>test</scope> -->
<!-- <scope>test</scope> -->
</dependency>
</dependencies>

Expand All @@ -89,8 +101,8 @@
</plugin>
</plugins>
</build>
<repositories>

<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.unimib.disco.aras.testsuite.stream.consumer;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -12,26 +12,23 @@
import it.unimib.disco.aras.testsuite.stream.TestConfigurationStream;
import it.unimib.disco.aras.testsuite.stream.message.AnalysisConfigurationMessage;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Service
@Data
@Slf4j
public class AnalysisConfigurationConsumerImpl implements Consumer<AnalysisConfigurationMessage> {

private ConcurrentMap<Long, AnalysisConfigurationMessage> messages;
private List<AnalysisConfigurationMessage> messages;
private CountDownLatch latch;

@Autowired
public AnalysisConfigurationConsumerImpl() {
this.messages = new ConcurrentHashMap<>();
this.messages = new LinkedList<>();
this.latch = new CountDownLatch(1);
}

@StreamListener(TestConfigurationStream.CONFIGURATIONS_INPUT)
public void consume(@Payload AnalysisConfigurationMessage configuration) {
log.info("Consumed configuration message!");
this.latch.countDown();
this.messages.put(this.latch.getCount() + 1, configuration);
this.messages.add(configuration);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.unimib.disco.aras.testsuite.stream.consumer;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,19 +17,18 @@
@Data
public class AnalysisConsumerImpl implements Consumer<AnalysisMessage> {


private ConcurrentMap<Long, AnalysisMessage> messages;
private List<AnalysisMessage> messages;
private CountDownLatch latch;

@Autowired
public AnalysisConsumerImpl() {
this.messages = new ConcurrentHashMap<>();
this.messages = new LinkedList<>();
this.latch = new CountDownLatch(4);
}

@StreamListener(TestConfigurationStream.ANALYSES_INPUT)
public void consume(@Payload AnalysisMessage analysis) {
this.latch.countDown();
this.messages.put(this.latch.getCount() + 1, analysis);
this.messages.add(analysis);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.unimib.disco.aras.testsuite.stream.consumer;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,18 +17,18 @@
@Data
public class AnalysisResultConsumerImpl implements Consumer<AnalysisResultsMessage> {

private ConcurrentMap<Long, AnalysisResultsMessage> messages;
private List<AnalysisResultsMessage> messages;
private CountDownLatch latch;

@Autowired
public AnalysisResultConsumerImpl() {
this.messages = new ConcurrentHashMap<>();
this.messages = new LinkedList<>();
this.latch = new CountDownLatch(1);
}

@StreamListener(TestConfigurationStream.RESULTS_INPUT)
public void consume(@Payload AnalysisResultsMessage result) {
this.latch.countDown();
this.messages.put(this.latch.getCount() + 1, result);
this.messages.add(result);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package it.unimib.disco.aras.testsuite.stream.consumer;

import java.util.concurrent.ConcurrentMap;
import java.util.List;
import java.util.concurrent.CountDownLatch;

public interface Consumer<T> {
void consume(T t);
CountDownLatch getLatch();
ConcurrentMap<Long, T> getMessages();
List<T> getMessages();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.unimib.disco.aras.testsuite.stream.consumer;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,18 +16,18 @@
@Service
@Data
public class NotificationConsumerImpl implements Consumer<NotificationMessage> {
private ConcurrentMap<Long, NotificationMessage> messages;
private List<NotificationMessage> messages;
private CountDownLatch latch;

@Autowired
public NotificationConsumerImpl() {
this.messages = new ConcurrentHashMap<>();
this.messages = new LinkedList<>();
this.latch = new CountDownLatch(1);
}

@StreamListener(TestConfigurationStream.NOTIFICATIONS_INPUT)
public void consume(@Payload NotificationMessage notification) {
this.latch.countDown();
this.messages.put(this.latch.getCount() + 1, notification);
this.messages.add(notification);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.unimib.disco.aras.testsuite.stream.consumer;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -17,18 +17,18 @@
@Data
public class ReportConsumerImpl implements Consumer<ReportMessage> {

private ConcurrentMap<Long, ReportMessage> messages;
private List<ReportMessage> messages;
private CountDownLatch latch;

@Autowired
public ReportConsumerImpl() {
this.messages = new ConcurrentHashMap<>();
this.messages = new LinkedList<>();
this.latch = new CountDownLatch(1);
}

@StreamListener(TestConfigurationStream.REPORTS_INPUT)
public void consume(@Payload ReportMessage report) {
this.latch.countDown();
this.messages.put(this.latch.getCount() + 1, report);
this.messages.add(report);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -43,8 +43,8 @@ public ResponseEntity<String> createConfiguration(ObjectNode jsonObject)
try {
response = this.client.postForEntity(baseUrl + "/configurations",
httpEntity, String.class);
} catch(HttpClientErrorException e) {
response = ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(new HttpHeaders()).body("");
} catch(HttpServerErrorException | HttpClientErrorException e) {
response = ResponseEntity.status(e.getStatusCode()).headers(e.getResponseHeaders()).body(e.getResponseBodyAsString());
}

return response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package it.unimib.disco.aras.testsuite.web.rest.client;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -41,10 +43,23 @@ public ResponseEntity<String> createAnalysis(ObjectNode jsonObject) throws JsonP
try {
response = this.client.postForEntity(baseUrl + "/analyses",
httpEntity, String.class);
} catch(HttpClientErrorException e) {
response = ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(new HttpHeaders()).body("");
} catch(HttpServerErrorException | HttpClientErrorException e) {
response = ResponseEntity.status(e.getStatusCode()).headers(e.getResponseHeaders()).body(e.getResponseBodyAsString());
}

return response;
}

public ResponseEntity<String> getAnalysisResultsByAnalysisId(String analysisId)
throws IOException {
ResponseEntity<String> response;

try {
response = this.client.getForEntity(baseUrl + "/results/search/findByAnalysisId?analysisId=" + analysisId, String.class);
} catch(HttpServerErrorException | HttpClientErrorException e) {
response = ResponseEntity.status(e.getStatusCode()).headers(e.getResponseHeaders()).body(e.getResponseBodyAsString());
}

return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;

@Service
public class NotificationsServiceClient {
private final RestTemplate client;

@Autowired
private ObjectMapper objectMapper;

@Value("${application.clients.notifications-service}")
private String baseUrl;

Expand All @@ -36,8 +29,8 @@ public ResponseEntity<String> getStatusNotificationsByAnalysisId(String analysis

try {
response = this.client.getForEntity(baseUrl + "/status-notifications/search/findByAnalysisId?analysisId=" + analysisId, String.class);
} catch(HttpClientErrorException e) {
response = ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(new HttpHeaders()).body("");
} catch(HttpServerErrorException | HttpClientErrorException e) {
response = ResponseEntity.status(e.getStatusCode()).headers(e.getResponseHeaders()).body(e.getResponseBodyAsString());
}

return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -50,8 +50,8 @@ public ResponseEntity<String> createProject(ObjectNode jsonObject) throws JsonPr
try {
response = this.client.postForEntity(baseUrl + "/projects",
httpEntity, String.class);
} catch(HttpClientErrorException e) {
response = ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(new HttpHeaders()).body("");
} catch(HttpServerErrorException | HttpClientErrorException e) {
response = ResponseEntity.status(e.getStatusCode()).headers(e.getResponseHeaders()).body(e.getResponseBodyAsString());
}

return response;
Expand All @@ -66,8 +66,8 @@ public ResponseEntity<String> createVersion(String projectId, ObjectNode jsonObj
try {
response = this.client.exchange(baseUrl + "/projects/" + projectId, HttpMethod.PATCH,
httpEntity, String.class);
} catch(HttpClientErrorException e) {
response = ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(new HttpHeaders()).body("");
} catch(HttpServerErrorException | HttpClientErrorException e) {
response = ResponseEntity.status(e.getStatusCode()).headers(e.getResponseHeaders()).body(e.getResponseBodyAsString());
}

return response;
Expand All @@ -91,9 +91,8 @@ public ResponseEntity<String> uploadVersionArtefactsZip(String projectId, String
try {
response = this.client.postForEntity(baseUrl + "/projects/" + projectId + "/versions/" + versionId,
httpEntity, String.class);
} catch(HttpClientErrorException e) {
log.info(e.getMessage());
response = ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(new HttpHeaders()).body("");
} catch(HttpServerErrorException | HttpClientErrorException e) {
response = ResponseEntity.status(e.getStatusCode()).headers(e.getResponseHeaders()).body(e.getResponseBodyAsString());
}

return response;
Expand Down

0 comments on commit 02a8ccf

Please sign in to comment.