Search in sources :

Example 56 with UriInfo

use of javax.ws.rs.core.UriInfo 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)

Example 57 with UriInfo

use of javax.ws.rs.core.UriInfo in project neo4j by neo4j.

the class DiscoveryServiceTest method uriInfo.

private UriInfo uriInfo(String host) {
    URI uri = URI.create(host);
    UriInfo uriInfo = mock(UriInfo.class);
    when(uriInfo.getBaseUri()).thenReturn(uri);
    return uriInfo;
}
Also used : URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo)

Example 58 with UriInfo

use of javax.ws.rs.core.UriInfo in project graylog2-server by Graylog2.

the class WebAppNotFoundResponseFilterTest method filterDoesFilterApplicationXhtml.

@Test
public void filterDoesFilterApplicationXhtml() throws Exception {
    final UriInfo uriInfo = mock(UriInfo.class);
    final List<MediaType> mediaTypes = Collections.singletonList(MediaType.APPLICATION_XHTML_XML_TYPE);
    when(uriInfo.getAbsolutePath()).thenReturn(URI.create("/web/search"));
    when(requestContext.getMethod()).thenReturn(CK_METHOD_GET);
    when(requestContext.getUriInfo()).thenReturn(uriInfo);
    when(requestContext.getAcceptableMediaTypes()).thenReturn(mediaTypes);
    when(responseContext.getStatusInfo()).thenReturn(Response.Status.NOT_FOUND);
    filter.filter(requestContext, responseContext);
    verify(responseContext, times(1)).setEntity("index.html", new Annotation[0], MediaType.TEXT_HTML_TYPE);
}
Also used : MediaType(javax.ws.rs.core.MediaType) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 59 with UriInfo

use of javax.ws.rs.core.UriInfo in project graylog2-server by Graylog2.

the class WebAppNotFoundResponseFilterTest method filterDoesFilterTextHtml.

@Test
public void filterDoesFilterTextHtml() throws Exception {
    final UriInfo uriInfo = mock(UriInfo.class);
    final List<MediaType> mediaTypes = Collections.singletonList(MediaType.TEXT_HTML_TYPE);
    when(uriInfo.getAbsolutePath()).thenReturn(URI.create("/web/search"));
    when(requestContext.getMethod()).thenReturn(CK_METHOD_GET);
    when(requestContext.getUriInfo()).thenReturn(uriInfo);
    when(requestContext.getAcceptableMediaTypes()).thenReturn(mediaTypes);
    when(responseContext.getStatusInfo()).thenReturn(Response.Status.NOT_FOUND);
    filter.filter(requestContext, responseContext);
    verify(responseContext, times(1)).setEntity("index.html", new Annotation[0], MediaType.TEXT_HTML_TYPE);
}
Also used : MediaType(javax.ws.rs.core.MediaType) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 60 with UriInfo

use of javax.ws.rs.core.UriInfo in project graylog2-server by Graylog2.

the class WebAppNotFoundResponseFilterTest method filterAddsUserAgentResponseHeader.

@Test
public void filterAddsUserAgentResponseHeader() throws Exception {
    final UriInfo uriInfo = mock(UriInfo.class);
    final List<MediaType> mediaTypes = Collections.singletonList(MediaType.TEXT_HTML_TYPE);
    when(uriInfo.getAbsolutePath()).thenReturn(URI.create("/web/search"));
    when(requestContext.getMethod()).thenReturn(CK_METHOD_GET);
    when(requestContext.getUriInfo()).thenReturn(uriInfo);
    when(requestContext.getAcceptableMediaTypes()).thenReturn(mediaTypes);
    when(responseContext.getStatusInfo()).thenReturn(Response.Status.NOT_FOUND);
    filter.filter(requestContext, responseContext);
    assertThat(responseHeaders).containsEntry("X-UA-Compatible", Collections.singletonList("IE=edge"));
}
Also used : MediaType(javax.ws.rs.core.MediaType) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

UriInfo (javax.ws.rs.core.UriInfo)86 Response (javax.ws.rs.core.Response)44 Test (org.junit.Test)43 URI (java.net.URI)31 Test (org.testng.annotations.Test)21 Request (org.apache.atlas.catalog.Request)12 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)12 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)12 MetadataService (org.apache.atlas.services.MetadataService)12 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 MediaType (javax.ws.rs.core.MediaType)10 Api (io.swagger.annotations.Api)8 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiParam (io.swagger.annotations.ApiParam)8 ApiResponse (io.swagger.annotations.ApiResponse)8 ApiResponses (io.swagger.annotations.ApiResponses)8 InputStream (java.io.InputStream)8