Search in sources :

Example 21 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class JerseyUriBuilderTest method shouldOnlyRemoveMatrixInFinalSegment.

// Reproducer for JERSEY-2537
@Test
public void shouldOnlyRemoveMatrixInFinalSegment() {
    final UriBuilder builder = UriBuilder.fromPath("/apples;order=random;color=blue/2006/bar;zot=baz").replaceMatrix(null);
    final URI result = builder.build();
    assertEquals("/apples;order=random;color=blue/2006/bar", result.toString());
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Example 22 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class JerseyUriBuilderTest method shouldKeepTrailingSlash.

// Reproducer for JERSEY-2537
@Test
public void shouldKeepTrailingSlash() throws MalformedURLException, URISyntaxException {
    final URL url = new URL("http://example.com/authentications;email=joe@joe.com/");
    final UriBuilder builder = UriBuilder.fromPath(url.getPath()).replaceMatrix(null);
    final URI result = builder.build();
    assertEquals("/authentications/", result.toString());
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) URL(java.net.URL) Test(org.junit.Test)

Example 23 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class JerseyUriBuilderTest method testReplaceQueryParamsEncoded2.

@Test
public void testReplaceQueryParamsEncoded2() throws URISyntaxException {
    final UriBuilder ubu = UriBuilder.fromUri(new URI("http://localhost")).replaceQuery("limit=10&sql=select+*+from+users");
    ubu.replaceQueryParam("limit", 100);
    final URI uri = ubu.build();
    Assert.assertEquals(URI.create("http://localhost/?limit=100&sql=select+%2A+from+users"), uri);
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) Test(org.junit.Test)

Example 24 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class JerseyUriBuilderTest method resolveTemplateTest.

@Test
public void resolveTemplateTest() {
    final UriBuilder uriBuilder = UriBuilder.fromPath("http://localhost:8080").path("{a}").path("{b}").queryParam("query", "{q}");
    uriBuilder.resolveTemplate("a", "param-a");
    uriBuilder.resolveTemplate("q", "param-q");
    final Map<String, Object> m = new HashMap<String, Object>();
    m.put("a", "ignored-a");
    m.put("b", "param-b");
    m.put("q", "ignored-q");
    Assert.assertEquals(URI.create("http://localhost:8080/param-a/param-b?query=param-q"), uriBuilder.buildFromMap(m));
}
Also used : HashMap(java.util.HashMap) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Example 25 with UriBuilder

use of javax.ws.rs.core.UriBuilder in project jersey by jersey.

the class JerseyUriBuilderTest method resolveTemplateFromEncodedTest.

@Test
public void resolveTemplateFromEncodedTest() {
    final UriBuilder uriBuilder = UriBuilder.fromPath("http://localhost:8080").path("{a}").path("{b}").path("{c}").queryParam("query", "{q}");
    uriBuilder.resolveTemplateFromEncoded("a", "x/y/z%3F%20");
    uriBuilder.resolveTemplateFromEncoded("q", "q?%20%26");
    uriBuilder.resolveTemplate("c", "paramc1/paramc2");
    final Map<String, Object> m = new HashMap<String, Object>();
    m.put("a", "ignored-a");
    m.put("b", "param-b/aaa");
    m.put("q", "ignored-q");
    Assert.assertEquals("http://localhost:8080/x/y/z%3F%20/param-b/aaa/paramc1%2Fparamc2?query=q%3F%20%26", uriBuilder.buildFromEncodedMap(m).toString());
}
Also used : HashMap(java.util.HashMap) UriBuilder(javax.ws.rs.core.UriBuilder) Test(org.junit.Test)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)123 URI (java.net.URI)45 Test (org.junit.Test)42 HashMap (java.util.HashMap)15 Consumes (javax.ws.rs.Consumes)15 Link (org.eclipse.che.api.core.rest.shared.dto.Link)15 PUT (javax.ws.rs.PUT)11 IOException (java.io.IOException)10 Path (javax.ws.rs.Path)10 ArrayList (java.util.ArrayList)8 Produces (javax.ws.rs.Produces)8 LinksHelper.createLink (org.eclipse.che.api.core.util.LinksHelper.createLink)8 GET (javax.ws.rs.GET)7 URL (java.net.URL)6 ServerException (org.eclipse.che.api.core.ServerException)6 POST (javax.ws.rs.POST)5 ApiException (org.eclipse.che.api.core.ApiException)4 WorkspaceService (org.eclipse.che.api.workspace.server.WorkspaceService)4 ExternalTestContainerFactory (org.glassfish.jersey.test.external.ExternalTestContainerFactory)4 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)3