use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class VirtualHostLoggerTest method setUp.
@Before
public void setUp() throws Exception {
_taskExecutor = new TaskExecutorImpl();
_taskExecutor.start();
Model model = BrokerModel.getInstance();
EventLogger eventLogger = mock(EventLogger.class);
SystemConfig<?> systemConfig = mock(SystemConfig.class);
when(systemConfig.getModel()).thenReturn(model);
when(systemConfig.getChildExecutor()).thenReturn(_taskExecutor);
when(systemConfig.getEventLogger()).thenReturn(eventLogger);
when(systemConfig.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
doReturn(SystemConfig.class).when(systemConfig).getCategoryClass();
Principal systemPrincipal = mock(Principal.class);
AccessControl accessControlMock = BrokerTestHelper.createAccessControlMock();
Broker broker = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(Broker.class, systemPrincipal, accessControlMock);
when(broker.getModel()).thenReturn(model);
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
when(broker.getParent()).thenReturn(systemConfig);
doReturn(Broker.class).when(broker).getCategoryClass();
VirtualHostNode node = BrokerTestHelper.mockWithSystemPrincipalAndAccessControl(VirtualHostNode.class, systemPrincipal, accessControlMock);
when(node.getModel()).thenReturn(model);
when(node.getChildExecutor()).thenReturn(_taskExecutor);
when(node.getParent()).thenReturn(broker);
when(node.getConfigurationStore()).thenReturn(mock(DurableConfigurationStore.class));
doReturn(VirtualHostNode.class).when(node).getCategoryClass();
when(node.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
// use real VH object rather then mock in order to test create/start/stop functionality
Map<String, Object> attributes = new HashMap<>();
attributes.put(VirtualHost.NAME, getTestName());
attributes.put(VirtualHost.TYPE, TestMemoryVirtualHost.VIRTUAL_HOST_TYPE);
_virtualHost = new TestMemoryVirtualHost(attributes, node);
_virtualHost.open();
_baseFolder = new File(TMP_FOLDER, "test-sub-folder");
_logFile = new File(_baseFolder, "tmp-virtual-host.log." + System.currentTimeMillis());
if (_baseFolder.exists()) {
FileUtils.delete(_baseFolder, true);
}
}
use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class RedirectingVirtualHostNodeImpl method validateChange.
@Override
protected void validateChange(final ConfiguredObject<?> proxyForValidation, final Set<String> changedAttributes) {
super.validateChange(proxyForValidation, changedAttributes);
VirtualHostNode updated = (VirtualHostNode) proxyForValidation;
if (changedAttributes.contains(DEFAULT_VIRTUAL_HOST_NODE) && updated.isDefaultVirtualHostNode()) {
VirtualHostNode existingDefault = _broker.findDefautVirtualHostNode();
if (existingDefault != null && existingDefault != this) {
throw new IntegrityViolationException("Cannot make '" + getName() + "' the default virtual host node for" + " the Broker as virtual host node '" + existingDefault.getName() + "' is already the default.");
}
}
}
use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNodeTest method testValidateOnCreateFails_ExistingDefaultVHN.
@Test
public void testValidateOnCreateFails_ExistingDefaultVHN() throws Exception {
String nodeName = getTestName();
Map<String, Object> attributes = new HashMap<>();
attributes.put(TestVirtualHostNode.NAME, nodeName);
attributes.put(TestVirtualHostNode.DEFAULT_VIRTUAL_HOST_NODE, Boolean.TRUE);
VirtualHostNode existingDefault = mock(VirtualHostNode.class);
when(existingDefault.getName()).thenReturn("existingDefault");
when(_broker.findDefautVirtualHostNode()).thenReturn(existingDefault);
final DurableConfigurationStore store = mock(DurableConfigurationStore.class);
AbstractStandardVirtualHostNode node = createTestStandardVirtualHostNode(attributes, store);
try {
node.create();
fail("Exception not thrown");
} catch (IllegalConfigurationException e) {
assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("The existing virtual host node 'existingDefault' is already the default for the Broker"));
}
}
use of org.apache.qpid.server.model.VirtualHostNode in project qpid-broker-j by apache.
the class JDBCVirtualHostTest method testInvalidTableNamePrefix.
@Test
public void testInvalidTableNamePrefix() throws Exception {
final VirtualHostNode vhn = BrokerTestHelper.createVirtualHostNodeMock("testNode", true, BrokerTestHelper.createAccessControlMock(), BrokerTestHelper.createBrokerMock());
Map<String, Object> attributes = new HashMap<>();
attributes.put(ConfiguredObject.NAME, getTestName());
attributes.put(ConfiguredObject.TYPE, JDBCVirtualHostImpl.VIRTUAL_HOST_TYPE);
attributes.put("connectionUrl", "jdbc://example.com");
JDBCVirtualHost<?> jdbcVirtualHost = new JDBCVirtualHostImpl(attributes, vhn);
// This list is not exhaustive
List<String> knownInvalidPrefixes = Arrays.asList("with\"dblquote", "with'quote", "with-dash", "with;semicolon", "with space", "with%percent", "with|pipe", "with(paren", "with)paren", "with[bracket", "with]bracket", "with{brace", "with}brace");
for (String invalidPrefix : knownInvalidPrefixes) {
try {
jdbcVirtualHost.setAttributes(Collections.<String, Object>singletonMap("tableNamePrefix", invalidPrefix));
fail(String.format("Should not be able to set prefix to '%s'", invalidPrefix));
} catch (IllegalConfigurationException e) {
// pass
}
}
}
Aggregations