use of org.apache.qpid.test.utils.QpidTestCase in project qpid-broker-j by apache.
the class BrokerTestHelper method createVirtualHost.
private static QueueManagingVirtualHost<?> createVirtualHost(final Map<String, Object> attributes, final Broker<?> broker, boolean defaultVHN, AccessControl accessControl) {
ConfiguredObjectFactory objectFactory = broker.getObjectFactory();
VirtualHostNode virtualHostNode = mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, SYSTEM_PRINCIPAL, accessControl);
String virtualHostNodeName = String.format("%s_%s", attributes.get(VirtualHostNode.NAME), "_node");
when(virtualHostNode.getName()).thenReturn(virtualHostNodeName);
when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.getChildExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.isDefaultVirtualHostNode()).thenReturn(defaultVHN);
when(virtualHostNode.getParent()).thenReturn(broker);
Collection<VirtualHostNode<?>> nodes = broker.getVirtualHostNodes();
nodes = new ArrayList<>(nodes != null ? nodes : Collections.<VirtualHostNode<?>>emptyList());
nodes.add(virtualHostNode);
when(broker.getVirtualHostNodes()).thenReturn(nodes);
DurableConfigurationStore dcs = mock(DurableConfigurationStore.class);
when(virtualHostNode.getConfigurationStore()).thenReturn(dcs);
when(virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
when(virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
when(virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.getChildExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
AbstractVirtualHost host = (AbstractVirtualHost) objectFactory.create(VirtualHost.class, attributes, virtualHostNode);
host.start();
when(virtualHostNode.getVirtualHost()).thenReturn(host);
_createdVirtualHosts.add(host);
QpidTestCase testCase = QpidTestCase.getCurrentInstance();
testCase.registerTearDown(_closeVirtualHosts);
return host;
}
Aggregations