Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-catalano committed Feb 15, 2024
1 parent 65d4cf1 commit 14a3ce1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ResponseValidator {
*/
// TODO: set your package
@AfterReturning(
pointcut = "execution(* it.gov.pagopa.microservice.controller.*.*(..))",
pointcut = "execution(* it.gov.pagopa.standinmanager.controller.*.*(..))",
returning = "result")
public void validateResponse(JoinPoint joinPoint, Object result) {
if (result instanceof ResponseEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import it.gov.pagopa.standinmanager.service.DataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Slf4j
public class DataController {
Expand All @@ -32,7 +36,8 @@ public class DataController {
@ApiResponse(responseCode = "400", description = "Invalid request", content = @Content)
})
@GetMapping("/stations")
public GetResponse getEvents() {
return GetResponse.builder().stations(dataService.getStations()).build();
@Valid
public ResponseEntity<GetResponse> getEvents() {
return ResponseEntity.status(HttpStatus.OK).body(GetResponse.builder().stations(dataService.getStations()).build());
}
}
5 changes: 5 additions & 0 deletions src/test/java/it/gov/pagopa/standinmanager/ApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ void swagger() throws Exception {
.andExpect(MockMvcResultMatchers.status().is3xxRedirection());
}
@Test
void notfound() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/notfound").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is4xxClientError());
}
@Test
void info() throws Exception {
when(cosmosStationRepository.getStations()).thenReturn(Arrays.asList(new CosmosStandInStation("","station1", Instant.now()),new CosmosStandInStation("","station2", Instant.now())));
mvc.perform(MockMvcRequestBuilders.get("/info").accept(MediaType.APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void setUp() throws KustoServiceQueryError, DataServiceException, DataClientExce

when(cosmosClient.getDatabase(any())).thenReturn(cosmosDatabase);
when(cosmosDatabase.getContainer(any())).thenReturn(cosmosContainer);
when(testBatch.tryAdd(any())).thenReturn(true);
when(testBatch.tryAdd(any())).thenReturn(false,true);
when(testBatch.getCount()).thenReturn(2);
when(producer.createBatch()).thenReturn(testBatch);
when(sesClient.sendEmail(any(SendEmailRequest.class))).thenReturn(testResponse);
Expand All @@ -116,7 +116,7 @@ void setUp() throws KustoServiceQueryError, DataServiceException, DataClientExce
@Test
void test1() throws Exception {
nodoCalcService.runCalculations();
verify(producer, times(2)).send(any(EventDataBatch.class));
verify(producer, times(3)).send(any(EventDataBatch.class));
verify(databaseStationsRepository, times(2)).save(any());
verify(cosmosStationRepository, times(2)).save(any());
verify(cosmosEventsRepository, times(2)).newEvent(any(),any(),any());
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ management.health.readinessState.enabled=true
springdoc.writer-with-order-by-keys=true
springdoc.writer-with-default-pretty-printer=true
# Server
server.servlet.context-path=/
server.servlet.context-path=
server.port=8080
# Logging
logging.level.root=INFO
Expand Down

0 comments on commit 14a3ce1

Please sign in to comment.