AecuServiceImpl implements AecuService { protected String getFallbackScript(ResourceResolver resolver, String path) { String name = path.substring(path.lastIndexOf('/') + 1); if (name.contains(".fallback.") || DIR_FALLBACK_SCRIPT.equals(name)) { return null; } String baseName = name.substring(0, name.indexOf('.')); String fallbackPath = path.substring(0, path.lastIndexOf('/') + 1) + baseName + ".fallback.groovy"; if (resolver.getResource(fallbackPath) != null) { return fallbackPath; } String directoryFallbackPath = path.substring(0, path.lastIndexOf('/') + 1) + DIR_FALLBACK_SCRIPT; if (resolver.getResource(directoryFallbackPath) != null) { return directoryFallbackPath; } return null; }  @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 public void getFallbackScript_Exists() { when(resolver.getResource("/path/to/script.fallback.groovy")).thenReturn(mock(Resource.class)); assertEquals("/path/to/script.fallback.groovy", service.getFallbackScript(resolver, "/path/to/script.always.groovy")); assertEquals("/path/to/script.fallback.groovy", service.getFallbackScript(resolver, "/path/to/script.groovy")); }
@Test public void getFallbackScript_NotExists() { assertNull(service.getFallbackScript(resolver, "/path/to/script.always.groovy")); assertNull(service.getFallbackScript(resolver, "/path/to/script.groovy")); }
@Test public void getFallbackScript_Fallback() { verify(resolver, never()).getResource("/path/to/script.fallback.groovy"); assertNull(service.getFallbackScript(resolver, "/path/to/script.fallback.groovy")); }
@Test public void getFallbackScript_DirectoryLevel() { when(resolver.getResource("/path/to/script1.fallback.groovy")).thenReturn(mock(Resource.class)); when(resolver.getResource("/path/to/fallback.groovy")).thenReturn(mock(Resource.class)); assertEquals("/path/to/script1.fallback.groovy", service.getFallbackScript(resolver, "/path/to/script1.always.groovy")); assertEquals("/path/to/script1.fallback.groovy", service.getFallbackScript(resolver, "/path/to/script1.groovy")); assertEquals("/path/to/fallback.groovy", service.getFallbackScript(resolver, "/path/to/script2.always.groovy")); assertEquals("/path/to/fallback.groovy", service.getFallbackScript(resolver, "/path/to/script2.groovy")); }
@Test public void getFallbackScript_DirectoryLevelFallback() { verify(resolver, never()).getResource("/path/to/fallback.groovy"); assertNull(service.getFallbackScript(resolver, "/path/to/fallback.groovy")); }