You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2017/01/09 15:24:45 UTC
[09/34] qpid-proton git commit: PROTON-1385: remove proton-j from the
existing repo, it now has its own repo at:
https://git-wip-us.apache.org/repos/asf/qpid-proton-j.git
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/amqp/BinaryTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/amqp/BinaryTest.java b/proton-j/src/test/java/org/apache/qpid/proton/amqp/BinaryTest.java
deleted file mode 100644
index 4ab4766..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/amqp/BinaryTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- *
- * 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.proton.amqp;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-
-import org.junit.Test;
-
-public class BinaryTest
-{
-
- @Test
- public void testNotEqualsWithDifferentTypeObject()
- {
- Binary bin = createSteppedValueBinary(10);
-
- assertFalse("Objects should not be equal with different type", bin.equals("not-a-Binary"));
- }
-
- @Test
- public void testEqualsWithItself()
- {
- Binary bin = createSteppedValueBinary(10);
-
- assertTrue("Object should be equal to itself", bin.equals(bin));
- }
-
- @Test
- public void testEqualsWithDifferentBinaryOfSameLengthAndContent()
- {
- int length = 10;
- Binary bin1 = createSteppedValueBinary(length);
- Binary bin2 = createSteppedValueBinary(length);
-
- assertTrue("Objects should be equal", bin1.equals(bin2));
- assertTrue("Objects should be equal", bin2.equals(bin1));
- }
-
- @Test
- public void testEqualsWithDifferentLengthBinaryOfDifferentBytes()
- {
- int length1 = 10;
- Binary bin1 = createSteppedValueBinary(length1);
- Binary bin2 = createSteppedValueBinary(length1 + 1);
-
- assertFalse("Objects should not be equal", bin1.equals(bin2));
- assertFalse("Objects should not be equal", bin2.equals(bin1));
- }
-
- @Test
- public void testEqualsWithDifferentLengthBinaryOfSameByte()
- {
- Binary bin1 = createNewRepeatedValueBinary(10, (byte) 1);
- Binary bin2 = createNewRepeatedValueBinary(123, (byte) 1);
-
- assertFalse("Objects should not be equal", bin1.equals(bin2));
- assertFalse("Objects should not be equal", bin2.equals(bin1));
- }
-
- @Test
- public void testEqualsWithDifferentContentBinary()
- {
- int length = 10;
- Binary bin1 = createNewRepeatedValueBinary(length, (byte) 1);
-
- Binary bin2 = createNewRepeatedValueBinary(length, (byte) 1);
- bin2.getArray()[5] = (byte) 0;
-
- assertFalse("Objects should not be equal", bin1.equals(bin2));
- assertFalse("Objects should not be equal", bin2.equals(bin1));
- }
-
- private Binary createSteppedValueBinary(int length) {
- byte[] bytes = new byte[length];
- for (int i = 0; i < length; i++) {
- bytes[i] = (byte) (length - i);
- }
-
- return new Binary(bytes);
- }
-
- private Binary createNewRepeatedValueBinary(int length, byte repeatedByte){
- byte[] bytes = new byte[length];
- Arrays.fill(bytes, repeatedByte);
-
- return new Binary(bytes);
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/amqp/UnsignedLongTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/amqp/UnsignedLongTest.java b/proton-j/src/test/java/org/apache/qpid/proton/amqp/UnsignedLongTest.java
deleted file mode 100644
index 8429017..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/amqp/UnsignedLongTest.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- *
- * 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.proton.amqp;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.math.BigInteger;
-
-import org.junit.Test;
-
-public class UnsignedLongTest
-{
- private static final byte[] TWO_TO_64_PLUS_ONE_BYTES = new byte[] { (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1 };
- private static final byte[] TWO_TO_64_MINUS_ONE_BYTES = new byte[] {(byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1 };
-
- @Test
- public void testValueOfStringWithNegativeNumberThrowsNFE() throws Exception
- {
- try
- {
- UnsignedLong.valueOf("-1");
- fail("Expected exception was not thrown");
- }
- catch(NumberFormatException nfe)
- {
- //expected
- }
- }
-
- @Test
- public void testValueOfBigIntegerWithNegativeNumberThrowsNFE() throws Exception
- {
- try
- {
- UnsignedLong.valueOf(BigInteger.valueOf(-1L));
- fail("Expected exception was not thrown");
- }
- catch(NumberFormatException nfe)
- {
- //expected
- }
- }
-
- @Test
- public void testValuesOfStringWithinRangeSucceed() throws Exception
- {
- //check 0 (min) to confirm success
- UnsignedLong min = UnsignedLong.valueOf("0");
- assertEquals("unexpected value", 0, min.longValue());
-
- //check 2^64 -1 (max) to confirm success
- BigInteger onLimit = new BigInteger(TWO_TO_64_MINUS_ONE_BYTES);
- String onlimitString = onLimit.toString();
- UnsignedLong max = UnsignedLong.valueOf(onlimitString);
- assertEquals("unexpected value", onLimit, max.bigIntegerValue());
- }
-
- @Test
- public void testValuesOfBigIntegerWithinRangeSucceed() throws Exception
- {
- //check 0 (min) to confirm success
- UnsignedLong min = UnsignedLong.valueOf(BigInteger.ZERO);
- assertEquals("unexpected value", 0, min.longValue());
-
- //check 2^64 -1 (max) to confirm success
- BigInteger onLimit = new BigInteger(TWO_TO_64_MINUS_ONE_BYTES);
- UnsignedLong max = UnsignedLong.valueOf(onLimit);
- assertEquals("unexpected value", onLimit, max.bigIntegerValue());
-
- //check Long.MAX_VALUE to confirm success
- UnsignedLong longMax = UnsignedLong.valueOf(BigInteger.valueOf(Long.MAX_VALUE));
- assertEquals("unexpected value", Long.MAX_VALUE, longMax.longValue());
- }
-
- @Test
- public void testValueOfStringAboveMaxValueThrowsNFE() throws Exception
- {
- //2^64 + 1 (value 2 over max)
- BigInteger aboveLimit = new BigInteger(TWO_TO_64_PLUS_ONE_BYTES);
- try
- {
- UnsignedLong.valueOf(aboveLimit.toString());
- fail("Expected exception was not thrown");
- }
- catch(NumberFormatException nfe)
- {
- //expected
- }
-
- //2^64 (value 1 over max)
- aboveLimit = aboveLimit.subtract(BigInteger.ONE);
- try
- {
- UnsignedLong.valueOf(aboveLimit.toString());
- fail("Expected exception was not thrown");
- }
- catch(NumberFormatException nfe)
- {
- //expected
- }
- }
-
- @Test
- public void testValueOfBigIntegerAboveMaxValueThrowsNFE() throws Exception
- {
- //2^64 + 1 (value 2 over max)
- BigInteger aboveLimit = new BigInteger(TWO_TO_64_PLUS_ONE_BYTES);
- try
- {
- UnsignedLong.valueOf(aboveLimit);
- fail("Expected exception was not thrown");
- }
- catch(NumberFormatException nfe)
- {
- //expected
- }
-
- //2^64 (value 1 over max)
- aboveLimit = aboveLimit.subtract(BigInteger.ONE);
- try
- {
- UnsignedLong.valueOf(aboveLimit);
- fail("Expected exception was not thrown");
- }
- catch(NumberFormatException nfe)
- {
- //expected
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ErrorConditionTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ErrorConditionTest.java b/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ErrorConditionTest.java
deleted file mode 100644
index 8ebb8cb..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ErrorConditionTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.proton.amqp.transport;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-
-import java.util.Collections;
-
-import org.apache.qpid.proton.amqp.Symbol;
-import org.junit.Test;
-
-public class ErrorConditionTest
-{
- @Test
- public void testEqualityOfNewlyConstructed()
- {
- ErrorCondition new1 = new ErrorCondition();
- ErrorCondition new2 = new ErrorCondition();
- assertErrorConditionsEqual(new1, new2);
- }
-
- @Test
- public void testSameObject()
- {
- ErrorCondition error = new ErrorCondition();
- assertErrorConditionsEqual(error, error);
- }
-
- @Test
- public void testConditionEquality()
- {
- String symbolValue = "symbol";
-
- ErrorCondition same1 = new ErrorCondition();
- same1.setCondition(Symbol.getSymbol(new String(symbolValue)));
-
- ErrorCondition same2 = new ErrorCondition();
- same2.setCondition(Symbol.getSymbol(new String(symbolValue)));
-
- assertErrorConditionsEqual(same1, same2);
-
- ErrorCondition different = new ErrorCondition();
- different.setCondition(Symbol.getSymbol("other"));
-
- assertErrorConditionsNotEqual(same1, different);
- }
-
- @Test
- public void testConditionAndDescriptionEquality()
- {
- String symbolValue = "symbol";
- String descriptionValue = "description";
-
- ErrorCondition same1 = new ErrorCondition();
- same1.setCondition(Symbol.getSymbol(new String(symbolValue)));
- same1.setDescription(new String(descriptionValue));
-
- ErrorCondition same2 = new ErrorCondition();
- same2.setCondition(Symbol.getSymbol(new String(symbolValue)));
- same2.setDescription(new String(descriptionValue));
-
- assertErrorConditionsEqual(same1, same2);
-
- ErrorCondition different = new ErrorCondition();
- different.setCondition(Symbol.getSymbol(symbolValue));
- different.setDescription("other");
-
- assertErrorConditionsNotEqual(same1, different);
- }
-
- @Test
- public void testConditionDescriptionInfoEquality()
- {
- String symbolValue = "symbol";
- String descriptionValue = "description";
-
- ErrorCondition same1 = new ErrorCondition();
- same1.setCondition(Symbol.getSymbol(new String(symbolValue)));
- same1.setDescription(new String(descriptionValue));
- same1.setInfo(Collections.singletonMap(Symbol.getSymbol("key"), "value"));
-
- ErrorCondition same2 = new ErrorCondition();
- same2.setCondition(Symbol.getSymbol(new String(symbolValue)));
- same2.setDescription(new String(descriptionValue));
- same2.setInfo(Collections.singletonMap(Symbol.getSymbol("key"), "value"));
-
- assertErrorConditionsEqual(same1, same2);
-
- ErrorCondition different = new ErrorCondition();
- different.setCondition(Symbol.getSymbol(symbolValue));
- different.setDescription(new String(descriptionValue));
- different.setInfo(Collections.singletonMap(Symbol.getSymbol("other"), "value"));
-
- assertErrorConditionsNotEqual(same1, different);
- }
-
- private void assertErrorConditionsNotEqual(ErrorCondition error1, ErrorCondition error2)
- {
- assertThat(error1, is(not(error2)));
- assertThat(error2, is(not(error1)));
- }
-
- private void assertErrorConditionsEqual(ErrorCondition error1, ErrorCondition error2)
- {
- assertEquals(error1, error2);
- assertEquals(error2, error1);
- assertEquals(error1.hashCode(), error2.hashCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ReceiverSettleModeTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ReceiverSettleModeTest.java b/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ReceiverSettleModeTest.java
deleted file mode 100644
index eb8472b..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/ReceiverSettleModeTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.proton.amqp.transport;
-
-import org.apache.qpid.proton.amqp.UnsignedByte;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-public class ReceiverSettleModeTest {
-
- @Test
- public void testEquality() {
-
- ReceiverSettleMode first = ReceiverSettleMode.FIRST;
- ReceiverSettleMode second = ReceiverSettleMode.SECOND;
-
- assertEquals(first, ReceiverSettleMode.valueOf(UnsignedByte.valueOf((byte)0)));
- assertEquals(second, ReceiverSettleMode.valueOf(UnsignedByte.valueOf((byte)1)));
-
- assertEquals(first.getValue(), UnsignedByte.valueOf((byte)0));
- assertEquals(second.getValue(), UnsignedByte.valueOf((byte)1));
- }
-
- @Test
- public void testNotEquality() {
-
- ReceiverSettleMode first = ReceiverSettleMode.FIRST;
- ReceiverSettleMode second = ReceiverSettleMode.SECOND;
-
- assertNotEquals(first, ReceiverSettleMode.valueOf(UnsignedByte.valueOf((byte)1)));
- assertNotEquals(second, ReceiverSettleMode.valueOf(UnsignedByte.valueOf((byte)0)));
-
- assertNotEquals(first.getValue(), UnsignedByte.valueOf((byte)1));
- assertNotEquals(second.getValue(), UnsignedByte.valueOf((byte)0));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testIllegalArgument() {
-
- ReceiverSettleMode.valueOf(UnsignedByte.valueOf((byte)2));
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/SenderSettleModeTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/SenderSettleModeTest.java b/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/SenderSettleModeTest.java
deleted file mode 100644
index 1ef5da1..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/amqp/transport/SenderSettleModeTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.proton.amqp.transport;
-
-import org.apache.qpid.proton.amqp.UnsignedByte;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-public class SenderSettleModeTest {
-
- @Test
- public void testEquality() {
-
- SenderSettleMode unsettled = SenderSettleMode.UNSETTLED;
- SenderSettleMode settled = SenderSettleMode.SETTLED;
- SenderSettleMode mixed = SenderSettleMode.MIXED;
-
- assertEquals(unsettled, SenderSettleMode.valueOf(UnsignedByte.valueOf((byte)0)));
- assertEquals(settled, SenderSettleMode.valueOf(UnsignedByte.valueOf((byte)1)));
- assertEquals(mixed, SenderSettleMode.valueOf(UnsignedByte.valueOf((byte)2)));
-
- assertEquals(unsettled.getValue(), UnsignedByte.valueOf((byte)0));
- assertEquals(settled.getValue(), UnsignedByte.valueOf((byte)1));
- assertEquals(mixed.getValue(), UnsignedByte.valueOf((byte)2));
- }
-
- @Test
- public void testNotEquality() {
-
- SenderSettleMode unsettled = SenderSettleMode.UNSETTLED;
- SenderSettleMode settled = SenderSettleMode.SETTLED;
- SenderSettleMode mixed = SenderSettleMode.MIXED;
-
- assertNotEquals(unsettled, SenderSettleMode.valueOf(UnsignedByte.valueOf((byte)2)));
- assertNotEquals(settled, SenderSettleMode.valueOf(UnsignedByte.valueOf((byte)0)));
- assertNotEquals(mixed, SenderSettleMode.valueOf(UnsignedByte.valueOf((byte)1)));
-
- assertNotEquals(unsettled.getValue(), UnsignedByte.valueOf((byte)2));
- assertNotEquals(settled.getValue(), UnsignedByte.valueOf((byte)0));
- assertNotEquals(mixed.getValue(), UnsignedByte.valueOf((byte)1));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testIllegalArgument() {
-
- SenderSettleMode.valueOf(UnsignedByte.valueOf((byte)3));
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java
deleted file mode 100644
index 90cfe26..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/StringTypeTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- *
- * 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.proton.codec;
-
-import static org.junit.Assert.assertEquals;
-
-import java.lang.Character.UnicodeBlock;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.qpid.proton.amqp.messaging.AmqpValue;
-import org.junit.Test;
-
-/**
- * Test the encoding and decoding of {@link StringType} values.
- */
-public class StringTypeTest
-{
- private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8");
-
- private static final List<String> TEST_DATA = generateTestData();
-
- /**
- * Loop over all the chars in given {@link UnicodeBlock}s and return a
- * {@link Set <String>} containing all the possible values as their
- * {@link String} values.
- *
- * @param blocks the {@link UnicodeBlock}s to loop over
- * @return a {@link Set <String>} containing all the possible values as
- * {@link String} values
- */
- private static Set<String> getAllStringsFromUnicodeBlocks(final UnicodeBlock... blocks)
- {
- final Set<UnicodeBlock> blockSet = new HashSet<UnicodeBlock>(Arrays.asList(blocks));
- final Set<String> strings = new HashSet<String>();
- for (int codePoint = 0; codePoint <= Character.MAX_CODE_POINT; codePoint++)
- {
- if (blockSet.contains(UnicodeBlock.of(codePoint)))
- {
- final int charCount = Character.charCount(codePoint);
- final StringBuilder sb = new StringBuilder(
- charCount);
- if (charCount == 1)
- {
- sb.append(String.valueOf((char) codePoint));
- }
- else if (charCount == 2)
- {
- //TODO: use Character.highSurrogate(codePoint) and Character.lowSurrogate(codePoint) when Java 7 is baseline
- char highSurrogate = (char) ((codePoint >>> 10) + ('\uD800' - (0x010000 >>> 10)));
- char lowSurrogate = (char) ((codePoint & 0x3ff) + '\uDC00');
-
- sb.append(highSurrogate);
- sb.append(lowSurrogate);
- }
- else
- {
- throw new IllegalArgumentException("Character.charCount of "
- + charCount + " not supported.");
- }
- strings.add(sb.toString());
- }
- }
- return strings;
- }
-
-
- /**
- * Test the encoding and decoding of various complicated Unicode characters
- * which will end up as "surrogate pairs" when encoded to UTF-8
- */
- @Test
- public void calculateUTF8Length()
- {
- for (final String input : TEST_DATA)
- {
- assertEquals("Incorrect string length calculated for string '"+input+"'",input.getBytes(CHARSET_UTF8).length, StringType.calculateUTF8Length(input));
- }
- }
-
- /**
- * Test the encoding and decoding of various Unicode characters
- */
- @Test
- public void encodeDecodeStrings()
- {
- final DecoderImpl decoder = new DecoderImpl();
- final EncoderImpl encoder = new EncoderImpl(decoder);
- AMQPDefinedTypes.registerAllTypes(decoder, encoder);
- final ByteBuffer bb = ByteBuffer.allocate(16);
-
- for (final String input : TEST_DATA)
- {
- bb.clear();
- final AmqpValue inputValue = new AmqpValue(input);
- encoder.setByteBuffer(bb);
- encoder.writeObject(inputValue);
- bb.clear();
- decoder.setByteBuffer(bb);
- final AmqpValue outputValue = (AmqpValue) decoder.readObject();
- assertEquals("Failed to round trip String correctly: ", input, outputValue.getValue());
- }
- }
-
- // build up some test data with a set of suitable Unicode characters
- private static List<String> generateTestData()
- {
- return new LinkedList<String>()
- {
- private static final long serialVersionUID = 7331717267070233454L;
- {
- // non-surrogate pair blocks
- addAll(getAllStringsFromUnicodeBlocks(UnicodeBlock.BASIC_LATIN,
- UnicodeBlock.LATIN_1_SUPPLEMENT,
- UnicodeBlock.GREEK,
- UnicodeBlock.LETTERLIKE_SYMBOLS));
- // blocks with surrogate pairs
- //TODO: restore others when Java 7 is baseline
- addAll(getAllStringsFromUnicodeBlocks(UnicodeBlock.LINEAR_B_SYLLABARY,
- /*UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_PICTOGRAPHS,*/
- UnicodeBlock.MUSICAL_SYMBOLS,
- /*UnicodeBlock.EMOTICONS,*/
- /*UnicodeBlock.PLAYING_CARDS,*/
- UnicodeBlock.BOX_DRAWING,
- UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS,
- UnicodeBlock.PRIVATE_USE_AREA,
- UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_A,
- UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_B));
- // some additional combinations of characters that could cause problems to the encoder
- String[] boxDrawing = getAllStringsFromUnicodeBlocks(UnicodeBlock.BOX_DRAWING).toArray(new String[0]);
- String[] halfFullWidthForms = getAllStringsFromUnicodeBlocks(UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS).toArray(new String[0]);
- for (int i = 0; i < halfFullWidthForms.length; i++)
- {
- add(halfFullWidthForms[i] + boxDrawing[i % boxDrawing.length]);
- }
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java
deleted file mode 100644
index 45523e2..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedIntegerTypeTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *
- * 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.proton.codec;
-
-import static org.junit.Assert.*;
-
-import org.apache.qpid.proton.amqp.UnsignedInteger;
-import org.apache.qpid.proton.codec.UnsignedIntegerType.UnsignedIntegerEncoding;
-import org.junit.Test;
-
-public class UnsignedIntegerTypeTest
-{
- @Test
- public void testGetEncodingWithZero()
- {
- DecoderImpl decoder = new DecoderImpl();
- EncoderImpl encoder = new EncoderImpl(decoder);
- UnsignedIntegerType ult = new UnsignedIntegerType(encoder, decoder);
-
- //values of 0 are encoded as a specific type
- UnsignedIntegerEncoding encoding = ult.getEncoding(UnsignedInteger.valueOf(0L));
- assertEquals("incorrect encoding returned", EncodingCodes.UINT0, encoding.getEncodingCode());
- }
-
- @Test
- public void testGetEncodingWithSmallPositiveValue()
- {
- DecoderImpl decoder = new DecoderImpl();
- EncoderImpl encoder = new EncoderImpl(decoder);
- UnsignedIntegerType ult = new UnsignedIntegerType(encoder, decoder);
-
- //values between 0 and 255 are encoded as a specific 'small' type using a single byte
- UnsignedIntegerEncoding encoding = ult.getEncoding(UnsignedInteger.valueOf(1L));
- assertEquals("incorrect encoding returned", EncodingCodes.SMALLUINT, encoding.getEncodingCode());
- }
-
- @Test
- public void testGetEncodingWithTwoToThirtyOne()
- {
- DecoderImpl decoder = new DecoderImpl();
- EncoderImpl encoder = new EncoderImpl(decoder);
- UnsignedIntegerType ult = new UnsignedIntegerType(encoder, decoder);
-
- long val = Integer.MAX_VALUE + 1L;
- UnsignedIntegerEncoding encoding = ult.getEncoding(UnsignedInteger.valueOf(val));
- assertEquals("incorrect encoding returned", EncodingCodes.UINT, encoding.getEncodingCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedLongTypeTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedLongTypeTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedLongTypeTest.java
deleted file mode 100644
index bcc6ff8..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/UnsignedLongTypeTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *
- * 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.proton.codec;
-
-import static org.junit.Assert.*;
-
-import java.math.BigInteger;
-
-import org.apache.qpid.proton.amqp.UnsignedLong;
-import org.apache.qpid.proton.codec.UnsignedLongType.UnsignedLongEncoding;
-import org.junit.Test;
-
-public class UnsignedLongTypeTest
-{
- @Test
- public void testGetEncodingWithZero()
- {
- DecoderImpl decoder = new DecoderImpl();
- EncoderImpl encoder = new EncoderImpl(decoder);
- UnsignedLongType ult = new UnsignedLongType(encoder, decoder);
-
- //values of 0 are encoded as a specific type
- UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(0L));
- assertEquals("incorrect encoding returned", EncodingCodes.ULONG0, encoding.getEncodingCode());
- }
-
- @Test
- public void testGetEncodingWithSmallPositiveValue()
- {
- DecoderImpl decoder = new DecoderImpl();
- EncoderImpl encoder = new EncoderImpl(decoder);
- UnsignedLongType ult = new UnsignedLongType(encoder, decoder);
-
- //values between 0 and 255 are encoded as a specific 'small' type using a single byte
- UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(1L));
- assertEquals("incorrect encoding returned", EncodingCodes.SMALLULONG, encoding.getEncodingCode());
- }
-
- @Test
- public void testGetEncodingWithTwoToSixtyThree()
- {
- DecoderImpl decoder = new DecoderImpl();
- EncoderImpl encoder = new EncoderImpl(decoder);
- UnsignedLongType ult = new UnsignedLongType(encoder, decoder);
-
- BigInteger bigInt = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
- UnsignedLongEncoding encoding = ult.getEncoding(UnsignedLong.valueOf(bigInt));
- assertEquals("incorrect encoding returned", EncodingCodes.ULONG, encoding.getEncodingCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java
deleted file mode 100644
index 6bb3f2c..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/codec/impl/DataImplTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- *
- * 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.proton.codec.impl;
-
-import static org.junit.Assert.*;
-
-import org.apache.qpid.proton.amqp.Binary;
-import org.apache.qpid.proton.amqp.Symbol;
-import org.apache.qpid.proton.codec.Data;
-import org.junit.Test;
-
-public class DataImplTest
-{
- @Test
- public void testEncodeDecodeSymbolArrayUsingPutArray()
- {
- Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1");
- Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2");
-
- Data data1 = new DataImpl();
- data1.putArray(false, Data.DataType.SYMBOL);
- data1.enter();
- data1.putSymbol(symbol1);
- data1.putSymbol(symbol2);
- data1.exit();
-
- Binary encoded = data1.encode();
- encoded.asByteBuffer();
-
- Data data2 = new DataImpl();
- data2.decode(encoded.asByteBuffer());
-
- assertEquals("unexpected array length", 2, data2.getArray());
- assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType());
-
- Object[] array = data2.getJavaArray();
- assertNotNull("Array should not be null", array);
- assertEquals("Expected a Symbol array", Symbol[].class, array.getClass());
- assertEquals("unexpected array length", 2, array.length);
- assertEquals("unexpected value", symbol1, array[0]);
- assertEquals("unexpected value", symbol2, array[1]);
- }
-
- @Test
- public void testEncodeDecodeSymbolArrayUsingPutObject()
- {
- Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1");
- Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2");
- Symbol[] input = new Symbol[]{symbol1, symbol2};
-
- Data data1 = new DataImpl();
- data1.putObject(input);
-
- Binary encoded = data1.encode();
- encoded.asByteBuffer();
-
- Data data2 = new DataImpl();
- data2.decode(encoded.asByteBuffer());
-
- assertEquals("unexpected array length", 2, data2.getArray());
- assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType());
-
- Object[] array = data2.getJavaArray();
- assertArrayEquals("Array not as expected", input, array);
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java
deleted file mode 100644
index a36f9cb..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventDelegationTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package org.apache.qpid.proton.engine;
-
-import static org.junit.Assert.*;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-import org.apache.qpid.proton.reactor.Reactor;
-import org.junit.Test;
-
-public class EventDelegationTest {
-
- private ArrayList<String> trace = new ArrayList<String>();
-
- class ExecutionFlowTracer extends BaseHandler {
- protected String name;
-
- ExecutionFlowTracer(String name) {
- this.name = name;
- }
-
- @Override
- public void onReactorInit(Event e) {
- trace.add(name);
- }
- }
-
- class DelegatingFlowTracer extends ExecutionFlowTracer {
- public DelegatingFlowTracer(String name) {
- super(name);
- }
-
- @Override
- public void onReactorInit(Event e) {
- trace.add("(" + name);
- e.delegate();
- trace.add(name + ")");
- }
- }
-
- Handler assemble(Handler outer, Handler...inner) {
- for(Handler h : inner) {
- outer.add(h);
- }
- return outer;
- }
-
- @Test
- public void testImplicitDelegate() throws IOException {
- Handler h =
- assemble(
- new ExecutionFlowTracer("A"),
- assemble(
- new ExecutionFlowTracer("A.A"),
- new ExecutionFlowTracer("A.A.A"),
- new ExecutionFlowTracer("A.A.B")
- ),
- assemble(
- new ExecutionFlowTracer("A.B")
- )
- );
- Reactor r = Reactor.Factory.create();
- r.getHandler().add(h);
- r.run();
- assertArrayEquals(new String[]{"A", "A.A", "A.A.A", "A.A.B", "A.B"}, trace.toArray());
- }
-
- @Test
- public void testExplicitDelegate() throws IOException {
- Handler h =
- assemble(
- new ExecutionFlowTracer("A"),
- assemble(
- new DelegatingFlowTracer("A.A"),
- new ExecutionFlowTracer("A.A.A"),
- new ExecutionFlowTracer("A.A.B")
- ),
- assemble(
- new ExecutionFlowTracer("A.B")
- )
- );
- Reactor r = Reactor.Factory.create();
- r.getHandler().add(h);
- r.run();
- assertArrayEquals(new String[]{"A", "(A.A", "A.A.A", "A.A.B", "A.A)", "A.B"}, trace.toArray());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
deleted file mode 100644
index 81c7470..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/EventExtensibilityTest.java
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- *
- * 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.proton.engine;
-
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-import org.apache.qpid.proton.engine.Event.Type;
-import org.apache.qpid.proton.engine.EventExtensibilityTest.ExtraEvent.ExtraTypes;
-import org.apache.qpid.proton.reactor.Reactor;
-import org.apache.qpid.proton.reactor.Selectable;
-import org.apache.qpid.proton.reactor.Task;
-import org.junit.Test;
-
-public class EventExtensibilityTest extends TestCase {
-
- // //////////////
- // / Extra package public API classes
- // //////////////
-
- /**
- * Sample additional information that gets generated and passed around with
- * the extension events. The information is stored inside
- * {@link Event#attachments()} see {@link ExtraEventImpl#getExtraInfo()}
- */
- public static class ExtraInfo {
- public int foo;
- }
-
- /**
- * Additional events generated by this extension.
- *
- */
- public interface ExtraEvent extends Event {
- /**
- * Enum is a convenient mechanism for defining new event types
- */
- public enum ExtraTypes implements EventType {
- FOO,
- BAR,
- NOT_A_EXTRA_EVENT {
- @Override public boolean isValid() { return false; }
- };
-
- @Override
- public boolean isValid() {
- return true;
- }
- }
-
- /**
- * typesafe access to event type generated by this extension useful for
- * handling in switch statements
- *
- * @return one of enum values. When invoked on an Event that is not an
- * ExtraEvent the return value shall be
- */
- ExtraTypes getExtraEventType();
-
- /**
- * typesafe access to extra information attached to additional events
- *
- * @return ExtraInfo stored in the event attachment
- */
- ExtraInfo getExtraInfo();
- }
-
- /**
- * New handler methods for handling the extended event types. These methods
- * can take {@link ExtraEvent} as a parameter to get typesafe access to
- * {@link ExtraInfo}
- *
- * The interface needs to extend the {@link Handler} interface.
- */
- public interface ExtraHandler extends Handler {
- void onFoo(ExtraEvent e);
-
- void onBar(ExtraEvent e);
- }
-
- /**
- * Implementation of the default base class for ExtraHandler. All events
- * should be forwarded to the {@link Handler#onUnhandled(Event)} method
- */
- public static class ExtraBaseHandler extends BaseHandler implements ExtraHandler {
-
- @Override
- public void onFoo(ExtraEvent e) {
- this.onUnhandled(e);
- }
-
- @Override
- public void onBar(ExtraEvent e) {
- this.onUnhandled(e);
- }
-
- @Override
- public void handle(Event e) {
- EventType type = e.getEventType();
- if (type instanceof ExtraEvent.ExtraTypes) {
- final ExtraEvent event;
- if (e instanceof ExtraEvent) {
- event = (ExtraEvent)e;
- } else {
- event = new ExtraEventImpl(e);
- }
- switch((ExtraEvent.ExtraTypes)type) {
- case BAR:
- onBar(event);
- break;
- case FOO:
- onFoo(event);
- break;
- case NOT_A_EXTRA_EVENT:
- super.handle(e);
- break;
- }
- } else {
- super.handle(e);
- }
- }
-
- }
-
- // //////////////
- // / Extra package implementation classes
- // //////////////
-
-
- /**
- * Typesafe access to ExtraInfo attached to event
- *
- */
- public static class ExtraEventImpl implements ExtraEvent {
- /**
- * making this accessor public allows for easy binding to the scripting language
- */
- public static final ExtendableAccessor<Event, ExtraInfo> extraInfoAccessor = new ExtendableAccessor<>(ExtraInfo.class);
-
- private Event impl;
-
- public ExtraEventImpl(Event impl) {
- this.impl = impl;
- }
-
- @Override
- public ExtraTypes getExtraEventType() {
- EventType type = impl.getEventType();
- if (type instanceof ExtraTypes)
- return (ExtraTypes) type;
- else
- return ExtraTypes.NOT_A_EXTRA_EVENT;
- }
-
- @Override
- public ExtraInfo getExtraInfo() {
- return extraInfoAccessor.get(impl);
- }
-
- // ---- delegate methods for the Event
-
- @Override
- public Record attachments() {
- return impl.attachments();
- }
-
- @Override
- public EventType getEventType() {
- return impl.getEventType();
- }
-
- @Override
- public Type getType() {
- return impl.getType();
- }
-
- @Override
- public Object getContext() {
- return impl.getContext();
- }
-
- @Override
- public Handler getRootHandler() {
- return impl.getRootHandler();
- }
-
- @Override
- public void dispatch(Handler handler) throws HandlerException {
- impl.dispatch(handler);
- }
-
- @Override
- public void redispatch(EventType as_type, Handler handler) throws HandlerException {
- impl.redispatch(as_type, handler);
- }
- @Override
- public Connection getConnection() {
- return impl.getConnection();
- }
-
- @Override
- public Session getSession() {
- return impl.getSession();
- }
-
- @Override
- public Link getLink() {
- return impl.getLink();
- }
-
- @Override
- public Sender getSender() {
- return impl.getSender();
- }
-
- @Override
- public Receiver getReceiver() {
- return impl.getReceiver();
- }
-
- @Override
- public Delivery getDelivery() {
- return impl.getDelivery();
- }
-
- @Override
- public Transport getTransport() {
- return impl.getTransport();
- }
-
- @Override
- public Reactor getReactor() {
- return impl.getReactor();
- }
-
- @Override
- public Selectable getSelectable() {
- return impl.getSelectable();
- }
-
- @Override
- public Task getTask() {
- return impl.getTask();
- }
-
- @Override
- public Event copy() {
- return new ExtraEventImpl(impl.copy());
- }
-
- @Override
- public void delegate() throws HandlerException {
- impl.delegate();
- }
- }
-
- public class ExtendedTestEventGenerator extends BaseHandler {
- @Override
- public void onReactorInit(Event e) {
- ExtraInfo extra = new ExtraInfo();
- extra.foo = 1234;
- ExtraEventImpl.extraInfoAccessor.set(e, extra);
- e.redispatch(ExtraEvent.ExtraTypes.FOO, this);
- }
- }
-
- public class ExtendedTestHandler extends ExtraBaseHandler {
- public boolean didFoo = false;
- @Override
- public void onFoo(ExtraEvent e) {
- assertEquals(ExtraEvent.ExtraTypes.FOO, e.getEventType());
- assertEquals(ExtraEvent.ExtraTypes.FOO, e.getExtraEventType());
- assertEquals(Event.Type.NON_CORE_EVENT, e.getType());
- assertNotNull(e.getExtraInfo());
- assertEquals(1234, e.getExtraInfo().foo);
- didFoo = true;
- }
- }
-
- public class FooUnawareTestHandler extends BaseHandler {
- public boolean seenFoo = false;
- @Override
- public void onUnhandled(Event e) {
- if (e.getEventType() == ExtraTypes.FOO) {
- seenFoo = true;
- }
- }
- }
-
- @Test
- public void testExtendedType() throws IOException {
- Reactor r = Reactor.Factory.create();
- ExtendedTestEventGenerator gen = new ExtendedTestEventGenerator();
- BaseHandler empty = new BaseHandler();
- ExtendedTestHandler extra = new ExtendedTestHandler();
- FooUnawareTestHandler unaware = new FooUnawareTestHandler();
- gen.add(empty);
- empty.add(extra);
- extra.add(unaware);
- r.setGlobalHandler(gen);
- r.run();
- assertTrue(extra.didFoo);
- assertTrue(unaware.seenFoo);
- }
-
- @Test
- public void test() {
- Event.Type t = Type.NON_CORE_EVENT;
- switch (extracted(t)) {
- case CONNECTION_BOUND:
- fail();
- case CONNECTION_FINAL:
- fail();
- case CONNECTION_INIT:
- fail();
- case CONNECTION_LOCAL_CLOSE:
- fail();
- case CONNECTION_LOCAL_OPEN:
- fail();
- case CONNECTION_REMOTE_CLOSE:
- fail();
- case CONNECTION_REMOTE_OPEN:
- fail();
- case CONNECTION_UNBOUND:
- fail();
- case DELIVERY:
- fail();
- case LINK_FINAL:
- fail();
- case LINK_FLOW:
- fail();
- case LINK_INIT:
- fail();
- case LINK_LOCAL_CLOSE:
- fail();
- case LINK_LOCAL_DETACH:
- fail();
- case LINK_LOCAL_OPEN:
- fail();
- case LINK_REMOTE_CLOSE:
- fail();
- case LINK_REMOTE_DETACH:
- fail();
- case LINK_REMOTE_OPEN:
- fail();
- case REACTOR_FINAL:
- fail();
- case REACTOR_INIT:
- fail();
- case REACTOR_QUIESCED:
- fail();
- case SELECTABLE_ERROR:
- fail();
- case SELECTABLE_EXPIRED:
- fail();
- case SELECTABLE_FINAL:
- fail();
- case SELECTABLE_INIT:
- fail();
- case SELECTABLE_READABLE:
- fail();
- case SELECTABLE_UPDATED:
- fail();
- case SELECTABLE_WRITABLE:
- fail();
- case SESSION_FINAL:
- fail();
- case SESSION_INIT:
- fail();
- case SESSION_LOCAL_CLOSE:
- fail();
- case SESSION_LOCAL_OPEN:
- fail();
- case SESSION_REMOTE_CLOSE:
- fail();
- case SESSION_REMOTE_OPEN:
- fail();
- case TIMER_TASK:
- fail();
- case TRANSPORT:
- fail();
- case TRANSPORT_CLOSED:
- fail();
- case TRANSPORT_ERROR:
- fail();
- case TRANSPORT_HEAD_CLOSED:
- fail();
- case TRANSPORT_TAIL_CLOSED:
- fail();
- case NON_CORE_EVENT:
- break;
- }
- }
-
- private Type extracted(Event.Type t) {
- return t;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/AmqpFramer.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/AmqpFramer.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/AmqpFramer.java
deleted file mode 100644
index 8195ccb..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/AmqpFramer.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.proton.engine.impl;
-
-import static org.junit.Assert.assertEquals;
-
-import java.nio.ByteBuffer;
-
-import org.apache.qpid.proton.amqp.security.SaslFrameBody;
-import org.apache.qpid.proton.amqp.transport.FrameBody;
-import org.apache.qpid.proton.codec.AMQPDefinedTypes;
-import org.apache.qpid.proton.codec.DecoderImpl;
-import org.apache.qpid.proton.codec.EncoderImpl;
-import org.apache.qpid.proton.codec.WritableBuffer;
-
-/**
- * Generates frames as per section 2.3.1 of the AMQP spec
- */
-public class AmqpFramer
-{
- // My test data is generated by the decoder and encoder from proton-j
- // although at run-time the Engine internally uses its own implementation.
-
- private DecoderImpl _decoder = new DecoderImpl();
- private EncoderImpl _encoder = new EncoderImpl(_decoder);
-
- public AmqpFramer()
- {
- AMQPDefinedTypes.registerAllTypes(_decoder, _encoder);
- }
-
- public byte[] createEmptyFrame(int channel)
- {
- byte[] emptyFrame = generateFrame(channel, null);
- return emptyFrame;
- }
-
- public byte[] generateFrame(int channel, FrameBody frameBody)
- {
- byte[] emptyExtendedHeader = new byte[] {};
- return generateFrame(channel, emptyExtendedHeader, frameBody);
- }
-
- public byte[] generateFrame(int channel, byte[] extendedHeader, FrameBody frameBody)
- {
- return generateFrame(channel, extendedHeader, frameBody, (byte)0);
- }
-
- public byte[] generateSaslFrame(int channel, byte[] extendedHeader, SaslFrameBody frameBody)
- {
- return generateFrame(channel, extendedHeader, frameBody, (byte)1);
- }
-
- /**
- * @param amqpFrameType indicates either AMQP or SASL
- * @param frameBody is currently expected to be a {@link FrameBody} or a {@link SaslFrameBody}
- */
- public byte[] generateFrame(int channel, byte[] extendedHeader, Object frameBody, byte amqpFrameType)
- {
- assertEquals("Extended header must be multiple of 4 bytes", 0, extendedHeader.length % 4);
- int numberOfExtendedHeaderFourByteWords = extendedHeader.length / 4;
-
- ByteBuffer buffer = ByteBuffer.allocate(1024);
-
- buffer.position(8); // leave hole for frame header
- _encoder.setByteBuffer(new WritableBuffer.ByteBufferWrapper(buffer));
-
- // write extended header - maybe empty
- buffer.put(extendedHeader);
- // write frame body
- if (frameBody != null)
- {
- _encoder.writeObject(frameBody);
- }
-
- int frameSize = buffer.position();
- int framePreambleSizeInFourByteWords = 2;
- byte dataOffsetFourByteWords = (byte)(framePreambleSizeInFourByteWords + numberOfExtendedHeaderFourByteWords);
- buffer.rewind();
- buffer.putInt(frameSize);
- buffer.put(dataOffsetFourByteWords);
- buffer.put(amqpFrameType);
- buffer.putShort((short)channel);
-
- byte[] target = new byte[frameSize];
-
- buffer.rewind();
- buffer.get(target, 0, frameSize);
- return target;
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java
deleted file mode 100644
index a063265..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/DeliveryImplTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.proton.engine.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-
-import org.apache.qpid.proton.engine.Record;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class DeliveryImplTest
-{
- @Test
- public void testDefaultMessageFormat() throws Exception
- {
- DeliveryImpl delivery = new DeliveryImpl(null, Mockito.mock(LinkImpl.class), null);
- assertEquals("Unexpected value", 0L, DeliveryImpl.DEFAULT_MESSAGE_FORMAT);
- assertEquals("Unexpected message format", DeliveryImpl.DEFAULT_MESSAGE_FORMAT, delivery.getMessageFormat());
- }
-
- @Test
- public void testSetGetMessageFormat() throws Exception
- {
- DeliveryImpl delivery = new DeliveryImpl(null, Mockito.mock(LinkImpl.class), null);
-
- // lowest value and default
- int newFormat = 0;
- delivery.setMessageFormat(newFormat);
- assertEquals("Unexpected message format", newFormat, delivery.getMessageFormat());
-
- newFormat = 123456;
- delivery.setMessageFormat(newFormat);
- assertEquals("Unexpected message format", newFormat, delivery.getMessageFormat());
-
- // Highest value
- newFormat = (1 << 32) - 1;
- delivery.setMessageFormat(newFormat);
- assertEquals("Unexpected message format", newFormat, delivery.getMessageFormat());
- }
-
- @Test
- public void testAttachmentsNonNull() throws Exception
- {
- DeliveryImpl delivery = new DeliveryImpl(null, Mockito.mock(LinkImpl.class), null);
-
- assertNotNull("Expected attachments to be non-null", delivery.attachments());
- }
-
- @Test
- public void testAttachmentsReturnsSameRecordOnSuccessiveCalls() throws Exception
- {
- DeliveryImpl delivery = new DeliveryImpl(null, Mockito.mock(LinkImpl.class), null);
-
- Record attachments = delivery.attachments();
- Record attachments2 = delivery.attachments();
- assertSame("Expected to get the same attachments", attachments, attachments2);
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EndpointImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EndpointImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EndpointImplTest.java
deleted file mode 100644
index b83f214..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EndpointImplTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 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.proton.engine.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class EndpointImplTest
-{
- @Test
- public void testRepeatOpenDoesNotModifyEndpoint()
- {
- ConnectionImpl mockConnection = Mockito.mock(ConnectionImpl.class);
- MockEndpointImpl endpoint = new MockEndpointImpl(mockConnection);
-
- // Check starting state
- assertFalse("Should not be modified", endpoint.isModified());
- assertEquals("Unexpected localOpen call count", 0, endpoint.getLocalOpenCallCount());
- Mockito.verify(mockConnection, Mockito.times(0)).addModified(Mockito.any(EndpointImpl.class));
-
- endpoint.open();
-
- // Check endpoint was modified
- assertTrue("Should be modified", endpoint.isModified());
- assertEquals("Unexpected localOpen call count", 1, endpoint.getLocalOpenCallCount());
- Mockito.verify(mockConnection, Mockito.times(1)).addModified(Mockito.any(EndpointImpl.class));
-
- // Clear the modified state, open again, verify no change
- endpoint.clearModified();
- assertFalse("Should no longer be modified", endpoint.isModified());
-
- endpoint.open();
-
- assertFalse("Should not be modified", endpoint.isModified());
- assertEquals("Unexpected localOpen call count", 1, endpoint.getLocalOpenCallCount());
- Mockito.verify(mockConnection, Mockito.times(1)).addModified(Mockito.any(EndpointImpl.class));
- }
-
- @Test
- public void testRepeatCloseDoesNotModifyEndpoint()
- {
- ConnectionImpl mockConnection = Mockito.mock(ConnectionImpl.class);
- MockEndpointImpl endpoint = new MockEndpointImpl(mockConnection);
-
- // Open endpoint, clear the modified state, verify current state
- endpoint.open();
- endpoint.clearModified();
- assertFalse("Should no longer be modified", endpoint.isModified());
- assertEquals("Unexpected localClose call count", 0, endpoint.getLocalCloseCallCount());
- Mockito.verify(mockConnection, Mockito.times(1)).addModified(Mockito.any(EndpointImpl.class));
-
- // Now close, verify changes
- endpoint.close();
-
- // Check endpoint was modified
- assertTrue("Should be modified", endpoint.isModified());
- assertEquals("Unexpected localClose call count", 1, endpoint.getLocalCloseCallCount());
- Mockito.verify(mockConnection, Mockito.times(2)).addModified(Mockito.any(EndpointImpl.class));
-
- // Clear the modified state, close again, verify no change
- endpoint.clearModified();
- assertFalse("Should no longer be modified", endpoint.isModified());
-
- endpoint.close();
-
- assertFalse("Should not be modified", endpoint.isModified());
- assertEquals("Unexpected localClose call count", 1, endpoint.getLocalCloseCallCount());
- Mockito.verify(mockConnection, Mockito.times(2)).addModified(Mockito.any(EndpointImpl.class));
- }
-
- private class MockEndpointImpl extends EndpointImpl
- {
- private int localOpenCallCount;
- private int localCloseCallCount;
- private ConnectionImpl connectionImpl;
- public MockEndpointImpl(ConnectionImpl connectionImpl)
- {
- this.connectionImpl = connectionImpl;
- }
-
- @Override
- void localOpen()
- {
- localOpenCallCount++;
- }
-
- @Override
- void localClose()
- {
- localCloseCallCount++;
- }
-
- @Override
- protected ConnectionImpl getConnectionImpl()
- {
- return connectionImpl;
- }
-
- @Override
- void doFree() { }
-
- @Override
- void postFinal() { }
-
- public int getLocalOpenCallCount()
- {
- return localOpenCallCount;
- }
-
- public int getLocalCloseCallCount()
- {
- return localCloseCallCount;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EventImplTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EventImplTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EventImplTest.java
deleted file mode 100644
index e46f45c..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/EventImplTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- *
- * 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.proton.engine.impl;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-
-import org.apache.qpid.proton.engine.Connection;
-import org.apache.qpid.proton.engine.Delivery;
-import org.apache.qpid.proton.engine.Event;
-import org.apache.qpid.proton.engine.EventType;
-import org.apache.qpid.proton.engine.Link;
-import org.apache.qpid.proton.engine.Sender;
-import org.apache.qpid.proton.engine.Session;
-import org.apache.qpid.proton.engine.Transport;
-import org.junit.Test;
-
-public class EventImplTest
-{
- @Test
- public void testGetTransportWithConnectionContext()
- {
- Transport transport = Transport.Factory.create();
- Connection connection = Connection.Factory.create();
- transport.bind(connection);
-
- EventImpl event = createEvent(connection, Event.Type.CONNECTION_BOUND);
-
- assertNotNull("No transport returned", event.getTransport());
- assertSame("Incorrect transport returned", transport, event.getTransport());
- }
-
- @Test
- public void testGetTransportWithTransportContext()
- {
- Transport transport = Transport.Factory.create();
- Connection connection = Connection.Factory.create();
- transport.bind(connection);
-
- EventImpl event = createEvent(transport, Event.Type.TRANSPORT);
-
- assertNotNull("No transport returned", event.getTransport());
- assertSame("Incorrect transport returned", transport, event.getTransport());
- }
-
- @Test
- public void testGetTransportWithSessionContext()
- {
- Transport transport = Transport.Factory.create();
- Connection connection = Connection.Factory.create();
- transport.bind(connection);
-
- Session session = connection.session();
-
- EventImpl event = createEvent(session, Event.Type.SESSION_INIT);
-
- assertNotNull("No transport returned", event.getTransport());
- assertSame("Incorrect transport returned", transport, event.getTransport());
- }
-
- @Test
- public void testGetTransportWithLinkContext()
- {
- Transport transport = Transport.Factory.create();
- Connection connection = Connection.Factory.create();
- transport.bind(connection);
-
- Session session = connection.session();
- Link link = session.receiver("myReceiver");
-
- EventImpl event = createEvent(link, Event.Type.LINK_INIT);
-
- assertNotNull("No transport returned", event.getTransport());
- assertSame("Incorrect transport returned", transport, event.getTransport());
- }
-
- @Test
- public void testGetTransportWithDeliveryContext()
- {
- Transport transport = Transport.Factory.create();
- Connection connection = Connection.Factory.create();
- transport.bind(connection);
-
- Session session = connection.session();
- Sender sender = session.sender("mySender");
-
- Delivery delivery = sender.delivery("tag".getBytes());
-
- EventImpl event = createEvent(delivery, Event.Type.DELIVERY);
-
- assertNotNull("No transport returned", event.getTransport());
- assertSame("Incorrect transport returned", transport, event.getTransport());
- }
-
- EventImpl createEvent(Object context, EventType type)
- {
- EventImpl event = new EventImpl();
- event.init(type, context);
- return event;
- }
-}
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/ccdcf329/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/FrameParserTest.java
----------------------------------------------------------------------
diff --git a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/FrameParserTest.java b/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/FrameParserTest.java
deleted file mode 100644
index be66b3b..0000000
--- a/proton-j/src/test/java/org/apache/qpid/proton/engine/impl/FrameParserTest.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
- * 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.proton.engine.impl;
-
-import static org.apache.qpid.proton.engine.Transport.DEFAULT_MAX_FRAME_SIZE;
-import static org.apache.qpid.proton.engine.impl.AmqpHeader.HEADER;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.nio.ByteBuffer;
-
-import org.apache.qpid.proton.amqp.transport.Close;
-import org.apache.qpid.proton.amqp.transport.FrameBody;
-import org.apache.qpid.proton.amqp.transport.Open;
-import org.apache.qpid.proton.codec.AMQPDefinedTypes;
-import org.apache.qpid.proton.codec.DecoderImpl;
-import org.apache.qpid.proton.codec.EncoderImpl;
-import org.apache.qpid.proton.engine.Transport;
-import org.apache.qpid.proton.engine.TransportException;
-import org.apache.qpid.proton.framing.TransportFrame;
-import org.hamcrest.Description;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.mockito.InOrder;
-
-// TODO test a frame with a payload (potentially followed by another frame)
-public class FrameParserTest
-{
- private FrameHandler _mockFrameHandler = mock(FrameHandler.class);
- private DecoderImpl _decoder = new DecoderImpl();
- private EncoderImpl _encoder = new EncoderImpl(_decoder);
- private final FrameParser _frameParser = new FrameParser(_mockFrameHandler, _decoder, DEFAULT_MAX_FRAME_SIZE);
-
- private final AmqpFramer _amqpFramer = new AmqpFramer();
-
- @Before
- public void setUp()
- {
- AMQPDefinedTypes.registerAllTypes(_decoder, _encoder);
-
- when(_mockFrameHandler.isHandlingFrames()).thenReturn(true);
- }
-
- @Test
- public void testInputOfInvalidProtocolHeader_causesErrorAndRefusesFurtherInput()
- {
- ByteBuffer buffer = _frameParser.tail();
- buffer.put("hello".getBytes());
- _frameParser.process();
- assertEquals(_frameParser.capacity(), Transport.END_OF_STREAM);
- }
-
- @Test
- public void testInputOfValidProtocolHeader()
- {
- ByteBuffer buffer = _frameParser.tail();
- buffer.put(HEADER);
- _frameParser.process();
-
- assertNotNull(_frameParser.tail());
- }
-
- @Test
- public void testInputOfValidProtocolHeaderInMultipleChunks()
- {
- {
- ByteBuffer buffer = _frameParser.tail();
- buffer.put(HEADER, 0, 2);
- _frameParser.process();
- }
-
- {
- ByteBuffer buffer = _frameParser.tail();
- buffer.put(HEADER, 2, HEADER.length - 2);
- _frameParser.process();
- }
-
- assertNotNull(_frameParser.tail());
- }
-
- @Test
- public void testInputOfValidFrame_invokesFrameTransportCallback()
- {
- sendHeader();
-
- // now send an open frame
- ByteBuffer buffer = _frameParser.tail();
-
- Open openFrame = generateOpenFrame();
- int channel = 0;
- byte[] frame = _amqpFramer.generateFrame(channel, openFrame);
- buffer.put(frame);
-
- _frameParser.process();
- verify(_mockFrameHandler).handleFrame(frameMatching(channel, openFrame));
- }
-
- @Test
- public void testInputOfFrameInMultipleChunks_invokesFrameTransportCallback()
- {
- sendHeader();
-
- Open openFrame = generateOpenFrame();
- int channel = 0;
- byte[] frame = _amqpFramer.generateFrame(channel, openFrame);
- int lengthOfFirstChunk = 2;
- int lengthOfSecondChunk = (frame.length - lengthOfFirstChunk)/2;
- int lengthOfThirdChunk = frame.length - lengthOfFirstChunk - lengthOfSecondChunk;
-
- // send the first chunk
- {
- ByteBuffer buffer = _frameParser.tail();
-
- buffer.put(frame, 0, lengthOfFirstChunk);
-
- _frameParser.process();
-
- verify(_mockFrameHandler, never()).handleFrame(any(TransportFrame.class));
- }
-
- // send the second chunk
- {
- ByteBuffer buffer = _frameParser.tail();
-
- int secondChunkOffset = lengthOfFirstChunk;
- buffer.put(frame, secondChunkOffset, lengthOfSecondChunk);
-
- _frameParser.process();
- verify(_mockFrameHandler, never()).handleFrame(any(TransportFrame.class));
- }
-
- // send the third and final chunk
- {
- ByteBuffer buffer = _frameParser.tail();
-
- int thirdChunkOffset = lengthOfFirstChunk + lengthOfSecondChunk;
- buffer.put(frame, thirdChunkOffset, lengthOfThirdChunk);
-
- _frameParser.process();
- verify(_mockFrameHandler).handleFrame(frameMatching(channel, openFrame));
- }
- }
-
- @Test
- public void testInputOfTwoFrames_invokesFrameTransportTwice()
- {
- sendHeader();
-
- int channel = 0;
- Open openFrame = generateOpenFrame();
- byte[] openFrameBytes = _amqpFramer.generateFrame(channel, openFrame);
-
- Close closeFrame = generateCloseFrame();
- byte[] closeFrameBytes = _amqpFramer.generateFrame(channel, closeFrame);
-
- _frameParser.tail()
- .put(openFrameBytes)
- .put(closeFrameBytes);
-
- _frameParser.process();
-
- InOrder inOrder = inOrder(_mockFrameHandler);
- inOrder.verify(_mockFrameHandler).handleFrame(frameMatching(channel, openFrame));
- inOrder.verify(_mockFrameHandler).handleFrame(frameMatching(channel, closeFrame));
- }
-
- @Test
- public void testFrameTransportTemporarilyRefusesOpenFrame()
- {
- when(_mockFrameHandler.isHandlingFrames()).thenReturn(false);
-
- sendHeader();
-
- // now send an open frame
- int channel = 0;
- Open openFrame = generateOpenFrame();
- {
- ByteBuffer buffer = _frameParser.tail();
-
- byte[] frame = _amqpFramer.generateFrame(channel, openFrame);
- buffer.put(frame);
-
- _frameParser.process();
- }
-
- verify(_mockFrameHandler, never()).handleFrame(any(TransportFrame.class));
-
- when(_mockFrameHandler.isHandlingFrames()).thenReturn(true);
-
- // now ensure that the held frame gets sent on second input
- Close closeFrame = generateCloseFrame();
- {
- ByteBuffer buffer = _frameParser.tail();
-
- byte[] frame = _amqpFramer.generateFrame(channel, closeFrame);
- buffer.put(frame);
-
- _frameParser.process();
- }
-
- InOrder inOrder = inOrder(_mockFrameHandler);
- inOrder.verify(_mockFrameHandler).handleFrame(frameMatching(channel, openFrame));
- inOrder.verify(_mockFrameHandler).handleFrame(frameMatching(channel, closeFrame));
- }
-
- @Test
- public void testFrameTransportTemporarilyRefusesOpenAndCloseFrame()
- {
- when(_mockFrameHandler.isHandlingFrames()).thenReturn(false);
-
- sendHeader();
-
- // now send an open frame
- int channel = 0;
- Open openFrame = generateOpenFrame();
- {
- ByteBuffer buffer = _frameParser.tail();
-
- byte[] frame = _amqpFramer.generateFrame(channel, openFrame);
- buffer.put(frame);
-
- _frameParser.process();
- }
- verify(_mockFrameHandler, never()).handleFrame(any(TransportFrame.class));
-
- // now send a close frame
- Close closeFrame = generateCloseFrame();
- {
- ByteBuffer buffer = _frameParser.tail();
-
- byte[] frame = _amqpFramer.generateFrame(channel, closeFrame);
- buffer.put(frame);
-
- _frameParser.process();
- }
- verify(_mockFrameHandler, never()).handleFrame(any(TransportFrame.class));
-
- when(_mockFrameHandler.isHandlingFrames()).thenReturn(true);
-
- _frameParser.flush();
-
- InOrder inOrder = inOrder(_mockFrameHandler);
- inOrder.verify(_mockFrameHandler).handleFrame(frameMatching(channel, openFrame));
- inOrder.verify(_mockFrameHandler).handleFrame(frameMatching(channel, closeFrame));
- }
-
- private void sendHeader() throws TransportException
- {
- ByteBuffer buffer = _frameParser.tail();
- buffer.put(HEADER);
- _frameParser.process();
- }
-
- private Open generateOpenFrame()
- {
- Open open = new Open();
- open.setContainerId("containerid");
- return open;
- }
-
- private Close generateCloseFrame()
- {
- Close close = new Close();
- return close;
- }
-
- private TransportFrame frameMatching(int channel, FrameBody frameBody)
- {
- return argThat(new TransportFrameMatcher(channel, frameBody));
- }
-
- private class TransportFrameMatcher extends ArgumentMatcher<TransportFrame>
- {
- private final TransportFrame _expectedTransportFrame;
-
- TransportFrameMatcher(int expectedChannel, FrameBody expectedFrameBody)
- {
- _expectedTransportFrame = new TransportFrame(expectedChannel, expectedFrameBody, null);
- }
-
- @Override
- public boolean matches(Object transportFrameObj)
- {
- if(transportFrameObj == null)
- {
- return false;
- }
-
- TransportFrame transportFrame = (TransportFrame)transportFrameObj;
- FrameBody actualFrame = transportFrame.getBody();
-
- int _expectedChannel = _expectedTransportFrame.getChannel();
- FrameBody expectedFrame = _expectedTransportFrame.getBody();
-
- return _expectedChannel == transportFrame.getChannel()
- && expectedFrame.getClass().equals(actualFrame.getClass());
- }
-
- @Override
- public void describeTo(Description description)
- {
- super.describeTo(description);
- description.appendText("Expected: " + _expectedTransportFrame);
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org