Skip to content

Commit

Permalink
[SELC-5587] feat: removed deprecated api for IVASS search by taxCode (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
empassaro authored Sep 18, 2024
1 parent 9012e3b commit 6eb1353
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 209 deletions.
78 changes: 2 additions & 76 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@
} ]
}
},
"/insurance-companies/origin/{originId}" : {
"/insurance-companies/{originId}" : {
"get" : {
"tags" : [ "insurance-companies" ],
"summary" : "Search insurance company by its IVASS code",
Expand Down Expand Up @@ -986,80 +986,6 @@
} ]
}
},
"/insurance-companies/{taxId}" : {
"get" : {
"tags" : [ "insurance-companies" ],
"summary" : "Search insurance company by its taxCode",
"description" : "Returns only one insurance company.",
"operationId" : "searchByTaxCodeUsingGET",
"parameters" : [ {
"name" : "taxId",
"in" : "path",
"description" : "taxCode of insurance company",
"required" : true,
"style" : "simple",
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/InsuranceCompanyResource"
}
}
}
},
"400" : {
"description" : "Bad Request",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"401" : {
"description" : "Unauthorized",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"404" : {
"description" : "Not Found",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
},
"500" : {
"description" : "Internal Server Error",
"content" : {
"application/problem+json" : {
"schema" : {
"$ref" : "#/components/schemas/Problem"
}
}
}
}
},
"deprecated" : true,
"security" : [ {
"bearerAuth" : [ "global" ]
} ]
}
},
"/national-registries/legal-address" : {
"get" : {
"tags" : [ "nationalRegistries" ],
Expand Down Expand Up @@ -1462,7 +1388,7 @@
"tags" : [ "stations" ],
"summary" : "Search station by its taxCode",
"description" : "Returns only one station.",
"operationId" : "searchByTaxCodeUsingGET_1",
"operationId" : "searchByTaxCodeUsingGET",
"parameters" : [ {
"name" : "taxId",
"in" : "path",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

public interface IvassService {
QueryResult<InsuranceCompany> search(Optional<String> searchText, int page, int limit);
InsuranceCompany findByTaxCode(String taxId);
InsuranceCompany findByOriginId(String ivassCode);
}

Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,6 @@ public class IvassServiceImpl implements IvassService {
this.ivassDataConnector = ivassDataConnector;
}

/**
* @deprecated method has been deprecated because a new method has been implemented.
*/
@Deprecated(forRemoval = true)
@Override
public InsuranceCompany findByTaxCode(String taxId) {
log.trace("findByTaxCode start");
log.debug("findByTaxCode parameter = {}", taxId.toUpperCase());
final List<InsuranceCompany> companies = indexSearchService.findById(InsuranceCompany.Field.TAX_CODE, taxId.toUpperCase());
if (companies.isEmpty()) {
throw new ResourceNotFoundException();
} else if (companies.size() > 1) {
throw new TooManyResourceFoundException();
}
final InsuranceCompany company = companies.get(0);
log.debug("findByTaxCode result = {}", company);
log.trace("findByTaxCode end");
return company;
}

@Override
public InsuranceCompany findByOriginId(String originId) {
log.trace("findByIvassCode start");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ class IvassServiceImplTest {
@InjectMocks
private IvassServiceImpl ivassService;

@Test
void findById_ResourceNotFound() {
// given
final String taxId = "taxId";
when(indexSearchService.findById(any(), anyString()))
.thenReturn(List.of());
// when
final Executable executable = () -> ivassService.findByTaxCode(taxId);
// then
assertThrows(ResourceNotFoundException.class, executable);
}

@Test
void findByOriginId_ResourceNotFound() {
// given
Expand All @@ -57,19 +45,6 @@ void findByOriginId_ResourceNotFound() {
assertThrows(ResourceNotFoundException.class, executable);
}

@Test
void findById_TooManyResourceFound() {
// given
final String taxId = "taxId";
final DummyInsuranceCompany dummyCompany = new DummyInsuranceCompany();
when(indexSearchService.findById(any(), anyString()))
.thenReturn(List.of(dummyCompany, dummyCompany));
// when
final Executable executable = () -> ivassService.findByTaxCode(taxId);
// then
assertThrows(TooManyResourceFoundException.class, executable);
}

@Test
void findByOriginId_TooManyResourceFound() {
// given
Expand All @@ -83,21 +58,6 @@ void findByOriginId_TooManyResourceFound() {
assertThrows(TooManyResourceFoundException.class, executable);
}

@Test
void findById_found() {
// given
final String taxId = "taxId";
final DummyInsuranceCompany dummyCompany = new DummyInsuranceCompany();
dummyCompany.setId("id");
dummyCompany.setTaxCode("taxId");
when(indexSearchService.findById(any(), anyString()))
.thenReturn(List.of(dummyCompany));
// when
final InsuranceCompany result = ivassService.findByTaxCode(taxId);
// then
assertSame(dummyCompany, result);
}

@Test
void findByOriginId_found() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,7 @@ public IvassController(IvassService ivassService,
this.insuranceCompanyMapper = insuranceCompanyMapper;
}

/**
* @deprecated since a new version has been implemented
*/
@Deprecated(forRemoval = true)
@GetMapping("/{taxId}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "${swagger.api.insurance-company.search.byId.summary}", notes = "${swagger.api.insurance-company.search.byId.notes}")
public InsuranceCompanyResource searchByTaxCode(@ApiParam("${swagger.model.insurance-company.taxCode}")
@PathVariable("taxId") String taxId) {
log.trace("searchByTaxCode start");
if (taxId.matches("\\w*")) {
log.debug("searchByTaxCode parameter = {}", taxId);
}
final InsuranceCompanyResource insuranceCompany = insuranceCompanyMapper.toResource(ivassService.findByTaxCode(taxId));
log.debug("searchByTaxCode result = {}", insuranceCompany);
log.trace("searchByTaxCode end");
return insuranceCompany;
}

@GetMapping("/origin/{originId}")
@GetMapping("/{originId}")
@ResponseStatus(HttpStatus.OK)
@ApiOperation(value = "${swagger.api.insurance-company.search.byOriginId.summary}", notes = "${swagger.api.insurance-company.search.byOriginId.notes}")
public InsuranceCompanyResource searchByOriginId(@ApiParam("${swagger.model.insurance-company.originId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,6 @@ class IvassControllerTest {

@MockBean
private IvassService ivassService;

/**
* Method under test: {@link IvassController#searchByTaxCode(String)}
*/
@Test
void findInsurance() throws Exception {
// given
final String taxId = "CODE";
when(ivassService.findByTaxCode(any()))
.thenReturn(mockInstance(new DummyInsuranceCompany()));
// when
mvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/{taxId}", taxId)
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", notNullValue()))
.andExpect(jsonPath("$.originId", notNullValue()))
.andExpect(jsonPath("$.taxCode", notNullValue()))
.andExpect(jsonPath("$.description", notNullValue()))
.andExpect(jsonPath("$.digitalAddress", notNullValue()))
.andExpect(jsonPath("$.address", notNullValue()));
// then

verify(ivassService, times(1))
.findByTaxCode(taxId);
verifyNoMoreInteractions(ivassService);
}

/**
* Method under test: {@link IvassController#searchByOriginId(String)}
Expand All @@ -81,7 +53,7 @@ void findInsuranceByOriginId() throws Exception {
.thenReturn(mockInstance(new DummyInsuranceCompany()));
// when
mvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/origin/{originId}", originId)
.get(BASE_URL + "/{originId}", originId)
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
Expand All @@ -97,28 +69,6 @@ void findInsuranceByOriginId() throws Exception {
.findByOriginId(originId);
verifyNoMoreInteractions(ivassService);
}


/**
* Method under test: {@link IvassController#searchByTaxCode(String)}
*/
@Test
void findInsuranceNotFound() throws Exception {
// given
final String taxId = "CODE";
when(ivassService.findByTaxCode(any()))
.thenThrow(ResourceNotFoundException.class);
// when
mvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/{taxId}", taxId)
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isNotFound());
// then
verify(ivassService, times(1))
.findByTaxCode(taxId);
verifyNoMoreInteractions(ivassService);
}

/**
* Method under test: {@link IvassController#searchByOriginId(String)}
Expand All @@ -131,7 +81,7 @@ void findInsuranceNyOriginIdNotFound() throws Exception {
.thenThrow(ResourceNotFoundException.class);
// when
mvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/origin/{originId}", originId)
.get(BASE_URL + "/{originId}", originId)
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isNotFound());
Expand Down

0 comments on commit 6eb1353

Please sign in to comment.