StreamingManagerImpl implements StreamingManager { @Subscribe public void handleStreamingEvent(final StreamingEvent event) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("handle streaming event: {}", event); } try { if (event.isSuccess()) { switch (event.getType()) { case PLAY: case RESUME: sessionDao.updateSessionStatus(event.getDeviceId(), PLAYING); break; case STOP: sessionDao.updateSessionStatus(event.getDeviceId(), WAITING); break; case PAUSE: sessionDao.updateSessionStatus(event.getDeviceId(), PAUSED); break; case STATUS: sessionDao.updateSessionPosition(event.getDeviceId(), event.getPosition(), event.getDuration()); break; default: break; } } else { LOGGER.error("Type: {} - Device: {} - Error: {}", event.getType(), event.getDeviceId(), event.getErrorMessage()); } } catch (UnknownSessionException e) { LOGGER.error(e.getMessage(), e); } } @Inject  StreamingManagerImpl(final ConfigurationManager configurationManager, final DeviceDao deviceDao, final SessionDao sessionDao,
                                @Named("upnp") final DeviceStreamer upnpStreamer,
                                @Named("airplay") final DeviceStreamer airplayStreamer); @Override void addDevice(final Device device); @Override void removeDevice(final String deviceId); @Override Collection<Device> findDevices(final String hostAddress); @Override Collection<Device> getDevices(); @Override Device getDevice(final String deviceId); @Override StreamingSession getSession(final String deviceId); @Override @SuppressWarnings("unchecked") void play(final String deviceId, final String contentUrl, final MediaNode node); @Override @SuppressWarnings("unchecked") void stop(final String deviceId); @Override @SuppressWarnings("unchecked") void pause(final String deviceId); @Override @SuppressWarnings("unchecked") void resume(final String deviceId); @Subscribe void handleStreamingEvent(final StreamingEvent event);  }
@Test public void testHandleErrorStreamingEvent() { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(STATUS, "deviceId", "errorMessage")); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test public void testHandleUnknownSessionStreamingEvent() throws Exception { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); sessionDao.updateSessionStatus("deviceId", PLAYING); expectLastCall().andThrow(new UnknownSessionException("deviceId")); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(PLAY, "deviceId", 0l, 0l)); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test public void testHandleUnknownStreamingEvent() throws Exception { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(UNKNOWN, "deviceId", 0l, 0l)); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test public void testHandlePlayStreamingEvent() throws Exception { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); sessionDao.updateSessionStatus("deviceId", PLAYING); expectLastCall(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(PLAY, "deviceId", 0l, 0l)); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test public void testHandleResumeStreamingEvent() throws Exception { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); sessionDao.updateSessionStatus("deviceId", PLAYING); expectLastCall(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(RESUME, "deviceId", 0l, 0l)); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test public void testHandleStopStreamingEvent() throws Exception { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); sessionDao.updateSessionStatus("deviceId", WAITING); expectLastCall(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(STOP, "deviceId", 0l, 0l)); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test public void testHandlePauseStreamingEvent() throws Exception { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); sessionDao.updateSessionStatus("deviceId", PAUSED); expectLastCall(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(PAUSE, "deviceId", 0l, 0l)); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }
@Test public void testHandleStatusStreamingEvent() throws Exception { DeviceDao deviceDao = createMock(DeviceDao.class); SessionDao sessionDao = createMock(SessionDao.class); DeviceStreamer upnpDeviceStreamer = createMock(DeviceStreamer.class); DeviceStreamer airplayDeviceStreamer = createMock(DeviceStreamer.class); ConfigurationManager configurationManager = createMock(ConfigurationManager.class); expect(configurationManager.getParameter(STREAMING_STATUS_UPDATE_DELAY_SECONDS)).andReturn(0).atLeastOnce(); sessionDao.updateSessionPosition("deviceId", 0l, 0l); expectLastCall(); replay(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); StreamingManagerImpl streamingManager = new StreamingManagerImpl(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); streamingManager.handleStreamingEvent(new StreamingEvent(STATUS, "deviceId", 0l, 0l)); verify(configurationManager, deviceDao, sessionDao, upnpDeviceStreamer, airplayDeviceStreamer); }