Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
[SELC-5058] Remove issues
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Jun 17, 2024
1 parent 1802e55 commit 58d52f0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SwaggerConfigTest {
void swaggerSpringPlugin() throws Exception {
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
mockMvc.perform(MockMvcRequestBuilders.get("/v3/api-docs").accept(MediaType.APPLICATION_JSON))
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo((result) -> {
.andExpect(MockMvcResultMatchers.status().is2xxSuccessful()).andDo(result -> {
assertNotNull(result);
assertNotNull(result.getResponse());
final String content = result.getResponse().getContentAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

import it.pagopa.selfcare.mscore.api.InstitutionConnector;
import it.pagopa.selfcare.mscore.model.institution.Onboarding;
import it.pagopa.selfcare.mscore.model.user.UserToOnboard;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@ void testVerifyOnboardingInfoByFilterNotFound() {
verify(institutionConnector).existsOnboardingByFilters(Mockito.any());
}

/**
* Method under test: {@link OnboardingServiceImpl#verifyOnboardingInfo(String, String)}
*/
@Test
void testVerifyOnboardingInfo4() {
doNothing().when(institutionService)
.retrieveInstitutionsWithFilter(any(), any(), any());
onboardingServiceImpl.verifyOnboardingInfo("42", "42");
verify(institutionService).retrieveInstitutionsWithFilter(any(), any(),
any());
}

/**
* Method under test: {@link OnboardingServiceImpl#verifyOnboardingInfo(String, String)}
*/
Expand All @@ -131,30 +119,6 @@ void testVerifyOnboardingInfo5() {
any());
}

/**
* Method under test: {@link OnboardingServiceImpl#verifyOnboardingInfo(String, String)}
*/
@Test
void testVerifyOnboardingInfo6() {
doNothing().when(institutionService)
.retrieveInstitutionsWithFilter(any(), any(), any());
onboardingServiceImpl.verifyOnboardingInfo("42", "42");
verify(institutionService).retrieveInstitutionsWithFilter(any(), any(),
any());
}

/**
* Method under test: {@link OnboardingServiceImpl#verifyOnboardingInfo(String, String)}
*/
@Test
void testVerifyOnboardingInfo7() {
doThrow(new InvalidRequestException("An error occurred", "Code")).when(institutionService)
.retrieveInstitutionsWithFilter(any(), any(), any());
assertThrows(InvalidRequestException.class, () -> onboardingServiceImpl.verifyOnboardingInfo("42", "42"));
verify(institutionService).retrieveInstitutionsWithFilter(any(), any(),
any());
}

@Test
void persistOnboarding_shouldThrowIfOnboardingExists() {

Expand All @@ -166,7 +130,9 @@ void persistOnboarding_shouldThrowIfOnboardingExists() {
institution.setOnboarding(List.of(onboarding, dummyOnboarding()));
when(institutionConnector.findById(institution.getId())).thenReturn(institution);

assertThrows(InvalidRequestException.class, () -> onboardingServiceImpl.persistOnboarding(institution.getId(),
String institutionId = institution.getId();

assertThrows(InvalidRequestException.class, () -> onboardingServiceImpl.persistOnboarding(institutionId,
onboarding.getProductId(), new Onboarding()));
}

Expand Down Expand Up @@ -195,8 +161,9 @@ void persistOnboarding_shouldRollback() {

when(institutionConnector.findById(institution.getId())).thenReturn(institution);
when(institutionConnector.findAndUpdate(any(), any(), any(), any())).thenThrow(new RuntimeException());
String institutionId = institution.getId();

Assertions.assertThrows(InvalidRequestException.class, () -> onboardingServiceImpl.persistOnboarding(institution.getId(), productId, onboardingToPersist));
Assertions.assertThrows(InvalidRequestException.class, () -> onboardingServiceImpl.persistOnboarding(institutionId, productId, onboardingToPersist));

verify(onboardingDao, times(1))
.rollbackPersistOnboarding(any(), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import it.pagopa.selfcare.mscore.core.InstitutionService;
import it.pagopa.selfcare.mscore.core.OnboardingService;
import it.pagopa.selfcare.mscore.model.institution.*;
import it.pagopa.selfcare.mscore.model.user.UserToOnboard;
import it.pagopa.selfcare.mscore.web.model.institution.*;
import it.pagopa.selfcare.mscore.web.model.mapper.*;
import it.pagopa.selfcare.mscore.web.model.onboarding.OnboardedProducts;
Expand Down Expand Up @@ -44,18 +43,15 @@ public class InstitutionController {
private final OnboardingResourceMapper onboardingResourceMapper;
private final InstitutionResourceMapper institutionResourceMapper;
private final BrokerMapper brokerMapper;
private final UserMapper userMapper;

public InstitutionController(InstitutionService institutionService,
OnboardingService onboardingService, OnboardingResourceMapper onboardingResourceMapper,
InstitutionResourceMapper institutionResourceMapper,
BrokerMapper brokerMapper,
UserMapper userMapper) {
BrokerMapper brokerMapper) {
this.institutionService = institutionService;
this.onboardingService = onboardingService;
this.onboardingResourceMapper = onboardingResourceMapper;
this.institutionResourceMapper = institutionResourceMapper;
this.userMapper = userMapper;
this.brokerMapper = brokerMapper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import it.pagopa.selfcare.mscore.web.TestUtils;
import it.pagopa.selfcare.mscore.web.model.institution.*;
import it.pagopa.selfcare.mscore.web.model.mapper.*;
import it.pagopa.selfcare.mscore.web.model.user.Person;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -80,20 +79,20 @@ class InstitutionControllerTest {


private final static Onboarding onboarding;
private final static Billing billing;
private final static Billing staticBilling;

private final static Institution institution;
private final static Institution staticInstitution;

static {
billing = new Billing();
billing.setVatNumber("example");
billing.setRecipientCode("example");
billing.setTaxCodeInvoicing("example");
staticBilling = new Billing();
staticBilling.setVatNumber("example");
staticBilling.setRecipientCode("example");
staticBilling.setTaxCodeInvoicing("example");

onboarding = new Onboarding();
onboarding.setProductId("example");
onboarding.setStatus(RelationshipState.ACTIVE);
onboarding.setBilling(billing);
onboarding.setBilling(staticBilling);
onboarding.setContract("contract");
onboarding.setTokenId("tokenId");
onboarding.setPricingPlan("setPricingPlan");
Expand All @@ -103,13 +102,13 @@ class InstitutionControllerTest {
attribute.setCode("code");
attribute.setDescription("description");

institution = new Institution();
institution.setId("42");
institution.setInstitutionType(InstitutionType.PG);
institution.setDescription("description");
institution.setOnboarding(List.of(onboarding));
institution.setAttributes(List.of(attribute));
institution.setIstatCode("istatCode");
staticInstitution = new Institution();
staticInstitution.setId("42");
staticInstitution.setInstitutionType(InstitutionType.PG);
staticInstitution.setDescription("description");
staticInstitution.setOnboarding(List.of(onboarding));
staticInstitution.setAttributes(List.of(attribute));
staticInstitution.setIstatCode("istatCode");

}

Expand Down Expand Up @@ -265,8 +264,8 @@ void shouldGetOnboardingsInstitutionByProductId() throws Exception {
void retrieveInstitutionById() throws Exception {
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
SecurityContextHolder.setContext(securityContext);
when(institutionService.retrieveInstitutionById("42")).thenReturn(institution);
institution.setId("id");
when(institutionService.retrieveInstitutionById("42")).thenReturn(staticInstitution);
staticInstitution.setId("id");
MockHttpServletRequestBuilder requestBuilder = get("/institutions/{id}", "42");
ResultActions actualPerformResult = MockMvcBuilders.standaloneSetup(institutionController)
.build()
Expand All @@ -280,7 +279,7 @@ void retrieveInstitutionById() throws Exception {
*/
@Test
void testRetrieveInstitutionById() throws Exception {
when(institutionService.retrieveInstitutionById(any())).thenReturn(institution);
when(institutionService.retrieveInstitutionById(any())).thenReturn(staticInstitution);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get("/institutions/{id}", "42");
MockMvcBuilders.standaloneSetup(institutionController)
.build()
Expand Down Expand Up @@ -1238,7 +1237,7 @@ void findFromProduct() throws Exception {
Integer sizeMock = 2;

// When
when(institutionService.getInstitutionsByProductId(any(), any(), any())).thenReturn(List.of(institution));
when(institutionService.getInstitutionsByProductId(any(), any(), any())).thenReturn(List.of(staticInstitution));
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.get(BASE_URL + "/products/{productId}", productIdMock)
.param("page", pageMock.toString())
.param("size", sizeMock.toString());
Expand Down

0 comments on commit 58d52f0

Please sign in to comment.