StreamingHandler { @GET @Path("/status/{deviceId}") @Produces(APPLICATION_JSON) public PlaybackStatus status(@PathParam("deviceId") final String deviceId) { PlaybackStatus status = new PlaybackStatus(); try { StreamingSession session = streamingManager.getSession(deviceId); status.setContentName(session.getContentName()); status.setDuration(session.getDuration()); status.setPosition(session.getPosition()); } catch (UnknownSessionException e) { LOGGER.error(e.getMessage(), e); status.setErrorMessage(e.getMessage()); } return status; } @Inject  StreamingHandler(final MediaManager mediaManager, final StreamingManager streamingManager); @GET @Path("/devices") @Produces(APPLICATION_JSON) List<PlaybackDevice> getDevices(); @GET @Path("/play/{deviceId}/{contentId}") @Produces(TEXT_PLAIN) String play(@PathParam("deviceId") final String deviceId, @PathParam("contentId") final String contentId); @GET @Path("/pause/{deviceId}") @Produces(TEXT_PLAIN) String pause(@PathParam("deviceId") final String deviceId); @GET @Path("/stop/{deviceId}") @Produces(TEXT_PLAIN) String stop(@PathParam("deviceId") final String deviceId); @GET @Path("/resume/{deviceId}") @Produces(TEXT_PLAIN) String resume(@PathParam("deviceId") final String deviceId); @GET @Path("/status/{deviceId}") @Produces(APPLICATION_JSON) PlaybackStatus status(@PathParam("deviceId") final String deviceId); @GET @Path("/browse/{deviceId}/{nodeId}") @Produces(APPLICATION_JSON) DeviceBrowseResult browse(@PathParam("deviceId") final String deviceId, @PathParam("nodeId") final String nodeId);  }
@Test public void testStatusOK() throws UnknownSessionException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); StreamingSession session = new StreamingSession("contentName", "contentUrl"); expect(streamingManager.getSession(eq("deviceId"))).andReturn(session).atLeastOnce(); replay(mediaManager, streamingManager); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); PlaybackStatus result = streamingHandler.status("deviceId"); assertNotNull(result); assertEquals(result.getContentName(), session.getContentName()); assertEquals(result.getDuration(), session.getDuration().longValue()); assertEquals(result.getPosition(), session.getPosition().longValue()); verify(mediaManager, streamingManager); }
@Test public void testStatusKO() throws UnknownSessionException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); expect(streamingManager.getSession(eq("deviceId"))).andThrow(new UnknownSessionException("deviceId")); replay(mediaManager, streamingManager); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); PlaybackStatus result = streamingHandler.status("deviceId"); assertNotNull(result); assertNotNull(result.getErrorMessage()); assertTrue(result.getErrorMessage().contains("deviceId")); verify(mediaManager, streamingManager); }