use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class JDBCVirtualHostNodeTest method testInvalidTableNamePrefix.
public void testInvalidTableNamePrefix() throws Exception {
SystemConfig systemConfig = mock(SystemConfig.class);
Broker broker = mock(Broker.class);
final ConfiguredObjectFactoryImpl factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
when(broker.getObjectFactory()).thenReturn(factory);
when(broker.getModel()).thenReturn(factory.getModel());
when(broker.getChildExecutor()).thenReturn(_taskExecutor);
when(broker.getParent()).thenReturn(systemConfig);
Map<String, Object> attributes = new HashMap<>();
attributes.put(ConfiguredObject.NAME, getTestName());
attributes.put(ConfiguredObject.TYPE, JDBCVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
attributes.put("connectionUrl", "jdbc://example.com");
JDBCVirtualHostNode<?> jdbcVirtualHostNode = new JDBCVirtualHostNodeImpl(attributes, broker);
// 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 {
jdbcVirtualHostNode.setAttributes(Collections.<String, Object>singletonMap("tableNamePrefix", invalidPrefix));
fail(String.format("Should not be able to set prefix to '%s'", invalidPrefix));
} catch (IllegalConfigurationException e) {
// pass
}
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class BrokerMemoryLoggerTest method doMemoryLoggerLimitsTest.
private void doMemoryLoggerLimitsTest(final int illegalValue, final int legalValue) {
final String brokerLoggerName = "TestBrokerLogger";
Broker broker = _systemConfig.getContainer(Broker.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put(ConfiguredObject.NAME, brokerLoggerName);
attributes.put(ConfiguredObject.TYPE, BrokerMemoryLogger.TYPE);
attributes.put(BrokerMemoryLogger.MAX_RECORDS, illegalValue);
try {
broker.createChild(BrokerLogger.class, attributes);
fail("Exception not thrown");
} catch (IllegalConfigurationException ice) {
// PASS
}
attributes.put(BrokerMemoryLogger.MAX_RECORDS, legalValue);
BrokerLogger brokerLogger = (BrokerLogger) broker.createChild(BrokerLogger.class, attributes);
try {
brokerLogger.setAttributes(Collections.singletonMap(BrokerMemoryLogger.MAX_RECORDS, illegalValue));
fail("Exception not thrown");
} catch (IllegalConfigurationException ice) {
// PASS
} finally {
brokerLogger.delete();
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class BrokerNameAndLevelLogInclusionRuleTest method testLoggerNameChangeNotAllowed.
public void testLoggerNameChangeNotAllowed() {
BrokerNameAndLevelLogInclusionRule<?> rule = createRule("org.apache.qpid", LogLevel.INFO);
LoggerNameAndLevelFilter filter = (LoggerNameAndLevelFilter) rule.asFilter();
assertEquals("Unexpected logger name", "org.apache.qpid", filter.getLoggerName());
try {
rule.setAttributes(Collections.<String, Object>singletonMap(BrokerNameAndLevelLogInclusionRule.LOGGER_NAME, "org.apache.qpid.foo"));
fail("IllegalConfigurationException is expected to throw on attempt to change logger name");
} catch (IllegalConfigurationException e) {
// pass
}
assertEquals("Unexpected logger name", "org.apache.qpid", filter.getLoggerName());
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class DerbyVirtualHostNodeTest method testOnCreateValidationForFileStorePath.
public void testOnCreateValidationForFileStorePath() throws Exception {
File file = new File(_workDir, getTestName());
file.createNewFile();
String nodeName = getTestName();
Map<String, Object> nodeData = new HashMap<>();
nodeData.put(VirtualHostNode.NAME, nodeName);
nodeData.put(VirtualHostNode.TYPE, DerbyVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
nodeData.put(DerbyVirtualHostNodeImpl.STORE_PATH, file.getAbsolutePath());
try {
_broker.createChild(VirtualHostNode.class, nodeData);
fail("Cannot create store for the file store path");
} catch (IllegalConfigurationException e) {
// pass
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class DerbyVirtualHostNodeTest method testOnCreateValidationForNonWritableStorePath.
public void testOnCreateValidationForNonWritableStorePath() throws Exception {
if (Files.getFileAttributeView(_workDir.toPath(), PosixFileAttributeView.class) != null) {
File file = new File(_workDir, getTestName());
file.mkdirs();
if (file.setWritable(false, false)) {
String nodeName = getTestName();
Map<String, Object> nodeData = new HashMap<>();
nodeData.put(VirtualHostNode.NAME, nodeName);
nodeData.put(VirtualHostNode.TYPE, DerbyVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
nodeData.put(DerbyVirtualHostNodeImpl.STORE_PATH, file.getAbsolutePath());
try {
_broker.createChild(VirtualHostNode.class, nodeData);
fail("Cannot create store for the non writable store path");
} catch (IllegalConfigurationException e) {
// pass
}
}
}
}
Aggregations