Search in sources :

Example 1 with LibraryPresenceDao

use of com.github.hakko.musiccabinet.dao.LibraryPresenceDao in project musiccabinet by hakko.

the class LibraryPresenceServiceTest method delegatesHandlingOfAddedAndDeletedResources.

@Test
public void delegatesHandlingOfAddedAndDeletedResources() {
    LibraryPresenceDao presenceDao = mock(LibraryPresenceDao.class);
    when(presenceDao.getFiles(dir1)).thenReturn(set(file1, file2, file3));
    when(presenceDao.getSubdirectories(dir1)).thenReturn(set(dir2));
    presenceService.setLibraryPresenceDao(presenceDao);
    file2b.setSize(file2.getSize() + 1);
    PollableChannel presenceChannel = presenceService.libraryPresenceChannel;
    presenceChannel.send(LibraryUtil.msg(dir1, set(dir2), set(file1, file2b)));
    presenceChannel.send(FINISHED_MESSAGE);
    presenceService.receive();
    Message<?> additionMessage, deletionMessage;
    assertNotNull(additionMessage = presenceService.libraryMetadataChannel.receive());
    assertNotNull(deletionMessage = presenceService.libraryDeletionChannel.receive());
    assertEquals(FINISHED_MESSAGE, presenceService.libraryMetadataChannel.receive());
    assertEquals(FINISHED_MESSAGE, presenceService.libraryDeletionChannel.receive());
    Set<File> addedFiles = ((DirectoryContent) additionMessage.getPayload()).getFiles();
    Set<File> deletedFiles = ((DirectoryContent) deletionMessage.getPayload()).getFiles();
    assertEquals(set(file2b), addedFiles);
    assertEquals(set(file2, file3), deletedFiles);
}
Also used : PollableChannel(org.springframework.integration.core.PollableChannel) DirectoryContent(com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent) LibraryPresenceDao(com.github.hakko.musiccabinet.dao.LibraryPresenceDao) UnittestLibraryUtil.getFile(com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile) File(com.github.hakko.musiccabinet.domain.model.library.File) Test(org.junit.Test)

Aggregations

LibraryPresenceDao (com.github.hakko.musiccabinet.dao.LibraryPresenceDao)1 DirectoryContent (com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent)1 File (com.github.hakko.musiccabinet.domain.model.library.File)1 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)1 Test (org.junit.Test)1 PollableChannel (org.springframework.integration.core.PollableChannel)1