diff options
Diffstat (limited to 'qpid/java/management/eclipse-plugin/src/test/java/org')
3 files changed, 342 insertions, 0 deletions
diff --git a/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ApiVersionTest.java b/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ApiVersionTest.java new file mode 100644 index 0000000000..b4f6aea57b --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ApiVersionTest.java @@ -0,0 +1,177 @@ +/* + * + * 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.management.ui; + +import junit.framework.TestCase; + +public class ApiVersionTest extends TestCase +{ + + public void testGetMajor() + { + ApiVersion ver = new ApiVersion(1,3); + assertEquals(1, ver.getMajor()); + } + + public void testGetMinor() + { + ApiVersion ver = new ApiVersion(1,3); + assertEquals(3, ver.getMinor()); + } + + public void testGreaterThanOrEqualTo() + { + ApiVersion ver = new ApiVersion(1,3); + + //equal + assertTrue(ver.greaterThanOrEqualTo(1, 3)); + //same major, higher minor + assertFalse(ver.greaterThanOrEqualTo(1, 4)); + //same major, lower minor + assertTrue(ver.greaterThanOrEqualTo(1, 2)); + + //higher major, lower minor + assertFalse(ver.greaterThanOrEqualTo(2, 0)); + //higher major, same minor + assertFalse(ver.greaterThanOrEqualTo(2, 3)); + //higher major, higher minor + assertFalse(ver.greaterThanOrEqualTo(2, 4)); + + //lower major, higher minor + assertTrue(ver.greaterThanOrEqualTo(0, 9)); + //lower major, lower minor + assertTrue(ver.greaterThanOrEqualTo(0, 2)); + //lower major, same minor + assertTrue(ver.greaterThanOrEqualTo(0, 3)); + } + + public void testLessThanOrEqualTo() + { + ApiVersion ver = new ApiVersion(1,3); + + //equal + assertTrue(ver.lessThanOrEqualTo(1, 3)); + //same major, higher minor + assertTrue(ver.lessThanOrEqualTo(1, 4)); + //same major, lower minor + assertFalse(ver.lessThanOrEqualTo(1, 2)); + + //higher major, lower minor + assertTrue(ver.lessThanOrEqualTo(2, 0)); + //higher major, same minor + assertTrue(ver.lessThanOrEqualTo(2, 3)); + //higher major, higher minor + assertTrue(ver.lessThanOrEqualTo(2, 4)); + + //lower major, higher minor + assertFalse(ver.lessThanOrEqualTo(0, 9)); + //lower major, lower minor + assertFalse(ver.lessThanOrEqualTo(0, 2)); + //lower major, same minor + assertFalse(ver.lessThanOrEqualTo(0, 3)); + } + + public void testGreaterThan() + { + ApiVersion ver = new ApiVersion(1,3); + + //equal + assertFalse(ver.greaterThan(1, 3)); + //same major, higher minor + assertFalse(ver.greaterThan(1, 4)); + //same major, lower minor + assertTrue(ver.greaterThan(1, 2)); + + //higher major, lower minor + assertFalse(ver.greaterThan(2, 0)); + //higher major, same minor + assertFalse(ver.greaterThan(2, 3)); + //higher major, higher minor + assertFalse(ver.greaterThan(2, 4)); + + //lower major, higher minor + assertTrue(ver.greaterThan(0, 9)); + //lower major, lower minor + assertTrue(ver.greaterThan(0, 2)); + //lower major, same minor + assertTrue(ver.greaterThan(0, 3)); + } + + public void testLessThan() + { + ApiVersion ver = new ApiVersion(1,3); + + //equal + assertFalse(ver.lessThan(1, 3)); + //same major, higher minor + assertTrue(ver.lessThan(1, 4)); + //same major, lower minor + assertFalse(ver.lessThan(1, 2)); + + //higher major, lower minor + assertTrue(ver.lessThan(2, 0)); + //higher major, same minor + assertTrue(ver.lessThan(2, 3)); + //higher major, higher minor + assertTrue(ver.lessThan(2, 4)); + + //lower major, higher minor + assertFalse(ver.lessThan(0, 9)); + //lower major, lower minor + assertFalse(ver.lessThan(0, 2)); + //lower major, same minor + assertFalse(ver.lessThan(0, 3)); + } + + public void testEqualsIntInt() + { + ApiVersion ver = new ApiVersion(1,3); + + //equal + assertTrue(ver.equals(1, 3)); + //same major, higher minor + assertFalse(ver.equals(1, 4)); + //same major, lower minor + assertFalse(ver.equals(1, 2)); + + //higher major, lower minor + assertFalse(ver.equals(2, 0)); + //higher major, same minor + assertFalse(ver.equals(2, 3)); + //higher major, higher minor + assertFalse(ver.equals(2, 4)); + + //lower major, higher minor + assertFalse(ver.equals(0, 9)); + //lower major, lower minor + assertFalse(ver.equals(0, 2)); + //lower major, same minor + assertFalse(ver.equals(0, 3)); + } + + public void testToString() + { + ApiVersion ver = new ApiVersion(1,3); + + assertEquals("major=1,minor=3", ver.toString()); + } + +} diff --git a/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ApplicationRegistryTest.java b/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ApplicationRegistryTest.java new file mode 100644 index 0000000000..1a56ab69b6 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ApplicationRegistryTest.java @@ -0,0 +1,43 @@ +/* + * + * 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.management.ui; + +import org.apache.qpid.management.common.mbeans.ServerInformation; + +import junit.framework.TestCase; + +public class ApplicationRegistryTest extends TestCase +{ + public void testSupportedManagementApiVersion() + { + //ensure that the console supported API version is kept in sync with the broker + + assertEquals("The management console does not support the same major version of management API as the broker. " + + "Make any required changes and update the supported value.", + ServerInformation.QPID_JMX_API_MAJOR_VERSION, + ApplicationRegistry.SUPPORTED_QPID_JMX_API_MAJOR_VERSION); + + assertEquals("The management console does not support the same minor version of management API as the broker. " + + "Make any required changes and update the supported value.", + ServerInformation.QPID_JMX_API_MINOR_VERSION, + ApplicationRegistry.SUPPORTED_QPID_JMX_API_MINOR_VERSION); + } +} diff --git a/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ManagementConsoleTest.java b/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ManagementConsoleTest.java new file mode 100644 index 0000000000..0f62fa8ab2 --- /dev/null +++ b/qpid/java/management/eclipse-plugin/src/test/java/org/apache/qpid/management/ui/ManagementConsoleTest.java @@ -0,0 +1,122 @@ +/* + * + * 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.management.ui; + +import junit.framework.TestCase; +import org.apache.qpid.exchange.ExchangeDefaults; +import org.apache.qpid.framing.AMQShortString; +import org.apache.qpid.server.exchange.DirectExchange; +import org.apache.qpid.server.management.AMQManagedObject; +import org.apache.qpid.server.queue.AMQQueueMBean; +import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.queue.AMQQueueFactory; +import org.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.registry.IApplicationRegistry; +import org.apache.qpid.server.util.InternalBrokerBaseCase; +import org.apache.qpid.server.virtualhost.VirtualHost; + +import javax.management.MBeanFeatureInfo; +import javax.management.MBeanInfo; +import java.util.ArrayList; +import java.util.List; + + +/** + * Test class to test if any change in the broker JMX code is affesting the management console + * There are some hardcoding of management feature names and parameter names to create a customized + * look in the console. + */ +public class ManagementConsoleTest extends InternalBrokerBaseCase +{ + private VirtualHost _virtualHost; + + @Override + public void setUp() throws Exception + { + super.setUp(); + IApplicationRegistry applicationRegistry = ApplicationRegistry.getInstance(); + _virtualHost = applicationRegistry.getVirtualHostRegistry().getVirtualHost("test"); + } + + + /** + * Test for AMQQueueMBean attribute and operation names, which are used in the management console + * @throws Exception + */ + public void testAMQQueueMBeanInfo() throws Exception + { + // If this test fails due to changes in the broker code, + // then the constants in the Constants.java shoule be updated accordingly + AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString("testQueueForManagement"), false, null, false, false, + _virtualHost, null); + AMQManagedObject mbean = new AMQQueueMBean(queue); + MBeanInfo mbeanInfo = mbean.getMBeanInfo(); + + List<String> operationNames = getNamesList(mbeanInfo.getOperations()); + assertTrue(operationNames.contains(Constants.OPERATION_MOVE_MESSAGES)); + + List<String> attributesList = getNamesList(mbeanInfo.getAttributes()); + assertTrue(attributesList.contains(Constants.ATTRIBUTE_QUEUE_CONSUMERCOUNT)); + assertTrue(attributesList.contains(Constants.ATTRIBUTE_QUEUE_DEPTH)); + } + + /** + * Test for Exchange MBean attribute and operation names, which are used in the management console + * @throws Exception + */ + public void testExchangeMBeanInfo() throws Exception + { + // If this test fails due to changes in the broker code, + // then the constants in the Constants.java shoule be updated accordingly + DirectExchange exchange = new DirectExchange(); + exchange.initialise(_virtualHost, ExchangeDefaults.DIRECT_EXCHANGE_NAME, false, 0, true); + AMQManagedObject mbean = (AMQManagedObject)exchange.getManagedObject(); + MBeanInfo mbeanInfo = mbean.getMBeanInfo(); + + // Check for the Exchange Type property in the ObjectName + assertNotNull(mbean.getObjectName().getKeyProperty(Constants.EXCHANGE_TYPE)); + + // Check for operation names + List<String> operationNames = getNamesList(mbeanInfo.getOperations()); + assertTrue(operationNames.contains(Constants.OPERATION_CREATE_BINDING)); + } + + /** + * Test for VirtualHostManagerMBean features used in Management console for customizing the GUI + * @throws Exception + */ + public void testVirtualHostManagerMBeanInfo() throws Exception + { + AMQManagedObject mbean = (AMQManagedObject)_virtualHost.getManagedObject(); + assertTrue(mbean.getType().equals(Constants.VIRTUAL_HOST)); + } + + private List<String> getNamesList(MBeanFeatureInfo[] features) + { + List<String> names = new ArrayList<String>(); + for (MBeanFeatureInfo feature : features) + { + names.add(feature.getName()); + } + + return names; + } +} |