Example #1
0
  @Test
  public void testReplaceMatrixParams() {
    UriBuilder ubu =
        UriBuilder.fromUri("http://localhost:8080/a/b/c;a=x;b=y")
            .replaceMatrixParam("a", "z", "zz");

    {
      URI uri = ubu.build();
      List<PathSegment> ps = UriComponent.decodePath(uri, true);
      MultivaluedMap<String, String> mps = ps.get(2).getMatrixParameters();
      List<String> a = mps.get("a");
      Assert.assertEquals(2, a.size());
      Assert.assertEquals("z", a.get(0));
      Assert.assertEquals("zz", a.get(1));
      List<String> b = mps.get("b");
      Assert.assertEquals(1, b.size());
      Assert.assertEquals("y", b.get(0));
    }

    {
      URI uri = ubu.replaceMatrixParam("a", "_z_", "_zz_").build();
      List<PathSegment> ps = UriComponent.decodePath(uri, true);
      MultivaluedMap<String, String> mps = ps.get(2).getMatrixParameters();
      List<String> a = mps.get("a");
      Assert.assertEquals(2, a.size());
      Assert.assertEquals("_z_", a.get(0));
      Assert.assertEquals("_zz_", a.get(1));
      List<String> b = mps.get("b");
      Assert.assertEquals(1, b.size());
      Assert.assertEquals("y", b.get(0));
    }

    {
      URI uri =
          UriBuilderImpl.fromUri("http://localhost:8080/a/b/c;a=x;b=y")
              .replaceMatrixParam("a", "z", "zz")
              .matrixParam("c", "c")
              .path("d")
              .build();

      List<PathSegment> ps = UriComponent.decodePath(uri, true);
      MultivaluedMap<String, String> mps = ps.get(2).getMatrixParameters();
      List<String> a = mps.get("a");
      Assert.assertEquals(2, a.size());
      Assert.assertEquals("z", a.get(0));
      Assert.assertEquals("zz", a.get(1));
      List<String> b = mps.get("b");
      Assert.assertEquals(1, b.size());
      Assert.assertEquals("y", b.get(0));
      List<String> c = mps.get("c");
      Assert.assertEquals(1, c.size());
      Assert.assertEquals("c", c.get(0));
    }
  }
Example #2
0
 @Test
 public void testReplaceMatrixParamsEmpty() {
   UriBuilder ubu =
       UriBuilder.fromUri("http://localhost:8080/a/b/c").replaceMatrixParam("a", "z", "zz");
   {
     URI uri = ubu.build();
     List<PathSegment> ps = UriComponent.decodePath(uri, true);
     MultivaluedMap<String, String> mps = ps.get(2).getMatrixParameters();
     List<String> a = mps.get("a");
     Assert.assertEquals(2, a.size());
     Assert.assertEquals("z", a.get(0));
     Assert.assertEquals("zz", a.get(1));
   }
 }