StreamingHandler { @GET @Path("/browse/{deviceId}/{nodeId}") @Produces(APPLICATION_JSON) public DeviceBrowseResult browse(@PathParam("deviceId") final String deviceId, @PathParam("nodeId") final String nodeId) { DeviceBrowseResult result = new DeviceBrowseResult(); result.setParentNodeId(nodeId); try { Device device = streamingManager.getDevice(deviceId); Optional<MediaNode> node = mediaManager.getNode(nodeId); if (!node.isPresent() && device.isVideoSupported()) { node = mediaManager.getNode(VIDEO.getId()); } if (node.isPresent()) { addBrowseResult(result, device, node.get()); } } catch (UnknownDeviceException e) { LOGGER.error(e.getMessage(), e); result.setErrorMessage(e.getMessage()); } return result; } @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 testBrowseRootVideoNotSupported() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); Device device = createMock(Device.class); expect(streamingManager.getDevice(eq("deviceId"))).andReturn(device).atLeastOnce(); expect(mediaManager.getNode(eq("0"))).andReturn(Optional.empty()).atLeastOnce(); expect(device.isVideoSupported()).andReturn(false).atLeastOnce(); replay(mediaManager, streamingManager, device); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); DeviceBrowseResult result = streamingHandler.browse("deviceId", "0"); assertNotNull(result); assertEquals(result.getParentNodeId(), "0"); verify(mediaManager, streamingManager, device); }
@Test public void testBrowseRootVideoSupported() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); Device device = createMock(Device.class); FolderNode videoRootNode = new FolderNode(VIDEO.getId(), VIDEO.getParentId(), VIDEO.getId()); ContentNode contentNode = new ContentNode("id", "parentId", "name", new File("file"), MimeType.valueOf("video/x-msvideo")); FolderNode folderNode = new FolderNode("id", "parentId", "name"); Collection<MediaNode> searchResult = newArrayList(contentNode, folderNode); expect(streamingManager.getDevice(eq("deviceId"))).andReturn(device).atLeastOnce(); expect(mediaManager.getNode(eq("0"))).andReturn(Optional.empty()).atLeastOnce(); expect(mediaManager.getNode(eq(VIDEO.getId()))).andReturn(Optional.of(videoRootNode)).atLeastOnce(); expect(mediaManager.searchChildNodes(isA(MediaSearchRequest.class))).andReturn(searchResult).atLeastOnce(); expect(mediaManager.getNodeUrl(isA(AbstractNode.class))).andReturn("nodeUrl").atLeastOnce(); expect(device.isVideoSupported()).andReturn(true).atLeastOnce(); expect(device.getSupportedMimeTypes()).andReturn(null).atLeastOnce(); replay(mediaManager, streamingManager, device); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); DeviceBrowseResult result = streamingHandler.browse("deviceId", "0"); assertNotNull(result); assertEquals(result.getParentNodeId(), "0"); assertEquals(1, result.getContents().size()); assertEquals(1, result.getFolders().size()); verify(mediaManager, streamingManager, device); }
@Test public void testBrowseValidNode() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); Device device = createMock(Device.class); FolderNode node = new FolderNode("nodeId", "nodeParentId", "nodeName"); ContentNode contentNode = new ContentNode("idContent", "parentId", "nameContent", new File("file"), MimeType.valueOf("video/x-msvideo")); FolderNode folderNode = new FolderNode("idFolder", "parentId", "nameFolder"); Collection<MediaNode> searchResult = newArrayList(contentNode, folderNode); expect(streamingManager.getDevice(eq("deviceId"))).andReturn(device).atLeastOnce(); expect(mediaManager.getNode(eq("nodeId"))).andReturn(Optional.of(node)).atLeastOnce(); expect(mediaManager.searchChildNodes(isA(MediaSearchRequest.class))).andReturn(searchResult).atLeastOnce(); expect(mediaManager.getNodeUrl(isA(AbstractNode.class))).andReturn("nodeUrl").atLeastOnce(); expect(device.getSupportedMimeTypes()).andReturn(null).atLeastOnce(); replay(mediaManager, streamingManager, device); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); DeviceBrowseResult result = streamingHandler.browse("deviceId", "nodeId"); assertNotNull(result); assertEquals(result.getParentNodeId(), "nodeId"); assertEquals(1, result.getContents().size()); BrowseContent browseContent = result.getContents().get(0); assertEquals("idContent", browseContent.getNodeId()); assertEquals("nameContent", browseContent.getContentName()); assertEquals("nodeUrl", browseContent.getContentUrl()); assertEquals(1, result.getFolders().size()); BrowseFolder browseFolder = result.getFolders().get(0); assertEquals("idFolder", browseFolder.getNodeId()); assertEquals("nameFolder", browseFolder.getFolderName()); verify(mediaManager, streamingManager, device); }
@Test public void testBrowseUnknownDevice() throws UnknownDeviceException { MediaManager mediaManager = createMock(MediaManager.class); StreamingManager streamingManager = createMock(StreamingManager.class); Device device = createMock(Device.class); expect(streamingManager.getDevice(eq("deviceId"))).andThrow(new UnknownDeviceException("deviceId")); replay(mediaManager, streamingManager, device); StreamingHandler streamingHandler = new StreamingHandler(mediaManager, streamingManager); DeviceBrowseResult result = streamingHandler.browse("deviceId", "0"); assertNotNull(result); assertEquals(result.getParentNodeId(), "0"); assertTrue(result.getErrorMessage().contains("deviceId")); verify(mediaManager, streamingManager, device); }