use of com.yahoo.pulsar.common.naming.DestinationName in project pulsar by yahoo.
the class NamespacesTest method testValidateDestinationOwnership.
@Test
public void testValidateDestinationOwnership() throws Exception {
try {
URL localWebServiceUrl = new URL(pulsar.getWebServiceAddress());
String bundledNsLocal = "test-bundled-namespace-1";
BundlesData bundleData = new BundlesData(Lists.newArrayList("0x00000000", "0xffffffff"));
createBundledTestNamespaces(this.testProperty, this.testLocalCluster, bundledNsLocal, bundleData);
final NamespaceName testNs = new NamespaceName(this.testProperty, this.testLocalCluster, bundledNsLocal);
OwnershipCache MockOwnershipCache = spy(pulsar.getNamespaceService().getOwnershipCache());
doNothing().when(MockOwnershipCache).disableOwnership(any(NamespaceBundle.class));
Field ownership = NamespaceService.class.getDeclaredField("ownershipCache");
ownership.setAccessible(true);
ownership.set(pulsar.getNamespaceService(), MockOwnershipCache);
DestinationName topicName = DestinationName.get(testNs.getPersistentTopicName("my-topic"));
PersistentTopics topics = spy(new PersistentTopics());
topics.setServletContext(new MockServletContext());
topics.setPulsar(pulsar);
doReturn(false).when(topics).isRequestHttps();
doReturn("test").when(topics).clientAppId();
mockWebUrl(localWebServiceUrl, testNs);
try {
topics.validateAdminOperationOnDestination(topicName, false);
} catch (RestException e) {
fail("validateAdminAccessOnProperty failed");
}
try {
topics.validateAdminOperationOnDestination(DestinationName.get(""), false);
fail("validateAdminAccessOnProperty failed");
} catch (Exception e) {
// OK
}
} catch (RestException e) {
fail("validateAdminAccessOnProperty failed");
}
}
Aggregations