StreamingHandler { @GET @Path("/play/{deviceId}/{contentId}") @Produces(TEXT_PLAIN) public String play(@PathParam("deviceId") final String deviceId, @PathParam("contentId") final String contentId) { Optional<MediaNode> contentNode = mediaManager.getNode(contentId); String url = mediaManager.getNodeUrl(contentNode.get()); try { streamingManager.play(deviceId, url, contentNode.get()); } catch (UnknownDeviceException e) { LOGGER.error(e.getMessage(), e); return e.getMessage(); } return null; } @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 testPlayOK() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); ContentNode contentNode = new ContentNode("id", "parentId", "name", new File("file"), MimeType.valueOf("video/x-msvideo")); expect(mediaManager.getNode(eq("contentId"))).andReturn(Optional.of(contentNode)).atLeastOnce(); expect(mediaManager.getNodeUrl(isA(AbstractNode.class))).andReturn("contentUrl").atLeastOnce(); streamingManager.play(eq("deviceId"), eq("contentUrl"), isA(AbstractNode.class)); expectLastCall().atLeastOnce(); replay(mediaManager, streamingManager); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); String result = streamingHandler.play("deviceId", "contentId"); assertNull(result); verify(mediaManager, streamingManager); }
@Test public void testPlayKO() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); ContentNode contentNode = new ContentNode("id", "parentId", "name", new File("file"), MimeType.valueOf("video/x-msvideo")); expect(mediaManager.getNode(eq("contentId"))).andReturn(Optional.of(contentNode)).atLeastOnce(); expect(mediaManager.getNodeUrl(isA(AbstractNode.class))).andReturn("contentUrl").atLeastOnce(); streamingManager.play(eq("deviceId"), eq("contentUrl"), isA(AbstractNode.class)); expectLastCall().andThrow(new UnknownDeviceException("deviceId")).atLeastOnce(); replay(mediaManager, streamingManager); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); String result = streamingHandler.play("deviceId", "contentId"); assertNotNull(result); assertTrue(result.contains("deviceId")); verify(mediaManager, streamingManager); }