Skip to content

Commit

Permalink
[P4ADEV-1831] added controller tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mscarsel committed Jan 16, 2025
1 parent c52f301 commit b8dfcc1
Showing 1 changed file with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ void givenCorrectRequestWhenUploadIngestionFlowFileThenOk() throws Exception {
.file(file)
.param("ingestionFlowFileType", IngestionFlowFileType.RECEIPT.toString())
.param("fileOrigin", FileOrigin.PAGOPA.toString())
.content("body")
.contentType(MediaType.MULTIPART_FORM_DATA)
).andExpect(status().isOk());

Expand All @@ -72,7 +71,8 @@ void givenInvalidIngestionFlowFileTypeWhenUploadIngestionFlowFileThenError() thr

mockMvc.perform(multipart("/ingestionflowfiles/"+organizationId)
.file(file)
.param("ingestionFlowFileType", "WrongValue").content("body")
.param("ingestionFlowFileType", "WrongValue")
.param("fileOrigin", FileOrigin.PAGOPA.toString())
.contentType(MediaType.MULTIPART_FORM_DATA)
).andExpect(status().is4xxClientError());

Expand All @@ -86,7 +86,8 @@ void givenNoFileWhenUploadIngestionFlowFileThenError() throws Exception {
TestUtils.addSampleUserIntoSecurityContext();

mockMvc.perform(multipart("/ingestionflowfiles/"+organizationId)
.param("ingestionFlowFileType", IngestionFlowFileType.RECEIPT.toString()).content("body")
.param("ingestionFlowFileType", IngestionFlowFileType.RECEIPT.toString())
.param("fileOrigin", FileOrigin.PAGOPA.toString())
.contentType(MediaType.MULTIPART_FORM_DATA)
).andExpect(status().is4xxClientError());

Expand All @@ -107,6 +108,50 @@ void givenNoIngestionFlowFileTypeWhenUploadIngestionFlowFileThenError() throws E

mockMvc.perform(multipart("/ingestionflowfiles/"+organizationId)
.file(file)
.param("fileOrigin", FileOrigin.PAGOPA.toString())
.contentType(MediaType.MULTIPART_FORM_DATA)
).andExpect(status().is4xxClientError());

Mockito.verify(serviceMock, Mockito.times(0)).uploadIngestionFlowFile(Mockito.any(),
Mockito.any(),Mockito.any(),Mockito.any(),Mockito.any(), Mockito.anyString());
}

@Test
void givenInvalidFileOriginWhenUploadIngestionFlowFileThenError() throws Exception {
long organizationId = 1L;
MockMultipartFile file = new MockMultipartFile(
"ingestionFlowFile",
"test.txt",
MediaType.TEXT_PLAIN_VALUE,
"this is a test file".getBytes()
);
TestUtils.addSampleUserIntoSecurityContext();

mockMvc.perform(multipart("/ingestionflowfiles/"+organizationId)
.file(file)
.param("ingestionFlowFileType", IngestionFlowFileType.RECEIPT.toString())
.param("fileOrigin", "WrongValue")
.contentType(MediaType.MULTIPART_FORM_DATA)
).andExpect(status().is4xxClientError());

Mockito.verify(serviceMock, Mockito.times(0)).uploadIngestionFlowFile(Mockito.any(),
Mockito.any(),Mockito.any(),Mockito.any(),Mockito.any(), Mockito.anyString());
}

@Test
void givenNoFileOriginWhenUploadIngestionFlowFileThenError() throws Exception {
long organizationId = 1L;
MockMultipartFile file = new MockMultipartFile(
"ingestionFlowFile",
"test.txt",
MediaType.TEXT_PLAIN_VALUE,
"this is a test file".getBytes()
);
TestUtils.addSampleUserIntoSecurityContext();

mockMvc.perform(multipart("/ingestionflowfiles/"+organizationId)
.file(file)
.param("ingestionFlowFileType", IngestionFlowFileType.RECEIPT.toString())
.contentType(MediaType.MULTIPART_FORM_DATA)
).andExpect(status().is4xxClientError());

Expand Down

0 comments on commit b8dfcc1

Please sign in to comment.