Skip to content

Commit

Permalink
[VAS-800] Added unit tests and fixed test packages
Browse files Browse the repository at this point in the history
  • Loading branch information
giomella committed Mar 14, 2024
1 parent d3d8bf1 commit 3873ff3
Show file tree
Hide file tree
Showing 21 changed files with 404 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import it.gov.pagopa.apiconfig.selfcareintegration.exception.ErrorHandler;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
* Object returned as response in case of an error.
*
* <p>See {@link it.gov.pagopa.apiconfig.exception.ErrorHandler}
* <p>See {@link ErrorHandler}
*/
@Data
@Builder(toBuilder = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public List<CreditorInstitutionInfo> getCreditorInstitutionInfoList(List<String>
if (optionalPaList.isEmpty()) {
throw new AppException(AppError.MULTIPLE_CREDITOR_INSTITUTIONS_NOT_FOUND, taxCodes);
}
List<Pa> paList = optionalPaList.get();

List<Pa> paList = optionalPaList.get();
if (paList.size() != taxCodes.size()) {
throw new AppException(AppError.INTERNAL_SERVER_ERROR, "Retrieved less creditor institutions than expected");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package it.gov.pagopa.apiconfig.selfcareintegration;
package it.gov.pagopa.apiconfig;

import static org.junit.jupiter.api.Assertions.assertTrue;

import it.gov.pagopa.apiconfig.Application;
import org.junit.jupiter.api.Test;

class ApplicationTest {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.apiconfig;
package it.gov.pagopa.apiconfig.selfcareintegration;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.apiconfig.controller;
package it.gov.pagopa.apiconfig.selfcareintegration.controller;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockChannelDetailsList;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockChannelDetailsList;
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.apiconfig.controller;
package it.gov.pagopa.apiconfig.selfcareintegration.controller;

import it.gov.pagopa.apiconfig.Application;
import it.gov.pagopa.apiconfig.selfcareintegration.service.BrokersService;
Expand All @@ -15,8 +15,8 @@

import java.io.IOException;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockCreditorInstitutionDetails;
import static it.gov.pagopa.apiconfig.util.TestUtil.getMockStationDetailsList;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockCreditorInstitutionDetails;
import static it.gov.pagopa.apiconfig.selfcareintegration.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;
Expand Down
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));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.apiconfig.controller;
package it.gov.pagopa.apiconfig.selfcareintegration.controller;

import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.apiconfig.controller;
package it.gov.pagopa.apiconfig.selfcareintegration.controller;

import it.gov.pagopa.apiconfig.Application;
import it.gov.pagopa.apiconfig.selfcareintegration.service.IbansService;
Expand All @@ -18,7 +18,7 @@
import java.util.List;
import java.util.TimeZone;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockIbanList;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockIbanList;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.apiconfig.controller;
package it.gov.pagopa.apiconfig.selfcareintegration.controller;

import it.gov.pagopa.apiconfig.Application;
import it.gov.pagopa.apiconfig.selfcareintegration.service.PspService;
Expand All @@ -15,7 +15,7 @@

import java.io.IOException;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockChannelDetailsList;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockChannelDetailsList;
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package it.gov.pagopa.apiconfig.exception;
package it.gov.pagopa.apiconfig.selfcareintegration.exception;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

import it.gov.pagopa.apiconfig.Application;
import it.gov.pagopa.apiconfig.selfcareintegration.exception.AppException;
import it.gov.pagopa.apiconfig.selfcareintegration.exception.ErrorHandler;
import it.gov.pagopa.apiconfig.selfcareintegration.model.ProblemJson;
import java.sql.SQLException;
import org.hibernate.exception.ConstraintViolationException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package it.gov.pagopa.apiconfig.mapper;
package it.gov.pagopa.apiconfig.selfcareintegration.mapper;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockChannelMapping;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockChannelMapping;

import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.apiconfig.Application;
import it.gov.pagopa.apiconfig.selfcareintegration.mapper.ConvertCanaliToChannelDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.model.channel.ChannelDetails;
import it.gov.pagopa.apiconfig.starter.entity.Canali;
import it.gov.pagopa.apiconfig.util.TestUtil;
import it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil;
import java.io.IOException;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package it.gov.pagopa.apiconfig.service;
package it.gov.pagopa.apiconfig.selfcareintegration.service;

import static it.gov.pagopa.apiconfig.util.TestUtil.getMockChannel;
import static it.gov.pagopa.apiconfig.util.TestUtil.getMockPSPBroker;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockChannel;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.getMockPSPBroker;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -13,11 +13,10 @@
import it.gov.pagopa.apiconfig.selfcareintegration.exception.AppException;
import it.gov.pagopa.apiconfig.selfcareintegration.model.channel.ChannelDetailsList;
import it.gov.pagopa.apiconfig.selfcareintegration.repository.ExtendedChannelRepository;
import it.gov.pagopa.apiconfig.selfcareintegration.service.BrokerPSPsService;
import it.gov.pagopa.apiconfig.starter.entity.Canali;
import it.gov.pagopa.apiconfig.starter.entity.IntermediariPsp;
import it.gov.pagopa.apiconfig.starter.repository.IntermediariPspRepository;
import it.gov.pagopa.apiconfig.util.TestUtil;
import it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil;
import java.io.IOException;
import java.util.Optional;
import java.util.TimeZone;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package it.gov.pagopa.apiconfig.service;
package it.gov.pagopa.apiconfig.selfcareintegration.service;

import it.gov.pagopa.apiconfig.Application;
import it.gov.pagopa.apiconfig.selfcareintegration.exception.AppException;
import it.gov.pagopa.apiconfig.selfcareintegration.model.creditorinstitution.CreditorInstitutionDetails;
import it.gov.pagopa.apiconfig.selfcareintegration.model.station.StationDetailsList;
import it.gov.pagopa.apiconfig.selfcareintegration.service.BrokersService;
import it.gov.pagopa.apiconfig.starter.entity.IntermediariPa;
import it.gov.pagopa.apiconfig.starter.entity.PaStazionePa;
import it.gov.pagopa.apiconfig.starter.entity.Stazioni;
import it.gov.pagopa.apiconfig.starter.repository.IntermediariPaRepository;
import it.gov.pagopa.apiconfig.starter.repository.PaStazionePaRepository;
import it.gov.pagopa.apiconfig.starter.repository.StazioniRepository;
import it.gov.pagopa.apiconfig.util.TestUtil;
import it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil;
import org.assertj.core.util.Lists;
import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -35,7 +34,7 @@
import java.util.Optional;
import java.util.TimeZone;

import static it.gov.pagopa.apiconfig.util.TestUtil.*;
import static it.gov.pagopa.apiconfig.selfcareintegration.util.TestUtil.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.*;
Expand Down
Loading

0 comments on commit 3873ff3

Please sign in to comment.