Search in sources :

Example 6 with PollableChannel

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

the class ScrobbleServiceTest method skipsIdenticalScrobble.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void skipsIdenticalScrobble() throws InterruptedException, ApplicationException {
    // a second scrobble of the same track is just silently thrown away.
    // verify by checking that it's the original scrobble (check startTime)
    // that remains in the queue when a dupe is scrobbled.
    Scrobble scrobble1 = new Scrobble(user1, track1, false);
    Thread.sleep(3);
    Scrobble scrobble2 = new Scrobble(user1, 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(1, scrobbleService.userScrobbles.keySet().size());
    assertEquals(1, scrobbleService.userScrobbles.get(scrobble1.getLastFmUser()).size());
    assertEquals(scrobble1.getStartTime(), scrobbleService.userScrobbles.get(scrobble1.getLastFmUser()).getFirst().getStartTime());
}
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 7 with PollableChannel

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

the class LibraryAdditionServiceTest method addsNestedDirectoriesAndFiles.

@Test
public void addsNestedDirectoriesAndFiles() {
    additionService.clearImport();
    PollableChannel additionChannel = additionService.libraryAdditionChannel;
    additionChannel.send(msg(dir2, new HashSet<String>(), set(file2a)));
    additionChannel.send(msg(dir1, set(dir2), set(file1a, file1b)));
    additionChannel.send(msg(null, set(dir1), new HashSet<File>()));
    additionChannel.send(FINISHED_MESSAGE);
    additionService.receive();
    additionService.updateLibrary();
    assertEquals(set(file1a, file1b), presenceDao.getFiles(dir1));
    assertEquals(set(file2a), presenceDao.getFiles(dir2));
}
Also used : PollableChannel(org.springframework.integration.core.PollableChannel) HashSet(java.util.HashSet) 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