@Test public void testLookupHandler() { registerHandler("root", "CompaniesHandler", "/companies", "/companies/{company}", "/companies/{company}/{id}"); registerHandler("root", "StocksHandler", "/stocks/{stock}", "/stocks/{stock}/{currency}"); registerHandler("root", "DirectorsHandler", "/directors", "/directors/director", "/directors/director/{personId}"); registerHandler("root", "InfoHandler", "/info", "/info/jvm", "/info/jvm/{format}", "/info/{format}/{encoding}"); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/dummy").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/fake/").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/stocks").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/stocks/2/USD/1").getStatus()); assertInvocation(resourceManager.lookupResource(GET, "/root/stocks/2"), "StocksHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/stocks/2/USD"), "StocksHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/directors"), "DirectorsHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/directors/director"), "DirectorsHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/directors/director/John"), "DirectorsHandler"); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/directors/1345").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/directors/director/Tim/123").getStatus()); assertInvocation(resourceManager.lookupResource(GET, "/root/companies"), "CompaniesHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info"), "InfoHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info/jvm"), "InfoHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info/jvm/json"), "InfoHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info/json/zip"), "InfoHandler"); }
@Override public LookupResult lookupResource(Method method, String path, String action) { List<PathItem> pathItems = Arrays.stream(path.replaceAll(" .map(s -> s.isEmpty() ? "/" : s).map(QueryStringDecoder::decodeComponent).map(PathItem::fromString).collect(Collectors.toList()); return resourceTree.find(method, pathItems, action); }
ResourceManagerImpl implements ResourceManager { @Override public LookupResult lookupResource(Method method, String path, String action) { List<PathItem> pathItems = Arrays.stream(path.replaceAll(" .map(s -> s.isEmpty() ? "/" : s).map(QueryStringDecoder::decodeComponent).map(PathItem::fromString).collect(Collectors.toList()); return resourceTree.find(method, pathItems, action); } }
ResourceManagerImpl implements ResourceManager { @Override public LookupResult lookupResource(Method method, String path, String action) { List<PathItem> pathItems = Arrays.stream(path.replaceAll(" .map(s -> s.isEmpty() ? "/" : s).map(QueryStringDecoder::decodeComponent).map(PathItem::fromString).collect(Collectors.toList()); return resourceTree.find(method, pathItems, action); } ResourceManagerImpl(); }
ResourceManagerImpl implements ResourceManager { @Override public LookupResult lookupResource(Method method, String path, String action) { List<PathItem> pathItems = Arrays.stream(path.replaceAll(" .map(s -> s.isEmpty() ? "/" : s).map(QueryStringDecoder::decodeComponent).map(PathItem::fromString).collect(Collectors.toList()); return resourceTree.find(method, pathItems, action); } ResourceManagerImpl(); @Override void registerResource(String context, ResourceHandler handler); @Override LookupResult lookupResource(Method method, String path, String action); }
ResourceManagerImpl implements ResourceManager { @Override public LookupResult lookupResource(Method method, String path, String action) { List<PathItem> pathItems = Arrays.stream(path.replaceAll(" .map(s -> s.isEmpty() ? "/" : s).map(QueryStringDecoder::decodeComponent).map(PathItem::fromString).collect(Collectors.toList()); return resourceTree.find(method, pathItems, action); } ResourceManagerImpl(); @Override void registerResource(String context, ResourceHandler handler); @Override LookupResult lookupResource(Method method, String path, String action);  }