Author: ritchiem
Date: Thu Oct 11 04:24:36 2007
New Revision: 583775
URL: http://svn.apache.org/viewvc?rev=583775&view=rev
Log:
QPID-635 Added a unit test and implemented the equals() method on
BlockingMethodFrameListener and SpecificMethodFrameListener.
Added:
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/client/SpecificMethodFrameListenerTest.java
(with props)
Modified:
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
Modified:
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java?rev=583775&r1=583774&r2=583775&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
(original)
+++
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/protocol/BlockingMethodFrameListener.java
Thu Oct 11 04:24:36 2007
@@ -293,4 +293,19 @@
_lock.unlock();
}
}
+
+ public boolean equals(Object o)
+ {
+
+ if (o instanceof BlockingMethodFrameListener)
+ {
+ BlockingMethodFrameListener other = (BlockingMethodFrameListener)
o;
+
+ return _channelId == other._channelId;
+ }
+
+ return false;
+ }
+
+
}
Modified:
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java?rev=583775&r1=583774&r2=583775&view=diff
==============================================================================
---
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
(original)
+++
incubator/qpid/branches/M2.1/java/client/src/main/java/org/apache/qpid/client/state/listener/SpecificMethodFrameListener.java
Thu Oct 11 04:24:36 2007
@@ -36,6 +36,22 @@
public boolean processMethod(int channelId, AMQMethodBody frame) //throws
AMQException
{
+
+ //equiv to: (frame instanceof _expectedClass)
return _expectedClass.isInstance(frame);
}
+
+ public boolean equals(Object o)
+ {
+ if (o instanceof SpecificMethodFrameListener)
+ {
+ SpecificMethodFrameListener other = (SpecificMethodFrameListener)
o;
+
+ // here we need to check if the two classes are the same.
+ return (_channelId == other._channelId) &&
(_expectedClass.equals(other._expectedClass));
+ }
+
+ return false;
+ }
+
}
Added:
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/client/SpecificMethodFrameListenerTest.java
URL:
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/client/SpecificMethodFrameListenerTest.java?rev=583775&view=auto
==============================================================================
---
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/client/SpecificMethodFrameListenerTest.java
(added)
+++
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/client/SpecificMethodFrameListenerTest.java
Thu Oct 11 04:24:36 2007
@@ -0,0 +1,71 @@
+package org.apache.qpid.framing;
+
+import junit.framework.TestCase;
+import org.apache.qpid.client.state.listener.SpecificMethodFrameListener;
+import org.apache.mina.common.ByteBuffer;
+
+/*
+*
+* 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.
+*
+*/
+
+public class SpecificMethodFrameListenerTest extends TestCase
+{
+
+ SpecificMethodFrameListener close1a = new SpecificMethodFrameListener(1,
ChannelCloseOkBody.class);
+ SpecificMethodFrameListener close1b = new SpecificMethodFrameListener(1,
ChannelCloseOkBody.class);
+ SpecificMethodFrameListener close2 = new SpecificMethodFrameListener(2,
ChannelCloseOkBody.class);
+ SpecificMethodFrameListener open1a = new SpecificMethodFrameListener(1,
ChannelOpenOkBody.class);
+ SpecificMethodFrameListener open1b = new SpecificMethodFrameListener(1,
ChannelOpenOkBody.class);
+
+ public void testEquals()
+ {
+ //Check that the the same objects are equal
+ assertEquals("ChannelCloseOKBody a should equal a", close1a, close1a);
+ assertEquals("ChannelOpenOkBody a should equal a", open1a, open1a);
+
+ //check that the same values in differnt objects are equal
+ assertEquals("ChannelCloseOKBody b should equal a", close1b, close1a);
+ assertEquals("ChannelCloseOKBody a should equal b", close1a, close1b);
+ assertEquals("ChannelOpenOkBody a should equal b", open1a, open1b);
+ assertEquals("ChannelOpenOkBody a should equal b", open1a, open1b);
+
+ //Chec that different values fail
+ //Different channels
+ assertFalse("ChannelCloseOKBody channel 1 should NOT equal channel 2",
close1a.equals(close2));
+ assertFalse("ChannelCloseOKBody channel 1 should NOT equal channel 2",
close2.equals(close1a));
+
+ //Different Bodies
+ assertFalse("ChannelCloseOKBody should not equal ChannelOpenOkBody",
close1a.equals(open1a));
+ assertFalse("ChannelOpenOkBody should not equal ChannelCloseOKBody",
open1a.equals(close1a));
+ }
+
+ public void testProcessMethod() throws AMQFrameDecodingException
+ {
+ ChannelCloseOkBody ccob = (ChannelCloseOkBody)
ChannelCloseOkBody.getFactory().newInstance((byte) 8, (byte) 0,
ByteBuffer.allocate(0), 0);
+ ChannelOpenOkBody coob = (ChannelOpenOkBody)
ChannelOpenOkBody.getFactory().newInstance((byte) 8, (byte) 0,
ByteBuffer.allocate(0), 0);
+
+ assertTrue("This SpecificMethodFrameListener should process a
ChannelCloseOkBody", close1a.processMethod(1, ccob));
+ assertFalse("This SpecificMethodFrameListener should NOT process a
ChannelOpenOkBody", close1a.processMethod(1, coob));
+
+
+
+
+ }
+}
Propchange:
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/client/SpecificMethodFrameListenerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/qpid/branches/M2.1/java/client/src/test/java/org/apache/qpid/client/SpecificMethodFrameListenerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date