@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")); }
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; }
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; } }
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; }  }
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); }
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);  }