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 2013/02/25 23:29:00 UTC
svn commit: r1449938 - in /qpid/proton/trunk:
proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java
proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java
tests/java/org/apache/qpid/proton/InteropTest.java
Author: aconway
Date: Mon Feb 25 22:29:00 2013
New Revision: 1449938
URL: http://svn.apache.org/r1449938
Log:
PROTON-215: Java InteropTest test for primitve types.
Added Java test coverage for just the primitive types, more types coming soon.
Added:
qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java (with props)
qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java (with props)
qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java (with props)
Added: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java?rev=1449938&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java (added)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java Mon Feb 25 22:29:00 2013
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import org.apache.qpid.proton.TestDecoder;
+import org.apache.qpid.proton.ProtonFactoryLoader;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.Decimal128;
+import org.apache.qpid.proton.amqp.Decimal32;
+import org.apache.qpid.proton.amqp.Decimal64;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.UnsignedByte;
+import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.amqp.UnsignedLong;
+import org.apache.qpid.proton.amqp.UnsignedShort;
+import org.apache.qpid.proton.codec.Data;
+import org.apache.qpid.proton.codec.DataFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+
+/**
+ * TestDecoder is a stripped-down decoder used by interop tests to decode AMQP
+ * data. The native version wraps a DecoderImpl, while the JNI version wraps a
+ * Data object.
+ */
+
+public class TestDecoder {
+ private Data data;
+
+ TestDecoder(byte[] encoded) {
+ DataFactory df =
+ new ProtonFactoryLoader<DataFactory>(DataFactory.class).loadFactory();
+ data = df.createData(encoded.length);
+ int offset = 0;
+ while (offset < encoded.length) {
+ ByteBuffer buffer = ByteBuffer.wrap(encoded, offset, encoded.length-offset);
+ offset += data.decode(buffer);
+ }
+ data.rewind();
+ }
+
+ public Boolean readBoolean() { data.next(); return data.getBoolean(); }
+ public Byte readByte() { data.next(); return data.getByte(); }
+ public Short readShort() { data.next(); return data.getShort(); }
+ public Integer readInteger() { data.next(); return data.getInt(); }
+ public Long readLong() { data.next(); return data.getLong(); }
+ public UnsignedByte readUnsignedByte() { data.next(); return data.getUnsignedByte(); }
+ public UnsignedShort readUnsignedShort() { data.next(); return data.getUnsignedShort(); }
+ public UnsignedInteger readUnsignedInteger() { data.next(); return data.getUnsignedInteger(); }
+ public UnsignedLong readUnsignedLong() { data.next(); return data.getUnsignedLong(); }
+ public Character readCharacter() { data.next(); return new Character((char)data.getChar()); }
+ public Float readFloat() { data.next(); return data.getFloat(); }
+ public Double readDouble() { data.next(); return data.getDouble(); }
+ public UUID readUUID() { data.next(); return data.getUUID(); }
+ public Decimal32 readDecimal32() { data.next(); return data.getDecimal32(); }
+ public Decimal64 readDecimal64() { data.next(); return data.getDecimal64(); }
+ public Decimal128 readDecimal128() { data.next(); return data.getDecimal128(); }
+ public Date readTimestamp() { data.next(); return data.getTimestamp(); }
+ public Binary readBinary() { data.next(); return data.getBinary(); }
+ public Symbol readSymbol() { data.next(); return data.getSymbol(); }
+ public String readString() { data.next(); return data.getString(); }
+
+ // FIXME aconway 2013-02-16:
+ // public List readList() { data.next(); return data.getList(); }
+ // public Map readMap() { data.next(); return data.getMap(); }
+ // public Object[] readArray() { data.next(); return data.getArray(); }
+ // public boolean[] readBooleanArray() { data.next(); return data.getBooleanArray(); }
+ // public byte[] readByteArray() { data.next(); return data.getByteArray(); }
+ // public short[] readShortArray() { data.next(); return data.getShortArray(); }
+ // public int[] readIntegerArray() { data.next(); return data.getIntegerArray(); }
+ // public long[] readLongArray() { data.next(); return data.getLongArray(); }
+ // public float[] readFloatArray() { data.next(); return data.getFloatArray(); }
+ // public double[] readDoubleArray() { data.next(); return data.getDoubleArray(); }
+ // public char[] readCharacterArray() { data.next(); return data.getCharacterArray(); }
+ // public Object readObject() { data.next(); return data.getObject(); }
+}
Propchange: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/TestDecoder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java?rev=1449938&view=auto
==============================================================================
--- qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java (added)
+++ qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java Mon Feb 25 22:29:00 2013
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import org.apache.qpid.proton.TestDecoder;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.Decimal128;
+import org.apache.qpid.proton.amqp.Decimal32;
+import org.apache.qpid.proton.amqp.Decimal64;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.UnsignedByte;
+import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.amqp.UnsignedLong;
+import org.apache.qpid.proton.amqp.UnsignedShort;
+import org.apache.qpid.proton.amqp.messaging.AmqpValue;
+import org.apache.qpid.proton.codec.AMQPDefinedTypes;
+
+import org.apache.qpid.proton.codec.DecoderImpl;
+import org.apache.qpid.proton.codec.EncoderImpl;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+
+/**
+ * TestDecoder is a stripped-down decoder used by interop tests to decode AMQP
+ * data. The native version wraps a DecoderImpl, while the JNI version wraps a
+ * Data object.
+ */
+
+public class TestDecoder {
+ private DecoderImpl decoder;
+ private EncoderImpl encoder;
+ private ByteBuffer buffer;
+
+ TestDecoder(byte[] data) {
+ decoder = new DecoderImpl();
+ encoder = new EncoderImpl(decoder);
+ AMQPDefinedTypes.registerAllTypes(decoder, encoder);
+ buffer = ByteBuffer.allocate(data.length);
+ buffer.put(data);
+ buffer.rewind();
+ decoder.setByteBuffer(buffer);
+ }
+
+ public Boolean readBoolean() { return decoder.readBoolean(); }
+ public Byte readByte() { return decoder.readByte(); }
+ public Short readShort() { return decoder.readShort(); }
+ public Integer readInteger() { return decoder.readInteger(); }
+ public Long readLong() { return decoder.readLong(); }
+ public UnsignedByte readUnsignedByte() { return decoder.readUnsignedByte(); }
+ public UnsignedShort readUnsignedShort() { return decoder.readUnsignedShort(); }
+ public UnsignedInteger readUnsignedInteger() { return decoder.readUnsignedInteger(); }
+ public UnsignedLong readUnsignedLong() { return decoder.readUnsignedLong(); }
+ public Character readCharacter() { return decoder.readCharacter(); }
+ public Float readFloat() { return decoder.readFloat(); }
+ public Double readDouble() { return decoder.readDouble(); }
+ public UUID readUUID() { return decoder.readUUID(); }
+ public Decimal32 readDecimal32() { return decoder.readDecimal32(); }
+ public Decimal64 readDecimal64() { return decoder.readDecimal64(); }
+ public Decimal128 readDecimal128() { return decoder.readDecimal128(); }
+ public Date readTimestamp() { return decoder.readTimestamp(); }
+ public Binary readBinary() { return decoder.readBinary(); }
+ public Symbol readSymbol() { return decoder.readSymbol(); }
+ public String readString() { return decoder.readString(); }
+ public List readList() { return decoder.readList(); }
+ public Map readMap() { return decoder.readMap(); }
+ public Object[] readArray() { return decoder.readArray(); }
+ public boolean[] readBooleanArray() { return decoder.readBooleanArray(); }
+ public byte[] readByteArray() { return decoder.readByteArray(); }
+ public short[] readShortArray() { return decoder.readShortArray(); }
+ public int[] readIntegerArray() { return decoder.readIntegerArray(); }
+ public long[] readLongArray() { return decoder.readLongArray(); }
+ public float[] readFloatArray() { return decoder.readFloatArray(); }
+ public double[] readDoubleArray() { return decoder.readDoubleArray(); }
+ public char[] readCharacterArray() { return decoder.readCharacterArray(); }
+ public Object readObject() { return decoder.readObject(); }
+}
Propchange: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/trunk/proton-j/proton/src/main/java/org/apache/qpid/proton/TestDecoder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java?rev=1449938&view=auto
==============================================================================
--- qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java (added)
+++ qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java Mon Feb 25 22:29:00 2013
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import org.apache.qpid.proton.TestDecoder;
+import org.apache.qpid.proton.ProtonFactoryLoader;
+import org.apache.qpid.proton.amqp.Binary;
+import org.apache.qpid.proton.amqp.UnsignedByte;
+import org.apache.qpid.proton.amqp.UnsignedInteger;
+import org.apache.qpid.proton.amqp.UnsignedLong;
+import org.apache.qpid.proton.amqp.UnsignedShort;
+import org.apache.qpid.proton.amqp.messaging.AmqpValue;
+import org.apache.qpid.proton.message.Message;
+import org.apache.qpid.proton.message.MessageFactory;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import java.lang.System;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+public class InteropTest {
+
+ static private File findTestsInteropDir() {
+ File f = new File(System.getProperty("user.dir"));
+ while (f != null && !f.getName().equals("tests"))
+ f = f.getParentFile();
+ if (f != null && f.isDirectory())
+ return new File(f,"interop");
+ else
+ throw new Error("Cannot find tests/interop directory");
+ }
+
+ static File testsInteropDir = findTestsInteropDir();
+
+ byte[] getBytes(String name) throws IOException {
+ File f = new File(testsInteropDir, name+".amqp");
+ byte[] data = new byte[(int)f.length()];
+ FileInputStream fi = new FileInputStream(f);
+ assertEquals(f.length(), fi.read(data));
+ fi.close();
+ return data;
+ }
+
+ Message decodeMessage(String name) throws IOException {
+ byte[] data = getBytes(name);
+ MessageFactory mf =
+ new ProtonFactoryLoader<MessageFactory>(MessageFactory.class).loadFactory();
+ Message m = mf.createMessage();
+ m.decode(data, 0, data.length);
+ return m;
+ }
+
+ TestDecoder createDecoder(byte[] data) {
+ TestDecoder td = new TestDecoder(data);
+ return td;
+ }
+
+ @Test
+ public void test_primitives() throws IOException {
+ TestDecoder d = createDecoder(getBytes("primitives"));
+ assertEquals(true, d.readBoolean());
+ assertEquals(false, d.readBoolean());
+ assertEquals(d.readUnsignedByte().intValue(), 42);
+ assertEquals(42, d.readUnsignedShort().intValue());
+ assertEquals(-42, d.readShort().intValue());
+ assertEquals(12345, d.readUnsignedInteger().intValue());
+ assertEquals(-12345, d.readInteger().intValue());
+ assertEquals(12345, d.readUnsignedLong().longValue());
+ assertEquals(-12345, d.readLong().longValue());
+ assertEquals(0.125, d.readFloat().floatValue(), 0e-10);
+ assertEquals(0.125, d.readDouble().doubleValue(), 0e-10);
+ }
+
+ @Test
+ public void test_strings() throws IOException {
+ // FIXME aconway 2013-02-18:
+ }
+
+ // FIXMEo aconway 2013-02-15: add tests for all fragments generated by
+ // interop-generate
+}
Propchange: qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/trunk/tests/java/org/apache/qpid/proton/InteropTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org