/** * Reads a list of entries from a path by filtering the files by a given filter. * @param rootPath a path for looking of the VFSRegistryEntry files. * @param filter a filter for selecting the files. * @return a list with the unmarshalled objects backed by the filtered files. */ public List<Object> readEntries(final Path rootPath, final DirectoryStream.Filter<Path> filter) throws Exception { final List<Object> entries = new ArrayList<>(); for (Path path : ioService.newDirectoryStream(rootPath, filter)) { try { entries.add(readEntry(path)); } catch (Exception e) { logger.error("An error was produced while processing entry for path: " + path, e); throw e; } } return entries; }
@Test public void testReadEntry() throws Exception { when(ioService.readAllString(path)).thenReturn(MARSHALLED_ENTRY); when(entryMarshaller.unmarshal(MARSHALLED_ENTRY)).thenReturn(entry); when(entry.getContentType()).thenReturn(Object.class.getName()); when(entry.getContent()).thenReturn(MARSHALLED_VALUE); when(marshallerRegistry.get(any(Class.class))).thenReturn(marshaller); Object unmarshalledValue = mock(Object.class); when(marshaller.unmarshal(MARSHALLED_VALUE)).thenReturn(unmarshalledValue); Object result = registryHelper.readEntry(path); assertEquals(unmarshalledValue, result); }
@Test public void testReadEntry() throws Exception { when(ioService.readAllString(path)).thenReturn(MARSHALLED_ENTRY); when(entryMarshaller.unmarshal(MARSHALLED_ENTRY)).thenReturn(entry); when(entry.getContentType()).thenReturn(Object.class.getName()); when(entry.getContent()).thenReturn(MARSHALLED_VALUE); when(marshallerRegistry.get(any(Class.class))).thenReturn(marshaller); Object unmarshalledValue = mock(Object.class); when(marshaller.unmarshal(MARSHALLED_VALUE)).thenReturn(unmarshalledValue); Object result = registryHelper.readEntry(path); assertEquals(unmarshalledValue, result); }
@Test public void testReadEntryWhenMarshallerNotExists() throws Exception { when(ioService.readAllString(path)).thenReturn(MARSHALLED_ENTRY); when(entryMarshaller.unmarshal(MARSHALLED_ENTRY)).thenReturn(entry); when(entry.getContentType()).thenReturn(Object.class.getName()); when(marshallerRegistry.get(Object.class.getClass())).thenReturn(null); expectedException.expectMessage("No marshaller was found for class: " + entry.getContentType()); registryHelper.readEntry(path); }
@Test public void testReadEntryWhenMarshallerNotExists() throws Exception { when(ioService.readAllString(path)).thenReturn(MARSHALLED_ENTRY); when(entryMarshaller.unmarshal(MARSHALLED_ENTRY)).thenReturn(entry); when(entry.getContentType()).thenReturn(Object.class.getName()); when(marshallerRegistry.get(Object.class.getClass())).thenReturn(null); expectedException.expectMessage("No marshaller was found for class: " + entry.getContentType()); registryHelper.readEntry(path); }
@Test public void testReadEntries() throws Exception { prepareReadEntries(); List<Object> result = registryHelper.readEntries(rootPath, filter); assertEquals(expectedObjects, result); for (Path path : entryPaths) { verify(registryHelper, times(1)).readEntry(path); } }
@Test public void testReadEntries() throws Exception { prepareReadEntries(); List<Object> result = registryHelper.readEntries(rootPath, filter); assertEquals(expectedObjects, result); for (Path path : entryPaths) { verify(registryHelper, times(1)).readEntry(path); } }