diff options
| author | Keith Wall <kwall@apache.org> | 2015-01-14 19:46:08 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2015-01-14 19:46:08 +0000 |
| commit | 52e0779fdc35b7ce6614f1b16f4328613c837655 (patch) | |
| tree | ef5f3dfd3d7b7901604871fe1a0e1e0698572dc0 /qpid/java | |
| parent | 49c2561fe332a2094c0f837d618b2f9c875b45c6 (diff) | |
| download | qpid-python-52e0779fdc35b7ce6614f1b16f4328613c837655.tar.gz | |
QPID-6304: [Java Broker] Remove now redundant FileKeyStoreCreationTest/FileTrustStoreCreationTest
* These test cases seemed to be testing features of the core model rather than anything specific to keystores/truststore. The core model
is tested by the AbstractConfiguredObject tests.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1651787 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
4 files changed, 46 insertions, 356 deletions
diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java deleted file mode 100644 index b4f92990eb..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileKeyStoreCreationTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.configuration.startup; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import javax.net.ssl.KeyManagerFactory; -import javax.security.auth.Subject; - -import junit.framework.TestCase; - -import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.model.AbstractConfiguredObject; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.BrokerModel; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.model.ConfiguredObjectFactory; -import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl; -import org.apache.qpid.server.model.KeyStore; -import org.apache.qpid.server.security.FileKeyStore; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.test.utils.TestSSLConstants; - -public class FileKeyStoreCreationTest extends TestCase -{ - - private ConfiguredObjectFactory _factory; - - public void setUp() throws Exception - { - super.setUp(); - _factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance()); - } - - public void testCreateWithAllAttributesProvided() - { - Map<String, Object> attributes = getKeyStoreAttributes(); - Map<String, Object> attributesCopy = new HashMap<String, Object>(attributes); - - Broker broker = mock(Broker.class); - TaskExecutor executor = CurrentThreadTaskExecutor.newStartedInstance(); - when(broker.getObjectFactory()).thenReturn(_factory); - when(broker.getModel()).thenReturn(_factory.getModel()); - when(broker.getTaskExecutor()).thenReturn(executor); - - final FileKeyStore keyStore = - createKeyStore(attributes, broker); - - - assertNotNull("Key store configured object is not created", keyStore); - assertEquals(attributes.get(ConfiguredObject.ID), keyStore.getId()); - - //verify we can retrieve the actual password using the method - Subject.doAs(SecurityManager.getSubjectWithAddedSystemRights(), new PrivilegedAction<Object>() - { - @Override - public Object run() - { - assertNotNull(keyStore.getPassword()); - assertEquals(TestSSLConstants.BROKER_TRUSTSTORE_PASSWORD, keyStore.getPassword()); - //verify that we haven't configured the key store with the actual dummy password value - assertFalse(AbstractConfiguredObject.SECURED_STRING_VALUE.equals(keyStore.getPassword())); - return null; - } - }); - - - // Verify the remaining attributes, including that the password value returned - // via getAttribute is actually the dummy value and not the real password - attributesCopy.put(FileKeyStore.PASSWORD, AbstractConfiguredObject.SECURED_STRING_VALUE); - for (Map.Entry<String, Object> attribute : attributesCopy.entrySet()) - { - Object attributeValue = keyStore.getAttribute(attribute.getKey()); - assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue); - } - } - - protected FileKeyStore createKeyStore(final Map<String, Object> attributes, final Broker broker) - { - return (FileKeyStore) _factory.create(KeyStore.class,attributes, broker); - } - - public void testCreateWithMissedRequiredAttributes() - { - Map<String, Object> attributes = getKeyStoreAttributes(); - - Broker broker = mock(Broker.class); - when(broker.getObjectFactory()).thenReturn(_factory); - when(broker.getModel()).thenReturn(_factory.getModel()); - when(broker.getTaskExecutor()).thenReturn(CurrentThreadTaskExecutor.newStartedInstance()); - String[] mandatoryProperties = {KeyStore.NAME, FileKeyStore.PATH, FileKeyStore.PASSWORD}; - for (int i = 0; i < mandatoryProperties.length; i++) - { - Map<String, Object> properties = new HashMap<String, Object>(attributes); - properties.remove(mandatoryProperties[i]); - try - { - createKeyStore(properties, broker); - fail("Cannot create key store without a " + mandatoryProperties[i]); - } - catch(IllegalArgumentException e) - { - // pass - } - } - } - - private Map<String, Object> getKeyStoreAttributes() - { - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(KeyStore.ID, UUID.randomUUID()); - attributes.put(KeyStore.NAME, getName()); - attributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); - attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - attributes.put(FileKeyStore.KEY_STORE_TYPE, "jks"); - attributes.put(FileKeyStore.KEY_MANAGER_FACTORY_ALGORITHM, KeyManagerFactory.getDefaultAlgorithm()); - attributes.put(FileKeyStore.CERTIFICATE_ALIAS, "java-broker"); - return attributes; - } - - -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileTrustStoreCreationTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileTrustStoreCreationTest.java deleted file mode 100644 index 1baad01e1e..0000000000 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/startup/FileTrustStoreCreationTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ -package org.apache.qpid.server.configuration.startup; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.security.PrivilegedAction; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import javax.net.ssl.TrustManagerFactory; -import javax.security.auth.Subject; - -import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; -import org.apache.qpid.server.configuration.updater.TaskExecutor; -import org.apache.qpid.server.model.AbstractConfiguredObject; -import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.BrokerModel; -import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl; -import org.apache.qpid.server.model.TrustStore; -import org.apache.qpid.server.security.FileTrustStore; -import org.apache.qpid.server.security.FileTrustStoreImpl; -import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.test.utils.QpidTestCase; -import org.apache.qpid.test.utils.TestSSLConstants; - -public class FileTrustStoreCreationTest extends QpidTestCase -{ - public void testCreateWithAllAttributesProvided() - { - UUID id = UUID.randomUUID(); - Map<String, Object> attributes = getTrustStoreAttributes(id); - Map<String, Object> attributesCopy = new HashMap<String, Object>(attributes); - - ConfiguredObjectFactoryImpl factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance()); - - Broker broker = mock(Broker.class); - when(broker.getObjectFactory()).thenReturn(factory); - when(broker.getModel()).thenReturn(factory.getModel()); - TaskExecutor executor = new CurrentThreadTaskExecutor(); - when(broker.getTaskExecutor()).thenReturn(executor); - - final FileTrustStore trustStore = new FileTrustStoreImpl(attributes, broker); - trustStore.open(); - assertNotNull("Trust store configured object is not created", trustStore); - assertEquals(id, trustStore.getId()); - - Subject.doAs(SecurityManager.getSubjectWithAddedSystemRights(), new PrivilegedAction<Object>() - { - @Override - public Object run() - { - //verify we can retrieve the actual password using the method - assertEquals(TestSSLConstants.BROKER_TRUSTSTORE_PASSWORD, trustStore.getPassword()); - assertNotNull(trustStore.getPassword()); - //verify that we haven't configured the trust store with the actual dummy password value - assertFalse(AbstractConfiguredObject.SECURED_STRING_VALUE.equals(trustStore.getPassword())); - return null; - } - }); - - - // Verify the remaining attributes, including that the password value returned - // via getAttribute is actually the dummy value and not the real password - attributesCopy.put(FileTrustStore.PASSWORD, AbstractConfiguredObject.SECURED_STRING_VALUE); - for (Map.Entry<String, Object> attribute : attributesCopy.entrySet()) - { - Object attributeValue = trustStore.getAttribute(attribute.getKey()); - assertEquals("Unexpected value of attribute '" + attribute.getKey() + "'", attribute.getValue(), attributeValue); - } - } - - public void testCreateWithMissedRequiredAttributes() - { - UUID id = UUID.randomUUID(); - Map<String, Object> attributes = getTrustStoreAttributes(id); - - ConfiguredObjectFactoryImpl factory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance()); - Broker broker = mock(Broker.class); - when(broker.getObjectFactory()).thenReturn(factory); - when(broker.getModel()).thenReturn(factory.getModel()); - when(broker.getTaskExecutor()).thenReturn(CurrentThreadTaskExecutor.newStartedInstance()); - String[] mandatoryProperties = {TrustStore.NAME, FileTrustStore.PATH, FileTrustStore.PASSWORD}; - for (int i = 0; i < mandatoryProperties.length; i++) - { - Map<String, Object> properties = new HashMap<String, Object>(attributes); - properties.remove(mandatoryProperties[i]); - try - { - TrustStore trustStore = new FileTrustStoreImpl(properties, broker); - trustStore.open(); - fail("Cannot create key store without a " + mandatoryProperties[i]); - } - catch(IllegalArgumentException e) - { - // pass - } - } - } - - private Map<String, Object> getTrustStoreAttributes(UUID id) - { - Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(TrustStore.NAME, getName()); - attributes.put(TrustStore.ID, id); - attributes.put(FileTrustStore.PATH, TestSSLConstants.BROKER_TRUSTSTORE); - attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.BROKER_TRUSTSTORE_PASSWORD); - attributes.put(FileTrustStore.TRUST_STORE_TYPE, "jks"); - attributes.put(FileTrustStore.TRUST_MANAGER_FACTORY_ALGORITHM, TrustManagerFactory.getDefaultAlgorithm()); - attributes.put(FileTrustStore.PEERS_ONLY, Boolean.TRUE); - return attributes; - } - - -} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileKeyStoreTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileKeyStoreTest.java index aa6f1ca630..0e45582d7c 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileKeyStoreTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileKeyStoreTest.java @@ -32,10 +32,14 @@ import javax.net.ssl.KeyManager; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; +import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ConfiguredObjectFactory; import org.apache.qpid.server.model.IntegrityViolationException; +import org.apache.qpid.server.model.KeyStore; +import org.apache.qpid.server.model.Model; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.security.access.Operation; import org.apache.qpid.test.utils.QpidTestCase; @@ -46,17 +50,18 @@ import org.apache.qpid.util.FileUtils; public class FileKeyStoreTest extends QpidTestCase { private final Broker<?> _broker = mock(Broker.class); - private final CurrentThreadTaskExecutor _taskExecutor = new CurrentThreadTaskExecutor(); + private final TaskExecutor _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance(); private final SecurityManager _securityManager = mock(SecurityManager.class); + private final Model _model = BrokerModel.getInstance(); + private final ConfiguredObjectFactory _factory = _model.getObjectFactory(); + public void setUp() throws Exception { super.setUp(); - _taskExecutor.start(); when(_broker.getTaskExecutor()).thenReturn(_taskExecutor); - when(_broker.getModel()).thenReturn(BrokerModel.getInstance()); - + when(_broker.getModel()).thenReturn(_model); when(_broker.getSecurityManager()).thenReturn(_securityManager); } @@ -67,9 +72,7 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - - fileKeyStore.create(); + FileKeyStoreImpl fileKeyStore = (FileKeyStoreImpl) _factory.create(KeyStore.class, attributes, _broker); KeyManager[] keyManager = fileKeyStore.getKeyManagers(); assertNotNull(keyManager); @@ -85,9 +88,7 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); attributes.put(FileKeyStore.CERTIFICATE_ALIAS, TestSSLConstants.BROKER_KEYSTORE_ALIAS); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - - fileKeyStore.create(); + FileKeyStoreImpl fileKeyStore = (FileKeyStoreImpl) _factory.create(KeyStore.class, attributes, _broker); KeyManager[] keyManager = fileKeyStore.getKeyManagers(); assertNotNull(keyManager); @@ -102,11 +103,9 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); attributes.put(FileKeyStore.PASSWORD, "wrong"); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - try { - fileKeyStore.create(); + _factory.create(KeyStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -124,11 +123,9 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.KEYSTORE_PASSWORD); attributes.put(FileKeyStore.CERTIFICATE_ALIAS, "notknown"); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - try { - fileKeyStore.create(); + _factory.create(KeyStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -147,9 +144,7 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PATH, trustStoreAsDataUrl); attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - - fileKeyStore.create(); + FileKeyStoreImpl fileKeyStore = (FileKeyStoreImpl) _factory.create(KeyStore.class, attributes, _broker); KeyManager[] keyManagers = fileKeyStore.getKeyManagers(); assertNotNull(keyManagers); @@ -167,9 +162,7 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); attributes.put(FileKeyStore.CERTIFICATE_ALIAS, TestSSLConstants.BROKER_KEYSTORE_ALIAS); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - - fileKeyStore.create(); + FileKeyStoreImpl fileKeyStore = (FileKeyStoreImpl) _factory.create(KeyStore.class, attributes, _broker); KeyManager[] keyManagers = fileKeyStore.getKeyManagers(); assertNotNull(keyManagers); @@ -186,12 +179,9 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PASSWORD, "wrong"); attributes.put(FileKeyStore.PATH, keyStoreAsDataUrl); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - try { - - fileKeyStore.create(); + _factory.create(KeyStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -210,11 +200,9 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); attributes.put(FileKeyStore.PATH, keyStoreAsDataUrl); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - try { - fileKeyStore.create(); + _factory.create(KeyStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -235,11 +223,9 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PATH, keyStoreAsDataUrl); attributes.put(FileKeyStore.CERTIFICATE_ALIAS, "notknown"); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - try { - fileKeyStore.create(); + _factory.create(KeyStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -259,9 +245,7 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - - fileKeyStore.create(); + FileKeyStoreImpl fileKeyStore = (FileKeyStoreImpl) _factory.create(KeyStore.class, attributes, _broker); assertNull("Unexpected alias value before change", fileKeyStore.getCertificateAlias()); @@ -302,9 +286,8 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); + FileKeyStoreImpl fileKeyStore = (FileKeyStoreImpl) _factory.create(KeyStore.class, attributes, _broker); - fileKeyStore.create(); fileKeyStore.delete(); } @@ -319,9 +302,7 @@ public class FileKeyStoreTest extends QpidTestCase attributes.put(FileKeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); attributes.put(FileKeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - FileKeyStoreImpl fileKeyStore = new FileKeyStoreImpl(attributes, _broker); - - fileKeyStore.create(); + FileKeyStoreImpl fileKeyStore = (FileKeyStoreImpl) _factory.create(KeyStore.class, attributes, _broker); Port<?> port = mock(Port.class); when(port.getKeyStore()).thenReturn(fileKeyStore); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileTrustStoreTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileTrustStoreTest.java index 85cda6cd80..d965549cdd 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileTrustStoreTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/security/FileTrustStoreTest.java @@ -33,11 +33,14 @@ import javax.net.ssl.TrustManager; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; +import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.BrokerModel; import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ConfiguredObjectFactory; import org.apache.qpid.server.model.IntegrityViolationException; +import org.apache.qpid.server.model.Model; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.TrustStore; import org.apache.qpid.server.security.access.Operation; @@ -51,18 +54,19 @@ import org.apache.qpid.util.FileUtils; public class FileTrustStoreTest extends QpidTestCase { private final Broker<?> _broker = mock(Broker.class); - private final CurrentThreadTaskExecutor _taskExecutor = new CurrentThreadTaskExecutor(); + private final TaskExecutor _taskExecutor = CurrentThreadTaskExecutor.newStartedInstance(); private final SecurityManager _securityManager = mock(SecurityManager.class); + private final Model _model = BrokerModel.getInstance(); + private final ConfiguredObjectFactory _factory = _model.getObjectFactory(); public void setUp() throws Exception { super.setUp(); - _taskExecutor.start(); when(_broker.getTaskExecutor()).thenReturn(_taskExecutor); - when(_broker.getModel()).thenReturn(BrokerModel.getInstance()); - + when(_broker.getModel()).thenReturn(_model); when(_broker.getSecurityManager()).thenReturn(_securityManager); + } public void testCreateTrustStoreFromFile_Success() throws Exception @@ -72,9 +76,8 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - - fileTrustStore.create(); + FileTrustStoreImpl fileTrustStore = + (FileTrustStoreImpl) _factory.create(TrustStore.class, attributes, _broker); TrustManager[] trustManagers = fileTrustStore.getTrustManagers(); assertNotNull(trustManagers); @@ -89,11 +92,9 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); attributes.put(FileTrustStore.PASSWORD, "wrong"); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - try { - fileTrustStore.create(); + _factory.create(TrustStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -111,9 +112,8 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.BROKER_PEERSTORE_PASSWORD); attributes.put(FileTrustStore.PEERS_ONLY, true); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - - fileTrustStore.create(); + FileTrustStoreImpl fileTrustStore = + (FileTrustStoreImpl) _factory.create(TrustStore.class, attributes, _broker); TrustManager[] trustManagers = fileTrustStore.getTrustManagers(); assertNotNull(trustManagers); @@ -132,9 +132,8 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PATH, trustStoreAsDataUrl); attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - - fileTrustStore.create(); + FileTrustStoreImpl fileTrustStore = + (FileTrustStoreImpl) _factory.create(TrustStore.class, attributes, _broker); TrustManager[] trustManagers = fileTrustStore.getTrustManagers(); assertNotNull(trustManagers); @@ -151,12 +150,9 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PASSWORD, "wrong"); attributes.put(FileTrustStore.PATH, trustStoreAsDataUrl); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - try { - - fileTrustStore.create(); + _factory.create(TrustStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -175,11 +171,9 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); attributes.put(FileTrustStore.PATH, trustStoreAsDataUrl); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - try { - fileTrustStore.create(); + _factory.create(TrustStore.class, attributes, _broker); fail("Exception not thrown"); } catch (IllegalConfigurationException ice) @@ -200,9 +194,8 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - - fileTrustStore.create(); + FileTrustStoreImpl fileTrustStore = + (FileTrustStoreImpl) _factory.create(TrustStore.class, attributes, _broker); assertEquals("Unexpected path value before change", TestSSLConstants.TRUSTSTORE, fileTrustStore.getPath()); @@ -243,9 +236,9 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); + FileTrustStoreImpl fileTrustStore = + (FileTrustStoreImpl) _factory.create(TrustStore.class, attributes, _broker); - fileTrustStore.create(); fileTrustStore.delete(); } @@ -260,9 +253,8 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - - fileTrustStore.create(); + FileTrustStoreImpl fileTrustStore = + (FileTrustStoreImpl) _factory.create(TrustStore.class, attributes, _broker); SimpleLDAPAuthenticationManager ldap = mock(SimpleLDAPAuthenticationManager.class); when(ldap.getTrustStore()).thenReturn(fileTrustStore); @@ -292,9 +284,8 @@ public class FileTrustStoreTest extends QpidTestCase attributes.put(FileTrustStore.PATH, TestSSLConstants.TRUSTSTORE); attributes.put(FileTrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - FileTrustStoreImpl fileTrustStore = new FileTrustStoreImpl(attributes, _broker); - - fileTrustStore.create(); + FileTrustStoreImpl fileTrustStore = + (FileTrustStoreImpl) _factory.create(TrustStore.class, attributes, _broker); Port<?> port = mock(Port.class); when(port.getTrustStores()).thenReturn(Collections.<TrustStore>singletonList(fileTrustStore)); |
