use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testStopVHNDeniedByACL.
@Test
public void testStopVHNDeniedByACL() throws Exception {
AccessControl mockAccessControl = mock(AccessControl.class);
DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
Map<String, Object> nodeAttributes = new HashMap<>();
nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
nodeAttributes.put(VirtualHostNode.ID, _nodeId);
TestVirtualHostNode node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
node.setAccessControl(mockAccessControl);
node.open();
node.start();
when(mockAccessControl.authorise(eq(null), eq(Operation.UPDATE), same(node), any())).thenReturn(Result.DENIED);
try {
node.stop();
fail("Exception not throws");
} catch (AccessControlException ace) {
// PASS
}
assertEquals("Virtual host node state changed unexpectedly", State.ACTIVE, node.getState());
node.close();
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testActivateVHN_StoreHasVH.
/**
* Tests activating a virtualhostnode with a config store that specifies a
* virtualhost. Ensures that the virtualhost created.
*/
@Test
public void testActivateVHN_StoreHasVH() throws Exception {
UUID virtualHostId = UUID.randomUUID();
ConfiguredObjectRecord vhostRecord = createVirtualHostConfiguredObjectRecord(virtualHostId);
DurableConfigurationStore configStore = configStoreThatProduces(vhostRecord);
Map<String, Object> nodeAttributes = new HashMap<>();
nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
nodeAttributes.put(VirtualHostNode.ID, _nodeId);
VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
node.open();
node.start();
VirtualHost<?> virtualHost = node.getVirtualHost();
assertNotNull("Virtual host was not recovered", virtualHost);
assertEquals("Unexpected virtual host name", TEST_VIRTUAL_HOST_NAME, virtualHost.getName());
assertEquals("Unexpected virtual host state", State.ACTIVE, virtualHost.getState());
assertEquals("Unexpected virtual host id", virtualHostId, virtualHost.getId());
node.close();
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testActivateVHNWithVHBlueprintUsed_StoreHasNoVH.
/**
* Tests activating a virtualhostnode with blueprint context variable and the
* but the virtualhostInitialConfiguration set to empty. Config store does not specify a virtualhost.
* Checks virtualhost is not recreated from the blueprint.
*/
@Test
public void testActivateVHNWithVHBlueprintUsed_StoreHasNoVH() throws Exception {
DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
String vhBlueprint = String.format("{ \"type\" : \"%s\", \"name\" : \"%s\"}", TestMemoryVirtualHost.VIRTUAL_HOST_TYPE, TEST_VIRTUAL_HOST_NAME);
Map<String, String> context = new HashMap<>();
context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, vhBlueprint);
Map<String, Object> nodeAttributes = new HashMap<>();
nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
nodeAttributes.put(VirtualHostNode.ID, _nodeId);
nodeAttributes.put(VirtualHostNode.CONTEXT, context);
nodeAttributes.put(VirtualHostNode.VIRTUALHOST_INITIAL_CONFIGURATION, "{}");
VirtualHostNode<?> node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
node.open();
node.start();
VirtualHost<?> virtualHost = node.getVirtualHost();
assertNull("Virtual host should not be created by blueprint", virtualHost);
node.close();
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testUpdateVHNDeniedByACL.
// *************** VHN Access Control Tests ***************
@Test
public void testUpdateVHNDeniedByACL() throws Exception {
AccessControl mockAccessControl = mock(AccessControl.class);
DurableConfigurationStore configStore = configStoreThatProducesNoRecords();
Map<String, Object> nodeAttributes = new HashMap<>();
nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
nodeAttributes.put(VirtualHostNode.ID, _nodeId);
TestVirtualHostNode node = new TestVirtualHostNode(_broker, nodeAttributes, configStore);
node.setAccessControl(mockAccessControl);
node.open();
node.start();
when(mockAccessControl.authorise(eq(null), eq(Operation.UPDATE), same(node), any())).thenReturn(Result.DENIED);
assertNull(node.getDescription());
try {
node.setAttributes(Collections.<String, Object>singletonMap(VirtualHostNode.DESCRIPTION, "My virtualhost node"));
fail("Exception not throws");
} catch (AccessControlException ace) {
// PASS
}
assertNull("Description unexpected updated", node.getDescription());
node.close();
}
use of org.apache.qpid.server.store.DurableConfigurationStore in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testValidateOnCreateFails_StoreFails.
@Test
public void testValidateOnCreateFails_StoreFails() throws Exception {
String nodeName = getTestName();
Map<String, Object> attributes = Collections.<String, Object>singletonMap(TestVirtualHostNode.NAME, nodeName);
final DurableConfigurationStore store = mock(DurableConfigurationStore.class);
doThrow(new RuntimeException("Cannot open store")).when(store).init(any(ConfiguredObject.class));
AbstractStandardVirtualHostNode node = createTestStandardVirtualHostNode(attributes, store);
try {
node.create();
fail("Exception not thrown");
} catch (IllegalConfigurationException e) {
assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store"));
}
}
Aggregations