package jnpf.dmsController.filecenter;
|
|
import jnpf.dmsController.DmsControllerTestSupport;
|
import jnpf.dmsEntity.storage.form.DmsFileExtendValidityForm;
|
import jnpf.dmsService.DmsFileValidityService;
|
import org.junit.jupiter.api.Test;
|
import org.mockito.ArgumentCaptor;
|
import org.springframework.http.MediaType;
|
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
import java.time.Instant;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.mockito.Mockito.*;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
class DmsFileValidityControllerTest extends DmsControllerTestSupport {
|
private final DmsFileValidityService service = mock(DmsFileValidityService.class);
|
private final MockMvc mvc = MockMvcBuilders.standaloneSetup(new DmsFileValidityController(service)).build();
|
|
@Test
|
void acceptsBatchAndParsesEachBeijingTimeWithoutShifting() throws Exception {
|
mvc.perform(post("/workflow-files/extend-validity").contentType(MediaType.APPLICATION_JSON)
|
.content(request("\"sourceId\":\"flow-1\",\"taskId\":\"task-1\",")))
|
.andExpect(status().isOk()).andExpect(jsonPath("$.code").value(200));
|
|
ArgumentCaptor<DmsFileExtendValidityForm> form = ArgumentCaptor.forClass(DmsFileExtendValidityForm.class);
|
verify(service).extendValidity(form.capture());
|
assertEquals("flow-1", form.getValue().getSourceId());
|
assertEquals(2, form.getValue().getFiles().size());
|
assertEquals(Instant.parse("2027-09-14T15:59:59Z"),
|
form.getValue().getFiles().get(0).getEffectiveTo().toInstant());
|
assertEquals(Instant.parse("2028-09-14T15:59:59Z"),
|
form.getValue().getFiles().get(1).getEffectiveTo().toInstant());
|
}
|
|
@Test
|
void acceptsBatchWithoutWorkflowIdentifiers() throws Exception {
|
mvc.perform(post("/workflow-files/extend-validity").contentType(MediaType.APPLICATION_JSON)
|
.content(request("")))
|
.andExpect(status().isOk());
|
|
ArgumentCaptor<DmsFileExtendValidityForm> form = ArgumentCaptor.forClass(DmsFileExtendValidityForm.class);
|
verify(service).extendValidity(form.capture());
|
assertNull(form.getValue().getSourceId());
|
assertNull(form.getValue().getTaskId());
|
}
|
|
@Test
|
void rejectsOnlyOneWorkflowIdentifier() throws Exception {
|
mvc.perform(post("/workflow-files/extend-validity").contentType(MediaType.APPLICATION_JSON)
|
.content(request("\"sourceId\":\"flow-1\",")))
|
.andExpect(status().isBadRequest());
|
verifyNoInteractions(service);
|
}
|
|
@Test
|
void rejectsMissingFileList() throws Exception {
|
mvc.perform(post("/workflow-files/extend-validity").contentType(MediaType.APPLICATION_JSON)
|
.content("{}"))
|
.andExpect(status().isBadRequest());
|
verifyNoInteractions(service);
|
}
|
|
@Test
|
void rejectsImpossibleCalendarDateInAnyFile() throws Exception {
|
mvc.perform(post("/workflow-files/extend-validity").contentType(MediaType.APPLICATION_JSON)
|
.content(request("").replace("2028-09-14 23:59:59", "2028-02-30 00:00:00")))
|
.andExpect(status().isBadRequest());
|
verifyNoInteractions(service);
|
}
|
|
private String request(String outerFields) {
|
return "{" + outerFields + "\"files\":["
|
+ "{\"fileVersionId\":\"018f0000-0000-7000-8000-000000000803\","
|
+ "\"effectiveTo\":\"2027-09-14 23:59:59\"},"
|
+ "{\"fileVersionId\":\"018f0000-0000-7000-8000-000000000804\","
|
+ "\"effectiveTo\":\"2028-09-14 23:59:59\"}]}";
|
}
|
}
|