AecuServiceImpl implements AecuService { @Override public List<String> getFiles(String path) throws AecuException { try (ResourceResolver resolver = resolverService.getServiceResourceResolver()) { return findCandidates(resolver, path); } catch (LoginException e) { throw new AecuException(ERR_NO_RESOLVER, e); } }  @Override String getVersion(); @Override List<String> getFiles(String path); @Override boolean matchesRunmodes(String name); @Override boolean isValidScriptName(String name); @Override ExecutionResult execute(String path); @Override HistoryEntry createHistoryEntry(); @Override HistoryEntry finishHistoryEntry(HistoryEntry history); @Override HistoryEntry storeExecutionInHistory(HistoryEntry history, ExecutionResult result); @Override List<HistoryEntry> getHistory(int startIndex, int count);  }
@Test(expected = AecuException.class) public void getFiles_invalidPath() throws AecuException { service.getFiles(FILE1); }
@Test public void getFiles_validSinglePath() throws AecuException { Resource fileResource = mock(Resource.class); when(resolver.getResource(FILE1)).thenReturn(fileResource); when(fileResource.getName()).thenReturn(FILE1); ValueMap fileValues = mock(ValueMap.class); when(fileValues.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(JcrConstants.NT_FILE); when(fileResource.getValueMap()).thenReturn(fileValues); assertEquals(Arrays.asList(FILE1), service.getFiles(FILE1)); }
@Test public void getFiles_validDirectoryPath() throws AecuException { Resource dirResource = mock(Resource.class); when(resolver.getResource(DIR)).thenReturn(dirResource); when(dirResource.getName()).thenReturn("dir.author"); ValueMap dirValues = mock(ValueMap.class); when(dirValues.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(JcrResourceConstants.NT_SLING_FOLDER); when(dirResource.getValueMap()).thenReturn(dirValues); Resource fileResource = mock(Resource.class); when(resolver.getResource(DIR + "/" + FILE1)).thenReturn(fileResource); when(fileResource.getName()).thenReturn(FILE1); ValueMap fileValues = mock(ValueMap.class); when(fileValues.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(JcrConstants.NT_FILE); when(fileResource.getValueMap()).thenReturn(fileValues); when(fileResource.getPath()).thenReturn(DIR + "/" + FILE1); when(dirResource.getChildren()).thenReturn(Arrays.asList(fileResource)); when(dirResource.getChild(FILE1)).thenReturn(fileResource); assertEquals(Arrays.asList(DIR + "/" + FILE1), service.getFiles(DIR)); }
@Test public void getFiles_wrongRunmode() throws AecuException { Resource dirResource = mock(Resource.class); when(resolver.getResource(DIR)).thenReturn(dirResource); when(dirResource.getName()).thenReturn("dir.invalid"); ValueMap dirValues = mock(ValueMap.class); when(dirValues.get(JcrConstants.JCR_PRIMARYTYPE, String.class)).thenReturn(JcrResourceConstants.NT_SLING_FOLDER); when(dirResource.getValueMap()).thenReturn(dirValues); assertEquals(Arrays.asList(), service.getFiles(DIR)); }