MediaDaoImpl implements MediaDao { @Override public Optional<MediaNode> getNode(final String nodeId) { Optional<MediaNode> node; MediaIndexElement indexElement = mediaIndexDao.get(nodeId); if (indexElement != null) { MediaType mediaType = MediaType.getByValue(indexElement.getMediaType()); node = getFileNode(nodeId, indexElement, mediaType); } else { LOGGER.warn("[getNode] {} not found in media index", nodeId); node = Optional.empty(); } return node; } @Inject  MediaDaoImpl(final ConfigurationManager configurationManager, final MimeTypeManager mimeTypeManager, final MediaIndexDao mediaIndexDao); @Override Optional<MediaNode> getNode(final String nodeId); @Override List<MediaNode> getChildNodes(final String parentNodeId); @Override List<MediaNode> getRootNodeChildren(final RootNode rootNode); @Override void cleanUpCache();  }
@Test public void testGetNodeNotInIndex() { ConfigurationManager configurationManager = new ConfigurationManagerImpl(new TestConfigurationDao()); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); MediaIndexDao mediaIndexDao = createMock(MediaIndexDao.class); expect(mediaIndexDao.get(eq("nodeId"))).andReturn(null); replay(mimeTypeManager, mediaIndexDao); MediaDaoImpl mediaDao = new MediaDaoImpl(configurationManager, mimeTypeManager, mediaIndexDao); Optional<MediaNode> result = mediaDao.getNode("nodeId"); assertNotNull(result); assertFalse(result.isPresent()); verify(mimeTypeManager, mediaIndexDao); }
@Test public void testGetBadFileNode() { ConfigurationManager configurationManager = new ConfigurationManagerImpl(new TestConfigurationDao()); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); MediaIndexDao mediaIndexDao = createMock(MediaIndexDao.class); MediaIndexElement videoElement = new MediaIndexElement(VIDEO.getId(), TYPE_VIDEO.getValue(), "video/avi", "path", "name", VIDEO.isLocalPath(), true); expect(mediaIndexDao.get(eq("nodeId"))).andReturn(videoElement); replay(mimeTypeManager, mediaIndexDao); MediaDaoImpl mediaDao = new MediaDaoImpl(configurationManager, mimeTypeManager, mediaIndexDao); Optional<MediaNode> result = mediaDao.getNode("nodeId"); assertNotNull(result); assertFalse(result.isPresent()); verify(mimeTypeManager, mediaIndexDao); }
@Test public void testGetVideoFolderNode() { ConfigurationManager configurationManager = new ConfigurationManagerImpl(new TestConfigurationDao()); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); MediaIndexDao mediaIndexDao = createMock(MediaIndexDao.class); ConfigurationNode videoNode = configurationManager.getNodes(VIDEO).get(0); MediaIndexElement videoElement = new MediaIndexElement(VIDEO.getId(), TYPE_VIDEO.getValue(), "video/avi", videoNode.getPath(), "name", VIDEO.isLocalPath(), true); expect(mediaIndexDao.get(eq("nodeId"))).andReturn(videoElement); replay(mimeTypeManager, mediaIndexDao); MediaDaoImpl mediaDao = new MediaDaoImpl(configurationManager, mimeTypeManager, mediaIndexDao); Optional<MediaNode> result = mediaDao.getNode("nodeId"); assertNotNull(result); assertTrue(result.isPresent()); assertEquals(result.get().getClass(), FolderNode.class); verify(mimeTypeManager, mediaIndexDao); }
@Test public void testGetVideoFolderNodeWithNoName() { ConfigurationManager configurationManager = new ConfigurationManagerImpl(new TestConfigurationDao()); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); MediaIndexDao mediaIndexDao = createMock(MediaIndexDao.class); ConfigurationNode videoNode = configurationManager.getNodes(VIDEO).get(0); MediaIndexElement videoElement = new MediaIndexElement(VIDEO.getId(), TYPE_VIDEO.getValue(), "video/avi", videoNode.getPath(), null, VIDEO.isLocalPath(), true); expect(mediaIndexDao.get(eq("nodeId"))).andReturn(videoElement); replay(mimeTypeManager, mediaIndexDao); MediaDaoImpl mediaDao = new MediaDaoImpl(configurationManager, mimeTypeManager, mediaIndexDao); Optional<MediaNode> result = mediaDao.getNode("nodeId"); assertNotNull(result); assertTrue(result.isPresent()); assertEquals(result.get().getClass(), FolderNode.class); verify(mimeTypeManager, mediaIndexDao); }
@Test public void testGetVideoFileNode() { ConfigurationManager configurationManager = new ConfigurationManagerImpl(new TestConfigurationDao()); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); MediaIndexDao mediaIndexDao = createMock(MediaIndexDao.class); ConfigurationNode videoNode = configurationManager.getNodes(VIDEO).get(0); Path videoFilePath = Paths.get(videoNode.getPath(), "video.avi"); MediaIndexElement videoElement = new MediaIndexElement(VIDEO.getId(), TYPE_VIDEO.getValue(), "video/avi", videoFilePath.toFile().getPath(), videoFilePath.toFile().getName(), VIDEO.isLocalPath(), true); expect(mediaIndexDao.get(eq("nodeId"))).andReturn(videoElement); expect(mimeTypeManager.getMimeType(eq("video.avi"))).andReturn(MimeType.valueOf("video/avi")); replay(mimeTypeManager, mediaIndexDao); MediaDaoImpl mediaDao = new MediaDaoImpl(configurationManager, mimeTypeManager, mediaIndexDao); Optional<MediaNode> result = mediaDao.getNode("nodeId"); assertNotNull(result); assertTrue(result.isPresent()); assertEquals(result.get().getClass(), ContentNode.class); verify(mimeTypeManager, mediaIndexDao); }
@Test public void testGetVideoFileNodeNoMimeType() { ConfigurationManager configurationManager = new ConfigurationManagerImpl(new TestConfigurationDao()); MimeTypeManager mimeTypeManager = createMock(MimeTypeManager.class); MediaIndexDao mediaIndexDao = createMock(MediaIndexDao.class); ConfigurationNode videoNode = configurationManager.getNodes(VIDEO).get(0); Path videoFilePath = Paths.get(videoNode.getPath(), "video.avi"); MediaIndexElement videoElement = new MediaIndexElement(VIDEO.getId(), TYPE_VIDEO.getValue(), "video/avi", videoFilePath.toFile().getPath(), videoFilePath.toFile().getName(), VIDEO.isLocalPath(), true); expect(mediaIndexDao.get(eq("nodeId"))).andReturn(videoElement); expect(mimeTypeManager.getMimeType(eq("video.avi"))).andReturn(null); replay(mimeTypeManager, mediaIndexDao); MediaDaoImpl mediaDao = new MediaDaoImpl(configurationManager, mimeTypeManager, mediaIndexDao); Optional<MediaNode> result = mediaDao.getNode("nodeId"); assertNotNull(result); assertFalse(result.isPresent()); verify(mimeTypeManager, mediaIndexDao); }