Skip to content

Commit

Permalink
[VAS-976] feat: add notice institutions api (#401)
Browse files Browse the repository at this point in the history
Co-authored-by: Jacopo Carlini <jacopo.carlini@gmail.com>
Co-authored-by: svariant <samuele.varianti@nttdata.com>
  • Loading branch information
3 people committed Jun 19, 2024
1 parent d156cb4 commit 747746c
Showing 1 changed file with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package it.pagopa.selfcare.pagopa.backoffice.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import it.pagopa.selfcare.pagopa.backoffice.model.notices.InstitutionUploadData;
import it.pagopa.selfcare.pagopa.backoffice.service.InstitutionsService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
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.http.MediaType;
import org.springframework.mock.web.MockPart;
import org.springframework.test.web.servlet.MockMvc;

import java.io.IOException;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.verify;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
class InstitutionsControllerTest {

@Autowired
private MockMvc mvc;

@MockBean
private InstitutionsService institutionsService;

private ObjectMapper objectMapper = new ObjectMapper();

@BeforeEach
void setUp() {
Mockito.reset(institutionsService);
}

@Test
void updateInstitutionsShouldReturnOk() throws Exception {
InstitutionUploadData uploadData =
InstitutionUploadData.builder()
.cbill("cbill")
.info("info")
.webChannel(true)
.taxCode("123132")
.posteAccountNumber("1313")
.fullName("121212")
.organization("test")
.physicalChannel("1212")
.build();
String url = "/notice/institutions/data";
mvc.perform(multipart(url)
.file("file","".getBytes())
.part(new MockPart("institutions-data",
objectMapper.writeValueAsString(uploadData).getBytes()))
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE))
.andExpect(status().isOk());
verify(institutionsService).uploadInstitutionsData(any(), any());
}

@Test
void updateInstitutionsShouldReturnKoOnIoException() throws Exception {
InstitutionUploadData uploadData =
InstitutionUploadData.builder()
.cbill("cbill")
.info("info")
.webChannel(true)
.taxCode("123132")
.posteAccountNumber("1313")
.fullName("121212")
.organization("test")
.physicalChannel("1212")
.build();
doAnswer(invocationOnMock -> {
throw new IOException();
}).when(institutionsService).uploadInstitutionsData(any(), any());
String url = "/notice/institutions/data";
mvc.perform(multipart(url)
.file("file", "".getBytes())
.part(new MockPart("institutions-data",
objectMapper.writeValueAsString(uploadData).getBytes()))
.contentType(MediaType.MULTIPART_FORM_DATA_VALUE))
.andExpect(status().is5xxServerError());
verify(institutionsService).uploadInstitutionsData(any(), any());
}

}

0 comments on commit 747746c

Please sign in to comment.