AecuServiceImpl implements AecuService { @Override public ExecutionResult execute(String path) throws AecuException { try (ResourceResolver resolver = resolverService.getContentMigratorResourceResolver()) { Resource resource = resolver.getResource(path); if (resource == null) { throw new AecuException("Path is invalid"); } if (!isValidScriptName(resource.getName())) { throw new AecuException("Invalid script name"); } return executeScript(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 execute_invalidResource() throws AecuException { service.execute("invalid"); }
@Test(expected = AecuException.class) public void execute_invalidFileName() throws AecuException { Resource resource = mock(Resource.class); when(resolver.getResource(DIR)).thenReturn(resource); when(resource.getName()).thenReturn("invalid"); service.execute(DIR); }
@Test public void execute() throws AecuException { Resource resource = mock(Resource.class); when(resolver.getResource(DIR)).thenReturn(resource); when(resource.getName()).thenReturn(FILE1); RunScriptResponse response = new RunScriptResponse(); when(groovyConsoleService.runScript(Mockito.any(), Mockito.any(), Mockito.eq(DIR))).thenReturn(response); service.execute(DIR); }