Search in sources :

Example 76 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 77 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 78 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)

Example 79 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 80 with UriInfo

use of javax.ws.rs.core.UriInfo in project pulsar by yahoo.

the class HttpDestinationLookupv2Test method testNotEnoughLookupPermits.

@Test
public void testNotEnoughLookupPermits() throws Exception {
    BrokerService brokerService = pulsar.getBrokerService();
    doReturn(new Semaphore(0)).when(brokerService).getLookupRequestSemaphore();
    DestinationLookup destLookup = spy(new DestinationLookup());
    doReturn(false).when(destLookup).isRequestHttps();
    destLookup.setPulsar(pulsar);
    doReturn("null").when(destLookup).clientAppId();
    Field uriField = PulsarWebResource.class.getDeclaredField("uri");
    uriField.setAccessible(true);
    UriInfo uriInfo = mock(UriInfo.class);
    uriField.set(destLookup, uriInfo);
    URI uri = URI.create("http://localhost:8080/lookup/v2/destination/topic/myprop/usc/ns2/topic1");
    doReturn(uri).when(uriInfo).getRequestUri();
    doReturn(true).when(config).isAuthorizationEnabled();
    AsyncResponse asyncResponse1 = mock(AsyncResponse.class);
    destLookup.lookupDestinationAsync("myprop", "usc", "ns2", "topic1", false, asyncResponse1);
    ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse1).resume(arg.capture());
    assertEquals(arg.getValue().getClass(), WebApplicationException.class);
    WebApplicationException wae = (WebApplicationException) arg.getValue();
    assertEquals(wae.getResponse().getStatus(), Status.SERVICE_UNAVAILABLE.getStatusCode());
}
Also used : Field(java.lang.reflect.Field) WebApplicationException(javax.ws.rs.WebApplicationException) DestinationLookup(com.yahoo.pulsar.broker.lookup.DestinationLookup) Semaphore(java.util.concurrent.Semaphore) AsyncResponse(javax.ws.rs.container.AsyncResponse) BrokerService(com.yahoo.pulsar.broker.service.BrokerService) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Aggregations

UriInfo (javax.ws.rs.core.UriInfo)105 Response (javax.ws.rs.core.Response)50 Test (org.junit.Test)49 URI (java.net.URI)32 Test (org.testng.annotations.Test)21 Map (java.util.Map)15 MediaType (javax.ws.rs.core.MediaType)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Context (javax.ws.rs.core.Context)12 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 PathParam (javax.ws.rs.PathParam)11 ArrayList (java.util.ArrayList)10 Api (io.swagger.annotations.Api)8 ApiOperation (io.swagger.annotations.ApiOperation)8