Ejemplo n.º 1
0
  @Test
  public void testExpressionWithTwoVars() throws Exception {
    URITemplate uriTemplate = new URITemplate("/{tenant : [^/]*}/resource/{id}");
    MultivaluedMap<String, String> values = new MetadataMap<String, String>();
    boolean match = uriTemplate.match("/t1/resource/1", values);
    assertTrue(match);
    String tenant = values.getFirst("tenant");
    assertEquals("t1", tenant);
    String id = values.getFirst("id");
    assertEquals("1", id);
    String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/", finalPath);

    values.clear();
    match = uriTemplate.match("//resource/1", values);
    assertTrue(match);
    tenant = values.getFirst("tenant");
    assertEquals("", tenant);
    id = values.getFirst("id");
    assertEquals("1", id);
    finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/", finalPath);

    values.clear();
    match = uriTemplate.match("/t1/resource/1/sub", values);
    assertTrue(match);
    tenant = values.getFirst("tenant");
    assertEquals("t1", tenant);
    id = values.getFirst("id");
    assertEquals("1", id);
    finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/sub", finalPath);
  }
Ejemplo n.º 2
0
  @Test
  public void testExpressionWithNestedGroupAndTwoVars2() throws Exception {
    URITemplate uriTemplate = new URITemplate("/foo/{bar}{resource:(/format/[^/]+?)?}");
    MultivaluedMap<String, String> values = new MetadataMap<String, String>();

    assertTrue(uriTemplate.match("/foo/1/format", values));
    assertEquals("1", values.getFirst("bar"));
    assertEquals("/format", values.getFirst("resource"));
    String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/", finalPath);
    values.clear();

    assertTrue(uriTemplate.match("/foo/1/format/2", values));
    assertEquals("1", values.getFirst("bar"));
    assertEquals("/format/2", values.getFirst("resource"));
    finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/", finalPath);
    values.clear();

    assertTrue(uriTemplate.match("/foo/1", values));
    assertEquals("1", values.getFirst("bar"));
    assertNull(values.getFirst("resource"));
    finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/", finalPath);
  }
 @Override
 public void reset() {
   if (committed) {
     throw new IllegalStateException(Messages.MESSAGES.alreadyCommitted());
   }
   outputHeaders.clear();
   outputHeaders.clear();
 }
Ejemplo n.º 4
0
  @Test
  public void testExpressionWithNestedGroup() throws Exception {
    URITemplate uriTemplate = new URITemplate("/{resource:.+\\.(js|css|gif|png)}");
    MultivaluedMap<String, String> values = new MetadataMap<String, String>();

    assertTrue(uriTemplate.match("/script.js", values));
    assertEquals("script.js", values.getFirst("resource"));
    String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/", finalPath);
    values.clear();

    assertTrue(uriTemplate.match("/script.js/bar", values));
    assertEquals("script.js", values.getFirst("resource"));
    finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/bar", finalPath);
    values.clear();

    assertFalse(uriTemplate.match("/script.pdf", values));
  }
Ejemplo n.º 5
0
  @Test
  public void testBasicCustomExpression4() throws Exception {
    URITemplate uriTemplate = new URITemplate("/books/{bookId:...\\.}");
    MultivaluedMap<String, String> values = new MetadataMap<String, String>();

    assertTrue(uriTemplate.match("/books/123.", values));
    assertEquals("123.", values.getFirst("bookId"));
    values.clear();
    assertTrue(uriTemplate.match("/books/abc.", values));
    assertEquals("abc.", values.getFirst("bookId"));
    assertFalse(uriTemplate.match("/books/abcd", values));
    assertFalse(uriTemplate.match("/books/abc", values));
  }
Ejemplo n.º 6
0
 @After
 public void tearDown() throws Exception {
   requestHeaders.clear();
 }
 public void clearAllMatrixParameters() {
   MultivaluedMap<String, String> matrixParameters = getMatrixParameters();
   matrixParameters.clear();
 }
 @Override
 public void clear() {
   delegate.clear();
 }
Ejemplo n.º 9
0
 public void reset() {
   requestHeaders.clear();
   response = null;
   currentBuilder = UriBuilder.fromUri(baseURI);
   templates = null;
 }