刘光辉
5 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package jnpf.dmsService.search;
 
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.context.ApplicationEventPublisher;
 
import java.util.UUID;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
 
class DmsSearchIndexJobServiceTest {
 
    @Test
    void publishesRedisTaskEventWhenSearchIsEnabled() {
        DmsSearchProperties properties = new DmsSearchProperties();
        properties.setEnabled(true);
        ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
        DmsSearchIndexJobService service = new DmsSearchIndexJobService(properties, publisher);
        UUID documentId = UUID.randomUUID();
        UUID versionId = UUID.randomUUID();
 
        service.enqueueContentUpsert("tenant-1", documentId, versionId, "A".repeat(64));
 
        ArgumentCaptor<DmsSearchIndexJobCreatedEvent> captor =
                ArgumentCaptor.forClass(DmsSearchIndexJobCreatedEvent.class);
        verify(publisher).publishEvent(captor.capture());
        DmsSearchIndexTask task = captor.getValue().getTask();
        assertEquals("tenant-1", task.getTenantId());
        assertEquals(documentId, task.getDocumentId());
        assertEquals(versionId, task.getFileVersionId());
        assertEquals("a".repeat(64), task.getChecksumSha256());
    }
 
    @Test
    void doesNothingWhenSearchIsDisabled() {
        DmsSearchProperties properties = new DmsSearchProperties();
        ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
        DmsSearchIndexJobService service = new DmsSearchIndexJobService(properties, publisher);
 
        service.enqueueContentUpsert("tenant-1", UUID.randomUUID(), UUID.randomUUID(), null);
 
        verify(publisher, never()).publishEvent(org.mockito.ArgumentMatchers.any());
    }
}