Search in sources :

Example 36 with IllegalConfigurationException

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
        }
    }
}
Also used : SystemConfig(org.apache.qpid.server.model.SystemConfig) Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFactoryImpl(org.apache.qpid.server.model.ConfiguredObjectFactoryImpl)

Example 37 with IllegalConfigurationException

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();
    }
}
Also used : Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) BrokerLogger(org.apache.qpid.server.model.BrokerLogger) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 38 with IllegalConfigurationException

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());
}
Also used : LoggerNameAndLevelFilter(org.apache.qpid.server.logging.logback.LoggerNameAndLevelFilter) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException)

Example 39 with IllegalConfigurationException

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
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File)

Example 40 with IllegalConfigurationException

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
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Aggregations

IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)87 HashMap (java.util.HashMap)31 IOException (java.io.IOException)25 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)20 File (java.io.File)15 UUID (java.util.UUID)12 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)12 GeneralSecurityException (java.security.GeneralSecurityException)10 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)9 LinkedHashMap (java.util.LinkedHashMap)7 Map (java.util.Map)7 ServerScopedRuntimeException (org.apache.qpid.server.util.ServerScopedRuntimeException)7 AccessControlException (java.security.AccessControlException)6 ArrayList (java.util.ArrayList)6 Protocol (org.apache.qpid.server.model.Protocol)5 UnknownAlternateBindingException (org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)5 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashSet (java.util.HashSet)4