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/10/22 12:19:51 UTC

svn commit: r707016 [2/2] - in /incubator/qpid/trunk/qpid/java: ./ management/client/src/main/java/org/apache/qpid/management/ management/client/src/main/java/org/apache/qpid/management/configuration/ management/client/src/main/java/org/apache/qpid/man...

Modified: incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java?rev=707016&r1=707015&r2=707016&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java (original)
+++ incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java Wed Oct 22 03:19:50 2008
@@ -1,47 +1,36 @@
-/*
- *
- * 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.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
 import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
+
+import junit.framework.TestCase;
 
 import org.apache.qpid.management.TestConstants;
 import org.apache.qpid.management.configuration.ConfigurationException;
 import org.apache.qpid.management.configuration.StubConfigurator;
+import org.apache.qpid.management.domain.handler.impl.MethodOrEventDataTransferObject;
 import org.apache.qpid.management.domain.model.QpidClass.QpidManagedObject;
 
-public class QpidClassTest extends BaseDomainModelTestCase
+public class QpidClassTest extends TestCase
 {
-    private QpidClass _qpidClass;
+    private QpidClass _class;
+    private QpidPackage _package;
     
     @Override
-    protected void setUp () throws Exception
+    protected void setUp () throws ConfigurationException
     {
-        QpidPackage qpidPackage = new QpidPackage(TestConstants.QPID_PACKAGE_NAME,TestConstants.DOMAIN_MODEL);
-        _qpidClass = new QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,qpidPackage);
+    	StubConfigurator configurator = new StubConfigurator();
+    	configurator.configure();
+    	_package = new QpidPackage(TestConstants.QPID_PACKAGE_NAME,TestConstants.DOMAIN_MODEL);
+        _class = new QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,_package);
     }
         
     /**
@@ -55,13 +44,15 @@
     {            
         assertFalse (
                 "Nobody set instance #"+TestConstants.OBJECT_ID+" into this class so why is it there?", 
-        		_qpidClass._objectInstances.containsKey(TestConstants.OBJECT_ID));
+        		_class._objectInstances.containsKey(TestConstants.OBJECT_ID));
 
-        _qpidClass.getObjectInstance(TestConstants.OBJECT_ID, false);
+        QpidManagedObject instance = _class.getObjectInstance(TestConstants.OBJECT_ID, false);
         
         assertTrue (
                 "Now the instance #"+TestConstants.OBJECT_ID+" should be there...",
-                _qpidClass._objectInstances.containsKey(TestConstants.OBJECT_ID));
+                _class._objectInstances.containsKey(TestConstants.OBJECT_ID));
+        
+        assertEquals(instance,_class.getObjectInstance(TestConstants.OBJECT_ID, false));
     }
        
     /**
@@ -73,8 +64,8 @@
      */
     public void testAddInstrumentationAndConfigurationDataBeforeSchemaInstallation() 
     {
-        _qpidClass._state = _qpidClass._schemaRequestedButNotYetInjected;
-        QpidManagedObject objectInstance = _qpidClass.getObjectInstance(TestConstants.OBJECT_ID,false);
+        _class._state = _class._schemaRequestedButNotYetInjected;
+        QpidManagedObject objectInstance = _class.getObjectInstance(TestConstants.OBJECT_ID,false);
         
         assertTrue(
                 "This object instance is a new one so how is it possible that it has already instrumentation data? ",
@@ -86,8 +77,8 @@
         byte [] dummyConfigurationData = {1,2,3,4,5,6,7,8};
         byte [] dummyInstrumentationData = {11,21,31,41,51,61,71,81};
         
-        _qpidClass.addConfigurationData(TestConstants.OBJECT_ID, dummyConfigurationData);
-        _qpidClass.addInstrumentationData(TestConstants.OBJECT_ID, dummyInstrumentationData);
+        _class.addConfigurationData(TestConstants.OBJECT_ID, dummyConfigurationData);
+        _class.addInstrumentationData(TestConstants.OBJECT_ID, dummyInstrumentationData);
         
         assertEquals("Now configuration data should be there...",1,objectInstance._rawConfigurationData.size());
         assertEquals("Now instrumentation data should be there...",1,objectInstance._rawInstrumentationData.size());
@@ -103,63 +94,292 @@
                 dummyInstrumentationData));        
     }
     
-    public void testBuildAttributesOK() throws UnableToBuildFeatureException, ConfigurationException
+    /**
+     * Tests the internal state change of a class definition.
+     */
+    public void testStateChange() throws UnableToBuildFeatureException
+    {
+    	_class = new QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,_package)
+    	{
+    		@Override
+    		void requestSchema() throws Exception {
+    			_state = _schemaRequestedButNotYetInjected;
+    		}
+    		
+    		@Override
+    		void setSchema(List<Map<String, Object>> propertyDefinitions,
+    				List<Map<String, Object>> statisticDefinitions,
+    				List<MethodOrEventDataTransferObject> methodDefinitions) throws UnableToBuildFeatureException {
+    			_state = _schemaInjected;
+    		}
+    	};
+    	
+    	assertSame(
+    			"Initial state doesn't match.",
+    			_class._schemaNotRequested,
+    			_class._state);
+    	
+    	_class.addConfigurationData(TestConstants.OBJECT_ID, TestConstants.TEST_RAW_DATA);
+    	_class.addInstrumentationData(TestConstants.OBJECT_ID, TestConstants.TEST_RAW_DATA);
+
+    	assertSame(
+    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+    			_class._schemaRequestedButNotYetInjected,
+    			_class._state);    	
+    	
+    	_class.setSchema(
+    			TestConstants.EMPTY_PROPERTIES_SCHEMA, 
+    			TestConstants.EMPTY_STATISTICS_SCHEMA, 
+    			new LinkedList<MethodOrEventDataTransferObject>());
+    	
+    	assertSame(
+    			"Request schema has been injected. The current state is not indicating that!",
+    			_class._schemaInjected,
+    			_class._state);    	
+    }
+    
+    /**
+     * Tests the injection of a valid schema on a QpidClass.
+     * 
+     * <br>precondition : a valid arguments is injected on the qpid class.
+     * <br>postcondition : class definition is built successfully.
+     */
+    public void testSchemaInjectionOk() throws UnableToBuildFeatureException
     {
-        StubConfigurator configurator = new StubConfigurator();
-        configurator.configure();
+    	_class = new QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,_package)
+    	{
+    		@Override
+    		void requestSchema() throws Exception 
+    		{
+    			// DO NOTHING : QMan is not running and therefore the schema will be manually injected.
+    		}
+    		
+    		 @Override
+    		void updateInstanceWithConfigurationData(QpidManagedObject instance, byte[] rawData) 
+    		{
+    			// DO NOTHING Given raw data is not valid so it cannot be converted.
+			}    		
+    	};
+    	
+        // Incoming configuration data : that will fire the schema request and a state change 
+    	// from schema-not-requested to schema-requested-but-not-injected
+    	_class.addConfigurationData(TestConstants.OBJECT_ID, TestConstants.TEST_RAW_DATA);
+    	
+        // I must be sure that what is obvious for me it's obvious for QMan... :)
+        assertSame(
+    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+    			_class._schemaRequestedButNotYetInjected,
+    			_class._state);
+        
+        List<Map<String,Object>> propertyDefinitions = new ArrayList<Map<String,Object>>(2);
+        propertyDefinitions.add(
+        		createProperty(
+	        		TestConstants.AGE_ATTRIBUTE_NAME, 
+	        		1, 
+	        		TestConstants.YEARS, 
+	        		TestConstants.SAMPLE_MIN_VALUE, 
+	        		TestConstants.SAMPLE_MAX_VALUE, 
+	        		null,
+	        		TestConstants.AGE_ATTRIBUTE_DESCRIPTION, 
+	        		TestConstants._1,
+	        		false, 
+	        		TestConstants._0));
+      
+        propertyDefinitions.add(
+        		createProperty(
+	        		TestConstants.SURNAME_ATTRIBUTE_NAME, 
+	        		TestConstants.SAMPLE_ACCESS_CODE,
+	        		null,
+	        		null, 
+	        		null, 
+	        		TestConstants.SAMPLE_MAX_VALUE,
+	        		TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION, 
+	        		TestConstants._1,
+	        		true, 
+	        		TestConstants._1));
 
-        List<Map<String,Object>> properties = new ArrayList<Map<String, Object>>();
-        List<Map<String,Object>> statistics = new ArrayList<Map<String, Object>>();
+        List<Map<String,Object>> statisticDefinitions = new ArrayList<Map<String,Object>>(2);        
+        
+        _class.setSchema(propertyDefinitions, TestConstants.EMPTY_STATISTICS_SCHEMA, TestConstants.EMPTY_METHODS_SCHEMA);
+        
+        assertEquals(2,_class._properties.size());
         
-        Map <String,Object> age = new HashMap<String, Object>();
-        
-        age.put("name","age");
-        age.put("access", new Integer(1));
-        age.put("unit","years");
-        age.put("min", new Integer(0));
-        age.put("max",new Integer(120));
-        age.put("desc", "The age of a person.");
-        age.put("type", new Integer(1));
-        age.put("optional",0);
-        age.put("index", new Integer(1));
-
-        Map <String,Object> surname = new HashMap<String, Object>();
-        surname.put("name","surname");
-        surname.put("access", new Integer(1));
-        surname.put("desc", "The surname of a person.");
-        surname.put("type", new Integer(1));
-        surname.put("optional",1);
-        surname.put("index", new Integer(1));
-        properties.add(age);
-        properties.add(surname);
-        
-        MBeanAttributeInfo [] info = new MBeanAttributeInfo[properties.size()+statistics.size()];
-        _qpidClass.buildAttributes(properties, statistics, info);
-        
-        assertEquals(2,_qpidClass._properties.size());
-        
-        QpidProperty property = _qpidClass._properties.get("age");
-        
-        assertEquals("age",property.getName());
-        assertEquals(AccessMode.RW,property.getAccessMode());
-        assertEquals("years",property.getUnit());
-        assertEquals(0,property.getMinValue());
-        assertEquals(120,property.getMaxValue());
+        QpidProperty property = _class._properties.get(TestConstants.AGE_ATTRIBUTE_NAME);
+        assertEquals(TestConstants.AGE_ATTRIBUTE_NAME,property.getName());
+        assertEquals(AccessMode.RC,property.getAccessMode());
+        assertEquals(TestConstants.YEARS,property.getUnit());
+        assertEquals(TestConstants.SAMPLE_MIN_VALUE,property.getMinValue());
+        assertEquals(TestConstants.SAMPLE_MAX_VALUE,property.getMaxValue());
         assertEquals(Integer.MIN_VALUE,property.getMaxLength());
-        assertEquals("The age of a person.",property.getDescription());
+        assertEquals(TestConstants.AGE_ATTRIBUTE_DESCRIPTION,property.getDescription());
         assertEquals(String.class,property.getJavaType());
         assertFalse(property.isOptional());
         
-        property = _qpidClass._properties.get("surname");
-        
-        assertEquals("surname",property.getName());
-        assertEquals(AccessMode.RW,property.getAccessMode());
+        property = _class._properties.get(TestConstants.SURNAME_ATTRIBUTE_NAME);
+        assertEquals(TestConstants.SURNAME_ATTRIBUTE_NAME,property.getName());
+        assertEquals(AccessMode.RC,property.getAccessMode());
         assertNull(property.getUnit());
         assertEquals(Integer.MIN_VALUE,property.getMinValue());
         assertEquals(Integer.MIN_VALUE,property.getMaxValue());
-        assertEquals(Integer.MIN_VALUE,property.getMaxLength());        
-        assertEquals("The surname of a person.",property.getDescription());
+        assertEquals(TestConstants.SAMPLE_MAX_VALUE,property.getMaxLength());
+        assertEquals(TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION,property.getDescription());
         assertEquals(String.class,property.getJavaType());
         assertTrue(property.isOptional());
-  }
-}
\ No newline at end of file
+        
+        MBeanInfo mbeanInfo = _class._metadata;
+        assertEquals(TestConstants.EXCHANGE_CLASS_NAME,mbeanInfo.getClassName());
+        
+        MBeanAttributeInfo [] attributes = mbeanInfo.getAttributes();
+        assertEquals(2,attributes.length);
+        
+        MBeanAttributeInfo attribute = attributes[0];
+        assertEquals(TestConstants.AGE_ATTRIBUTE_NAME,attribute.getName());
+        assertEquals(TestConstants.AGE_ATTRIBUTE_DESCRIPTION,attribute.getDescription());
+        assertFalse(attribute.isWritable());
+        assertTrue(attribute.isReadable());
+        assertEquals(String.class.getName(),attribute.getType());
+        
+        attribute = attributes[1];
+        assertEquals(TestConstants.SURNAME_ATTRIBUTE_NAME,attribute.getName());
+        assertEquals(TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION,attribute.getDescription());
+        assertFalse(attribute.isWritable());
+        assertTrue(attribute.isReadable());
+        assertEquals(String.class.getName(),attribute.getType());
+    }
+        
+    /**
+     * Tests the behaviour of the class when a schema request can't be made.
+     * 
+     * <br>precondition : class must be in "schema-not-requested" state when incoming data arrives.
+     * <br>postcondition : no exception is thrown and no state transition happens.
+     */
+    public void testStateChange_withRequestSchemaFailure()
+    {
+    	_class= new QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,_package)
+    	{
+    		@Override
+    		void requestSchema() throws Exception {
+    			throw new Exception();
+    		}
+    		
+    		@Override
+    		void setSchema(
+    				List<Map<String, Object>> propertyDefinitions,
+    				List<Map<String, Object>> statisticDefinitions,
+    				List<MethodOrEventDataTransferObject> methodDefinitions) throws UnableToBuildFeatureException 
+    		{
+    		}
+    	};
+    	
+    	assertSame(
+    			"Initial state must be schema-not-requested.",
+    			_class._schemaNotRequested,
+    			_class._state);
+
+    	_class.addInstrumentationData(TestConstants.OBJECT_ID, TestConstants.TEST_RAW_DATA);
+    	
+    	assertSame(
+    			"Current state must be still schema-not-requested.",
+    			_class._schemaNotRequested,
+    			_class._state);
+    }
+
+    /**
+     * Tests the behaviour of the class when a schema injection fails.
+     * 
+     * <br>precondition : class must be in "schema-not-requested" state when incoming data arrives.
+     * <br>postcondition : an exception is thrown and no state transition happens.
+     */
+    public void testStateChange_withSchemaInjectionFailure()
+    {
+    	_class = new QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,_package)
+    	{
+    		@Override
+    		void requestSchema() throws Exception 
+    		{
+    			// DO NOTHING.
+    		}
+    		
+    		@Override
+    		void setSchema(List<Map<String, Object>> propertyDefinitions,
+    				List<Map<String, Object>> statisticDefinitions,
+    				List<MethodOrEventDataTransferObject> methodDefinitions)
+    				throws UnableToBuildFeatureException 
+    		{
+    			throw new UnableToBuildFeatureException("");
+    		}
+    	};
+    	
+    	assertSame(
+    			"Initial state must be schema-not-requested.",
+    			_class._schemaNotRequested,
+    			_class._state);
+    	
+    	_class.addInstrumentationData(TestConstants.OBJECT_ID, TestConstants.TEST_RAW_DATA);
+    	
+      	assertSame(
+    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+    			_class._schemaRequestedButNotYetInjected,
+    			_class._state);
+      	
+      	try {
+			_class.setSchema(
+					TestConstants.EMPTY_PROPERTIES_SCHEMA,
+					TestConstants.EMPTY_STATISTICS_SCHEMA,
+					TestConstants.EMPTY_METHODS_SCHEMA);
+			fail("If we are here something was wrong becuase the setSchema() of this event is throwing an exception...");
+		} catch (UnableToBuildFeatureException expected) {
+	      	assertSame(
+	    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+	    			_class._schemaRequestedButNotYetInjected,
+	    			_class._state);
+		}
+    }    
+    
+    private Map<String,Object> createProperty(
+    		String name,
+    		Integer accessCode, 
+    		String unit,
+    		Integer min, 
+    		Integer max, 
+    		Integer maxLength,
+    		String description,
+    		Integer type,
+    		boolean optional,
+    		Integer index)
+    {
+        Map <String,Object> result = new HashMap<String, Object>();
+        result.put(QpidFeatureBuilder.Attribute.name.name(),name);
+        result.put(QpidFeatureBuilder.Attribute.access.name(), accessCode);
+
+        if (unit != null)
+        {
+        	result.put(QpidFeatureBuilder.Attribute.unit.name(),unit);
+        }
+        
+        if (min != null)
+        {
+        	result.put(QpidFeatureBuilder.Attribute.min.name(), min);
+        }
+        
+        if (max != null) 
+        {
+            result.put(QpidFeatureBuilder.Attribute.max.name(),max);        	
+        }
+
+        if (maxLength != null) 
+        {
+            result.put(QpidFeatureBuilder.Attribute.maxlen.name(),maxLength);        	
+        }
+        
+        result.put(QpidFeatureBuilder.Attribute.desc.name(), description);
+        result.put(QpidFeatureBuilder.Attribute.type.name(), type);
+        result.put(QpidFeatureBuilder.Attribute.optional.name(),optional ? 1 : 0);
+
+        if (index != null)
+        {
+        	result.put(QpidFeatureBuilder.Attribute.index.name(), index);
+        }
+    	return result;
+    }    
+}

Added: incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java?rev=707016&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java (added)
+++ incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidEventTest.java Wed Oct 22 03:19:50 2008
@@ -0,0 +1,293 @@
+/*
+ *
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.management.TestConstants;
+import org.apache.qpid.management.configuration.ConfigurationException;
+import org.apache.qpid.management.configuration.StubConfigurator;
+import org.apache.qpid.management.domain.model.QpidEvent.QpidManagedEvent;
+
+/**
+ * Test case for qpid class entity.
+ * 
+ * @author Andrea Gazzarini
+ */
+public class QpidEventTest extends TestCase
+{
+    private QpidEvent _event;
+    private QpidPackage _qpidPackage;
+    
+    @Override
+    protected void setUp () throws Exception
+    {
+        _qpidPackage = new QpidPackage(TestConstants.QPID_PACKAGE_NAME,TestConstants.DOMAIN_MODEL);
+        _event = new QpidEvent(TestConstants.BIND_EVENT_NAME,TestConstants.HASH,_qpidPackage);
+    }
+        
+    /**
+     * Tests the execution of the createEventInstance() method.
+     * Basically it tests the addition of a new event instance.
+     * 
+     * <br>precondition: event deifinition has no object instances.
+     * <br>precondition : event definition contains the new object instance.
+     */
+    public void testCreateEventInstance() 
+    {            
+        assertTrue(
+                "A just created event should be empty. I mean there shouldn't be event instances inside.", 
+        		_event.hasNoInstances());
+
+        QpidManagedEvent instance = createEventInstance();
+        
+        assertFalse (
+                "Now a new instance should be there...",
+                _event.hasNoInstances());
+        
+        assertEquals(TestConstants.TEST_RAW_DATA,instance._rawEventData);
+        assertEquals(TestConstants.NOW,instance._timestamp);
+        assertEquals(TestConstants.SEVERITY, instance._severity);
+    }
+    
+    /**
+     * Tests the internal state change of an event definition.
+     */
+    public void testStateChange() throws UnableToBuildFeatureException
+    {
+    	// Let's override this class because this is not an online tests and therefore
+    	// QMan is not supposed to be up.
+    	_event = new QpidEvent(TestConstants.BIND_EVENT_NAME,TestConstants.HASH,_qpidPackage)
+    	{
+    		@Override
+    		void requestSchema() throws Exception {
+    			// Do Nothing.
+    		}
+    		
+    		@Override
+    		void setSchema(List<Map<String, Object>> argumentDefinitions)throws UnableToBuildFeatureException {
+    			_state = _schemaInjected;
+    		}
+    	};
+    	
+    	assertSame(
+    			"Initial state doesn't match.",
+    			_event._schemaNotRequested,
+    			_event._state);
+    	
+    	_event.addEventData(TestConstants.TEST_RAW_DATA, TestConstants.NOW, TestConstants.SEVERITY);
+    	
+    	assertSame(
+    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+    			_event._schemaRequestedButNotYetInjected,
+    			_event._state);
+    	
+    	_event.setSchema(TestConstants.EMPTY_ARGUMENTS_SCHEMA);
+    	
+    	assertSame(
+    			"Request schema has been injected. The current state is not indicating that!",
+    			_event._schemaInjected,
+    			_event._state);    	
+    }
+    
+    /**
+     * Tests the injection of a valid schema on a QpidEvent.
+     * 
+     * <br>precondition : a valid arguments is injected on the qpid event.
+     * <br>postcondition : event definition is built successfully.
+     */
+    public void testSchemaInjectionOK() throws UnableToBuildFeatureException, ConfigurationException, InstanceNotFoundException, MBeanException, ReflectionException
+    {
+    	_event = new QpidEvent(TestConstants.BIND_EVENT_NAME,TestConstants.HASH,_qpidPackage)
+    	{
+    		@Override
+    		void requestSchema() throws Exception 
+    		{
+    			// DO NOTHING : QMan is not running and therefore the schema will be manually injected.
+    		}
+    		
+    		@Override
+    		void updateEventInstanceWithData(QpidManagedEvent instance) 
+    		{
+    			// DO NOTHING : otherwise we should supply a valid raw data to be converted. ;-)
+    		}
+    	};
+    	
+        StubConfigurator configurator = new StubConfigurator();
+        configurator.configure();
+
+        List<Map<String,Object>> arguments = new ArrayList<Map<String, Object>>();
+        arguments.add(createArgument(TestConstants.AGE_ATTRIBUTE_NAME, TestConstants.AGE_ATTRIBUTE_DESCRIPTION));
+        arguments.add(createArgument(TestConstants.SURNAME_ATTRIBUTE_NAME, TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION));
+        
+        // Incoming data : that will fire the schema request and a state change from schema-not-requested to schema-requested-but-not-injected
+        _event.addEventData(TestConstants.TEST_RAW_DATA, TestConstants.NOW, TestConstants.SEVERITY);
+        
+        // I must be sure that what is obvious for me it's obvious for QMan... :)
+        assertSame(
+    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+    			_event._schemaRequestedButNotYetInjected,
+    			_event._state);
+        
+        // Inject schema
+        _event.setSchema(arguments);
+
+        // Arguments must be 2 + 2 (severity)
+        assertEquals(2,_event._arguments.size());
+        
+        QpidProperty argument = _event._arguments.get(TestConstants.AGE_ATTRIBUTE_NAME);
+        assertEquals(TestConstants.AGE_ATTRIBUTE_NAME,argument.getName());
+        assertEquals(AccessMode.RO,argument.getAccessMode());
+        assertEquals(TestConstants.AGE_ATTRIBUTE_DESCRIPTION,argument.getDescription());
+        assertEquals(String.class,argument.getJavaType());
+        assertFalse(argument.isOptional());
+        
+        argument = _event._arguments.get(TestConstants.SURNAME_ATTRIBUTE_NAME);
+        assertEquals(TestConstants.SURNAME_ATTRIBUTE_NAME,argument.getName());
+        assertEquals(AccessMode.RO,argument.getAccessMode());
+        assertEquals(TestConstants.SURNAME_ATTRIBUTE_DESCRIPTION,argument.getDescription());
+        assertEquals(String.class,argument.getJavaType());
+        assertFalse(argument.isOptional());
+        
+        assertEquals(1,_event._eventInstances.size());
+        
+        JmxService service = new JmxService();
+        Set<ObjectName> objectNames = service.getEventMBeans();
+        
+        assertEquals(1,objectNames.size());
+    }    
+    
+    /**
+     * Tests the behaviour of the event class when a schema request can't be made.
+     * 
+     * <br>precondition : event must be in "schema-not-requested" state when incoming data arrives.
+     * <br>postcondition : no exception is thrown and no state transition happens.
+     */
+    public void testStateChange_withRequestSchemaFailure()
+    {
+    	_event = new QpidEvent(TestConstants.BIND_EVENT_NAME,TestConstants.HASH,_qpidPackage)
+    	{
+    		@Override
+    		void requestSchema() throws Exception {
+    			throw new Exception();
+    		}
+    		
+    		@Override
+    		void setSchema(List<Map<String, Object>> argumentDefinitions)throws UnableToBuildFeatureException {
+    			_state = _schemaInjected;
+    		}
+    	};
+    	
+    	assertSame(
+    			"Initial state must be schema-not-requested.",
+    			_event._schemaNotRequested,
+    			_event._state);
+    	
+    	_event.addEventData(TestConstants.TEST_RAW_DATA, TestConstants.NOW, TestConstants.SEVERITY);
+    	
+    	assertSame(
+    			"Current state must be still schema-not-requested.",
+    			_event._schemaNotRequested,
+    			_event._state);
+    }
+    
+    /**
+     * Tests the behaviour of the event class when a schema injection fails.
+     * 
+     * <br>precondition : event must be in "schema-not-requested" state when incoming data arrives.
+     * <br>postcondition : an exception is thrown and no state transition happens.
+     */
+    public void testStateChange_withSchemaInjectionFailure()
+    {
+    	_event = new QpidEvent(TestConstants.BIND_EVENT_NAME,TestConstants.HASH,_qpidPackage)
+    	{
+    		@Override
+    		void requestSchema() throws Exception {
+    			// DO NOTHING.
+    		}
+    		
+    		@Override
+    		void setSchema(List<Map<String, Object>> argumentDefinitions)throws UnableToBuildFeatureException {
+    			throw new UnableToBuildFeatureException("");
+    		}
+    	};
+    	
+    	assertSame(
+    			"Initial state must be schema-not-requested.",
+    			_event._schemaNotRequested,
+    			_event._state);
+    	
+    	_event.addEventData(TestConstants.TEST_RAW_DATA, TestConstants.NOW, TestConstants.SEVERITY);
+    	
+      	assertSame(
+    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+    			_event._schemaRequestedButNotYetInjected,
+    			_event._state);
+      	
+      	try {
+			_event.setSchema(TestConstants.EMPTY_ARGUMENTS_SCHEMA);
+			fail("If we are here something was wrong becuase the setSchema() of this event is throwing an exception...");
+		} catch (UnableToBuildFeatureException expected) {
+	      	assertSame(
+	    			"Request schema has been requested but not yet injected. The current state is not indicating that!",
+	    			_event._schemaRequestedButNotYetInjected,
+	    			_event._state);
+		}
+    }    
+
+    /**
+     * Factory method for qpid managed event instances.
+     * 
+     * @return a new QpidManagedEvent with test data inside.
+     */
+    private QpidManagedEvent createEventInstance()
+    {
+    	return  _event.createEventInstance(
+        		TestConstants.TEST_RAW_DATA, 
+        		TestConstants.NOW,
+        		TestConstants.SEVERITY);
+    }
+    
+    /**
+     * Factory method for event argument.
+     * 
+     * @return a new argument metadata.
+     */
+    private Map<String,Object> createArgument(String name,String desc)
+    {
+    	 Map <String,Object> argument = new HashMap<String, Object>();
+         argument.put(QpidFeatureBuilder.Attribute.name.name(),name);
+         argument.put(QpidFeatureBuilder.Attribute.desc.name(), desc);
+         argument.put(QpidFeatureBuilder.Attribute.type.name(), TestConstants._1);       
+         return argument;
+    }
+}

Modified: incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/BrokerMessageListenerTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/BrokerMessageListenerTest.java?rev=707016&r1=707015&r2=707016&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/BrokerMessageListenerTest.java (original)
+++ incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/BrokerMessageListenerTest.java Wed Oct 22 03:19:50 2008
@@ -127,7 +127,7 @@
                 _listener._handlers.isEmpty());
         
         _handlers.put(opcodeForWrongHandler,wrongMessageHandler);
-        
+
         _listener.setHandlers(_handlers);
         
         assertEquals("Now we should have two handlers configured.",2,_listener._handlers.size());
@@ -167,4 +167,4 @@
         
         _listener.onMessage(message);
     }
-}
\ No newline at end of file
+}