@Before public void setUp() { MockitoAnnotations.initMocks(this); pathResolver.setApi(api); final Map<String, Path> paths = new HashMap<>(); // TreeMap<>((Comparator<String>) (path1, path2) -> // path2.compareTo(path1)); paths.putAll( new HashMap<String, Path>() { { Path p1 = new Path(); p1.setPath("/"); put(p1.getPath(), p1); Path p2 = new Path(); p2.setPath("/products"); put(p2.getPath(), p2); Path p3 = new Path(); p3.setPath("/stores"); put(p3.getPath(), p3); Path p4 = new Path(); p4.setPath("/stores/:storeId"); put(p4.getPath(), p4); } }); Proxy proxy = new Proxy(); proxy.setContextPath("/"); when(api.getProxy()).thenReturn(proxy); when(api.getPaths()).thenReturn(paths); }
@Test public void resolve_exactPath() { when(request.path()).thenReturn("/stores"); Path path = pathResolver.resolve(request); Assert.assertNotNull(path); Assert.assertEquals("/stores", path.getPath()); }
@Test public void resolve_root() { when(request.path()).thenReturn("/myapi"); Path path = pathResolver.resolve(request); Assert.assertNotNull(path); Assert.assertEquals("/", path.getPath()); }
@Test public void resolve_pathParameterizedPath_mustReturnRoot2() { when(request.path()).thenReturn("/weather_invalidpath"); Path path = pathResolver.resolve(request); Assert.assertNotNull(path); Assert.assertEquals("/", path.getPath()); }
@Test public void resolve_noParameterizedPath_checkChildren() { when(request.path()).thenReturn("/products/99/data"); Path path = pathResolver.resolve(request); Assert.assertNotNull(path); Assert.assertEquals("/products", path.getPath()); }
@Test public void resolve_pathParameterizedPath() { when(request.path()).thenReturn("/stores/99"); Path path = pathResolver.resolve(request); Assert.assertNotNull(path); Assert.assertEquals("/stores/:storeId", path.getPath()); }