Search in sources :

Example 16 with UriInfo

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

the class AdminTest method brokers.

@Test
void brokers() throws Exception {
    clusters.createCluster("use", new ClusterData("http://broker.messaging.use.example.com", "https://broker.messaging.use.example.com:4443"));
    URI requestUri = new URI("http://broker.messaging.use.example.com" + ":" + BROKER_WEBSERVICE_PORT + "/admin/brokers/use");
    UriInfo mockUri = mock(UriInfo.class);
    doReturn(requestUri).when(mockUri).getRequestUri();
    Field uriField = PulsarWebResource.class.getDeclaredField("uri");
    uriField.setAccessible(true);
    uriField.set(brokers, mockUri);
    Set<String> activeBrokers = brokers.getActiveBrokers("use");
    assertEquals(activeBrokers.size(), 1);
    assertEquals(activeBrokers, Sets.newHashSet(pulsar.getAdvertisedAddress() + ":" + BROKER_WEBSERVICE_PORT));
}
Also used : Field(java.lang.reflect.Field) ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 17 with UriInfo

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

the class NamespacesTest method initNamespace.

@BeforeClass
public void initNamespace() throws Exception {
    testLocalNamespaces = Lists.newArrayList();
    testGlobalNamespaces = Lists.newArrayList();
    testLocalNamespaces.add(new NamespaceName(this.testProperty, this.testLocalCluster, "test-namespace-1"));
    testLocalNamespaces.add(new NamespaceName(this.testProperty, this.testLocalCluster, "test-namespace-2"));
    testLocalNamespaces.add(new NamespaceName(this.testProperty, this.testOtherCluster, "test-other-namespace-1"));
    testGlobalNamespaces.add(new NamespaceName(this.testProperty, "global", "test-global-ns1"));
    uriField = PulsarWebResource.class.getDeclaredField("uri");
    uriField.setAccessible(true);
    uriInfo = mock(UriInfo.class);
}
Also used : NamespaceName(com.yahoo.pulsar.common.naming.NamespaceName) PulsarWebResource(com.yahoo.pulsar.broker.web.PulsarWebResource) UriInfo(javax.ws.rs.core.UriInfo) BeforeClass(org.testng.annotations.BeforeClass)

Example 18 with UriInfo

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

the class HttpDestinationLookupv2Test method testValidateReplicationSettingsOnNamespace.

@Test
public void testValidateReplicationSettingsOnNamespace() throws Exception {
    final String property = "my-prop";
    final String cluster = "global";
    final String ns1 = "ns1";
    final String ns2 = "ns2";
    Policies policies1 = new Policies();
    doReturn(Optional.of(policies1)).when(policiesCache).get(AdminResource.path("policies", property, cluster, ns1));
    Policies policies2 = new Policies();
    policies2.replication_clusters = Lists.newArrayList("invalid-localCluster");
    doReturn(Optional.of(policies2)).when(policiesCache).get(AdminResource.path("policies", property, cluster, ns2));
    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);
    doReturn(false).when(config).isAuthorizationEnabled();
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    destLookup.lookupDestinationAsync(property, cluster, ns1, "empty-cluster", false, asyncResponse);
    ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse).resume(arg.capture());
    assertEquals(arg.getValue().getClass(), RestException.class);
    AsyncResponse asyncResponse2 = mock(AsyncResponse.class);
    destLookup.lookupDestinationAsync(property, cluster, ns2, "invalid-localCluster", false, asyncResponse2);
    ArgumentCaptor<Throwable> arg2 = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse2).resume(arg2.capture());
    // Should have raised exception for invalid cluster
    assertEquals(arg2.getValue().getClass(), RestException.class);
}
Also used : Field(java.lang.reflect.Field) Policies(com.yahoo.pulsar.common.policies.data.Policies) DestinationLookup(com.yahoo.pulsar.broker.lookup.DestinationLookup) AsyncResponse(javax.ws.rs.container.AsyncResponse) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 19 with UriInfo

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

the class HttpDestinationLookupv2Test method crossColoLookup.

@Test
public void crossColoLookup() throws Exception {
    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 asyncResponse = mock(AsyncResponse.class);
    destLookup.lookupDestinationAsync("myprop", "usc", "ns2", "topic1", false, asyncResponse);
    ArgumentCaptor<Throwable> arg = ArgumentCaptor.forClass(Throwable.class);
    verify(asyncResponse).resume(arg.capture());
    assertEquals(arg.getValue().getClass(), WebApplicationException.class);
    WebApplicationException wae = (WebApplicationException) arg.getValue();
    assertEquals(wae.getResponse().getStatus(), Status.TEMPORARY_REDIRECT.getStatusCode());
}
Also used : Field(java.lang.reflect.Field) WebApplicationException(javax.ws.rs.WebApplicationException) DestinationLookup(com.yahoo.pulsar.broker.lookup.DestinationLookup) AsyncResponse(javax.ws.rs.container.AsyncResponse) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) Test(org.testng.annotations.Test)

Example 20 with UriInfo

use of javax.ws.rs.core.UriInfo in project ORCID-Source by ORCID.

the class RDFWriterTest method injectFakeUriInfo.

@Before
public void injectFakeUriInfo() {
    UriInfo uriInfo = mock(UriInfo.class);
    when(uriInfo.getAbsolutePath()).thenReturn(URI.create(EXAMPLE_RDF_URI));
    rdfWriter.setUriInfo(uriInfo);
}
Also used : UriInfo(javax.ws.rs.core.UriInfo) Before(org.junit.Before)

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