Repository: activemq-6 Updated Branches: refs/heads/master 260f579c1 -> 475f2322e
http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/AddressSettingsDeployerTest.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/AddressSettingsDeployerTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/AddressSettingsDeployerTest.java deleted file mode 100644 index c41f192..0000000 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/AddressSettingsDeployerTest.java +++ /dev/null @@ -1,136 +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.activemq.tests.unit.core.deployers.impl; -import org.junit.Before; - -import org.junit.Test; - -import org.junit.Assert; - -import org.apache.activemq.api.core.SimpleString; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.deployers.impl.AddressSettingsDeployer; -import org.apache.activemq.core.settings.HierarchicalRepository; -import org.apache.activemq.core.settings.impl.AddressFullMessagePolicy; -import org.apache.activemq.core.settings.impl.AddressSettings; -import org.apache.activemq.core.settings.impl.HierarchicalObjectRepository; -import org.apache.activemq.tests.util.UnitTestCase; -import org.apache.activemq.utils.XMLUtil; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * @author <a href="[email protected]">Andy Taylor</a> - */ -public class AddressSettingsDeployerTest extends UnitTestCase -{ - private final String conf = "<address-setting match=\"queues.*\">\n" + " <dead-letter-address>DLQtest</dead-letter-address>\n" - + " <expiry-address>ExpiryQueueTest</expiry-address>\n" - + " <redelivery-delay>100</redelivery-delay>\n" - + " <max-delivery-attempts>32</max-delivery-attempts>\n" - + " <max-size-bytes>18238172365765</max-size-bytes>\n" - + " <page-size-bytes>2387273767666</page-size-bytes>\n" - + " <address-full-policy>DROP</address-full-policy>\n" - + " <message-counter-history-day-limit>1000</message-counter-history-day-limit>\n" - + " <last-value-queue>true</last-value-queue>\n" - + " <redistribution-delay>38383</redistribution-delay>\n" - + " <redelivery-delay-multiplier>2</redelivery-delay-multiplier>\n" - + " <max-redelivery-delay>12000</max-redelivery-delay>\n" - + " <send-to-dla-on-no-route>true</send-to-dla-on-no-route>\n" - + " </address-setting>"; - - private AddressSettingsDeployer addressSettingsDeployer; - - private HierarchicalRepository<AddressSettings> repository; - - @Override - @Before - public void setUp() throws Exception - { - super.setUp(); - - repository = new HierarchicalObjectRepository<AddressSettings>(); - DeploymentManager deploymentManager = new FakeDeploymentManager(); - addressSettingsDeployer = new AddressSettingsDeployer(deploymentManager, repository); - } - - @Test - public void testDeploy() throws Exception - { - addressSettingsDeployer.deploy(XMLUtil.stringToElement(conf)); - AddressSettings as = repository.getMatch("queues.aq"); - Assert.assertNotNull(as); - Assert.assertEquals(new SimpleString("DLQtest"), as.getDeadLetterAddress()); - Assert.assertEquals(new SimpleString("ExpiryQueueTest"), as.getExpiryAddress()); - Assert.assertEquals(100, as.getRedeliveryDelay()); - Assert.assertEquals(32, as.getMaxDeliveryAttempts()); - Assert.assertEquals(18238172365765L, as.getMaxSizeBytes()); - Assert.assertEquals(2387273767666L, as.getPageSizeBytes()); - Assert.assertEquals(AddressFullMessagePolicy.DROP, as.getAddressFullMessagePolicy()); - Assert.assertEquals(1000, as.getMessageCounterHistoryDayLimit()); - Assert.assertTrue(as.isLastValueQueue()); - Assert.assertEquals(38383, as.getRedistributionDelay()); - Assert.assertEquals(2.0, as.getRedeliveryMultiplier(), 0.000001); - Assert.assertEquals(12000, as.getMaxRedeliveryDelay()); - Assert.assertTrue(as.isSendToDLAOnNoRoute()); - - } - - @Test - public void testDeployFromConfigurationFile() throws Exception - { - String xml = "<configuration xmlns='urn:activemq'> " + "<address-settings>" + - conf + - "</address-settings>" + - "</configuration>"; - - Element rootNode = org.apache.activemq.utils.XMLUtil.stringToElement(xml); - addressSettingsDeployer.validate(rootNode); - NodeList addressSettingsNode = rootNode.getElementsByTagName("address-setting"); - Assert.assertEquals(1, addressSettingsNode.getLength()); - - addressSettingsDeployer.deploy(addressSettingsNode.item(0)); - AddressSettings as = repository.getMatch("queues.aq"); - Assert.assertNotNull(as); - Assert.assertEquals(new SimpleString("DLQtest"), as.getDeadLetterAddress()); - Assert.assertEquals(new SimpleString("ExpiryQueueTest"), as.getExpiryAddress()); - Assert.assertEquals(100, as.getRedeliveryDelay()); - Assert.assertEquals(2.0, as.getRedeliveryMultiplier(), 0.000001); - Assert.assertEquals(12000, as.getMaxRedeliveryDelay()); - Assert.assertEquals(32, as.getMaxDeliveryAttempts()); - Assert.assertEquals(18238172365765L, as.getMaxSizeBytes()); - Assert.assertEquals(2387273767666L, as.getPageSizeBytes()); - Assert.assertEquals(AddressFullMessagePolicy.DROP, as.getAddressFullMessagePolicy()); - Assert.assertEquals(1000, as.getMessageCounterHistoryDayLimit()); - Assert.assertTrue(as.isLastValueQueue()); - Assert.assertEquals(38383, as.getRedistributionDelay()); - Assert.assertTrue(as.isSendToDLAOnNoRoute()); - } - - @Test - public void testUndeploy() throws Exception - { - addressSettingsDeployer.deploy(XMLUtil.stringToElement(conf)); - AddressSettings as = repository.getMatch("queues.aq"); - Assert.assertNotNull(as); - addressSettingsDeployer.undeploy(XMLUtil.stringToElement(conf)); - as = repository.getMatch("queues.aq"); - Assert.assertNull(as); - } - -} - http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/BasicUserCredentialsDeployerTest.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/BasicUserCredentialsDeployerTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/BasicUserCredentialsDeployerTest.java deleted file mode 100644 index 92bcb8d..0000000 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/BasicUserCredentialsDeployerTest.java +++ /dev/null @@ -1,546 +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.activemq.tests.unit.core.deployers.impl; -import org.junit.Before; -import org.junit.After; - -import org.junit.Test; - -import org.junit.Assert; -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.deployers.impl.BasicUserCredentialsDeployer; -import org.apache.activemq.core.security.CheckType; -import org.apache.activemq.core.security.Role; -import org.apache.activemq.spi.core.security.ActiveMQSecurityManager; -import org.apache.activemq.tests.util.UnitTestCase; -import org.apache.activemq.utils.DefaultSensitiveStringCodec; -import org.apache.activemq.utils.XMLUtil; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * tests BasicUserCredentialsDeployer - * - * @author <a href="[email protected]">Andy Taylor</a> - */ -public class BasicUserCredentialsDeployerTest extends UnitTestCase -{ - private FakeDeployer deployer; - - private FakeActiveMQUpdateableSecurityManager securityManager; - - private URI url; - - private static final String simpleSecurityXml = "<configuration>\n" - + "<defaultuser name=\"guest\" password=\"guest\">\n" - + " <role name=\"guest\"/>\n" - + " </defaultuser>" - + "</configuration>"; - - private static final String singleUserXml = "<configuration>\n" - + " <user name=\"guest\" password=\"guest\">\n" - + " <role name=\"guest\"/>\n" - + " </user>\n" - + "</configuration>"; - - private static final String multipleUserXml = "<configuration>\n" - + " <user name=\"guest\" password=\"guest\">\n" - + " <role name=\"guest\"/>\n" - + " <role name=\"foo\"/>\n" - + " </user>\n" - + " <user name=\"anotherguest\" password=\"anotherguest\">\n" - + " <role name=\"anotherguest\"/>\n" - + " <role name=\"foo\"/>\n" - + " <role name=\"bar\"/>\n" - + " </user>\n" - + "</configuration>"; - - private static final String maskedPasswordXml = "<configuration>\n" - + "<mask-password>true</mask-password>\n" - + "<defaultuser name=\"guest\" password=\"PASSWORD_TOKEN1\">\n" - + " <role name=\"guest\"/>\n" - + " </defaultuser>\n" - + " <user name=\"user1\" password=\"PASSWORD_TOKEN2\">\n" - + " <role name=\"guest\"/>\n" - + " <role name=\"foo\"/>\n" - + " </user>\n" - + " <user name=\"user2\" password=\"PASSWORD_TOKEN3\">\n" - + " <role name=\"anotherguest\"/>\n" - + " <role name=\"foo\"/>\n" - + " <role name=\"bar\"/>\n" - + " </user>\n" - + "</configuration>"; - - private static final String passwordCodecXml = "<configuration>\n" - + "<mask-password>true</mask-password>\n" - + "<password-codec>PASSWORD_CODEC_TOKEN</password-codec>\n" - + "<defaultuser name=\"guest\" password=\"PASSWORD_TOKEN1\">\n" - + " <role name=\"guest\"/>\n" - + " </defaultuser>\n" - + " <user name=\"user1\" password=\"PASSWORD_TOKEN2\">\n" - + " <role name=\"guest\"/>\n" - + " <role name=\"foo\"/>\n" - + " </user>\n" - + " <user name=\"user2\" password=\"PASSWORD_TOKEN3\">\n" - + " <role name=\"anotherguest\"/>\n" - + " <role name=\"foo\"/>\n" - + " <role name=\"bar\"/>\n" - + " </user>\n" - + "</configuration>"; - - @Override - @Before - public void setUp() throws Exception - { - super.setUp(); - DeploymentManager deploymentManager = new FakeDeploymentManager(); - securityManager = new FakeActiveMQUpdateableSecurityManager(); - deployer = new FakeDeployer(deploymentManager, securityManager); - - url = new URI("http://localhost"); - } - - @Override - @After - public void tearDown() throws Exception - { - deployer = null; - - super.tearDown(); - } - - @Test - public void testSimpleDefaultSecurity() throws Exception - { - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.simpleSecurityXml)); - deployer.deploy(url); - - Assert.assertEquals("guest", securityManager.defaultUser); - User user = securityManager.users.get("guest"); - Assert.assertNotNull(user); - Assert.assertEquals("guest", user.user); - Assert.assertEquals("guest", user.password); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNotNull(roles); - Assert.assertEquals(1, roles.size()); - Assert.assertEquals("guest", roles.get(0)); - } - - @Test - public void testSingleUserDeploySecurity() throws Exception - { - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.singleUserXml)); - deployer.deploy(url); - - Assert.assertNull(securityManager.defaultUser); - User user = securityManager.users.get("guest"); - Assert.assertNotNull(user); - Assert.assertEquals("guest", user.user); - Assert.assertEquals("guest", user.password); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNotNull(roles); - Assert.assertEquals(1, roles.size()); - Assert.assertEquals("guest", roles.get(0)); - } - - @Test - public void testMultipleUserDeploySecurity() throws Exception - { - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.multipleUserXml)); - deployer.deploy(url); - - Assert.assertNull(securityManager.defaultUser); - User user = securityManager.users.get("guest"); - Assert.assertNotNull(user); - Assert.assertEquals("guest", user.user); - Assert.assertEquals("guest", user.password); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNotNull(roles); - Assert.assertEquals(2, roles.size()); - Assert.assertEquals("guest", roles.get(0)); - Assert.assertEquals("foo", roles.get(1)); - user = securityManager.users.get("anotherguest"); - Assert.assertNotNull(user); - Assert.assertEquals("anotherguest", user.user); - Assert.assertEquals("anotherguest", user.password); - roles = securityManager.roles.get("anotherguest"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - Assert.assertEquals("anotherguest", roles.get(0)); - Assert.assertEquals("foo", roles.get(1)); - Assert.assertEquals("bar", roles.get(2)); - } - - @Test - public void testMaskedPassword() throws Exception - { - String password1 = "helloworld1"; - String password2 = "helloworld2"; - String password3 = "helloworld3"; - - DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec(); - String mask1 = (String) codec.encode(password1); - String mask2 = (String) codec.encode(password2); - String mask3 = (String) codec.encode(password3); - - String config = maskedPasswordXml.replace("PASSWORD_TOKEN1", mask1); - config = config.replace("PASSWORD_TOKEN2", mask2); - config = config.replace("PASSWORD_TOKEN3", mask3); - - deployer.setElement(XMLUtil.stringToElement(config)); - deployer.deploy(url); - - User user1 = securityManager.users.get("guest"); - User user2 = securityManager.users.get("user1"); - User user3 = securityManager.users.get("user2"); - - assertEquals(password1, user1.password); - assertEquals(password2, user2.password); - assertEquals(password3, user3.password); - } - - @Test - public void testPasswordCodec() throws Exception - { - String password1 = "helloworld1"; - String password2 = "helloworld2"; - String password3 = "helloworld3"; - - DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec(); - Map<String, String> prop = new HashMap<String, String>(); - prop.put("key", "blahblah"); - codec.init(prop); - - String mask1 = (String) codec.encode(password1); - String mask2 = (String) codec.encode(password2); - String mask3 = (String) codec.encode(password3); - - String config = passwordCodecXml.replace("PASSWORD_TOKEN1", mask1); - config = config.replace("PASSWORD_TOKEN2", mask2); - config = config.replace("PASSWORD_TOKEN3", mask3); - config = config.replace("PASSWORD_CODEC_TOKEN", codec.getClass() - .getName() + ";key=blahblah"); - - deployer.setElement(XMLUtil.stringToElement(config)); - deployer.deploy(url); - - User user1 = securityManager.users.get("guest"); - User user2 = securityManager.users.get("user1"); - User user3 = securityManager.users.get("user2"); - - assertEquals(password1, user1.password); - assertEquals(password2, user2.password); - assertEquals(password3, user3.password); - } - - @Test - public void testUndeploy() throws Exception - { - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.simpleSecurityXml)); - deployer.deploy(url); - - deployer.undeploy(url); - - User user = securityManager.users.get("guest"); - Assert.assertNull(user); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNull(roles); - } - - @Test - public void testUndeployDifferentXml() throws Exception - { - - URI otherUrl = new URI("http://otherHost"); - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.multipleUserXml)); - deployer.deploy(url); - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.singleUserXml)); - deployer.deploy(otherUrl); - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.singleUserXml)); - deployer.undeploy(otherUrl); - - Assert.assertNull(securityManager.defaultUser); - User user = securityManager.users.get("guest"); - Assert.assertNull(user); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNull(roles); - - user = securityManager.users.get("anotherguest"); - Assert.assertNotNull(user); - Assert.assertEquals("anotherguest", user.user); - Assert.assertEquals("anotherguest", user.password); - roles = securityManager.roles.get("anotherguest"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - Assert.assertEquals("anotherguest", roles.get(0)); - Assert.assertEquals("foo", roles.get(1)); - Assert.assertEquals("bar", roles.get(2)); - } - - @Test - public void testRedeploy() throws Exception - { - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.singleUserXml)); - deployer.redeploy(url); - - Assert.assertNull(securityManager.defaultUser); - - User user = securityManager.users.get("guest"); - Assert.assertNotNull(user); - Assert.assertEquals("guest", user.user); - Assert.assertEquals("guest", user.password); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNotNull(roles); - Assert.assertEquals(1, roles.size()); - Assert.assertEquals("guest", roles.get(0)); - } - - @Test - public void testRedeploySingleUser() throws Exception - { - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.multipleUserXml)); - deployer.deploy(url); - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.singleUserXml)); - deployer.redeploy(url); - - Assert.assertNull(securityManager.defaultUser); - - User user = securityManager.users.get("guest"); - Assert.assertNotNull(user); - Assert.assertEquals("guest", user.user); - Assert.assertEquals("guest", user.password); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNotNull(roles); - Assert.assertEquals(1, roles.size()); - Assert.assertEquals("guest", roles.get(0)); - - user = securityManager.users.get("anotherguest"); - Assert.assertNull(user); - roles = securityManager.roles.get("anotherguest"); - Assert.assertNull(roles); - } - - @Test - public void testRedeployMultipleUser() throws Exception - { - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.singleUserXml)); - deployer.deploy(url); - - deployer.setElement(XMLUtil.stringToElement(BasicUserCredentialsDeployerTest.multipleUserXml)); - deployer.redeploy(url); - - Assert.assertNull(securityManager.defaultUser); - - User user = securityManager.users.get("guest"); - Assert.assertNotNull(user); - Assert.assertEquals("guest", user.user); - Assert.assertEquals("guest", user.password); - List<String> roles = securityManager.roles.get("guest"); - Assert.assertNotNull(roles); - Assert.assertEquals(2, roles.size()); - Assert.assertEquals("guest", roles.get(0)); - Assert.assertEquals("foo", roles.get(1)); - - user = securityManager.users.get("anotherguest"); - Assert.assertNotNull(user); - Assert.assertEquals("anotherguest", user.user); - Assert.assertEquals("anotherguest", user.password); - roles = securityManager.roles.get("anotherguest"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - Assert.assertEquals("anotherguest", roles.get(0)); - Assert.assertEquals("foo", roles.get(1)); - Assert.assertEquals("bar", roles.get(2)); - } - - class FakeDeployer extends BasicUserCredentialsDeployer - { - private Element element; - - public FakeDeployer(DeploymentManager deploymentManager, ActiveMQSecurityManager activeMQSecurityManager) - { - super(deploymentManager, activeMQSecurityManager); - } - - public Element getElement() - { - return element; - } - - public void setElement(Element element) - { - this.element = element; - } - - @Override - protected Element getRootElement(URI url) throws Exception - { - return this.element; - } - - @Override - public void validate(Node rootNode) throws Exception - { - - } - } - - class FakeActiveMQUpdateableSecurityManager implements ActiveMQSecurityManager - { - String defaultUser; - - private final Map<String, User> users = new HashMap<String, User>(); - - private final Map<String, List<String>> roles = new HashMap<String, List<String>>(); - - public void addUser(final String user, final String password) - { - if (user == null) - { - throw new IllegalArgumentException("User cannot be null"); - } - if (password == null) - { - throw new IllegalArgumentException("password cannot be null"); - } - users.put(user, new User(user, password)); - } - - public void removeUser(final String user) - { - users.remove(user); - roles.remove(user); - } - - public void addRole(final String user, final String role) - { - if (roles.get(user) == null) - { - roles.put(user, new ArrayList<String>()); - } - roles.get(user).add(role); - } - - public void removeRole(final String user, final String role) - { - if (roles.get(user) == null) - { - return; - } - roles.get(user).remove(role); - } - - public void setDefaultUser(final String username) - { - defaultUser = username; - } - - public boolean validateUser(final String user, final String password) - { - return false; - } - - public boolean validateUserAndRole(final String user, - final String password, - final Set<Role> roles, - final CheckType checkType) - { - return false; - } - - public void start() - { - } - - public void stop() - { - } - - public boolean isStarted() - { - return true; - } - } - - static class User - { - final String user; - - final String password; - - User(final String user, final String password) - { - this.user = user; - this.password = password; - } - - @Override - public boolean equals(final Object o) - { - if (this == o) - { - return true; - } - if (o == null || getClass() != o.getClass()) - { - return false; - } - - User user1 = (User)o; - - if (!user.equals(user1.user)) - { - return false; - } - - return true; - } - - @Override - public int hashCode() - { - return user.hashCode(); - } - - public boolean isValid(final String user, final String password) - { - if (user == null) - { - return false; - } - return this.user.equals(user) && this.password.equals(password); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FakeDeploymentManager.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FakeDeploymentManager.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FakeDeploymentManager.java deleted file mode 100644 index d5447ce..0000000 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FakeDeploymentManager.java +++ /dev/null @@ -1,51 +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.activemq.tests.unit.core.deployers.impl; - -import org.apache.activemq.core.deployers.Deployer; -import org.apache.activemq.core.deployers.DeploymentManager; - -/** - * @author <a href="mailto:[email protected]">Andy Taylor</a> -*/ -class FakeDeploymentManager implements DeploymentManager -{ - private boolean started; - - public boolean isStarted() - { - return started; - } - - public void start() throws Exception - { - started = true; - } - - public void stop() throws Exception - { - started = false; - } - - public void registerDeployer(final Deployer deployer) throws Exception - { - } - - public void unregisterDeployer(final Deployer deployer) throws Exception - { - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java deleted file mode 100644 index 96a23fc..0000000 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/FileDeploymentManagerTest.java +++ /dev/null @@ -1,439 +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.activemq.tests.unit.core.deployers.impl; - -import java.io.File; -import java.net.URI; -import java.util.Map; - -import org.apache.activemq.api.core.Pair; -import org.apache.activemq.core.deployers.Deployer; -import org.apache.activemq.core.deployers.impl.FileDeploymentManager; -import org.apache.activemq.core.deployers.impl.FileDeploymentManager.DeployInfo; -import org.apache.activemq.tests.unit.UnitTestLogger; -import org.apache.activemq.tests.util.UnitTestCase; -import org.junit.Assert; -import org.junit.Test; - -/** - * A FileDeploymentManagerTest - * - * @author <a href="mailto:[email protected]">Tim Fox</a> - */ -public class FileDeploymentManagerTest extends UnitTestCase -{ - @Test - public void testStartStop1() throws Exception - { - testStartStop1("fdm_test_file.xml"); - } - - @Test - public void testStartStop2() throws Exception - { - testStartStop2("fdm_test_file.xml"); - } - - @Test - public void testStartStop1WithWhitespace() throws Exception - { - testStartStop1("fdm test file.xml"); - if (!isWindows()) - { - testStartStop1("fdm\ttest\tfile.xml"); - } - } - - @Test - public void testStartStop2WithWhitespace() throws Exception - { - testStartStop2("fdm test file.xml"); - if (!isWindows()) - { - testStartStop2("fdm\ttest\tfile.xml"); - } - } - - private void testStartStop1(final String filename) throws Exception - { - FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE); - - UnitTestLogger.LOGGER.debug("Filename is " + filename); - - File file = new File("target/test-classes/"); - - file.mkdirs(); - - file = new File("target/test-classes/" + filename); - - UnitTestLogger.LOGGER.debug(file.getAbsoluteFile()); - - file.createNewFile(); - - FakeDeployer deployer = new FakeDeployer(filename); - - fdm.registerDeployer(deployer); - - fdm.unregisterDeployer(deployer); - - fdm.registerDeployer(deployer); - - fdm.start(); - try - { - URI expected = file.toURI(); - URI deployedUrl = deployer.deployedUri; - Assert.assertTrue(expected.toString().equalsIgnoreCase(deployedUrl.toString())); - deployer.deployedUri = null; - fdm.start(); - Assert.assertNull(deployer.deployedUri); - fdm.stop(); - - } - finally - { - file.delete(); - fdm.stop(); - } - } - - private void testStartStop2(final String filename) throws Exception - { - FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE); - - UnitTestLogger.LOGGER.debug("Filename is " + filename); - - File file = new File("target/test-classes/"); - - file.mkdirs(); - - file = new File("target/test-classes/" + filename); - - UnitTestLogger.LOGGER.debug(file.getAbsoluteFile()); - - file.createNewFile(); - - FakeDeployer deployer = new FakeDeployer(filename); - - fdm.start(); - - try - { - fdm.registerDeployer(deployer); - URI expected = file.toURI(); - URI deployedUrl = deployer.deployedUri; - Assert.assertTrue(expected.toString().equalsIgnoreCase(deployedUrl.toString())); - deployer.deployedUri = null; - fdm.start(); - Assert.assertNull(deployer.deployedUri); - fdm.stop(); - } - finally - { - file.delete(); - fdm.stop(); - } - } - - @Test - public void testRegisterUnregister() throws Exception - { - FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE); - - fdm.start(); - - String filename1 = "fdm_test_file.xml1"; - String filename2 = "fdm_test_file.xml2"; - String filename3 = "fdm_test_file.xml3"; - - File file1 = new File("target/test-classes/"); - File file2 = new File("target/test-classes/"); - File file3 = new File("target/test-classes/"); - - file1.mkdirs(); - file2.mkdirs(); - file3.mkdirs(); - - file1 = new File("target/test-classes/" + filename1); - file2 = new File("target/test-classes/" + filename2); - file3 = new File("target/test-classes/" + filename3); - - file1.createNewFile(); - file2.createNewFile(); - file3.createNewFile(); - - FakeDeployer deployer1 = new FakeDeployer(filename1); - FakeDeployer deployer2 = new FakeDeployer(filename2); - FakeDeployer deployer3 = new FakeDeployer(filename3); - FakeDeployer deployer4 = new FakeDeployer(filename3); // Can have multiple deployers on the same file - try - { - URI url1 = file1.toURI(); - deployer1.deploy(url1); - - URI url2 = file2.toURI(); - deployer2.deploy(url2); - - URI url3 = file3.toURI(); - deployer3.deploy(url3); - - deployer4.deploy(url3); - - fdm.registerDeployer(deployer1); - fdm.registerDeployer(deployer2); - fdm.registerDeployer(deployer3); - fdm.registerDeployer(deployer4); - - Assert.assertEquals(4, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer1)); - Assert.assertTrue(fdm.getDeployers().contains(deployer2)); - Assert.assertTrue(fdm.getDeployers().contains(deployer3)); - Assert.assertTrue(fdm.getDeployers().contains(deployer4)); - Assert.assertEquals(4, fdm.getDeployed().size()); - - Assert.assertEquals(file1.toURI(), deployer1.deployedUri); - Assert.assertEquals(file2.toURI(), deployer2.deployedUri); - Assert.assertEquals(file3.toURI(), deployer3.deployedUri); - Assert.assertEquals(file3.toURI(), deployer4.deployedUri); - // Registering same again should do nothing - - fdm.registerDeployer(deployer1); - - Assert.assertEquals(4, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer1)); - Assert.assertTrue(fdm.getDeployers().contains(deployer2)); - Assert.assertTrue(fdm.getDeployers().contains(deployer3)); - Assert.assertTrue(fdm.getDeployers().contains(deployer4)); - Assert.assertEquals(4, fdm.getDeployed().size()); - - fdm.unregisterDeployer(deployer1); - - Assert.assertEquals(3, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer2)); - Assert.assertTrue(fdm.getDeployers().contains(deployer3)); - Assert.assertTrue(fdm.getDeployers().contains(deployer4)); - Assert.assertEquals(3, fdm.getDeployed().size()); - - fdm.unregisterDeployer(deployer2); - fdm.unregisterDeployer(deployer3); - - Assert.assertEquals(1, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer4)); - Assert.assertEquals(1, fdm.getDeployed().size()); - - fdm.unregisterDeployer(deployer4); - - Assert.assertEquals(0, fdm.getDeployers().size()); - Assert.assertEquals(0, fdm.getDeployed().size()); - - // Now unregister again - should do nothing - - fdm.unregisterDeployer(deployer1); - - Assert.assertEquals(0, fdm.getDeployers().size()); - Assert.assertEquals(0, fdm.getDeployed().size()); - } - finally - { - file1.delete(); - file2.delete(); - file3.delete(); - fdm.stop(); - } - - } - - @Test - public void testRedeploy() throws Exception - { - FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE); - - fdm.start(); - - String filename = "fdm_test_file.xml1"; - - File file = new File("target/test-classes/"); - - file.mkdirs(); - - file = new File("target/test-classes/" + filename); - - file.createNewFile(); - long oldLastModified = file.lastModified(); - - FakeDeployer deployer = new FakeDeployer(filename); - try - { - URI url = file.toURI(); - deployer.deploy(url); - - fdm.registerDeployer(deployer); - Assert.assertEquals(file.toURI(), deployer.deployedUri); - // Touch the file - file.setLastModified(oldLastModified + 1000); - - deployer.redeploy(url); - - fdm.run(); - - Assert.assertEquals(1, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer)); - Map<Pair<URI, Deployer>, DeployInfo> info = fdm.getDeployed(); - Assert.assertEquals(1, info.size()); - URI expected = file.toURI(); - URI deployedUrl = deployer.deployedUri; - Assert.assertTrue(expected.toString().equalsIgnoreCase(deployedUrl.toString())); - Pair<URI, Deployer> pair = new Pair<URI, Deployer>(url, deployer); - Assert.assertEquals(oldLastModified + 1000, fdm.getDeployed().get(pair).lastModified); - deployer.reDeployedUri = null; - // Scanning again should not redeploy - - fdm.run(); - - Assert.assertEquals(oldLastModified + 1000, fdm.getDeployed().get(pair).lastModified); - Assert.assertNull(deployer.reDeployedUri); - } - finally - { - file.delete(); - fdm.stop(); - } - } - - @Test - public void testUndeployAndDeployAgain() throws Exception - { - FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE); - - fdm.start(); - - String filename = "fdm_test_file.xml1"; - - File file = new File("target/test-classes/"); - - file.mkdirs(); - - file = new File("target/test-classes/" + filename); - - file.createNewFile(); - - FakeDeployer deployer = new FakeDeployer(filename); - try - { - URI uri = file.toURI(); - deployer.deploy(uri); - - fdm.registerDeployer(deployer); - - Assert.assertEquals(1, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer)); - Assert.assertEquals(1, fdm.getDeployed().size()); - Assert.assertEquals(file.toURI(), deployer.deployedUri); - deployer.deployedUri = null; - file.delete(); - - // This should cause undeployment - - deployer.undeploy(uri); - Assert.assertEquals(file.toURI(), deployer.unDeployedUri); - - fdm.run(); - - Assert.assertEquals(1, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer)); - Assert.assertEquals(0, fdm.getDeployed().size()); - - // Recreate file and it should be redeployed - - file.createNewFile(); - - deployer.deploy(uri); - - fdm.run(); - - Assert.assertEquals(1, fdm.getDeployers().size()); - Assert.assertTrue(fdm.getDeployers().contains(deployer)); - Assert.assertEquals(1, fdm.getDeployed().size()); - - Assert.assertEquals(file.toURI(), deployer.deployedUri); - } - finally - { - file.delete(); - fdm.stop(); - } - } - - class FakeDeployer implements Deployer - { - URI deployedUri; - - URI unDeployedUri; - - URI reDeployedUri; - - boolean started; - - private final String file; - - public FakeDeployer(final String file) - { - this.file = file; - } - - public String[] getConfigFileNames() - { - return new String[]{file}; - } - - @Override - public void deploy(final URI url) throws Exception - { - deployedUri = url; - } - - @Override - public void redeploy(final URI url) throws Exception - { - reDeployedUri = url; - } - - @Override - public void undeploy(final URI url) throws Exception - { - unDeployedUri = url; - } - - @Override - public void start() throws Exception - { - started = true; - } - - @Override - public void stop() throws Exception - { - started = false; - } - - @Override - public boolean isStarted() - { - return started; - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/SecurityDeployerTest.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/SecurityDeployerTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/SecurityDeployerTest.java deleted file mode 100644 index e16519e..0000000 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/SecurityDeployerTest.java +++ /dev/null @@ -1,317 +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.activemq.tests.unit.core.deployers.impl; - -import java.util.HashSet; -import java.util.Set; - -import org.apache.activemq.core.deployers.DeploymentManager; -import org.apache.activemq.core.deployers.impl.SecurityDeployer; -import org.apache.activemq.core.security.Role; -import org.apache.activemq.core.settings.HierarchicalRepository; -import org.apache.activemq.core.settings.impl.HierarchicalObjectRepository; -import org.apache.activemq.tests.util.UnitTestCase; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.w3c.dom.Element; -import org.w3c.dom.NodeList; - -/** - * @author <a href="[email protected]">Andy Taylor</a> - */ -public class SecurityDeployerTest extends UnitTestCase -{ - private SecurityDeployer deployer; - - private final String conf = "<security-setting match=\"jms.topic.testTopic\">\n" + " <permission type=\"createDurableQueue\" roles=\"durpublisher\"/>\n" - + " <permission type=\"deleteDurableQueue\" roles=\"durpublisher\"/>\n" - + " <permission type=\"consume\" roles=\"guest,publisher,durpublisher\"/>\n" - + " <permission type=\"send\" roles=\"guest,publisher,durpublisher\"/>\n" - + " <permission type=\"manage\" roles=\"guest,publisher,durpublisher\"/>\n" - + " </security-setting>"; - - private final String confWithWhiteSpace1 = "<security-setting match=\"jms.topic.testTopic\">\n" - + " <permission type=\"createDurableQueue\" roles=\"guest, publisher, durpublisher\"/>\n" - + " <permission type=\"createNonDurableQueue\" roles=\"guest, publisher, durpublisher\"/>\n" - + " <permission type=\"deleteNonDurableQueue\" roles=\"guest, publisher, durpublisher\"/>\n" - + " <permission type=\"deleteDurableQueue\" roles=\"guest, publisher, durpublisher\"/>\n" - - + " <permission type=\"consume\" roles=\"guest, publisher, durpublisher\"/>\n" - + " <permission type=\"send\" roles=\"guest, publisher, durpublisher\"/>\n" - + " <permission type=\"manage\" roles=\"guest, publisher, durpublisher\"/>\n" - + " <permission type=\"manage\" roles=\"guest, publisher, durpublisher\"/>\n" - + " </security-setting>"; - - private final String confWithWhiteSpace2 = "<security-setting match=\"jms.topic.testTopic\">\n" - + " <permission type=\"createDurableQueue\" roles=\"guest , publisher , durpublisher\"/>\n" - + " <permission type=\"createNonDurableQueue\" roles=\"guest , publisher , durpublisher\"/>\n" - + " <permission type=\"deleteNonDurableQueue\" roles=\"guest , publisher , durpublisher\"/>\n" - + " <permission type=\"deleteDurableQueue\" roles=\"guest , publisher , durpublisher\"/>\n" - - + " <permission type=\"consume\" roles=\"guest , publisher , durpublisher\"/>\n" - + " <permission type=\"send\" roles=\"guest , publisher , durpublisher\"/>\n" - + " <permission type=\"manage\" roles=\"guest , publisher , durpublisher\"/>\n" - + " </security-setting>"; - - private final String conf2 = "<security-setting match=\"jms.topic.testQueue\">\n" - + " <permission type=\"createNonDurableQueue\" roles=\"durpublisher\"/>\n" - + " <permission type=\"deleteNonDurableQueue\" roles=\"durpublisher\"/>\n" - + " <permission type=\"consume\" roles=\"guest,publisher,durpublisher\"/>\n" - + " <permission type=\"send\" roles=\"guest,publisher,durpublisher\"/>\n" - + " </security-setting>"; - - private final String noRoles = " <securityfoo match=\"queues.testQueue\">\n" + " </securityfoo>"; - - private HierarchicalRepository<Set<Role>> repository; - - @Override - @Before - public void setUp() throws Exception - { - super.setUp(); - - repository = new HierarchicalObjectRepository<Set<Role>>(); - DeploymentManager deploymentManager = new FakeDeploymentManager(); - deployer = new SecurityDeployer(deploymentManager, repository); - } - - @Test - public void testSingle() throws Exception - { - Element e = org.apache.activemq.utils.XMLUtil.stringToElement(conf); - deployer.deploy(e); - HashSet<Role> roles = (HashSet<Role>) repository.getMatch("jms.topic.testTopic"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - for (Role role : roles) - { - if (role.getName().equals("guest")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertFalse(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertFalse(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("publisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertFalse(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertFalse(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("durpublisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertTrue(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertTrue(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else - { - Assert.fail("unexpected role"); - } - } - } - - @Test - public void testWithWhiteSpace1() throws Exception - { - testWithWhiteSpace(confWithWhiteSpace1); - } - - @Test - public void testWithWhiteSpace2() throws Exception - { - testWithWhiteSpace(confWithWhiteSpace2); - } - - private void testWithWhiteSpace(String conf) throws Exception - { - Element e = org.apache.activemq.utils.XMLUtil.stringToElement(confWithWhiteSpace1); - deployer.deploy(e); - HashSet<Role> roles = (HashSet<Role>) repository.getMatch("jms.topic.testTopic"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - for (Role role : roles) - { - if (role.getName().equals("guest")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertTrue(role.isCreateDurableQueue()); - Assert.assertTrue(role.isCreateNonDurableQueue()); - Assert.assertTrue(role.isDeleteDurableQueue()); - Assert.assertTrue(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("publisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertTrue(role.isCreateDurableQueue()); - Assert.assertTrue(role.isCreateNonDurableQueue()); - Assert.assertTrue(role.isDeleteDurableQueue()); - Assert.assertTrue(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("durpublisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertTrue(role.isCreateDurableQueue()); - Assert.assertTrue(role.isCreateNonDurableQueue()); - Assert.assertTrue(role.isDeleteDurableQueue()); - Assert.assertTrue(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else - { - Assert.fail("unexpected role"); - } - } - } - - @Test - public void testMultiple() throws Exception - { - deployer.deploy(org.apache.activemq.utils.XMLUtil.stringToElement(conf)); - deployer.deploy(org.apache.activemq.utils.XMLUtil.stringToElement(conf2)); - HashSet<Role> roles = (HashSet<Role>) repository.getMatch("jms.topic.testTopic"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - for (Role role : roles) - { - if (role.getName().equals("guest")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertFalse(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertFalse(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("publisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertFalse(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertFalse(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("durpublisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertTrue(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertTrue(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertTrue(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else - { - Assert.fail("unexpected role"); - } - } - roles = (HashSet<Role>) repository.getMatch("jms.topic.testQueue"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - for (Role role : roles) - { - if (role.getName().equals("guest")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertFalse(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertFalse(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertFalse(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("publisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertFalse(role.isCreateDurableQueue()); - Assert.assertFalse(role.isCreateNonDurableQueue()); - Assert.assertFalse(role.isDeleteDurableQueue()); - Assert.assertFalse(role.isDeleteNonDurableQueue()); - Assert.assertFalse(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else if (role.getName().equals("durpublisher")) - { - Assert.assertTrue(role.isConsume()); - Assert.assertFalse(role.isCreateDurableQueue()); - Assert.assertTrue(role.isCreateNonDurableQueue()); - Assert.assertFalse(role.isDeleteDurableQueue()); - Assert.assertTrue(role.isDeleteNonDurableQueue()); - Assert.assertFalse(role.isManage()); - Assert.assertTrue(role.isSend()); - } - else - { - Assert.fail("unexpected role"); - } - } - } - - @Test - public void testNoRolesAdded() throws Exception - { - deployer.deploy(org.apache.activemq.utils.XMLUtil.stringToElement(noRoles)); - HashSet<Role> roles = (HashSet<Role>) repository.getMatch("jms.topic.testQueue"); - Assert.assertNull(roles); - } - - @Test - public void testDeployFromConfigurationFile() throws Exception - { - String xml = "<configuration xmlns='urn:activemq'> " + "<security-settings>" - + " <security-setting match=\"jms.topic.testTopic\">" - + " <permission type=\"createDurableQueue\" roles=\"durpublisher\"/>" - + " <permission type=\"deleteDurableQueue\" roles=\"durpublisher\"/>" - + " <permission type=\"consume\" roles=\"guest,publisher,durpublisher\"/>" - + " <permission type=\"send\" roles=\"guest,publisher,durpublisher\"/>" - + " <permission type=\"manage\" roles=\"guest,publisher,durpublisher\"/>" - + " </security-setting>" - + "</security-settings>" - + "</configuration>"; - - Element rootNode = org.apache.activemq.utils.XMLUtil.stringToElement(xml); - deployer.validate(rootNode); - NodeList securityNodes = rootNode.getElementsByTagName("security-setting"); - Assert.assertEquals(1, securityNodes.getLength()); - - deployer.deploy(securityNodes.item(0)); - HashSet<Role> roles = (HashSet<Role>) repository.getMatch("jms.topic.testTopic"); - Assert.assertNotNull(roles); - Assert.assertEquals(3, roles.size()); - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/XMLDeployerTest.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/XMLDeployerTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/XMLDeployerTest.java deleted file mode 100644 index 1d4b3b7..0000000 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/deployers/impl/XMLDeployerTest.java +++ /dev/null @@ -1,267 +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.activemq.tests.unit.core.deployers.impl; - -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; - -import org.apache.activemq.core.deployers.impl.XmlDeployer; -import org.apache.activemq.tests.util.UnitTestCase; -import org.apache.activemq.utils.XMLUtil; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * tests the abstract xml deployer class - * - * @author <a href="[email protected]">Andy Taylor</a> - */ -public class XMLDeployerTest extends UnitTestCase -{ - private static final String conf1 = "<configuration>\n" + " <test name=\"test1\">content1</test>\n" - + " <test name=\"test2\">content2</test>\n" - + " <test name=\"test3\">content3</test>\n" - + " <test name=\"test4\">content4</test>\n" - + "</configuration>"; - - private static final String conf2 = "<configuration>\n" + " <test name=\"test1\">content1</test>\n" - + " <test name=\"test2\">contenthaschanged2</test>\n" - + " <test name=\"test3\">contenthaschanged3</test>\n" - + " <test name=\"test4\">content4</test>\n" - + "</configuration>"; - - private static final String conf3 = "<configuration>\n" + " <test name=\"test1\">content1</test>\n" - + " <test name=\"test2\">contenthaschanged2</test>\n" - + "</configuration>"; - - private static final String conf4 = "<configuration>\n" + " <test name=\"test1\">content1</test>\n" - + " <test name=\"test2\">content2</test>\n" - + " <test name=\"test3\">content3</test>\n" - + " <test name=\"test4\">content4</test>\n" - + " <test name=\"test5\">content5</test>\n" - + " <test name=\"test6\">content6</test>\n" - + "</configuration>"; - - private URI url; - - @Override - @Before - public void setUp() throws Exception - { - super.setUp(); - url = new URI("http://localhost"); - } - - @Test - public void testDeploy() throws Exception - { - Element e = XMLUtil.stringToElement(XMLDeployerTest.conf1); - TestDeployer testDeployer = new TestDeployer(); - testDeployer.setElement(e); - testDeployer.deploy(url); - Assert.assertEquals(testDeployer.getDeployments(), 4); - Assert.assertNotNull(testDeployer.getNodes().get("test1")); - Assert.assertNotNull(testDeployer.getNodes().get("test2")); - Assert.assertNotNull(testDeployer.getNodes().get("test3")); - Assert.assertNotNull(testDeployer.getNodes().get("test4")); - Assert.assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1"); - Assert.assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "content2"); - Assert.assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "content3"); - Assert.assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4"); - } - - @Test - public void testRedeploy() throws Exception - { - Element e = XMLUtil.stringToElement(XMLDeployerTest.conf1); - TestDeployer testDeployer = new TestDeployer(); - testDeployer.setElement(e); - testDeployer.deploy(url); - e = org.apache.activemq.utils.XMLUtil.stringToElement(XMLDeployerTest.conf2); - testDeployer.setElement(e); - testDeployer.redeploy(url); - Assert.assertEquals(testDeployer.getDeployments(), 4); - Assert.assertNotNull(testDeployer.getNodes().get("test1")); - Assert.assertNotNull(testDeployer.getNodes().get("test2")); - Assert.assertNotNull(testDeployer.getNodes().get("test3")); - Assert.assertNotNull(testDeployer.getNodes().get("test4")); - Assert.assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1"); - Assert.assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "contenthaschanged2"); - Assert.assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "contenthaschanged3"); - Assert.assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4"); - } - - @Test - public void testRedeployRemovingNodes() throws Exception - { - Element e = XMLUtil.stringToElement(XMLDeployerTest.conf1); - TestDeployer testDeployer = new TestDeployer(); - testDeployer.setElement(e); - testDeployer.deploy(url); - e = org.apache.activemq.utils.XMLUtil.stringToElement(XMLDeployerTest.conf3); - testDeployer.setElement(e); - testDeployer.redeploy(url); - Assert.assertEquals(testDeployer.getDeployments(), 2); - Assert.assertNotNull(testDeployer.getNodes().get("test1")); - Assert.assertNotNull(testDeployer.getNodes().get("test2")); - Assert.assertNull(testDeployer.getNodes().get("test3")); - Assert.assertNull(testDeployer.getNodes().get("test4")); - Assert.assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1"); - Assert.assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "contenthaschanged2"); - } - - @Test - public void testRedeployAddingNodes() throws Exception - { - Element e = XMLUtil.stringToElement(XMLDeployerTest.conf1); - TestDeployer testDeployer = new TestDeployer(); - testDeployer.setElement(e); - testDeployer.deploy(url); - e = org.apache.activemq.utils.XMLUtil.stringToElement(XMLDeployerTest.conf4); - testDeployer.setElement(e); - testDeployer.redeploy(url); - Assert.assertEquals(testDeployer.getDeployments(), 6); - Assert.assertNotNull(testDeployer.getNodes().get("test1")); - Assert.assertNotNull(testDeployer.getNodes().get("test2")); - Assert.assertNotNull(testDeployer.getNodes().get("test3")); - Assert.assertNotNull(testDeployer.getNodes().get("test4")); - Assert.assertNotNull(testDeployer.getNodes().get("test5")); - Assert.assertNotNull(testDeployer.getNodes().get("test6")); - Assert.assertEquals(testDeployer.getNodes().get("test1").getTextContent(), "content1"); - Assert.assertEquals(testDeployer.getNodes().get("test2").getTextContent(), "content2"); - Assert.assertEquals(testDeployer.getNodes().get("test3").getTextContent(), "content3"); - Assert.assertEquals(testDeployer.getNodes().get("test4").getTextContent(), "content4"); - Assert.assertEquals(testDeployer.getNodes().get("test5").getTextContent(), "content5"); - Assert.assertEquals(testDeployer.getNodes().get("test6").getTextContent(), "content6"); - } - - @Test - public void testUndeploy() throws Exception - { - Element e = org.apache.activemq.utils.XMLUtil.stringToElement(XMLDeployerTest.conf1); - TestDeployer testDeployer = new TestDeployer(); - testDeployer.setElement(e); - testDeployer.deploy(url); - testDeployer.undeploy(url); - Assert.assertEquals(testDeployer.getDeployments(), 0); - Assert.assertNull(testDeployer.getNodes().get("test1")); - Assert.assertNull(testDeployer.getNodes().get("test2")); - Assert.assertNull(testDeployer.getNodes().get("test3")); - Assert.assertNull(testDeployer.getNodes().get("test4")); - } - - class TestDeployer extends XmlDeployer - { - private String elementname = "test"; - - Element element = null; - - private int deployments = 0; - - ArrayList<String> contents = new ArrayList<String>(); - - HashMap<String, Node> nodes = new HashMap<String, Node>(); - - public TestDeployer() - { - super(null); - } - - public HashMap<String, Node> getNodes() - { - return nodes; - } - - public ArrayList<String> getContents() - { - return contents; - } - - public int getDeployments() - { - return deployments; - } - - public String getElementname() - { - return elementname; - } - - public void setElementname(final String elementname) - { - this.elementname = elementname; - } - - public Element getElement() - { - return element; - } - - public void setElement(final Element element) - { - this.element = element; - } - - @Override - public String[] getElementTagName() - { - return new String[]{elementname}; - } - - @Override - public String[] getConfigFileNames() - { - return new String[]{"test"}; - } - - @Override - public String[] getDefaultConfigFileNames() - { - return new String[0]; - } - - @Override - public void validate(final Node rootNode) throws Exception - { - } - - @Override - public void deploy(final Node node) throws Exception - { - deployments++; - contents.add(node.getTextContent()); - nodes.put(node.getAttributes().getNamedItem(XmlDeployer.NAME_ATTR).getNodeValue(), node); - } - - @Override - public void undeploy(final Node node) throws Exception - { - deployments--; - nodes.remove(node.getAttributes().getNamedItem(XmlDeployer.NAME_ATTR).getNodeValue()); - } - - @Override - protected Element getRootElement(final URI url) - { - return element; - } - } -} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/4b63891a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/security/impl/ActiveMQSecurityManagerImplTest.java ---------------------------------------------------------------------- diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/security/impl/ActiveMQSecurityManagerImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/security/impl/ActiveMQSecurityManagerImplTest.java index 52cdbc3..b958306 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/security/impl/ActiveMQSecurityManagerImplTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/tests/unit/core/security/impl/ActiveMQSecurityManagerImplTest.java @@ -59,9 +59,9 @@ public class ActiveMQSecurityManagerImplTest extends UnitTestCase @Test public void testDefaultSecurity() { - securityManager.addUser("guest", "guest"); - securityManager.addRole("guest", "guest"); - securityManager.setDefaultUser("guest"); + securityManager.getConfiguration().addUser("guest", "guest"); + securityManager.getConfiguration().addRole("guest", "guest"); + securityManager.getConfiguration().setDefaultUser("guest"); Assert.assertTrue(securityManager.validateUser(null, null)); Assert.assertTrue(securityManager.validateUser("guest", "guest")); HashSet<Role> roles = new HashSet<Role>(); @@ -89,13 +89,13 @@ public class ActiveMQSecurityManagerImplTest extends UnitTestCase @Test public void testAddingUsers() { - securityManager.addUser("newuser1", "newpassword1"); + securityManager.getConfiguration().addUser("newuser1", "newpassword1"); Assert.assertTrue(securityManager.validateUser("newuser1", "newpassword1")); Assert.assertFalse(securityManager.validateUser("newuser1", "guest")); Assert.assertFalse(securityManager.validateUser("newuser1", null)); try { - securityManager.addUser("newuser2", null); + securityManager.getConfiguration().addUser("newuser2", null); Assert.fail("password cannot be null"); } catch (IllegalArgumentException e) @@ -104,7 +104,7 @@ public class ActiveMQSecurityManagerImplTest extends UnitTestCase } try { - securityManager.addUser(null, "newpassword2"); + securityManager.getConfiguration().addUser(null, "newpassword2"); Assert.fail("password cannot be null"); } catch (IllegalArgumentException e) @@ -116,29 +116,29 @@ public class ActiveMQSecurityManagerImplTest extends UnitTestCase @Test public void testRemovingUsers() { - securityManager.addUser("newuser1", "newpassword1"); + securityManager.getConfiguration().addUser("newuser1", "newpassword1"); Assert.assertTrue(securityManager.validateUser("newuser1", "newpassword1")); - securityManager.removeUser("newuser1"); + securityManager.getConfiguration().removeUser("newuser1"); Assert.assertFalse(securityManager.validateUser("newuser1", "newpassword1")); } @Test public void testRemovingInvalidUsers() { - securityManager.addUser("newuser1", "newpassword1"); + securityManager.getConfiguration().addUser("newuser1", "newpassword1"); Assert.assertTrue(securityManager.validateUser("newuser1", "newpassword1")); - securityManager.removeUser("nonuser"); + securityManager.getConfiguration().removeUser("nonuser"); Assert.assertTrue(securityManager.validateUser("newuser1", "newpassword1")); } @Test public void testAddingRoles() { - securityManager.addUser("newuser1", "newpassword1"); - securityManager.addRole("newuser1", "role1"); - securityManager.addRole("newuser1", "role2"); - securityManager.addRole("newuser1", "role3"); - securityManager.addRole("newuser1", "role4"); + securityManager.getConfiguration().addUser("newuser1", "newpassword1"); + securityManager.getConfiguration().addRole("newuser1", "role1"); + securityManager.getConfiguration().addRole("newuser1", "role2"); + securityManager.getConfiguration().addRole("newuser1", "role3"); + securityManager.getConfiguration().addRole("newuser1", "role4"); HashSet<Role> roles = new HashSet<Role>(); roles.add(new Role("role1", true, true, true, true, true, true, true)); Assert.assertTrue(securityManager.validateUserAndRole("newuser1", "newpassword1", roles, CheckType.SEND)); @@ -159,13 +159,13 @@ public class ActiveMQSecurityManagerImplTest extends UnitTestCase @Test public void testRemovingRoles() { - securityManager.addUser("newuser1", "newpassword1"); - securityManager.addRole("newuser1", "role1"); - securityManager.addRole("newuser1", "role2"); - securityManager.addRole("newuser1", "role3"); - securityManager.addRole("newuser1", "role4"); - securityManager.removeRole("newuser1", "role2"); - securityManager.removeRole("newuser1", "role4"); + securityManager.getConfiguration().addUser("newuser1", "newpassword1"); + securityManager.getConfiguration().addRole("newuser1", "role1"); + securityManager.getConfiguration().addRole("newuser1", "role2"); + securityManager.getConfiguration().addRole("newuser1", "role3"); + securityManager.getConfiguration().addRole("newuser1", "role4"); + securityManager.getConfiguration().removeRole("newuser1", "role2"); + securityManager.getConfiguration().removeRole("newuser1", "role4"); HashSet<Role> roles = new HashSet<Role>(); roles.add(new Role("role1", true, true, true, true, true, true, true)); Assert.assertTrue(securityManager.validateUserAndRole("newuser1", "newpassword1", roles, CheckType.SEND));
