コード例 #1
0
  @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);
  }
コード例 #2
0
  @Test
  public void resolve_exactPath() {
    when(request.path()).thenReturn("/stores");

    Path path = pathResolver.resolve(request);
    Assert.assertNotNull(path);

    Assert.assertEquals("/stores", path.getPath());
  }
コード例 #3
0
  @Test
  public void resolve_root() {
    when(request.path()).thenReturn("/myapi");

    Path path = pathResolver.resolve(request);
    Assert.assertNotNull(path);

    Assert.assertEquals("/", path.getPath());
  }
コード例 #4
0
  @Test
  public void resolve_pathParameterizedPath_mustReturnRoot2() {
    when(request.path()).thenReturn("/weather_invalidpath");

    Path path = pathResolver.resolve(request);
    Assert.assertNotNull(path);

    Assert.assertEquals("/", path.getPath());
  }
コード例 #5
0
  @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());
  }
コード例 #6
0
  @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());
  }