generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VAS-800] Added unit tests and fixed test packages
- Loading branch information
giomella
committed
Mar 14, 2024
1 parent
d3d8bf1
commit 3873ff3
Showing
21 changed files
with
404 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
.../selfcareintegration/ApplicationTest.java → ...gov/pagopa/apiconfig/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
src/test/java/it/gov/pagopa/apiconfig/controller/CreditorInstitutionsControllerTest.java
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...gopa/apiconfig/OpenApiGenerationTest.java → ...areintegration/OpenApiGenerationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../controller/BrokerPspsControllerTest.java → .../controller/BrokerPspsControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...v/pagopa/apiconfig/selfcareintegration/controller/CreditorInstitutionsControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package it.gov.pagopa.apiconfig.selfcareintegration.controller; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import it.gov.pagopa.apiconfig.Application; | ||
import it.gov.pagopa.apiconfig.selfcareintegration.service.CreditorInstitutionsService; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import java.util.Collections; | ||
|
||
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockApplicationCodesList; | ||
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockSegregationCodesList; | ||
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockStationDetailsList; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
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 CreditorInstitutionsControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mvc; | ||
|
||
@MockBean | ||
private CreditorInstitutionsService creditorInstitutionsService; | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"/creditorinstitutions/1234/stations?limit=50&page=0", | ||
}) | ||
void testGetStations(String url) throws Exception { | ||
when(creditorInstitutionsService.getStationsDetailsFromCreditorInstitution( | ||
"1234", PageRequest.of(0, 50))) | ||
.thenReturn(getMockStationDetailsList()); | ||
mvc.perform(get(url).contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"/creditorinstitutions/1234/applicationcodes", | ||
}) | ||
void testGetApplicationCodes(String url) throws Exception { | ||
when(creditorInstitutionsService.getApplicationCodesFromCreditorInstitution( | ||
anyString(), anyBoolean())) | ||
.thenReturn(getMockApplicationCodesList()); | ||
mvc.perform(get(url).contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ | ||
"/creditorinstitutions/1234/segregationcodes", | ||
}) | ||
void testGetSegregationCodes(String url) throws Exception { | ||
when(creditorInstitutionsService.getSegregationCodesFromCreditorInstitution( | ||
anyString(), anyBoolean(), any())) | ||
.thenReturn(getMockSegregationCodesList()); | ||
mvc.perform(get(url).contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); | ||
} | ||
|
||
@Test | ||
void getCreditorInstitutionsTest() throws Exception { | ||
when(creditorInstitutionsService.getSegregationCodesFromCreditorInstitution( | ||
anyString(), anyBoolean(), any())) | ||
.thenReturn(getMockSegregationCodesList()); | ||
mvc.perform(post("/creditorinstitutions/") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(Collections.singletonList("00168480242")))) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...config/controller/HomeControllerTest.java → ...ration/controller/HomeControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
...apiconfig/exception/ErrorHandlerTest.java → ...tegration/exception/ErrorHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...er/ConvertCanaliToChannelDetailsTest.java → ...er/ConvertCanaliToChannelDetailsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.