Java Code Examples for javax.ws.rs.core.MultivaluedMap#clear()

The following examples show how to use javax.ws.rs.core.MultivaluedMap#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: URITemplateTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpressionWithNestedGroup() throws Exception {
    URITemplate uriTemplate = new URITemplate("/{resource:.+\\.(js|css|gif|png)}");
    MultivaluedMap<String, String> values = new MetadataMap<>();

    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));
}
 
Example 2
Source File: URITemplateTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpressionWithNestedGroupAndTwoVars2() throws Exception {
    URITemplate uriTemplate = new URITemplate("/foo/{bar}{resource:(/format/[^/]+?)?}");
    MultivaluedMap<String, String> values = new MetadataMap<>();

    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);
}
 
Example 3
Source File: HttpHeadersImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void testUnmodifiableRequestHeaders() throws Exception {

    MetadataMap<String, String> headers =
        createHeader(HttpHeaders.ACCEPT_LANGUAGE,
                     "en;q=0.7, en-gb;q=0.8, da");
    Message m = createMessage(headers);
    m.put(HttpHeadersImpl.HEADER_SPLIT_PROPERTY, "true");
    HttpHeaders h = new HttpHeadersImpl(m);
    List<Locale> languages = h.getAcceptableLanguages();
    assertEquals(3, languages.size());
    languages.clear();
    languages = h.getAcceptableLanguages();
    assertEquals(3, languages.size());

    MultivaluedMap<String, String> rHeaders = h.getRequestHeaders();
    List<String> acceptL = rHeaders.get(HttpHeaders.ACCEPT_LANGUAGE);
    assertEquals(3, acceptL.size());

    rHeaders.clear();
}
 
Example 4
Source File: QuickStartV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void verifyTypesCreated() throws Exception {
    MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();

    for (String typeName : TYPES) {
        searchParams.clear();
        searchParams.add(SearchFilter.PARAM_NAME, typeName);

        SearchFilter  searchFilter = new SearchFilter(searchParams);
        AtlasTypesDef searchDefs   = atlasClientV2.getAllTypeDefs(searchFilter);

        assert (!searchDefs.isEmpty());

        System.out.println("Created type [" + typeName + "]");
    }
}
 
Example 5
Source File: QuickStartV2.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void verifyTypesCreated() throws Exception {
    MultivaluedMap<String, String> searchParams = new MultivaluedMapImpl();

    for (String typeName : TYPES) {
        searchParams.clear();
        searchParams.add(SearchFilter.PARAM_NAME, typeName);
        SearchFilter searchFilter = new SearchFilter(searchParams);
        AtlasTypesDef searchDefs = atlasClientV2.getAllTypeDefs(searchFilter);

        assert (!searchDefs.isEmpty());
        System.out.println("Created type [" + typeName + "]");
    }
}
 
Example 6
Source File: URITemplateTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompareRegExTemplates2() {
    // The purpose of this test is to ensure that enclosing a regex expression does not result
    // in the matcher creating extraneous values.  See CXF-8278
    URITemplate t1 = new URITemplate("/test/{uniqueid : ([0-9a-f]{4}-.*|[0-9a-f]{7}-.*)}/file/{file}");
    URITemplate t2 = new URITemplate("/test/{uniqueid : [0-9a-f]{4}-.*|[0-9a-f]{7}-.*}/file/{file}");
    MultivaluedMap<String, String> template = new MetadataMap<String, String>();
    assertTrue(t1.match("/test/123e-12345/file/test.jpg", template));
    assertEquals(template.getFirst("uniqueid"), "123e-12345");
    assertEquals("test.jpg", template.getFirst("file"));

    template.clear();
    assertTrue(t1.match("/test/123456e-12345/file/test.jpg", template));
    assertEquals(template.getFirst("uniqueid"), "123456e-12345");
    assertEquals(template.getFirst("file"), "test.jpg");

    template.clear();
    assertTrue(t2.match("/test/123e-12345/file/test.jpg", template));
    assertEquals(template.getFirst("uniqueid"), "123e-12345");
    assertEquals(template.getFirst("file"), "test.jpg");

    template.clear();
    assertTrue(t2.match("/test/123456e-12345/file/test.jpg", template));
    assertEquals(template.getFirst("uniqueid"), "123456e-12345");
    assertEquals(template.getFirst("file"), "test.jpg");

    template.clear();
    assertFalse(t2.match("/test/12345678-12345/file/test.jpg", template));

}
 
Example 7
Source File: URITemplateTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicCustomExpression4() throws Exception {
    URITemplate uriTemplate = new URITemplate("/books/{bookId:...\\.}");
    MultivaluedMap<String, String> values = new MetadataMap<>();

    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));
}
 
Example 8
Source File: URITemplateTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpressionWithTwoVars() throws Exception {
    URITemplate uriTemplate = new URITemplate("/{tenant : [^/]*}/resource/{id}");
    MultivaluedMap<String, String> values = new MetadataMap<>();
    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);
}
 
Example 9
Source File: URITemplateTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testExpressionWithNestedGroupAndManySegments() throws Exception {
    URITemplate uriTemplate = new URITemplate("/foo/{bar}{resource:(/format/[^/]+?)?}/baz");
    MultivaluedMap<String, String> values = new MetadataMap<>();

    assertTrue(uriTemplate.match("/foo/1/format/2/baz/3", values));
    assertEquals("1", values.getFirst("bar"));
    assertEquals("/format/2", values.getFirst("resource"));
    String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
    assertEquals("/3", finalPath);
    values.clear();
}
 
Example 10
Source File: UriInfoImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTemplateParameters() {

    MultivaluedMap<String, String> values = new MetadataMap<>();
    new URITemplate("/bar").match("/baz", values);

    UriInfoImpl u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"),
                                    values);
    assertEquals("unexpected templates", 0, u.getPathParameters().size());

    values.clear();
    new URITemplate("/{id}").match("/bar%201", values);
    u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar%201"),
                        values);

    MultivaluedMap<String, String> tps = u.getPathParameters(false);
    assertEquals("Number of templates is wrong", 1, tps.size());
    assertEquals("Wrong template value", tps.getFirst("id"), "bar%201");

    values.clear();
    new URITemplate("/{id}/{baz}").match("/1%202/bar", values);
    u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/1%202/bar"),
                        values);

    tps = u.getPathParameters();
    assertEquals("Number of templates is wrong", 2, tps.size());
    assertEquals("Wrong template value", tps.getFirst("id"), "1 2");
    assertEquals("Wrong template value", tps.getFirst("baz"), "bar");

    // with suffix
    values.clear();
    new URITemplate("/bar").match("/bar", values);

    u = new UriInfoImpl(mockMessage("http://localhost:8080/baz", "/bar"),
                        values);
    assertEquals("unexpected templates", 0, u.getPathParameters().size());
}
 
Example 11
Source File: LimitParamTest.java    From amforeas with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testIncorrect () {
    MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
    params.add("limit", "-1");
    assertDefault(LimitParam.valueOf(params));

    params.remove("limit");
    params.add("limit", "foo");
    assertDefault(LimitParam.valueOf(params));

    params.add("offset", "-1");
    assertDefault(LimitParam.valueOf(params));

    params.remove("offset");
    params.add("offset", "foo");
    assertDefault(LimitParam.valueOf(params));

    /* with an invalid limit, the offset is still the default */
    params.remove("offset");
    params.add("offset", "10");
    assertDefault(LimitParam.valueOf(params));

    /* with an invalid offset, limit works and offset is default */
    params = new MultivaluedHashMap<>();
    params.add("limit", "10");
    params.add("offset", "foo");
    assertEquals(LimitParam.valueOf(params).getLimit(), 10);
    assertEquals(LimitParam.valueOf(params).getStart(), 0);

    /* if the limit is too big */
    params.clear();
    params.add("limit", "1001");
    assertEquals(LimitParam.valueOf(params).getLimit(), 1000);
}