You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ar...@apache.org on 2008/09/29 16:06:19 UTC
svn commit: r700134 [1/2] - in
/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management:
./ configuration/ domain/ domain/handler/ domain/handler/base/
domain/model/ domain/model/type/
Author: arnaudsimon
Date: Mon Sep 29 07:06:18 2008
New Revision: 700134
URL: http://svn.apache.org/viewvc?rev=700134&view=rev
Log:
qpid-1284: Qman unit tests
Added:
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/TestConstants.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/handler/
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPropertyBuilderTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStatisticBuilderTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidStringPropertyTest.java
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/type/
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/type/BinaryTest.java
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/TestConstants.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/TestConstants.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/TestConstants.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/TestConstants.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.management.domain.model.DomainModel;
+import org.apache.qpid.management.domain.model.type.Binary;
+
+public interface TestConstants
+{
+ String QPID_PACKAGE_NAME = "qpid";
+ String EXCHANGE_CLASS_NAME = "exchange";
+ Binary HASH = new Binary(new byte []{1,2,3,4,5,6,7,8,9});
+ int VALID_CODE = 1;
+
+
+ UUID BROKER_ID = UUID.randomUUID();
+ Binary OBJECT_ID = new Binary(new byte []{1,2,3,2,1,1,2,3});
+
+ DomainModel DOMAIN_MODEL = new DomainModel(BROKER_ID);
+
+ List<Map<String, Object>> EMPTY_PROPERTIES_SCHEMA = new LinkedList<Map<String,Object>>();
+ List<Map<String, Object>> EMPTY_STATISTICS_SCHEMA = new LinkedList<Map<String,Object>>();
+ List<Map<String, Object>> EMPTY_METHODS_SCHEMA = new LinkedList<Map<String,Object>>();
+ List<Map<String, Object>> EMPTY_EVENTS_SCHEMA = new LinkedList<Map<String,Object>>();
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/AccessModeMappingTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,107 @@
+/*
+ *
+ * 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.configuration;
+
+import org.apache.qpid.management.TestConstants;
+import org.apache.qpid.management.domain.model.AccessMode;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for AccessMode mapping.
+ *
+ * @author Andrea Gazzarini
+ */
+public class AccessModeMappingTest extends TestCase
+{
+ private AccessModeMapping _mapping;
+
+ /**
+ * Set up fixture for this test case.
+ */
+ @Override
+ protected void setUp () throws Exception
+ {
+ _mapping = new AccessModeMapping();
+ }
+
+ /**
+ * Tests the execution of the setCode method when a valid code is given.
+ *
+ * <br>precondition : given code is a valid number.
+ * <br>postcondition : no exception is thrown and the mapping contained the requested code.
+ */
+ public void testSetCodeOK()
+ {
+ _mapping.setCode(String.valueOf(TestConstants.VALID_CODE));
+ assertEquals(TestConstants.VALID_CODE,_mapping.getCode());
+ }
+
+ /**
+ * Tests the execution of the setCode method when an invalid code is given.
+ *
+ * <br>precondition : given code is an invalid number.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testSetCodeKO_withInvalidNumber ()
+ {
+ try {
+ _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)+"a");
+ fail("The given string is not a number and therefore an exception must be thrown.");
+ } catch(NumberFormatException expected) {
+
+ }
+ }
+
+ /**
+ * Tests the execution of the setAccessMode method when a valid access code is given.
+ *
+ * <br>precondition : given code is valid (i.e. RW, RC or RO).
+ * <br>postcondition : no exception is thrown and the mapping contained the requested access mode.
+ */
+ public void testSetAccessModeOK()
+ {
+ _mapping.setAccessMode("RW");
+ assertEquals(AccessMode.RW,_mapping.getAccessMode());
+
+ _mapping.setAccessMode("RC");
+ assertEquals(AccessMode.RC,_mapping.getAccessMode());
+
+ _mapping.setAccessMode("RO");
+ assertEquals(AccessMode.RO,_mapping.getAccessMode());
+ }
+
+ /**
+ * Tests the execution of the setAccessMode method when an unknown code is given.
+ *
+ * <br>precondition : given code is an unknown code.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testSetAccessModeKO ()
+ {
+ try {
+ _mapping.setAccessMode(AccessMode.RW.toString()+"X");
+ fail("The given string is not a string representation of a valid access mode.");
+ } catch(IllegalArgumentException expected) {
+
+ }
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfigurationTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,237 @@
+/*
+ *
+ * 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.configuration;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.management.TestConstants;
+import org.apache.qpid.management.domain.handler.base.IMessageHandler;
+import org.apache.qpid.management.domain.handler.impl.ConfigurationMessageHandler;
+import org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler;
+import org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler;
+import org.apache.qpid.management.domain.model.AccessMode;
+import org.apache.qpid.management.domain.model.type.Type;
+import org.apache.qpid.management.domain.model.type.Uint8;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for Configuration singleton.
+ *
+ * @author Andrea Gazzarini
+ */
+public class ConfigurationTest extends TestCase
+{
+ /**
+ * Tests the singleton behaviour of the configuration object.
+ */
+ public void testSingleton()
+ {
+ assertSame(Configuration.getInstance(),Configuration.getInstance());
+ }
+
+ /**
+ * Tests the execution of getType() method when a valid code is supplied.
+ *
+ * <br>precondition : the requested type already exist on the configuration.
+ * <br>postcondition : the requested type is returned and no exception is thrown.
+ */
+ public void testGetTypeOk() throws UnknownTypeCodeException
+ {
+ TypeMapping mapping = new TypeMapping();
+ mapping.setCode(String.valueOf(TestConstants.VALID_CODE));
+ mapping.setType(Uint8.class.getName());
+ Configuration.getInstance().addTypeMapping(mapping);
+
+ Type type = Configuration.getInstance().getType(TestConstants.VALID_CODE);
+
+ assertTrue(type instanceof Uint8);
+ }
+
+ /**
+ * Tests the execution of getType() method when a unknown code is supplied.
+ *
+ * <br>precondition : the requested type doesn't exist on the configuration.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testGetTypeKO()
+ {
+ try
+ {
+ Configuration.getInstance().getType(TestConstants.VALID_CODE+1);
+ fail("If an unknwon code is supplied an exception must be thrown.");
+ } catch (UnknownTypeCodeException expected)
+ {
+ assertEquals(TestConstants.VALID_CODE+1,expected.getCode());
+ }
+ }
+
+ /**
+ * Tests the execution of getAccessMode() method when a valid code is supplied.
+ *
+ * <br>precondition : the requested access mode already exist on the configuration.
+ * <br>postcondition : the requested access mode is returned and no exception is thrown.
+ */
+ public void testGetAccessModeOk() throws UnknownAccessCodeException
+ {
+ String accessModeAsString = "RW";
+
+ AccessModeMapping mapping = new AccessModeMapping();
+ mapping.setCode(String.valueOf(TestConstants.VALID_CODE));
+ mapping.setAccessMode(accessModeAsString);
+ Configuration.getInstance().addAccessModeMapping(mapping);
+
+ AccessMode accessMode = Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE);
+ assertSame(AccessMode.RW,accessMode);
+ }
+
+ /**
+ * Tests the execution of getAccessMode() method when a unknown code is supplied.
+ *
+ * <br>precondition : the requested access mode doesn't exist on the configuration.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testGetAccessModeKO()
+ {
+ try
+ {
+ Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE+1);
+ fail("If an unknwon code is supplied an exception must be thrown.");
+ } catch (UnknownAccessCodeException expected)
+ {
+ assertEquals(TestConstants.VALID_CODE+1,expected.getCode());
+ }
+ }
+
+ /**
+ * Tests the execution of the getBrokerConnectionData when a valid broker id is supplied.
+ *
+ * <br>precondition : on configuration a connection data is stored and associated with the supplied id.
+ * <br>postcondition : the requested connection data is returned and no exception is thrown.
+ */
+ public void testGetBrokerConnectionDataOK() throws Exception
+ {
+ BrokerConnectionData connectionData = new BrokerConnectionData();
+ connectionData.setHost("host");
+ connectionData.setPort("7001");
+ connectionData.setInitialPoolCapacity("0");
+ connectionData.setMaxPoolCapacity("10");
+ connectionData.setMaxWaitTimeout("1");
+ Configuration.getInstance().addBrokerConnectionData(TestConstants.BROKER_ID, connectionData);
+
+ BrokerConnectionData result = Configuration.getInstance().getBrokerConnectionData(TestConstants.BROKER_ID);
+ assertSame(connectionData, result);
+ }
+
+ /**
+ * Tests the execution of the getBrokerConnectionData when a unknown broker id is supplied.
+ *
+ * <br>precondition : on configuration there's no connection data associated with the supplied id.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testGetBrokerConnectionDataKO_withUnknownBrokerId()
+ {
+ UUID brokerId = UUID.randomUUID();
+ try
+ {
+ Configuration.getInstance().getBrokerConnectionData(brokerId);
+ fail("If an unknown broker id is supplied then an exception must be thrown.");
+ } catch(UnknownBrokerException expected)
+ {
+ assertEquals(brokerId.toString(),expected.getMessage());
+ }
+ }
+
+ /**
+ * Tests the execution of the getBrokerConnectionData when a null id is supplied.
+ *
+ * <br>precondition : a null broker is given.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testGetBrokerConnectionDataKO_withNullBrokerId()
+ {
+ try
+ {
+ Configuration.getInstance().getBrokerConnectionData(null);
+ fail("If a null broker id is supplied then an exception must be thrown.");
+ } catch(UnknownBrokerException expected)
+ {
+ }
+ }
+
+ /**
+ * Tests the behaviour of the getManagementQueueHandlers() method.
+ *
+ * <br>precondition: 2 management handlers are in stored configuration
+ * <br>postcondition : 2 management handlers are returned.
+ */
+ public void testGetManagementQueueHandlersOk()
+ {
+ String i = "i";
+ String c = "c";
+
+ String instrMessageHandlerClassName = InstrumentationMessageHandler.class.getName();
+ String configMessageHandlerClassName = ConfigurationMessageHandler.class.getName();
+
+ MessageHandlerMapping instrMapping = new MessageHandlerMapping();
+ MessageHandlerMapping configMapping = new MessageHandlerMapping();
+
+ instrMapping.setOpcode(i);
+ instrMapping.setMessageHandlerClass(instrMessageHandlerClassName);
+
+ configMapping.setOpcode(c);
+ configMapping.setMessageHandlerClass(configMessageHandlerClassName);
+
+ Configuration.getInstance().addManagementMessageHandlerMapping(instrMapping);
+ Configuration.getInstance().addManagementMessageHandlerMapping(configMapping);
+
+ Map<Character, IMessageHandler> handlerMappings = Configuration.getInstance().getManagementQueueHandlers();
+
+ assertEquals(2,handlerMappings.size());
+ assertEquals(instrMessageHandlerClassName,handlerMappings.get(instrMapping.getOpcode()).getClass().getName());
+ assertEquals(configMessageHandlerClassName,handlerMappings.get(configMapping.getOpcode()).getClass().getName());
+ }
+
+ /**
+ * Tests the behaviour of the getManagementQueueHandlers() method.
+ *
+ * <br>precondition: 2 management handlers are in stored configuration
+ * <br>postcondition : 2 management handlers are returned.
+ */
+ public void testGetMethodReplyQueueHandlersOk()
+ {
+ String s = "s";
+
+ String schemaMessageHandlerClassName = SchemaResponseMessageHandler.class.getName();
+
+ MessageHandlerMapping schemaMapping = new MessageHandlerMapping();
+
+ schemaMapping.setOpcode(s);
+ schemaMapping.setMessageHandlerClass(schemaMessageHandlerClassName);
+
+ Configuration.getInstance().addMethodReplyMessageHandlerMapping(schemaMapping);
+
+ Map<Character, IMessageHandler> handlerMappings = Configuration.getInstance().getMethodReplyQueueHandlers();
+
+ assertEquals(schemaMessageHandlerClassName,handlerMappings.get(schemaMapping.getOpcode()).getClass().getName());
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/ConfiguratorTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,112 @@
+/*
+ *
+ * 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.configuration;
+
+import org.xml.sax.SAXException;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for configurator.
+ *
+ * @author Andrea Gazzarini
+ *
+ */
+public class ConfiguratorTest extends TestCase
+{
+
+ /**
+ * Tests the execution of the configure() method when a inexistent configuration file is used.
+ *
+ * <br>precondition : the configuration file doesn't exist.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testConfigureKO_WithConfigFileNotFound()
+ {
+ Configurator configurator = getConfiguratorWithDatafileInjected("pippo/pluto/paperino.xml");
+ try {
+ configurator.configure();
+ fail("If there's no configuration file the configuration cannot be built.");
+ } catch(ConfigurationException expected) {
+
+ }
+ }
+
+ /**
+ * Tests the execution of the configure() method when configuration file is null.
+ *
+ * <br>precondition : the configuration file is null.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testConfigureKO_WithNullConfig()
+ {
+ Configurator configurator = getConfiguratorWithDatafileInjected(null);
+ try {
+ configurator.configure();
+ fail("If there's no configuration file the configuration cannot be built.");
+ } catch(ConfigurationException expected) {
+
+ }
+ }
+
+ /**
+ * Tests the changes of the configurator internal state while configuration file is parsed.
+ *
+ * <br>precondition: N.A.
+ * <br>postcondition: N.A.
+ */
+ public void testDirectorParsing() throws SAXException{
+ Configurator configurator = new Configurator();
+
+ assertSame(Configurator.DEFAULT_PARSER,configurator._currentParser);
+
+ configurator.startElement(null, null, Tag.TYPE_MAPPINGS.toString(), null);
+ assertSame(configurator._typeMappingParser,configurator._currentParser);
+
+ configurator.startElement(null, null, Tag.ACCESS_MODE_MAPPINGS.toString(), null);
+ assertSame(configurator._accessModeMappingParser,configurator._currentParser);
+
+ configurator.startElement(null, null, Tag.BROKERS.toString(), null);
+ assertSame(configurator._brokerConfigurationParser,configurator._currentParser);
+
+ configurator.startElement(null, null, Tag.MANAGEMENT_QUEUE.toString(), null);
+ assertSame(configurator._managementQueueHandlerParser,configurator._currentParser);
+
+ configurator.startElement(null, null, Tag.METHOD_REPLY_QUEUE.toString(), null);
+ assertSame(configurator._methodReplyQueueHandlerParser,configurator._currentParser);
+ }
+ /**
+ * Create a stub configurator which returns the given datafile path.
+ *
+ * @param filename the configuration file to be injected.
+ * @return a configurator which returns the given datafile path.
+ */
+ private Configurator getConfiguratorWithDatafileInjected(final String filename) {
+ return new Configurator()
+ {
+ @Override
+ String getConfigurationFileName ()
+ {
+ return filename;
+ }
+ };
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/MappingParsersTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,201 @@
+/*
+ *
+ * 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.configuration;
+
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.management.TestConstants;
+import org.apache.qpid.management.domain.handler.base.IMessageHandler;
+import org.apache.qpid.management.domain.handler.impl.ConfigurationMessageHandler;
+import org.apache.qpid.management.domain.handler.impl.InstrumentationMessageHandler;
+import org.apache.qpid.management.domain.handler.impl.SchemaResponseMessageHandler;
+import org.apache.qpid.management.domain.model.AccessMode;
+import org.apache.qpid.management.domain.model.type.Type;
+import org.apache.qpid.management.domain.model.type.Uint8;
+
+/**
+ * Test case for mapping parsers.
+ *
+ * @author Andrea Gazzarini.
+ */
+public class MappingParsersTest extends TestCase
+{
+ /**
+ * Tests the execution of the access mode mapping parser.
+ *
+ * <br>precondition: An access mode mapping is built by the parser;
+ * <br>postcondition: the corresponding access mode is available on the configuration.
+ */
+ public void testAccessModeMappingParser() throws UnknownAccessCodeException
+ {
+ AccessModeMappingParser parser = new AccessModeMappingParser();
+ parser.setCurrrentAttributeValue(String.valueOf(TestConstants.VALID_CODE));
+ parser.setCurrentAttributeName(Tag.CODE.toString());
+ parser.setCurrrentAttributeValue("RW");
+ parser.setCurrentAttributeName(Tag.VALUE.toString());
+ parser.setCurrentAttributeName(Tag.MAPPING.toString());
+
+ AccessMode result = Configuration.getInstance().getAccessMode(TestConstants.VALID_CODE);
+ assertEquals(AccessMode.RW,result);
+ }
+
+ /**
+ * Tests the execution of the broker connection data mapping parser.
+ *
+ * <br>precondition: A broker connection datamapping is built by the parser;
+ * <br>postcondition: the corresponding connection data is available on the configuration.
+ */
+ public void testBrokerConnectionDataParser() throws UnknownBrokerException
+ {
+ String host = "127.0.0.1";
+ String port = "7001";
+ String virtualHost = "test";
+ String username = "username_guest";
+ String password ="password_guest";
+
+ BrokerConnectionDataParser parser = new BrokerConnectionDataParser()
+ {
+ @Override
+ UUID getUUId ()
+ {
+ return TestConstants.BROKER_ID;
+ }
+ };
+
+ parser.setCurrrentAttributeValue(host);
+ parser.setCurrentAttributeName(Tag.HOST.toString());
+ parser.setCurrrentAttributeValue(port);
+ parser.setCurrentAttributeName(Tag.PORT.toString());
+ parser.setCurrrentAttributeValue(virtualHost);
+ parser.setCurrentAttributeName(Tag.VIRTUAL_HOST.toString());
+ parser.setCurrrentAttributeValue(username);
+ parser.setCurrentAttributeName(Tag.USER.toString());
+ parser.setCurrrentAttributeValue(password);
+ parser.setCurrentAttributeName(Tag.PASSWORD.toString());
+ parser.setCurrentAttributeName(Tag.BROKER.toString());
+
+ BrokerConnectionData result = Configuration.getInstance().getBrokerConnectionData(TestConstants.BROKER_ID);
+
+ assertEquals(host,result.getHost());
+ assertEquals(Integer.parseInt(port),result.getPort());
+ assertEquals(virtualHost,result.getVirtualHost());
+ assertEquals(username,result.getUsername());
+ assertEquals(password,result.getPassword());
+ }
+
+ /**
+ * Tests the execution of the management queue handler mapping parser.
+ *
+ * <br>precondition: Two managenent queue handlers mapping are built by the parser;
+ * <br>postcondition: the corresponding management handlers are available on the configuration.
+ */
+ public void testManagementQueueMessageListenerParser()
+ {
+ String instrOpcode = "i";
+ String configOpCode = "c";
+
+ ManagementQueueMessageListenerParser parser = new ManagementQueueMessageListenerParser();
+
+ parser.setCurrrentAttributeValue(instrOpcode);
+ parser.setCurrentAttributeName(Tag.OPCODE.toString());
+ parser.setCurrrentAttributeValue(InstrumentationMessageHandler.class.getName());
+ parser.setCurrentAttributeName(Tag.CLASS_NAME.toString());
+ parser.setCurrentAttributeName(Tag.HANDLER.toString());
+
+ parser.setCurrrentAttributeValue(configOpCode);
+ parser.setCurrentAttributeName(Tag.OPCODE.toString());
+ parser.setCurrrentAttributeValue(ConfigurationMessageHandler.class.getName());
+ parser.setCurrentAttributeName(Tag.CLASS_NAME.toString());
+ parser.setCurrentAttributeName(Tag.HANDLER.toString());
+
+
+ Map<Character,IMessageHandler> result = Configuration.getInstance().getManagementQueueHandlers();
+
+ assertEquals(2,result.size());
+
+ assertEquals(InstrumentationMessageHandler.class,result.get(instrOpcode.charAt(0)).getClass());
+ assertEquals(ConfigurationMessageHandler.class,result.get(configOpCode.charAt(0)).getClass());
+ }
+
+ /**
+ * Tests the execution of the method-reply queue handler mapping parser.
+ *
+ * <br>precondition: two method-reply queue handler mappings are built by the parser;
+ * <br>postcondition: the corresponding method-reply handlers are available on the configuration.
+ */
+ public void testMethodReplyQueueMessageListenerParser()
+ {
+ String schemaOpcode = "s";
+ String configOpCode = "c";
+
+ MethodReplyQueueMessageListenerParser parser = new MethodReplyQueueMessageListenerParser();
+
+ parser.setCurrrentAttributeValue(schemaOpcode);
+ parser.setCurrentAttributeName(Tag.OPCODE.toString());
+ parser.setCurrrentAttributeValue(SchemaResponseMessageHandler.class.getName());
+ parser.setCurrentAttributeName(Tag.CLASS_NAME.toString());
+ parser.setCurrentAttributeName(Tag.HANDLER.toString());
+
+ parser.setCurrrentAttributeValue(configOpCode);
+ parser.setCurrentAttributeName(Tag.OPCODE.toString());
+ parser.setCurrrentAttributeValue(ConfigurationMessageHandler.class.getName());
+ parser.setCurrentAttributeName(Tag.CLASS_NAME.toString());
+ parser.setCurrentAttributeName(Tag.HANDLER.toString());
+
+ Map<Character,IMessageHandler> result = Configuration.getInstance().getMethodReplyQueueHandlers();
+
+ assertEquals(2,result.size());
+
+ assertEquals(SchemaResponseMessageHandler.class,result.get(schemaOpcode.charAt(0)).getClass());
+ assertEquals(ConfigurationMessageHandler.class,result.get(configOpCode.charAt(0)).getClass());
+ }
+
+ /**
+ * Tests the execution of the type mapping parser.
+ *
+ * <br>precondition: two type mappings are built by the parser;
+ * <br>postcondition: the corresponding types are available on the configuration.
+ */
+ public void testMappingParser() throws NumberFormatException, UnknownTypeCodeException
+ {
+ TypeMappingParser parser = new TypeMappingParser();
+
+ String className = Uint8.class.getName();
+ String validatorClassName = "a.b.c.Validator";
+
+ parser.setCurrrentAttributeValue(String.valueOf(TestConstants.VALID_CODE));
+ parser.setCurrentAttributeName(Tag.CODE.toString());
+ parser.setCurrrentAttributeValue(className);
+ parser.setCurrentAttributeName(Tag.CLASS_NAME.toString());
+ parser.setCurrrentAttributeValue(validatorClassName);
+ parser.setCurrentAttributeName(Tag.VALIDATOR_CLASS_NAME.toString());
+ parser.setCurrentAttributeName(Tag.MAPPING.toString());
+
+ Type type =Configuration.getInstance().getType(TestConstants.VALID_CODE);
+ String vClassName = Configuration.getInstance().getValidatorClassName(type);
+
+ assertEquals(Uint8.class, type.getClass());
+ assertEquals(validatorClassName,vClassName);
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/StubConfigurator.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.configuration;
+
+import org.apache.qpid.management.domain.model.type.Str8;
+
+public class StubConfigurator extends Configurator
+{
+ /**
+ * Builds whole configuration.
+ *
+ * @throws ConfigurationException when the build fails.
+ */
+ public void configure() throws ConfigurationException
+ {
+ addAccessModeMapping("1", "RW");
+ addAccessModeMapping("2", "RO");
+ addAccessModeMapping("3", "RC");
+
+ addTypeMapping("1", Str8.class.getName());
+ }
+
+ public void addTypeMapping(String code,String clazzName)
+ {
+ TypeMapping mapping = new TypeMapping();
+ mapping.setCode(code);
+ mapping.setType(clazzName);
+ Configuration.getInstance().addTypeMapping(mapping);
+ }
+
+ public void addAccessModeMapping(String code, String value)
+ {
+ AccessModeMapping mapping = new AccessModeMapping();
+ mapping.setCode(code);;
+ mapping.setAccessMode(value);
+ Configuration.getInstance().addAccessModeMapping(mapping);
+ }
+}
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/configuration/TypeMappingTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,117 @@
+/*
+ *
+ * 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.configuration;
+
+import org.apache.qpid.management.TestConstants;
+import org.apache.qpid.management.domain.model.type.Uint8;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for type mapping.
+ *
+ * @author Andrea Gazzarini
+ */
+public class TypeMappingTest extends TestCase
+{
+ private TypeMapping _mapping;
+
+ @Override
+ protected void setUp () throws Exception
+ {
+ _mapping = new TypeMapping();
+ }
+
+ /**
+ * Tests the execution of the setCode method when a valid code is given.
+ *
+ * <br>precondition : given code is a valid number.
+ * <br>postcondition : no exception is thrown and the mapping contained the requested code.
+ */
+ public void testSetCodeOK()
+ {
+ _mapping.setCode(String.valueOf(TestConstants.VALID_CODE));
+ assertEquals(TestConstants.VALID_CODE,_mapping.getCode());
+ }
+
+ /**
+ * Tests the execution of the setCode method when an invalid code is given.
+ *
+ * <br>precondition : given code is an invalid number.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testSetCodeKO_withInvalidNumber ()
+ {
+ try {
+ _mapping.setCode(String.valueOf(TestConstants.VALID_CODE)+"a");
+ fail("The given string is not a number and therefore an exception must be thrown.");
+ } catch(NumberFormatException expected)
+ {
+
+ }
+ }
+
+ /**
+ * Tests the execution of the setType() method when a valid type class is given.
+ *
+ * <br>precondition : a valid class type is supplied.
+ * <br>postcondition : no exception is thrown and the mapping contains the previously associated type.
+ */
+ public void testSetTypeOK()
+ {
+ _mapping.setType(Uint8.class.getName());
+ assertTrue(_mapping.getType() instanceof Uint8);
+ }
+
+ /**
+ * Tests the execution of the setType() method when a invalid type class is given.
+ *
+ * <br>precondition : an invalid class type is supplied.
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testSetTypeKO_withTypeClassNotFound()
+ {
+ try
+ {
+ _mapping.setType(Uint8.class.getName()+"a");
+ fail("If the supplied class doesn't exist an exception must be thrown.");
+ } catch(IllegalArgumentException expected) {
+ assertTrue(expected.getCause() instanceof ClassNotFoundException);
+ }
+ }
+
+ /**
+ * Tests the execution of the setType() method when a invalid type class is given.
+ *
+ * <br>precondition : an invalid class type is supplied (is not a Type).
+ * <br>postcondition : an exception is thrown indicating the failure.
+ */
+ public void testSetTypeKO_withInvalidType()
+ {
+ try
+ {
+ _mapping.setType(String.class.getName());
+ fail("If the supplied class is not a Type an exception must be thrown.");
+ } catch(IllegalArgumentException expected) {
+ assertTrue(expected.getCause() instanceof ClassCastException);
+ }
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/handler/base/ContentIndicationMessageHandlerTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,120 @@
+/*
+ *
+ * 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.domain.handler.base;
+
+import java.nio.ByteBuffer;
+
+import org.apache.qpid.management.TestConstants;
+import org.apache.qpid.management.domain.model.type.Binary;
+import org.apache.qpid.transport.codec.ManagementDecoder;
+import org.apache.qpid.transport.codec.ManagementEncoder;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for Content indication message handler (base class).
+ *
+ * @author Andrea Gazzarini
+ */
+public class ContentIndicationMessageHandlerTest extends TestCase
+{
+ /**
+ * Tests the execution of the process method when the message is processed correctly.
+ */
+ public void testProcessOk() {
+ final String expectedPackageName = "org.apache.qpid.broker";
+ final String expectedClassName ="connection";
+ final long expectedMessageTimestamp = System.currentTimeMillis();
+ final long expectedCreationTime = expectedMessageTimestamp - 1000;
+ final long expectedDeletionTime = 0;
+ final Binary expectedClassHash = new Binary(new byte[]{9,9,9,9,8,8,8,8,7,7,7,7,6,6,6,6});
+ final Binary expectedObjectId = new Binary(new byte[]{1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16});
+ final Binary expectedBody = new Binary(new byte[]{1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4});
+
+ ContentIndicationMessageHandler mockHandler = new ContentIndicationMessageHandler()
+ {
+ @Override
+ protected void updateDomainModel (String packageName, String className, Binary classHash, Binary objectId,
+ long timeStampOfCurrentSample, long timeObjectWasCreated, long timeObjectWasDeleted, byte[] contentData)
+ {
+ assertEquals(expectedPackageName,packageName);
+ assertEquals(expectedClassName,className);
+ assertEquals(expectedClassHash,classHash);
+ assertEquals(expectedMessageTimestamp,timeStampOfCurrentSample);
+ assertEquals(expectedCreationTime,timeObjectWasCreated);
+ assertEquals(expectedDeletionTime,timeObjectWasDeleted);
+ assertEquals(expectedObjectId,objectId);
+ assertEquals(expectedBody,new Binary(contentData));
+ }
+
+ @Override
+ void removeObjectInstance (String packageName, String className, Binary classHash, Binary objectId)
+ {
+ fail("The object shouldn't be deleted because deletion time was set to 0!");
+ }
+ };
+ mockHandler.setDomainModel(TestConstants.DOMAIN_MODEL);
+
+ ByteBuffer buffer = ByteBuffer.allocate(1000);
+ ManagementEncoder encoder = new ManagementEncoder(buffer);
+
+ encoder.writeStr8(expectedPackageName);
+ encoder.writeStr8(expectedClassName);
+ expectedClassHash.encode(encoder);
+ encoder.writeDatetime(expectedMessageTimestamp);
+ encoder.writeDatetime(expectedCreationTime);
+ encoder.writeDatetime(expectedDeletionTime);
+ expectedObjectId.encode(encoder);
+ expectedBody.encode(encoder);
+
+ buffer.flip();
+ ManagementDecoder decoder = new ManagementDecoder();
+ decoder.init(buffer);
+
+ mockHandler.process(decoder, 1);
+ }
+
+ /**
+ * Tests the behaviour of the objectHasBeenRemoved method().
+ */
+ public void testObjectHasBeenRemoved()
+ {
+ ContentIndicationMessageHandler mockHandler = new ContentIndicationMessageHandler()
+ {
+ @Override
+ protected void updateDomainModel (String packageName, String className, Binary classHash, Binary objectId,
+ long timeStampOfCurrentSample, long timeObjectWasCreated, long timeObjectWasDeleted, byte[] contentData)
+ {
+ }
+ };
+
+ long deletionTimestamp = 0;
+ long now = System.currentTimeMillis();
+
+ assertFalse(mockHandler.objectHasBeenRemoved(deletionTimestamp, now));
+
+ deletionTimestamp = now + 1000;
+ assertFalse(mockHandler.objectHasBeenRemoved(deletionTimestamp, now));
+
+ deletionTimestamp = now - 1000;
+ assertTrue(mockHandler.objectHasBeenRemoved(deletionTimestamp, now));
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseDomainModelTestCase.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,44 @@
+/*
+ *
+ * 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.domain.model;
+
+import org.apache.qpid.management.configuration.Configurator;
+
+import junit.framework.TestCase;;
+
+/**
+ * Layer supertype for all domain model related test cases.
+ *
+ * @author Andrea Gazzarini
+ */
+public class BaseDomainModelTestCase extends TestCase
+{
+ /**
+ * Set up fixture for this test case.
+ * In order to execute tests on domain model we need to build the configuration.
+ */
+ @Override
+ protected void setUp () throws Exception
+ {
+ Configurator configurator = new Configurator();
+ configurator.configure();
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/BaseQpidFeatureBuilderTestCase.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,102 @@
+/*
+ *
+ * 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.domain.model;
+
+import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.desc;
+import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.name;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.management.configuration.StubConfigurator;
+import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute;
+import org.apache.qpid.management.domain.model.type.Uint16;
+
+/**
+ * Layer supertype for feature builder test cases.
+ *
+ * @author Andrea Gazzarini
+ */
+public abstract class BaseQpidFeatureBuilderTestCase extends TestCase
+{
+ protected final static String NAME = "aName";
+
+ protected final static String DESCRIPTION = "A description.";
+ protected Integer _type;
+
+ protected Map <String,Object> _featureDefinition;
+ protected QpidFeatureBuilder _builder;
+
+ protected StubConfigurator configurator;
+
+ /**
+ * Set up fixture for all concrete builder test cases.
+ */
+ @Override
+ protected void setUp () throws Exception
+ {
+ _type = 1;
+ configurator = new StubConfigurator();
+ configurator.addTypeMapping(_type.toString(),Uint16.class.getName());
+
+ _featureDefinition = new HashMap<String, Object>();
+ _featureDefinition.put(name.name(),NAME);
+ _featureDefinition.put(desc.name(), DESCRIPTION);
+ }
+
+ // Internal test used to avoid code duplication.
+ protected void internalTestForMissingMandatoryAttribute(Attribute ...toBeRemoved)
+ {
+ try
+ {
+ for (Attribute attribute : toBeRemoved)
+ {
+ _featureDefinition.remove(attribute.name());
+ }
+ _builder.build();
+ fail("If a mandatory attribute is missing an exception must be thrown!");
+ } catch (UnableToBuildFeatureException expected)
+ {
+ assertTrue(expected instanceof MissingFeatureAttributesException);
+ for (Attribute attribute : toBeRemoved)
+ {
+ assertTrue(expected.getMessage().contains(attribute.name()));
+ }
+ }
+ }
+
+ // Internal test used to avoid code duplication.
+ protected void internalTestForMissingOptionalAttribute(Attribute ...toBeRemoved) throws UnableToBuildFeatureException
+ {
+ for (Attribute attribute : toBeRemoved)
+ {
+ _featureDefinition.remove(attribute.name());
+ }
+ _builder.build();
+
+ assertNotNull(_builder.getQpidFeature());
+ assertNotNull(_builder.getManagementFeature());
+ }
+
+
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/DomainModelTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.domain.model;
+
+import java.util.UUID;
+
+import org.apache.qpid.management.TestConstants;
+
+/**
+ * Test case for domain model entity.
+ *
+ * @author Andrea Gazzarini
+ */
+public class DomainModelTest extends BaseDomainModelTestCase
+{
+ private DomainModel _model;
+
+ @Override
+ protected void setUp () throws Exception
+ {
+ super.setUp();
+ _model = new DomainModel(UUID.randomUUID());
+ }
+
+ /**
+ * Tests the execution of the getPackage() method.
+ */
+ public void testGetPackage()
+ {
+ assertFalse(_model.containsPackage(TestConstants.QPID_PACKAGE_NAME));
+
+ QpidPackage qpidPackage = _model.getPackageByName(TestConstants.QPID_PACKAGE_NAME);
+ assertEquals(TestConstants.QPID_PACKAGE_NAME,qpidPackage.getName());
+
+ QpidPackage theSameAsPreviousOne = _model.getPackageByName(TestConstants.QPID_PACKAGE_NAME);
+ assertSame(qpidPackage, theSameAsPreviousOne);
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/OptionalPropertiesTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,187 @@
+/*
+ *
+ * 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.domain.model;
+
+import java.nio.ByteBuffer;
+import java.util.LinkedList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.management.domain.model.type.Uint64;
+import org.apache.qpid.transport.codec.ManagementDecoder;
+
+public class OptionalPropertiesTest extends TestCase
+{
+ public void testDecoderStateChange()
+ {
+ QpidProperty property = new QpidProperty();
+ assertSame(
+ "Default decoder for properties is the one for mandatory properties.",
+ property._mandatoryPropertyDecoder,
+ property._decoder);
+
+ property.markAsOptional(1);
+ assertSame(
+ "After a property has been marked as optional the corresponding decoder must be installed.",
+ property._optionalPropertyDecoder,
+ property._decoder);
+ }
+
+ /**
+ * Tests the execution of the decode() method when the current property is optional but in the presence bitmask
+ * there's no the corresponding bit set.
+ *
+ * <br>precondition : property is optional and corresponding presence bit is not set.
+ * <br>postcondition : result must be null.
+ */
+ public void testDecodeValueWithOptionalPropertyAndMissingValue()
+ {
+ byte [] presenceBytes = {2};
+
+ QpidProperty property = new QpidProperty();
+
+ // We don't need a decoder so in order to be sure that it won't be invoked set it to null.
+ ManagementDecoder nullDecoder = null;
+
+ for (int i = 0; i < 8; i++)
+ {
+ // Property number 1 is declaring a value so skip it!
+ if (i != 1)
+ {
+ property.markAsOptional(i);
+ assertNull(property.decodeValue(nullDecoder, presenceBytes));
+ }
+ }
+ }
+
+ /**
+ * Tests the execution of the decode() method when the current property is optional but in the presence bitmask
+ * there's no the corresponding bit set.
+ *
+ * <br>precondition : property is optional and corresponding presence bit is not set.
+ * <br>postcondition : result must be null.
+ */
+ public void testDecodeValueWithOptionalPropertyAndDeclaredValue()
+ {
+ byte [] presenceBytes = {4};
+ Long _44 = new Long(44);
+
+ QpidProperty property = new QpidProperty();
+ property.setType(new Uint64());
+ property.markAsOptional(2);
+
+ ByteBuffer buffer = ByteBuffer.allocate(8);
+ buffer.putLong(_44);
+ buffer.rewind();
+ ManagementDecoder decoder = new ManagementDecoder();
+
+ decoder.init(buffer);
+ assertEquals(_44,property.decodeValue(decoder, presenceBytes));
+ }
+
+ /**
+ * Tests the execution of the decode() method with a real scenario where there are mandatory and optional
+ * properties.
+ */
+ public void testDecodeValueWithOptionalAndMandatoryProperties()
+ {
+ // With this bitset :
+ //
+ // 1th opt property is null;
+ // 2th opt property is null;
+ // 3th opt property is not null;
+ // 4th opt property is null;
+ // 5th opt propertyis null;
+ // 6th opt property is null;
+ // 7th opt property is null;
+ // 8th opt property is not null;
+ byte [] presenceBytes = {4,1};
+
+ List<QpidProperty> properties = new LinkedList<QpidProperty>();
+
+ properties.add(createProperty(false, -1));
+ properties.add(createProperty(false, -1));
+ properties.add(createProperty(true, 0));
+ properties.add(createProperty(false, -1));
+ properties.add(createProperty(false, -1));
+ properties.add(createProperty(true, 1));
+ properties.add(createProperty(false, -1));
+ properties.add(createProperty(false, -1));
+ properties.add(createProperty(true, 2));
+ properties.add(createProperty(true, 3));
+ properties.add(createProperty(true, 4));
+ properties.add(createProperty(true, 5));
+ properties.add(createProperty(true, 6));
+ properties.add(createProperty(true, 7));
+ properties.add(createProperty(false, -1));
+ properties.add(createProperty(true, 8));
+
+ Long expectedResults [] = {
+ 1L, // p1
+ 22L, // p2
+ null, // p3
+ 232L, // p4
+ 211L, // p5
+ null, // p6
+ 232L, // p7
+ 211L, // p8
+ 999L, // p9
+ null, // p10
+ null, // p11
+ null, // p12
+ null, // p13
+ null, // p14
+ 626L, // p15
+ 969L // p16
+ };
+
+
+ ByteBuffer buffer = ByteBuffer.allocate(expectedResults.length * 8);
+ for (Long expected : expectedResults)
+ {
+ if (expected != null)
+ {
+ buffer.putLong(expected);
+ }
+ }
+ buffer.rewind();
+ ManagementDecoder decoder = new ManagementDecoder();
+
+ decoder.init(buffer);
+ int index = 0;
+ for (QpidProperty property : properties)
+ {
+ assertEquals(expectedResults[index++],property.decodeValue(decoder, presenceBytes));
+ }
+ }
+
+ private QpidProperty createProperty(boolean isOptional, int optionalIndex)
+ {
+ QpidProperty property = new QpidProperty();
+ property.setType(new Uint64());
+ if (isOptional)
+ {
+ property.markAsOptional(optionalIndex);
+ }
+ return property;
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidMethodBuilderTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,166 @@
+/*
+ *
+ * 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.domain.model;
+
+import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.dir;
+import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.name;
+import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.type;
+import static org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute.unit;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.MBeanOperationInfo;
+
+import org.apache.qpid.management.Names;
+import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject;
+import org.apache.qpid.management.domain.model.QpidFeatureBuilder.Attribute;
+import org.apache.qpid.transport.codec.ManagementEncoder;
+
+/**
+ * Test case for Qpid Statistic builder.
+ *
+ * @author Andrea Gazzarini
+ */
+public class QpidMethodBuilderTest extends BaseQpidFeatureBuilderTestCase
+{
+ private final static Integer ARG_COUNT = 3;
+ private MethodOrEventDataTransferObject _methodDefinition;
+
+ private List<Map<String,Object>> _argumentsDefinitons = new ArrayList<Map<String, Object>>();
+
+ @Override
+ protected void setUp () throws Exception
+ {
+ super.setUp();
+ _featureDefinition.put(Names.ARG_COUNT_PARAM_NAME, ARG_COUNT);
+
+ Map<String,Object> arg1 = new HashMap<String,Object>();
+ arg1.put(name.name(), "arg1");
+ arg1.put(type.name(),_type);
+ arg1.put(dir.name(),Direction.I.name());
+ arg1.put(unit.name(), "bytes");
+
+ Map<String,Object> arg2 = new HashMap<String,Object>();
+ arg2.put(name.name(), "arg2");
+ arg2.put(type.name(),_type);
+ arg2.put(dir.name(),Direction.O.name());
+ arg2.put(unit.name(), "bytes");
+
+ Map<String,Object> arg3 = new HashMap<String,Object>();
+ arg3.put(name.name(), "arg3");
+ arg3.put(type.name(),_type);
+ arg3.put(dir.name(),Direction.IO.name());
+ arg3.put(unit.name(), "bytes");
+
+ /*
+ dir yes no yes Direction code for method arguments
+ unit yes yes yes Units for numeric values (i.e. seconds, bytes, etc.)
+ min yes no yes Minimum value for numerics
+ max yes no yes Maximum value for numerics
+ maxlen yes no yes Maximum length for strings
+ desc yes yes yes Description of the argument
+ default yes no yes Default value for the argument
+ */
+ _argumentsDefinitons.add(arg1);
+ _argumentsDefinitons.add(arg2);
+
+ _methodDefinition = new MethodOrEventDataTransferObject(_featureDefinition,_argumentsDefinitons);
+ _builder = QpidFeatureBuilder.createMethodBuilder(_methodDefinition);
+ }
+
+ /**
+ * Tests the build process for a statistic when the definition map doesn't contains type attribute.
+ *
+ * <br>precondition: definition map doesn't contains type attribute.
+ * <br>postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the
+ * missing attribute.
+ */
+ public void testMethodBuilderKO_WithMissingName()
+ {
+ internalTestForMissingMandatoryAttribute(Attribute.name);
+ }
+
+ /**
+ * Tests the build process for a statistic when the definition map doesn't contain type, name, index & optional attributes.
+ *
+ * <br>precondition: definition map doesn't contain type, name, index & optional attributes.
+ * <br>postcondition : an exception should be thrown indicating the failure. That exception must contain the name of the
+ * missing attributes.
+ */
+ public void testMethodBuilderOK_WithMissingUnit() throws UnableToBuildFeatureException
+ {
+ internalTestForMissingOptionalAttribute(Attribute.unit);
+ }
+
+ /**
+ * Tests the build process for a statistic when the definition map doesn't unit attribute.
+ * Note that this attribute is optional and therefore the build must succeed.
+ *
+ * <br>precondition: definition map doesn't contain unit attribute.
+ * <br>postcondition : no exception is thrown and the statistic is built.
+ */
+ public void testMethodBuilderOK_WithMissingDescription() throws UnableToBuildFeatureException
+ {
+ internalTestForMissingOptionalAttribute(Attribute.desc);
+ }
+
+ /**
+ * Tests the build process for a statistic when the definition map contains valid values.
+ *
+ * <br>precondition : the statistic definiton map contains valid values.
+ * <br>postcondition : no exception is thrown and the statistisc is built as expected.
+ */
+ public void testMethodBuilderOK() throws UnableToBuildFeatureException
+ {
+ _builder.build();
+
+ QpidMethod method = (QpidMethod) _builder.getQpidFeature();
+ MBeanOperationInfo info = (MBeanOperationInfo) _builder.getManagementFeature();
+
+ assertEquals(NAME,method.getName());
+
+ assertEquals(DESCRIPTION,method.getDescription());
+
+ assertEquals(method.getDescription(),info.getDescription());
+ assertEquals(method.getName(),info.getName());
+ }
+
+ public void testEncodeParameters() throws ValidationException, UnableToBuildFeatureException {
+ _builder.build();
+
+ Object [] parameters = new Object[]{new Integer(1), new Integer(2),new Integer(3)};
+
+ ManagementEncoder encoder = new ManagementEncoder(ByteBuffer.allocate(1)){
+ @Override
+ public void writeUint16 (int s)
+ {
+ assertTrue(s == 1 || s == 2);
+ }
+ };
+
+ QpidMethod method = (QpidMethod) _builder.getQpidFeature();
+ method.encodeParameters(parameters, encoder);
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidNumberPropertyTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,167 @@
+/*
+ *
+ * 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.domain.model;
+
+import org.apache.qpid.management.domain.model.type.Uint64;
+
+public class QpidNumberPropertyTest extends BaseDomainModelTestCase
+{
+ private QpidProperty _property;
+ private Long _value = 55432L;
+
+ @Override
+ protected void setUp () throws Exception
+ {
+ super.setUp();
+ _property = new QpidProperty();
+ _property.setName("average");
+ _property.setAccessMode(AccessMode.RW);
+ _property.setType(new Uint64());
+ }
+
+ /**
+ * Tests the validation of a qpid property when the type is a number and no constraint has been set.
+ *
+ * <br>precondition : property type is a string, no constraint has been set.
+ * <br>postcondition : no exception is thrown and the validation succeeds.
+ */
+ public void testValidationWithoutConstraints() {
+ try
+ {
+ _property.validate(_value);
+ } catch (ValidationException notExpected)
+ {
+ fail("If no constraint has been set on this property why the validation is failing?");
+ }
+ }
+
+ /**
+ * Tests the validation of a qpid property when the type is a number and a max value constraint has been set.
+ *
+ * <br>precondition : property type is a number, max value has been set and property value is greater than max value.
+ * <br>postcondition : an exception is thrown indicating the validation failure.
+ */
+ public void testValidationKO_withMaxValue() {
+ int maxValue = (int)(_value-1);
+ _property.setMaxValue(maxValue);
+
+ try
+ {
+ _property.validate(_value);
+ fail("The given value is violating the installed constraint so an exception must be thrown.");
+ } catch (ValidationException expected)
+ {
+ assertEquals(ValidationException.MAX_VALUE,expected.getConstraintName());
+ assertEquals(maxValue,expected.getConstraintValue());
+ assertEquals((double)_value,expected.getFeatureValue());
+ assertEquals(_property.getName(),expected.getFeatureName());
+ }
+ }
+
+ /**
+ * Tests the validation of a qpid property when the type is a number and a min value constraint has been set.
+ *
+ * <br>precondition : property type is a number, min value has been set and property value is lesser than min value.
+ * <br>postcondition : an exception is thrown indicating the validation failure.
+ */
+ public void testValidationKO_withMinValue() {
+ int minValue = (int)(_value+1);
+ _property.setMinValue(minValue);
+
+ try
+ {
+ _property.validate(_value);
+ fail("The given value is violating the installed constraint so an exception must be thrown.");
+ } catch (ValidationException expected)
+ {
+ assertEquals(ValidationException.MIN_VALUE,expected.getConstraintName());
+ assertEquals(minValue,expected.getConstraintValue());
+ assertEquals((double)_value,expected.getFeatureValue());
+ assertEquals(_property.getName(),expected.getFeatureName());
+ }
+ }
+
+
+ /**
+ * Tests the validation of a qpid property when the number is a string and the property value is null.
+ *
+ * <br>precondition : property type is a number and property value is null..
+ * <br>postcondition : no exception is thrown. That is : the validation succeeds.
+ */
+ public void testValidationOK_withNullValue() {
+ try
+ {
+ _property.validate(null);
+ } catch (ValidationException notExpected)
+ {
+ fail("No constraint has been violated so validate() shouldn't raise an exception.");
+ }
+
+ _property.setMinValue(1);
+ _property.setMaxValue(10);
+
+ try
+ {
+ _property.validate(null);
+ } catch (ValidationException notExpected)
+ {
+ fail("No constraint has been violated so validate() shouldn't raise an exception.");
+ }
+ }
+
+ /**
+ * Tests the validation of a qpid property when the type is a number and a max / min constraints have been set.
+ *
+ * <br>precondition : property type is a number, max / min constraint have been set and property value is wrong.
+ * <br>postcondition : an exception is thrown indicating the validation failure.
+ */
+ public void testValidationOK_withMinAndMaxConstraint() {
+ int minValue = (int)(_value+1);
+ int maxValue = (int)(_value-1);
+ _property.setMinValue(minValue);
+ _property.setMaxValue(maxValue);
+
+ try
+ {
+ _property.validate(_value);
+ fail("The given value is violating the installed constraint so an exception must be thrown.");
+ } catch (ValidationException expected)
+ {
+ assertEquals(ValidationException.MIN_VALUE,expected.getConstraintName());
+ assertEquals(minValue,expected.getConstraintValue());
+ assertEquals((double)_value,expected.getFeatureValue());
+ assertEquals(_property.getName(),expected.getFeatureName());
+ }
+
+ _property.setMinValue(0);
+ try
+ {
+ _property.validate(_value);
+ fail("The given value is violating the installed constraint so an exception must be thrown.");
+ } catch (ValidationException expected)
+ {
+ assertEquals(ValidationException.MAX_VALUE,expected.getConstraintName());
+ assertEquals(maxValue,expected.getConstraintValue());
+ assertEquals((double)_value,expected.getFeatureValue());
+ assertEquals(_property.getName(),expected.getFeatureName());
+ }
+ }
+}
\ No newline at end of file
Added: incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java?rev=700134&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/management/domain/model/QpidPackageTest.java Mon Sep 29 07:06:18 2008
@@ -0,0 +1,54 @@
+/*
+ *
+ * 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.domain.model;
+
+import org.apache.qpid.management.TestConstants;
+
+/**
+ * Test case for Qpid package entity.
+ *
+ * @author Andrea Gazzarini
+ */
+public class QpidPackageTest extends BaseDomainModelTestCase
+{
+ private QpidPackage _qpidPackage;
+
+ @Override
+ protected void setUp () throws Exception
+ {
+ super.setUp();
+ _qpidPackage = new QpidPackage(TestConstants.QPID_PACKAGE_NAME, TestConstants.DOMAIN_MODEL);
+ }
+
+ /**
+ * Tests the association of a new class with a qpid package.
+ *
+ * <br>precondition : the package is not associated with any class.
+ * <br>postcondition : the package is now associated with the given class.
+ */
+ public void testAddClass() throws UnableToBuildFeatureException {
+ assertFalse(_qpidPackage.alreadyContainsClassDefinition(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH));
+
+ _qpidPackage.getQpidClass(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH, true);
+
+ assertTrue(_qpidPackage.alreadyContainsClassDefinition(TestConstants.EXCHANGE_CLASS_NAME, TestConstants.HASH));
+ }
+}
\ No newline at end of file