diff --git a/src/main/java/it/gov/pagopa/pu/organization/service/TaxonomyService.java b/src/main/java/it/gov/pagopa/pu/organization/service/TaxonomyService.java index 86e6f08..0e2008c 100644 --- a/src/main/java/it/gov/pagopa/pu/organization/service/TaxonomyService.java +++ b/src/main/java/it/gov/pagopa/pu/organization/service/TaxonomyService.java @@ -1,20 +1,10 @@ package it.gov.pagopa.pu.organization.service; import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO; -import it.gov.pagopa.pu.organization.repository.TaxonomyRepository; import java.util.List; import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Service; -@Service -public class TaxonomyService { - private TaxonomyRepository taxonomyRepository; - public TaxonomyService(TaxonomyRepository taxonomyRepository){ - this.taxonomyRepository = taxonomyRepository; - } - - public List getDistinctOrganizationType(Sort sort){ - return taxonomyRepository.findDistinctOrganizationTypes(sort); - } +public interface TaxonomyService { + List getDistinctOrganizationType(Sort sort); } diff --git a/src/main/java/it/gov/pagopa/pu/organization/service/TaxonomyServiceImpl.java b/src/main/java/it/gov/pagopa/pu/organization/service/TaxonomyServiceImpl.java new file mode 100644 index 0000000..a353f83 --- /dev/null +++ b/src/main/java/it/gov/pagopa/pu/organization/service/TaxonomyServiceImpl.java @@ -0,0 +1,19 @@ +package it.gov.pagopa.pu.organization.service; + +import it.gov.pagopa.pu.organization.model.DistinctOrganizationTypeDTO; +import it.gov.pagopa.pu.organization.repository.TaxonomyRepository; +import java.util.List; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +@Service +public class TaxonomyServiceImpl implements TaxonomyService{ + private TaxonomyRepository taxonomyRepository; + public TaxonomyServiceImpl(TaxonomyRepository taxonomyRepository){ + this.taxonomyRepository = taxonomyRepository; + } + + public List getDistinctOrganizationType(Sort sort){ + return taxonomyRepository.findDistinctOrganizationTypes(sort); + } +} diff --git a/src/test/java/it/gov/pagopa/pu/organization/controller/TaxonomyControllerTest.java b/src/test/java/it/gov/pagopa/pu/organization/controller/TaxonomyControllerTest.java index 0922bf5..fe59d5f 100644 --- a/src/test/java/it/gov/pagopa/pu/organization/controller/TaxonomyControllerTest.java +++ b/src/test/java/it/gov/pagopa/pu/organization/controller/TaxonomyControllerTest.java @@ -1,39 +1,35 @@ package it.gov.pagopa.pu.organization.controller; -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.pu.organization.model.DistinctOrganizationTypeDTO; import it.gov.pagopa.pu.organization.service.TaxonomyService; import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; import org.springframework.data.domain.Sort; -import org.springframework.http.MediaType; -import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.http.ResponseEntity; import org.springframework.test.web.servlet.MockMvc; -@WebMvcTest(value = TaxonomyController.class, excludeFilters = { - @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE) -}) -@AutoConfigureMockMvc(addFilters = false) +@ExtendWith(MockitoExtension.class) class TaxonomyControllerTest { @Autowired private MockMvc mockMvc; - @MockitoBean + @Mock private TaxonomyService taxonomyServiceMock; + @InjectMocks + private TaxonomyController taxonomyController; + @Test - void getDistinctOrgType() throws Exception { + void getDistinctOrgType() { List orgTypes = new ArrayList<>(); orgTypes.add(new DistinctOrganizationTypeDTO() { @Override @@ -49,12 +45,9 @@ public String getOrganizationTypeDescription() { Mockito.when(taxonomyServiceMock.getDistinctOrganizationType(Sort.by(Sort.Order.asc("organizationType")))).thenReturn(orgTypes); - mockMvc.perform(get("/taxonomy/custom/getDistinctOrganizationType") - .param("sort", "organizationType,ASC") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(content().json( - "[{\"organizationType\":\"test\",\"organizationTypeDescription\":\"test\"}]")); + ResponseEntity> orgTypesResult = taxonomyController.getDistinctOrgType(Sort.by(Sort.Order.asc("organizationType"))); + + Assertions.assertEquals(200,orgTypesResult.getStatusCode().value()); + Assertions.assertEquals(orgTypes,orgTypesResult.getBody()); } } diff --git a/src/test/java/it/gov/pagopa/pu/organization/exception/ControllerExceptionHandlerTest.java b/src/test/java/it/gov/pagopa/pu/organization/exception/ControllerExceptionHandlerTest.java index 5d6f319..78e58b9 100644 --- a/src/test/java/it/gov/pagopa/pu/organization/exception/ControllerExceptionHandlerTest.java +++ b/src/test/java/it/gov/pagopa/pu/organization/exception/ControllerExceptionHandlerTest.java @@ -1,6 +1,7 @@ package it.gov.pagopa.pu.organization.exception; import it.gov.pagopa.pu.organization.controller.BrokerController; +import it.gov.pagopa.pu.organization.controller.TaxonomyController; import it.gov.pagopa.pu.organization.service.broker.BrokerService; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -22,6 +23,9 @@ class ControllerExceptionHandlerTest { @MockitoBean private BrokerService brokerServiceMock; + @MockitoBean + private TaxonomyController taxonomyController; + @Autowired private MockMvc mockMvc; diff --git a/src/test/java/it/gov/pagopa/pu/organization/service/TaxonomyServiceTest.java b/src/test/java/it/gov/pagopa/pu/organization/service/TaxonomyServiceTest.java index b33e1c2..587165e 100644 --- a/src/test/java/it/gov/pagopa/pu/organization/service/TaxonomyServiceTest.java +++ b/src/test/java/it/gov/pagopa/pu/organization/service/TaxonomyServiceTest.java @@ -20,7 +20,7 @@ class TaxonomyServiceTest { private TaxonomyRepository taxonomyRepository; @InjectMocks - private TaxonomyService taxonomyService; + private TaxonomyServiceImpl taxonomyService; @Test void testGetDistinctOrganizationType() {