Skip to content

Commit

Permalink
[PASELC-655] feat: added JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-deri committed Jan 18, 2024
1 parent 195a4e1 commit fa95d68
Show file tree
Hide file tree
Showing 12 changed files with 1,757 additions and 1,755 deletions.
3,029 changes: 1,425 additions & 1,604 deletions openapi/openapi.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ public ResponseEntity<CreditorInstitutionDetails> getCreditorInstitutionsAssocia
@Parameter(description = "Filter by enabled station")
@RequestParam(required = false, name = "enabled")
Boolean enabled) {
return ResponseEntity.ok(brokersService.getCreditorInstitutionsAssociatedToBroker(limit, page, brokerId, enabled));
return ResponseEntity.ok(brokersService.getCreditorInstitutionsAssociatedToBroker(brokerId, enabled, PageRequest.of(page, limit)));
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.ser.OffsetDateTimeSerializer;
import io.swagger.v3.oas.annotations.media.Schema;
import it.gov.pagopa.apiconfig.selfcareintegration.util.Constants;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.OffsetDateTime;

/**
* Creditor Institutions
Expand Down Expand Up @@ -81,11 +75,4 @@ public class CreditorInstitutionDetail {
@JsonProperty("broadcast")
@Schema(description = "The flag that define if the station is made for broadcast operations", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Boolean broadcast;

@JsonProperty("activation_date")
@JsonFormat(pattern = Constants.DATE_TIME_WITHOUT_SECONDS_FORMAT)
@JsonSerialize(using = OffsetDateTimeSerializer.class)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Schema(example = "2021-01-01T12:00Z", description = "The activation date of the station", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private OffsetDateTime activationDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -63,11 +62,9 @@ public StationDetailsList getStationsDetailsFromBroker(
.build();
}

public CreditorInstitutionDetails getCreditorInstitutionsAssociatedToBroker(@NotNull Integer limit, @NotNull Integer pageNumber, @NotNull String brokerId, Boolean enabled) {
public CreditorInstitutionDetails getCreditorInstitutionsAssociatedToBroker(@NotNull String brokerId, Boolean enabled, Pageable pageable) {

Page<PaStazionePa> page = paStazionePaRepository.findAll(
PaStazionePaSpecifications.filter(brokerId, enabled),
PageRequest.of(pageNumber, limit));
Page<PaStazionePa> page = paStazionePaRepository.findAll(PaStazionePaSpecifications.filter(brokerId, enabled), pageable);

return CreditorInstitutionDetails.builder()
.creditorInstitutions(page.stream()
Expand Down
10 changes: 3 additions & 7 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# Info
info.properties.environment=local

# Logging
logging.level.root=INFO
logging.level.it.gov.pagopa=DEBUG

# CORS configuration
cors.configuration={"origins": ["*"], "methods": ["*"]}

# Database settings
#spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCLCDB
#spring.datasource.username=NODO4_CFG
#spring.datasource.password=NODO4_CFG
#spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:postgresql://pagopa-d-weu-nodo-flexible-postgresql.postgres.database.azure.com:6432/nodo?sslmode=require&prepareThreshold=0&currentSchema=cfg
spring.datasource.username=cfg
spring.datasource.password=password
spring.datasource.password=${PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver

# Applicative parameters
sc-int.application_code.max_value: 48
sc-int.segregation_code.max_value: 48
sc-int.application_code.max_value=48
sc-int.segregation_code.max_value=48
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package it.gov.pagopa.apiconfig.controller;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockStationDetailsList;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import it.gov.pagopa.apiconfig.Application;
import it.gov.pagopa.apiconfig.selfcareintegration.service.BrokersService;
import java.io.IOException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand All @@ -20,40 +13,49 @@
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import java.io.IOException;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockCreditorInstitutionDetails;
import static it.gov.pagopa.apiconfig.util.TestUtil.getMockStationDetailsList;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest(classes = Application.class)
@AutoConfigureMockMvc
class BrokersControllerTest {

@Autowired private MockMvc mvc;

@MockBean private BrokersService brokersService;

@BeforeEach
void setup() throws IOException {
when(brokersService.getStationsDetailsFromBroker("1234", null, PageRequest.of(0, 50)))
.thenReturn(getMockStationDetailsList());
when(brokersService.getStationsDetailsFromBroker(
"1234", "80007580279_01", PageRequest.of(0, 50)))
.thenReturn(getMockStationDetailsList());
}

@ParameterizedTest
@CsvSource({
"/brokers/1234/stations?limit=50&page=0",
})
void testGetWithoutStationId(String url) throws Exception {
mvc.perform(get(url).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}

@ParameterizedTest
@CsvSource({
"/brokers/1234/stations?stationId=80007580279_01&limit=50&page=0",
})
void testGetWithStationId(String url) throws Exception {
mvc.perform(get(url).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}
@Autowired
private MockMvc mvc;

@MockBean
private BrokersService brokersService;

@BeforeEach
void setup() throws IOException {
when(brokersService.getStationsDetailsFromBroker("1234", null, PageRequest.of(0, 50)))
.thenReturn(getMockStationDetailsList());
when(brokersService.getStationsDetailsFromBroker(
"1234", "80007580279_01", PageRequest.of(0, 50)))
.thenReturn(getMockStationDetailsList());
when(brokersService.getCreditorInstitutionsAssociatedToBroker("1234", null, PageRequest.of(0, 50)))
.thenReturn(getMockCreditorInstitutionDetails());
when(brokersService.getCreditorInstitutionsAssociatedToBroker("1234", true, PageRequest.of(0, 50)))
.thenReturn(getMockCreditorInstitutionDetails());
}

@ParameterizedTest
@CsvSource({
"/brokers/1234/stations?limit=50&page=0",
"/brokers/1234/stations?stationId=80007580279_01&limit=50&page=0",
"/brokers/1234/creditor-institutions?limit=50&page=0",
"/brokers/1234/creditor-institutions?enabled=true&limit=50&page=0",
})
void testGetOk(String url) throws Exception {
mvc.perform(get(url).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
}

}
Loading

0 comments on commit fa95d68

Please sign in to comment.