package jnpf.dmsService;
|
|
import jnpf.dmsEntity.storage.approval.DmsDisableRequest;
|
import jnpf.dmsEntity.storage.approval.DmsApprovedBatch;
|
import jnpf.dmsMapper.*;
|
import jnpf.flowable.WorkFlowApi;
|
import jnpf.flowable.entity.TaskEntity;
|
import jnpf.exception.DataException;
|
import org.junit.jupiter.api.*;
|
import java.util.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
import static org.mockito.Mockito.*;
|
import org.springframework.test.util.ReflectionTestUtils;
|
|
class DmsApprovedDisableServiceTest {
|
DmsApprovedDisableMapper mapper=mock(DmsApprovedDisableMapper.class);
|
DmsWenjianZiyuanMapper resources=mock(DmsWenjianZiyuanMapper.class);
|
WorkFlowApi workflow=mock(WorkFlowApi.class);
|
DmsApprovedBatchMapper batches=mock(DmsApprovedBatchMapper.class);
|
DmsApprovedDisableService service=new DmsApprovedDisableService(mapper,resources,workflow,batches);
|
Date approvedAt=new Date(System.currentTimeMillis()-60000);
|
@BeforeEach void enable(){ReflectionTestUtils.setField(service,"enabled",true);}
|
DmsDisableRequest row() {
|
DmsDisableRequest r=new DmsDisableRequest(); r.setId(UUID.randomUUID());r.setTenantId("tenant");
|
r.setFlowId("flow");r.setTaskId("task");r.setOperation("yishixiao");r.setApplicationId("application");
|
r.setSourceRowId("child");r.setFileId("main");r.setBusinessVersionId("version");
|
r.setDocumentId(UUID.randomUUID());r.setFileVersionId(UUID.randomUUID());r.setFolderId(UUID.randomUUID());
|
r.setSourceFileId("new");r.setSourceVersionId("newVersion");r.setApprovedAt(approvedAt);
|
r.setActorId("persisted-actor");r.setScheduledAt(approvedAt);r.setStatus("WAITING");r.setLeaseToken("lease");return r;
|
}
|
void approved() {
|
TaskEntity task=new TaskEntity();task.setId("task");task.setFlowId("flow");task.setStatus(2);
|
task.setEndTime(approvedAt);when(workflow.getInfoSubmit("task")).thenReturn(task);
|
}
|
@Test void noReceiptWithoutRealApproval() {
|
assertThrows(DataException.class,()->service.enqueue("tenant","flow","task","yishixiao"));
|
verifyNoInteractions(mapper,resources);
|
}
|
@Test void enqueueUsesPersistedActorWhenWorkflowProjectionOmitsActor() {
|
approved();
|
for (String operation : List.of("yichexiao", "yishixiao")) {
|
DmsDisableRequest r=row();r.setOperation(operation);
|
when(mapper.nativeRows("tenant","flow","task",operation)).thenReturn(List.of(r));
|
when(mapper.validateTarget(r)).thenReturn(1);when(mapper.candidateExists(r)).thenReturn(1);
|
DmsApprovedBatch batch=service.enqueue("tenant","flow","task",operation);
|
assertEquals("persisted-actor",batch.getActorId());
|
assertEquals("persisted-actor",r.getActorId());verify(mapper).enqueue(r);
|
}
|
}
|
@Test void missingPersistedActorFailsBeforeWritingAnyProgress() {
|
approved();DmsDisableRequest r=row();r.setActorId(null);
|
when(mapper.nativeRows("tenant","flow","task","yishixiao")).thenReturn(List.of(r));
|
assertThrows(DataException.class,()->service.enqueue("tenant","flow","task","yishixiao"));
|
verifyNoInteractions(batches,resources);verify(mapper,never()).enqueue(any());
|
}
|
@Test void datesAreIndependentAndNeverEarlierThanApproval() {
|
approved();DmsDisableRequest a=row(),b=row();b.setSourceRowId("child2");b.setFileId("main2");
|
b.setRequestedAt(new Date(approvedAt.getTime()+3*86400000L));
|
when(mapper.nativeRows("tenant","flow","task","yishixiao")).thenReturn(List.of(a,b));
|
when(mapper.validateTarget(any())).thenReturn(1);when(mapper.candidateExists(any())).thenReturn(1);
|
DmsApprovedBatch batch=service.enqueue("tenant","flow","task","yishixiao");
|
assertEquals(batch.getId(),a.getBatchId());assertEquals(batch.getId(),b.getBatchId());
|
assertEquals(approvedAt,batch.getScheduledAt());verify(batches).insertBatch(batch);
|
assertEquals(approvedAt,a.getScheduledAt());assertTrue(b.getScheduledAt().after(approvedAt));
|
verify(mapper).enqueue(a);verify(mapper).enqueue(b);
|
}
|
@Test void duplicateCallbackReusesTaskButChangedOrRemovedRowsAreRejected() {
|
approved();DmsDisableRequest a=row(),b=row();b.setSourceRowId("child2");b.setFileId("main2");
|
when(mapper.nativeRows("tenant","flow","task","yishixiao")).thenReturn(List.of(a,b));
|
when(mapper.validateTarget(any())).thenReturn(1);when(mapper.candidateExists(any())).thenReturn(1);
|
DmsApprovedBatch batch=service.enqueue("tenant","flow","task","yishixiao");
|
when(batches.find("tenant","task","shixiao_shenqing")).thenReturn(batch);
|
when(mapper.nativeRows("tenant","flow","task","yishixiao")).thenReturn(List.of(b,a));
|
assertSame(batch,service.enqueue("tenant","flow","task","yishixiao"));
|
verify(batches,times(1)).insertBatch(any());verify(mapper,times(2)).validateTarget(any());
|
when(mapper.nativeRows("tenant","flow","task","yishixiao")).thenReturn(List.of(a));
|
assertThrows(DataException.class,()->service.enqueue("tenant","flow","task","yishixiao"));
|
}
|
@Test void changedDateRejectsDuplicateCallback() {
|
approved();DmsDisableRequest a=row();
|
when(mapper.nativeRows("tenant","flow","task","yishixiao")).thenReturn(List.of(a));
|
when(mapper.validateTarget(any())).thenReturn(1);when(mapper.candidateExists(any())).thenReturn(1);
|
DmsApprovedBatch batch=service.enqueue("tenant","flow","task","yishixiao");
|
when(batches.find("tenant","task","shixiao_shenqing")).thenReturn(batch);
|
a.setRequestedAt(new Date());
|
assertThrows(DataException.class,()->service.enqueue("tenant","flow","task","yishixiao"));
|
}
|
}
|