Search in sources :

Example 1 with JaxrsUriBuilder

use of org.killbill.billing.jaxrs.util.JaxrsUriBuilder in project killbill by killbill.

the class TestBuildResponse method testUriBuilderWithPathLikeUrlAndNonRoot.

@Test(groups = "fast", description = "Tests Uri Builder with Path Like URL and non root Location")
public void testUriBuilderWithPathLikeUrlAndNonRoot() throws Exception {
    UUID objectId = UUID.randomUUID();
    final UriInfo uriInfo = mock(UriInfo.class);
    URI uri = URI.create("http://localhost:8080/killbill");
    when(uriInfo.getBaseUri()).thenReturn(uri);
    JaxrsConfig jaxrsConfig = mock(JaxrsConfig.class);
    when(jaxrsConfig.isJaxrsLocationFullUrl()).thenReturn(false);
    JaxrsUriBuilder uriBuilder = new JaxrsUriBuilder(jaxrsConfig);
    Response response = uriBuilder.buildResponse(uriInfo, AccountResource.class, "getAccount", objectId, mockRequest(uriInfo));
    assertEquals(response.getStatus(), Status.CREATED.getStatusCode());
    assertEquals(response.getMetadata().get("Location").get(0), "/killbill/1.0/kb/accounts/" + objectId.toString());
}
Also used : Response(javax.ws.rs.core.Response) UUID(java.util.UUID) JaxrsUriBuilder(org.killbill.billing.jaxrs.util.JaxrsUriBuilder) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) JaxrsConfig(org.killbill.billing.util.config.definition.JaxrsConfig) Test(org.testng.annotations.Test)

Example 2 with JaxrsUriBuilder

use of org.killbill.billing.jaxrs.util.JaxrsUriBuilder in project killbill by killbill.

the class TestBuildResponse method testUriBuilderWithPathLikeUrlAndRoot.

@Test(groups = "fast", description = "Tests Uri Builder with Path Like URL and root Location")
public void testUriBuilderWithPathLikeUrlAndRoot() throws Exception {
    UUID objectId = UUID.randomUUID();
    final UriInfo uriInfo = mock(UriInfo.class);
    URI uri = URI.create("http://localhost:8080");
    when(uriInfo.getBaseUri()).thenReturn(uri);
    JaxrsConfig jaxrsConfig = mock(JaxrsConfig.class);
    when(jaxrsConfig.isJaxrsLocationFullUrl()).thenReturn(false);
    JaxrsUriBuilder uriBuilder = new JaxrsUriBuilder(jaxrsConfig);
    Response response = uriBuilder.buildResponse(uriInfo, AccountResource.class, "getAccount", objectId, mockRequest(uriInfo));
    assertEquals(response.getStatus(), Status.CREATED.getStatusCode());
    assertEquals(response.getMetadata().get("Location").get(0), "/1.0/kb/accounts/" + objectId.toString());
}
Also used : Response(javax.ws.rs.core.Response) UUID(java.util.UUID) JaxrsUriBuilder(org.killbill.billing.jaxrs.util.JaxrsUriBuilder) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) JaxrsConfig(org.killbill.billing.util.config.definition.JaxrsConfig) Test(org.testng.annotations.Test)

Example 3 with JaxrsUriBuilder

use of org.killbill.billing.jaxrs.util.JaxrsUriBuilder in project killbill by killbill.

the class TestBuildResponse method testUriBuilderWithoutPathLikeUrlAndRoot.

@Test(groups = "fast", description = "Tests Uri Builder with Full URL and root Location")
public void testUriBuilderWithoutPathLikeUrlAndRoot() throws Exception {
    UUID objectId = UUID.randomUUID();
    final UriInfo uriInfo = mock(UriInfo.class);
    URI uri = URI.create("http://localhost:8080");
    when(uriInfo.getBaseUri()).thenReturn(uri);
    when(uriInfo.getAbsolutePath()).thenReturn(uri);
    JaxrsConfig jaxrsConfig = mock(JaxrsConfig.class);
    when(jaxrsConfig.isJaxrsLocationFullUrl()).thenReturn(true);
    JaxrsUriBuilder uriBuilder = new JaxrsUriBuilder(jaxrsConfig);
    Response response = uriBuilder.buildResponse(uriInfo, AccountResource.class, "getAccount", objectId, mockRequest(uriInfo));
    assertEquals(response.getStatus(), Status.CREATED.getStatusCode());
    assertEquals(response.getMetadata().get("Location").get(0).toString(), uri.toString() + "/1.0/kb/accounts/" + objectId.toString());
}
Also used : Response(javax.ws.rs.core.Response) UUID(java.util.UUID) JaxrsUriBuilder(org.killbill.billing.jaxrs.util.JaxrsUriBuilder) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) JaxrsConfig(org.killbill.billing.util.config.definition.JaxrsConfig) Test(org.testng.annotations.Test)

Example 4 with JaxrsUriBuilder

use of org.killbill.billing.jaxrs.util.JaxrsUriBuilder in project killbill by killbill.

the class TestBuildResponse method testUriBuilderWithoutPathLikeUrlAndNonRoot.

@Test(groups = "fast", description = "Tests Uri Builder with Full URL and non root Location")
public void testUriBuilderWithoutPathLikeUrlAndNonRoot() throws Exception {
    UUID objectId = UUID.randomUUID();
    final UriInfo uriInfo = mock(UriInfo.class);
    URI uri = URI.create("http://localhost:8080/killbill");
    when(uriInfo.getBaseUri()).thenReturn(uri);
    when(uriInfo.getAbsolutePath()).thenReturn(uri);
    JaxrsConfig jaxrsConfig = mock(JaxrsConfig.class);
    when(jaxrsConfig.isJaxrsLocationFullUrl()).thenReturn(true);
    JaxrsUriBuilder uriBuilder = new JaxrsUriBuilder(jaxrsConfig);
    Response response = uriBuilder.buildResponse(uriInfo, AccountResource.class, "getAccount", objectId, mockRequest(uriInfo));
    assertEquals(response.getStatus(), Status.CREATED.getStatusCode());
    assertEquals(response.getMetadata().get("Location").get(0).toString(), uri.toString() + "/1.0/kb/accounts/" + objectId.toString());
}
Also used : Response(javax.ws.rs.core.Response) UUID(java.util.UUID) JaxrsUriBuilder(org.killbill.billing.jaxrs.util.JaxrsUriBuilder) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) JaxrsConfig(org.killbill.billing.util.config.definition.JaxrsConfig) Test(org.testng.annotations.Test)

Aggregations

URI (java.net.URI)4 UUID (java.util.UUID)4 Response (javax.ws.rs.core.Response)4 UriInfo (javax.ws.rs.core.UriInfo)4 JaxrsUriBuilder (org.killbill.billing.jaxrs.util.JaxrsUriBuilder)4 JaxrsConfig (org.killbill.billing.util.config.definition.JaxrsConfig)4 Test (org.testng.annotations.Test)4