Author: arnaudsimon
Date: Mon Oct 13 02:09:24 2008
New Revision: 703980
URL: http://svn.apache.org/viewvc?rev=703980&view=rev
Log:
qpid-1284: on behalf Adnrea (lnew unit tests)
Added:
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/BrokerMessageListenerTest.java
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/BaseOnlineTestCase.java
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java
Added:
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=703980&view=auto
==============================================================================
---
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java
(added)
+++
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/model/QpidClassTest.java
Mon Oct 13 02:09:24 2008
@@ -0,0 +1,165 @@
+/*
+ *
+ * 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.List;
+import java.util.Map;
+
+import javax.management.MBeanAttributeInfo;
+
+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.QpidClass.QpidManagedObject;
+
+public class QpidClassTest extends BaseDomainModelTestCase
+{
+ private QpidClass _qpidClass;
+
+ @Override
+ protected void setUp () throws Exception
+ {
+ QpidPackage qpidPackage = new
QpidPackage(TestConstants.QPID_PACKAGE_NAME,TestConstants.DOMAIN_MODEL);
+ _qpidClass = new
QpidClass(TestConstants.EXCHANGE_CLASS_NAME,TestConstants.HASH,qpidPackage);
+ }
+
+ /**
+ * Tests the execution of the getObjectInstance() method.
+ * Basically it tests the addition of a new object instance.
+ *
+ * <br>precondition: class has no object instances.
+ * <br>precondition : class contains the added object instance.
+ */
+ public void testGetObjectInstance()
+ {
+ assertFalse (
+ "Nobody set instance #"+TestConstants.OBJECT_ID+" into this
class so why is it there?",
+
_qpidClass._objectInstances.containsKey(TestConstants.OBJECT_ID));
+
+ _qpidClass.getObjectInstance(TestConstants.OBJECT_ID, false);
+
+ assertTrue (
+ "Now the instance #"+TestConstants.OBJECT_ID+" should be
there...",
+
_qpidClass._objectInstances.containsKey(TestConstants.OBJECT_ID));
+ }
+
+ /**
+ * Tests the injection of instrumentation and configuration data (related
to a specific object instance) before the
+ * schema is installed.
+ *
+ * <br>precondition : the schema hasn't yet installed on this class.
+ * <br>postcondition : incoming configuration & instrumentation data is
stored into the corresponding object instance.
+ */
+ public void
testAddInstrumentationAndConfigurationDataBeforeSchemaInstallation()
+ {
+ _qpidClass._state = _qpidClass._schemaRequestedButNotYetInjected;
+ QpidManagedObject objectInstance =
_qpidClass.getObjectInstance(TestConstants.OBJECT_ID,false);
+
+ assertTrue(
+ "This object instance is a new one so how is it possible that
it has already instrumentation data? ",
+ objectInstance._rawInstrumentationData.isEmpty());
+ assertTrue(
+ "This object instance is a new one so how is it possible that
it has already configuration data? ",
+ objectInstance._rawConfigurationData.isEmpty());
+
+ 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);
+
+ assertEquals("Now configuration data should be
there...",1,objectInstance._rawConfigurationData.size());
+ assertEquals("Now instrumentation data should be
there...",1,objectInstance._rawInstrumentationData.size());
+
+ assertTrue(
+ "Object instance configuration data should be the previously
set...",
+ Arrays.equals(objectInstance._rawConfigurationData.get(0),
+ dummyConfigurationData));
+
+ assertTrue(
+ "Object instance instrumentation data should be the previously
set...",
+ Arrays.equals(objectInstance._rawInstrumentationData.get(0),
+ dummyInstrumentationData));
+ }
+
+ public void testBuildAttributesOK() throws UnableToBuildFeatureException,
ConfigurationException
+ {
+ StubConfigurator configurator = new StubConfigurator();
+ configurator.configure();
+
+ List<Map<String,Object>> properties = new ArrayList<Map<String,
Object>>();
+ List<Map<String,Object>> statistics = new ArrayList<Map<String,
Object>>();
+
+ 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());
+ assertEquals(Integer.MIN_VALUE,property.getMaxLength());
+ assertEquals("The age of a person.",property.getDescription());
+ assertEquals(String.class,property.getJavaType());
+ assertFalse(property.isOptional());
+
+ property = _qpidClass._properties.get("surname");
+
+ assertEquals("surname",property.getName());
+ assertEquals(AccessMode.RW,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(String.class,property.getJavaType());
+ assertTrue(property.isOptional());
+ }
+}
\ No newline at end of file
Added:
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=703980&view=auto
==============================================================================
---
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/BrokerMessageListenerTest.java
(added)
+++
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/domain/services/BrokerMessageListenerTest.java
Mon Oct 13 02:09:24 2008
@@ -0,0 +1,170 @@
+/*
+ *
+ * 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.services;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.api.Message;
+import org.apache.qpid.management.TestConstants;
+import org.apache.qpid.management.domain.handler.base.IMessageHandler;
+import org.apache.qpid.management.domain.model.DomainModel;
+import org.apache.qpid.nclient.util.ByteBufferMessage;
+import org.apache.qpid.transport.codec.ManagementDecoder;
+
+/**
+ * Test case for Broker Message Listener.
+ *
+ * @author Andrea Gazzarini
+ */
+public class BrokerMessageListenerTest extends TestCase
+{
+ // An empty message handler user for test.
+ private IMessageHandler _emptyMessageHandler = new IMessageHandler()
+ {
+ public void process (ManagementDecoder decoder, int sequenceNumber)
+ {
+ }
+ public void setDomainModel (DomainModel domainModel)
+ {
+ }
+ };
+
+ // Another empty message handler user for test.
+ private IMessageHandler _anotherEmptyMessageHandler = new
IMessageHandler()
+ {
+ public void process (ManagementDecoder decoder, int sequenceNumber)
+ {
+ }
+ public void setDomainModel (DomainModel domainModel)
+ {
+ }
+ };
+
+ private Map<Character,IMessageHandler> _handlers = new HashMap<Character,
IMessageHandler>();
+ private BrokerMessageListener _listener;
+ private final char opcode1 = 'x';
+ private final char opcode2 = 'y';
+
+
+ @Override
+ protected void setUp () throws Exception
+ {
+ DomainModel domainModel = new DomainModel(TestConstants.BROKER_ID);
+ _listener = new BrokerMessageListener(domainModel);
+
+ _handlers.put(opcode1, _emptyMessageHandler);
+ _handlers.put(opcode2, _anotherEmptyMessageHandler);
+ }
+
+ /**
+ * Tests the installation of message handlers on a broker message listener.
+ *
+ * <br>precondition : no message handler has been installed on message
listener.
+ * <br>postcondition : two message handlers are installed on message
listener.
+ */
+ public void testSetHandlersOK()
+ {
+ assertTrue(
+ "No handler has yet been installed so how is it possible that
the handlers map is not empty?",
+ _listener._handlers.isEmpty());
+
+ _listener.setHandlers(_handlers);
+
+ assertEquals("Now we should have two handlers
configured.",2,_listener._handlers.size());
+ assertSame(_listener._handlers.get(opcode1),_emptyMessageHandler);
+
assertSame(_listener._handlers.get(opcode2),_anotherEmptyMessageHandler);
+ }
+
+ /**
+ * Tests the installation of message handlers on a broker message
listener.
+ * Specifically it tries to install three message handlers and one of them
is throwing an exception at installation time.
+ *
+ * <br>precondition : no message handler has been installed on message
listener.
+ * <br>postcondition : two message handlers are installed on message
listener. (the one that thrown exception has been
+ * discarded).
+ */
+ public void testSetHandlerOK()
+ {
+ IMessageHandler wrongMessageHandler = new IMessageHandler()
+ {
+
+ public void process (ManagementDecoder decoder, int sequenceNumber)
+ {
+ }
+
+ public void setDomainModel (DomainModel domainModel)
+ {
+ throw new RuntimeException();
+ }
+ };
+
+ char opcodeForWrongHandler = 'k';
+
+ assertTrue(
+ "No handler has yet been installed so how is it possible that
the handlers map is not empty?",
+ _listener._handlers.isEmpty());
+
+ _handlers.put(opcodeForWrongHandler,wrongMessageHandler);
+
+ _listener.setHandlers(_handlers);
+
+ assertEquals("Now we should have two handlers
configured.",2,_listener._handlers.size());
+ assertSame(_listener._handlers.get(opcode1),_emptyMessageHandler);
+
assertSame(_listener._handlers.get(opcode2),_anotherEmptyMessageHandler);
+ assertNull(_listener._handlers.get(opcodeForWrongHandler));
+ }
+
+ /**
+ * Tests the execution of the onMessage() method when a message with a bad
magic number is received.
+ *
+ * <br>precondition : a message with a bad magic number is received.
+ * <br>postcondition : the processing of the incoming message is skipped
and therefore no handler will be called.
+ */
+ public void testOnMessageKO_withBadMagicNumber() throws IOException
+ {
+ IMessageHandler neverCallMe = new IMessageHandler()
+ {
+
+ public void process (ManagementDecoder decoder, int sequenceNumber)
+ {
+ fail("This test shouldn't never arrive at this point...");
+ }
+
+ public void setDomainModel (DomainModel domainModel)
+ {
+ }
+ };
+
+ String opcodeForNeverCallMeHandler = "w";
+
+ _handlers.put('w',neverCallMe);
+ _listener.setHandlers(_handlers);
+
+ Message message = new ByteBufferMessage();
+ message.appendData( ("AMG"+opcodeForNeverCallMeHandler).getBytes());
+
+ _listener.onMessage(message);
+ }
+}
\ No newline at end of file
Added:
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/BaseOnlineTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/BaseOnlineTestCase.java?rev=703980&view=auto
==============================================================================
---
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/BaseOnlineTestCase.java
(added)
+++
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/BaseOnlineTestCase.java
Mon Oct 13 02:09:24 2008
@@ -0,0 +1,58 @@
+/*
+ *
+ * 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.online;
+
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import junit.framework.TestCase;
+
+/**
+ * Layer supertype for all online QMan test cases.
+ * Note that QMan must be running and up in order to run concrete subclasses
(test cases).
+ *
+ * @author AGazzarini
+ */
+public abstract class BaseOnlineTestCase extends TestCase
+{
+ protected MBeanServerConnection connection;
+
+ /**
+ * Setup fixture for this test case.
+ * Basically it estabilishes a connection to QMan using RMI JMX connector.
+ */
+ @Override
+ protected void setUp ()
+ {
+ try
+ {
+ JMXServiceURL url = new
JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
+ JMXConnector jmxc = JMXConnectorFactory.connect(url);
+ connection = jmxc.getMBeanServerConnection();
+ } catch(Exception exception)
+ {
+ fail("QMan must be running and up in order to run this test!");
+ exception.printStackTrace();
+ }
+ }
+}
Added:
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java?rev=703980&view=auto
==============================================================================
---
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java
(added)
+++
incubator/qpid/trunk/qpid/java/management/client/src/test/java/org/apache/qpid/management/online/TestMethodInvocation.java
Mon Oct 13 02:09:24 2008
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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.online;
+
+import java.io.IOException;
+import java.util.Set;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+import org.apache.qpid.management.domain.handler.impl.InvocationResult;
+
+public class TestMethodInvocation extends BaseOnlineTestCase
+{
+ /**
+ * Tests the execution of the purge() method on a queue instance.
+ *
+ * <br>precondition : QMan is up and running; managed domain model
contains at least one queue.
+ * <br>postcondition : method is invoked and result object indicates that
all was performed correctly.
+ */
+ public void testInvokePurgeOnQueue() throws Exception
+ {
+ Set<ObjectName> names = connection.queryNames(
+ new
ObjectName("Q-MAN:*,package=org.apache.qpid.broker,class=queue"),null);
+
+ for (ObjectName objectName : names)
+ {
+ InvocationResult result = (InvocationResult)
connection.invoke(objectName,"purge",new Object[]{0},new
String[]{Integer.class.getName()});
+ assertEquals(0,result.getReturnCode());
+ assertEquals("OK",result.getStatusText());
+ }
+ }
+
+ /**
+ * Tests the execution of the invocation request with an unknown method.
+ *
+ * <br>precondition : QMan is up and running; managed domain model
contains at least one queue.
+ * <br>postcondition An exception is thrown indicating that the method was
not found.
+ */
+ public void testInvokeWithUnknwonMethod() throws
MalformedObjectNameException, NullPointerException, IOException,
InstanceNotFoundException, MBeanException
+ {
+ Set<ObjectName> names = connection.queryNames(new
ObjectName("Q-MAN:*,package=org.apache.qpid.broker,class=queue"),null);
+ System.out.println(names.size());
+
+ for (ObjectName objectName : names)
+ {
+ try
+ {
+ InvocationResult result = (InvocationResult)
connection.invoke(objectName,"spurgexyzhopethatitwontexists",new
Object[]{1},new String[]{Integer.class.getName()});
+ } catch (ReflectionException expected)
+ {
+ NoSuchMethodException exception = (NoSuchMethodException)
expected.getCause();
+ assertEquals("spurge",exception.getMessage());
+ }
+ }
+ }
+}
\ No newline at end of file