summaryrefslogtreecommitdiffstats
path: root/sandbox/jboynes/sdoproxy/src/test/java/org/apache/tuscany/sdo/proxy/PrimitivesTestCase.java
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/jboynes/sdoproxy/src/test/java/org/apache/tuscany/sdo/proxy/PrimitivesTestCase.java')
-rw-r--r--sandbox/jboynes/sdoproxy/src/test/java/org/apache/tuscany/sdo/proxy/PrimitivesTestCase.java202
1 files changed, 202 insertions, 0 deletions
diff --git a/sandbox/jboynes/sdoproxy/src/test/java/org/apache/tuscany/sdo/proxy/PrimitivesTestCase.java b/sandbox/jboynes/sdoproxy/src/test/java/org/apache/tuscany/sdo/proxy/PrimitivesTestCase.java
new file mode 100644
index 0000000000..ea2c031d8b
--- /dev/null
+++ b/sandbox/jboynes/sdoproxy/src/test/java/org/apache/tuscany/sdo/proxy/PrimitivesTestCase.java
@@ -0,0 +1,202 @@
+/**
+ *
+ * Copyright 2005 BEA Systems Inc.
+ * Copyright 2005 International Business Machines Corporation
+ *
+ * Licensed 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.tuscany.sdo.proxy;
+
+import junit.framework.TestCase;
+import org.osoa.sdo.Type;
+import org.osoa.sdo.DataObject;
+import org.osoa.sdo.Property;
+import org.osoa.sdo.helper.TypeHelper;
+
+import org.apache.tuscany.sdo.impl.TypeHelperImpl;
+import org.apache.tuscany.sdo.proxy.interfaces.Primitives;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings({"InstanceofIncompatibleInterface", "CastToIncompatibleInterface"})
+public class PrimitivesTestCase extends TestCase {
+ private Primitives primitives;
+ private Type<Primitives> type;
+
+ public void testIsDataObject() {
+ assertTrue(primitives instanceof DataObject);
+ DataObject<Primitives> o = (DataObject<Primitives>) primitives;
+ Type<Primitives> type = o.getType();
+ assertNotNull(type);
+ assertEquals(this.type, type);
+ assertEquals(Primitives.class, type.getJavaType());
+ }
+
+ public void testBoolean() {
+ primitives.setBoolean(false);
+ assertEquals(false, primitives.isBoolean());
+ primitives.setBoolean(true);
+ assertEquals(true, primitives.isBoolean());
+ }
+
+ public void testCharacter() {
+ primitives.setCharacter('A');
+ assertEquals('A', primitives.getCharacter());
+ }
+
+ public void testByte() {
+ primitives.setByte((byte) 12);
+ assertEquals((byte) 12, primitives.getByte());
+ }
+
+ public void testShort() {
+ primitives.setShort((short) 1234);
+ assertEquals((short) 1234, primitives.getShort());
+ }
+
+ public void testInt() {
+ primitives.setInt(1234);
+ assertEquals(1234, primitives.getInt());
+ }
+
+ public void testLong() {
+ primitives.setLong(1234l);
+ assertEquals(1234l, primitives.getLong());
+ }
+
+ public void testFloat() {
+ primitives.setFloat(1234f);
+ assertEquals(1234f, primitives.getFloat());
+ }
+
+ public void testDouble() {
+ primitives.setDouble(1234d);
+ assertEquals(1234d, primitives.getDouble());
+ }
+
+ public void testGetIndex() {
+ DataObject o = (DataObject) primitives;
+ int i = 0;
+ for (Property<?> prop : type.getProperties()) {
+ String name = prop.getName();
+ if ("boolean".equals(name)) {
+ primitives.setBoolean(true);
+ assertEquals(true, o.get(i));
+ } else if ("character".equals(name)) {
+ primitives.setCharacter('A');
+ assertEquals('A', o.get(i));
+ } else if ("byte".equals(name)) {
+ primitives.setByte((byte) 12);
+ assertEquals((byte) 12, o.get(i));
+ } else if ("short".equals(name)) {
+ primitives.setShort((short) 123);
+ assertEquals((short)123, o.get(i));
+ } else if ("int".equals(name)) {
+ primitives.setInt(1234);
+ assertEquals(1234, o.get(i));
+ } else if ("long".equals(name)) {
+ primitives.setLong(12345l);
+ assertEquals(12345l, o.get(i));
+ } else if ("float".equals(name)) {
+ primitives.setFloat(1234.56f);
+ assertEquals(1234.56f, o.get(i));
+ } else if ("double".equals(name)) {
+ primitives.setDouble(1234.5678d);
+ assertEquals(1234.5678d, o.get(i));
+ } else {
+ fail();
+ }
+ i++;
+ }
+ }
+
+ public void testSetIndex() {
+ DataObject o = (DataObject) primitives;
+ int i = 0;
+ for (Property<?> prop : type.getProperties()) {
+ String name = prop.getName();
+ if ("boolean".equals(name)) {
+ o.set(i, true);
+ assertEquals(true, primitives.isBoolean());
+ } else if ("character".equals(name)) {
+ o.set(i, 'A');
+ assertEquals('A', primitives.getCharacter());
+ } else if ("byte".equals(name)) {
+ o.set(i, (byte) 12);
+ assertEquals((byte)12, primitives.getByte());
+ } else if ("short".equals(name)) {
+ o.set(i, (short)123);
+ assertEquals((short)123, primitives.getShort());
+ } else if ("int".equals(name)) {
+ o.set(i, 1234);
+ assertEquals(1234, primitives.getInt());
+ } else if ("long".equals(name)) {
+ o.set(i, 12345l);
+ assertEquals(12345l, primitives.getLong());
+ } else if ("float".equals(name)) {
+ o.set(i, 1234.56f);
+ assertEquals(1234.56f, primitives.getFloat());
+ } else if ("double".equals(name)) {
+ o.set(i, 1234.5678d);
+ assertEquals(1234.5678d, primitives.getDouble());
+ } else {
+ fail();
+ }
+ i++;
+ }
+ }
+
+ public void testCannotSetNull() {
+ DataObject o = (DataObject) primitives;
+ assertNotNull(o);
+ for (int i=0 ; i < type.getProperties().size(); i++) {
+ try {
+ o.set(i, null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ }
+ }
+
+ public void testIndexRange() {
+ DataObject o = (DataObject) primitives;
+ try {
+ o.get(-1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ o.get(8);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ o.set(-1, null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ o.set(8, null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ TypeHelper typeHelper = new TypeHelperImpl(getClass().getClassLoader());
+ type = typeHelper.define(Primitives.class);
+ primitives = type.newInstance();
+ }
+}