Search in sources :

Example 11 with VirtualHostNode

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);
    }
}
Also used : TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) TestMemoryVirtualHost(org.apache.qpid.server.virtualhost.TestMemoryVirtualHost) Broker(org.apache.qpid.server.model.Broker) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) EventLogger(org.apache.qpid.server.logging.EventLogger) HashMap(java.util.HashMap) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) AccessControl(org.apache.qpid.server.security.AccessControl) BrokerModel(org.apache.qpid.server.model.BrokerModel) Model(org.apache.qpid.server.model.Model) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) File(java.io.File) Principal(java.security.Principal) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) Before(org.junit.Before)

Example 12 with VirtualHostNode

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.");
        }
    }
}
Also used : VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) IntegrityViolationException(org.apache.qpid.server.model.IntegrityViolationException)

Example 13 with VirtualHostNode

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"));
    }
}
Also used : DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) HashMap(java.util.HashMap) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) Test(org.junit.Test)

Example 14 with VirtualHostNode

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

Aggregations

VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)14 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 HashMap (java.util.HashMap)6 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)3 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)3 Broker (org.apache.qpid.server.model.Broker)3 VirtualHost (org.apache.qpid.server.model.VirtualHost)3 Test (org.junit.Test)3 File (java.io.File)2 Principal (java.security.Principal)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)2 EventLogger (org.apache.qpid.server.logging.EventLogger)2 BrokerModel (org.apache.qpid.server.model.BrokerModel)2 AccessControl (org.apache.qpid.server.security.AccessControl)2 MessageStoreProvider (org.apache.qpid.server.store.MessageStoreProvider)2 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)2 Cache (com.google.common.cache.Cache)1