public static VirtualHostImpl<?, ?, ?> createVirtualHost(final Map<String, Object> attributes,
final Broker<?> broker)
{
ConfiguredObjectFactory objectFactory = broker.getObjectFactory();
VirtualHostNode virtualHostNode = mock(VirtualHostNode.class);
when(virtualHostNode.getName()).thenReturn((String) attributes.get(VirtualHostNode.NAME));
when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
when(virtualHostNode.getParent(eq(Broker.class))).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.getParent(eq(VirtualHostNode.class))).thenReturn(virtualHostNode);
when(virtualHostNode.getModel()).thenReturn(objectFactory.getModel());
when(virtualHostNode.getObjectFactory()).thenReturn(objectFactory);
when(virtualHostNode.getCategoryClass()).thenReturn(VirtualHostNode.class);
when(virtualHostNode.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
AbstractVirtualHost
host = (AbstractVirtualHost) objectFactory.create(VirtualHost.class, attributes, virtualHostNode );
host.start();
when(virtualHostNode.getVirtualHost()).thenReturn(host);
return host;
}