ExecutorPathResolver { public String getExecutorPath(String path) { String executorPath = path; if (Validator.isNull(executorPath)) { executorPath = StringPool.SLASH; } while (!executorPath.isEmpty() && !_availableExecutorPaths.contains(executorPath)) { int index = executorPath.lastIndexOf(StringPool.SLASH); executorPath = executorPath.substring(0, index); } if (!executorPath.isEmpty()) { return executorPath; } return ROOT_EXECUTOR_PATH; } ExecutorPathResolver(Set<String> availableExecutorPaths); String getExecutorPath(String path); List<String> getNextExecutorsPaths(String path); static final String ROOT_EXECUTOR_PATH; }
@Test public void testGetExactMatchExecutor() { Assert.assertEquals("/", _executorPathResolver.getExecutorPath("/")); Assert.assertEquals( "/server", _executorPathResolver.getExecutorPath("/server")); Assert.assertEquals( "/plugins", _executorPathResolver.getExecutorPath("/plugins")); }
@Test public void testGetNullPathMatchExecutor() { Assert.assertEquals("/", _executorPathResolver.getExecutorPath(null)); Assert.assertEquals("/", _executorPathResolver.getExecutorPath("")); }
@Test public void testGetPartialMatchExecutor() { Assert.assertEquals("/", _executorPathResolver.getExecutorPath("/xyz")); Assert.assertEquals( "/server/log", _executorPathResolver.getExecutorPath("/server/log/xyz")); Assert.assertEquals( "/plugins", _executorPathResolver.getExecutorPath("/plugins/xyz")); }