Search in sources :

Example 1 with PollableChannel

use of org.springframework.integration.core.PollableChannel in project musiccabinet by hakko.

the class LibraryDeletionServiceTest method deletesNestedDirectoriesAndFiles.

@Test
public void deletesNestedDirectoriesAndFiles() {
    PollableChannel deletionChannel = deletionService.libraryDeletionChannel;
    deletionChannel.send(msg(dir1, set(dir2), set(file1a)));
    deletionChannel.send(FINISHED_MESSAGE);
    deletionService.receive();
    deletionService.updateLibrary();
    assertEquals(set(file1b), presenceDao.getFiles(dir1));
    assertFalse(presenceDao.exists(dir2));
}
Also used : PollableChannel(org.springframework.integration.core.PollableChannel) Test(org.junit.Test)

Example 2 with PollableChannel

use of org.springframework.integration.core.PollableChannel 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)

Example 3 with PollableChannel

use of org.springframework.integration.core.PollableChannel in project musiccabinet by hakko.

the class ScrobbleServiceTest method differentUsersCanScrobbleSameTrack.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void differentUsersCanScrobbleSameTrack() throws ApplicationException {
    Scrobble scrobble1 = new Scrobble(user1, track1, false);
    Scrobble scrobble2 = new Scrobble(user2, track1, false);
    Message message1 = new GenericMessage<Scrobble>(scrobble1);
    Message message2 = new GenericMessage<Scrobble>(scrobble2);
    PollableChannel scrobbleChannel = mock(PollableChannel.class);
    when(scrobbleChannel.receive()).thenReturn(message1, message2, null);
    scrobbleService.setScrobbleChannel(scrobbleChannel);
    scrobbleService.receive();
    assertNotNull(scrobbleService.userScrobbles);
    assertEquals(2, scrobbleService.userScrobbles.keySet().size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble1.getLastFmUser()).size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble2.getLastFmUser()).size());
}
Also used : GenericMessage(org.springframework.integration.message.GenericMessage) Message(org.springframework.integration.Message) GenericMessage(org.springframework.integration.message.GenericMessage) PollableChannel(org.springframework.integration.core.PollableChannel) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) Test(org.junit.Test)

Example 4 with PollableChannel

use of org.springframework.integration.core.PollableChannel in project musiccabinet by hakko.

the class ScrobbleServiceTest method previousScrobbleGetsRemovedOnImmediateOtherScrobble.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void previousScrobbleGetsRemovedOnImmediateOtherScrobble() throws InterruptedException, ApplicationException {
    // differently from test case above, a close subsequent scan of a
    // new track removes the previous scrobble from the queue (not the new).
    Scrobble scrobble1 = new Scrobble(user1, track1, false);
    Thread.sleep(3);
    Scrobble scrobble2 = new Scrobble(user1, track2, false);
    assertFalse(scrobble1.getStartTime().equals(scrobble2.getStartTime()));
    Message message1 = new GenericMessage<Scrobble>(scrobble1);
    Message message2 = new GenericMessage<Scrobble>(scrobble2);
    PollableChannel scrobbleChannel = mock(PollableChannel.class);
    when(scrobbleChannel.receive()).thenReturn(message1, message2, null);
    scrobbleService.setScrobbleChannel(scrobbleChannel);
    scrobbleService.receive();
    assertNotNull(scrobbleService.userScrobbles);
    assertEquals(1, scrobbleService.userScrobbles.keySet().size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble1.getLastFmUser()).size());
    assertEquals(track2Id, scrobbleService.userScrobbles.get(scrobble1.getLastFmUser()).getFirst().getTrack().getId());
}
Also used : GenericMessage(org.springframework.integration.message.GenericMessage) Message(org.springframework.integration.Message) GenericMessage(org.springframework.integration.message.GenericMessage) PollableChannel(org.springframework.integration.core.PollableChannel) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) Test(org.junit.Test)

Example 5 with PollableChannel

use of org.springframework.integration.core.PollableChannel in project musiccabinet by hakko.

the class ScrobbleServiceTest method scrobblerIgnoresTooNewSubmissions.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void scrobblerIgnoresTooNewSubmissions() throws ApplicationException {
    Scrobble scrobble = new Scrobble(user1, track1, false);
    Message message = new GenericMessage<Scrobble>(scrobble);
    PollableChannel scrobbleChannel = mock(PollableChannel.class);
    when(scrobbleChannel.receive()).thenReturn(message, (Message) null);
    scrobbleService.setScrobbleChannel(scrobbleChannel);
    scrobbleService.receive();
    scrobbleService.scrobbleTracks();
    assertNotNull(scrobbleService.userScrobbles);
    assertEquals(1, scrobbleService.userScrobbles.keySet().size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble.getLastFmUser()).size());
    scrobble.setStartTime(scrobble.getStartTime().minusSeconds(10));
    scrobbleService.scrobbleTracks();
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble.getLastFmUser()).size());
    scrobble.setStartTime(scrobble.getStartTime().minusMinutes(10));
    scrobbleService.scrobbleTracks();
    assertEquals(0, scrobbleService.userScrobbles.get(scrobble.getLastFmUser()).size());
}
Also used : GenericMessage(org.springframework.integration.message.GenericMessage) Message(org.springframework.integration.Message) GenericMessage(org.springframework.integration.message.GenericMessage) PollableChannel(org.springframework.integration.core.PollableChannel) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 PollableChannel (org.springframework.integration.core.PollableChannel)7 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)4 Message (org.springframework.integration.Message)4 GenericMessage (org.springframework.integration.message.GenericMessage)4 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 HashSet (java.util.HashSet)1