diff options
Diffstat (limited to 'sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test')
51 files changed, 3129 insertions, 0 deletions
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/configuration/config.ini b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/configuration/config.ini new file mode 100644 index 0000000000..3b8be1b173 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/configuration/config.ini @@ -0,0 +1,6 @@ +#Product Runtime Configuration File
+
+osgi.bundles=\
+ org.eclipse.equinox.common@2\:start,\
+ org.eclipse.update.configurator@3:start,\
+ org.eclipse.core.runtime@4:start
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/implementation/BytesTypeConverterTest.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/implementation/BytesTypeConverterTest.java new file mode 100644 index 0000000000..b86f6ed42d --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/implementation/BytesTypeConverterTest.java @@ -0,0 +1,24 @@ +package com.agfa.hap.sdo.implementation;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.impl.BytesTypeConverter;
+
+public class BytesTypeConverterTest {
+ @Test
+ public void convert(){
+ BytesTypeConverter converter = new BytesTypeConverter();
+ byte[] input = new byte[256];
+ int i = 0;
+ for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++, i++){
+ input[i] = b;
+ }
+ byte[] output = converter.parse(converter.toString(input));
+ for (int j = 0; j < output.length; j++){
+ Assert.assertEquals(input[j], output[j]);
+ }
+ }
+
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/implementation/TestLongUTFSerialization.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/implementation/TestLongUTFSerialization.java new file mode 100644 index 0000000000..e3c56c3f46 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/implementation/TestLongUTFSerialization.java @@ -0,0 +1,56 @@ +package com.agfa.hap.sdo.implementation;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.implementation.SnapshotImplementation.SnapshotSerializer;
+
+public class TestLongUTFSerialization {
+
+ private SnapshotSerializer serializer;
+
+ @Before
+ public void setup(){
+ serializer = new SnapshotImplementation.SnapshotSerializer(null);
+ }
+
+ @Test
+ public void testShort() throws IOException{
+ testUTFRoundtrip("test123");
+ }
+ @Test
+ public void testMaxUTF() throws IOException{
+ StringBuilder maxUTFString = new StringBuilder();
+ for (int i = 0; i < SnapshotSerializer.MAX_UTF_LENGTH; i++){
+ maxUTFString.append(i % 9);
+ }
+ testUTFRoundtrip(maxUTFString.toString());
+ }
+
+ @Test
+ public void testLongUTF() throws IOException {
+ StringBuilder maxUTFString = new StringBuilder();
+ for (int i = 0; i < 2*SnapshotSerializer.MAX_UTF_LENGTH; i++){
+ maxUTFString.append(i % 9);
+ }
+ maxUTFString.append("somemorecharacters");
+ testUTFRoundtrip(maxUTFString.toString());
+
+ }
+
+ private void testUTFRoundtrip(String inputString) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ serializer.writePotentiallyLongStringUTF(inputString, new DataOutputStream(bos));
+ String outputString = serializer.readPotentiallyLongUTF(new DataInputStream(new ByteArrayInputStream(bos.toByteArray())));
+ Assert.assertEquals(inputString, outputString);
+ }
+
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/BeanPropertyAccessorBuilderTest.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/BeanPropertyAccessorBuilderTest.java new file mode 100644 index 0000000000..11335f290c --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/BeanPropertyAccessorBuilderTest.java @@ -0,0 +1,30 @@ +package com.agfa.hap.sdo.mapper;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import com.agfa.hap.sdo.implementation.PropertyImplementation;
+import com.agfa.hap.sdo.mapper.BeanPropertyAccessor;
+import com.agfa.hap.sdo.mapper.BeanPropertyAccessorBuilder;
+
+public class BeanPropertyAccessorBuilderTest {
+ @Test
+ public void booleanProperties(){
+ BeanPropertyAccessorBuilder builder = new BeanPropertyAccessorBuilder();
+ Property isCancelledProp = new PropertyImplementation("isCancelled", TypeHelper.INSTANCE.getType(Boolean.class), null, 0);
+ Assert.assertNotNull((BeanPropertyAccessor) builder.createPropertyAccessor(SomePojo.class, isCancelledProp));
+ Property someBooleanProp = new PropertyImplementation("someBoolean", TypeHelper.INSTANCE.getType(Boolean.class), null, 0);
+ Assert.assertNotNull((BeanPropertyAccessor) builder.createPropertyAccessor(SomePojo.class, someBooleanProp));
+ }
+
+ @Test
+ public void someRegularProp(){
+ BeanPropertyAccessorBuilder builder = new BeanPropertyAccessorBuilder();
+ Property someProp = new PropertyImplementation("someProperty", TypeHelper.INSTANCE.getType(String.class), null, 0);
+ BeanPropertyAccessor propAccessor = (BeanPropertyAccessor) builder.createPropertyAccessor(SomePojo.class, someProp );
+ Assert.assertNotNull(propAccessor);
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/DummyPropertyAccessor.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/DummyPropertyAccessor.java new file mode 100644 index 0000000000..5a0e945b59 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/DummyPropertyAccessor.java @@ -0,0 +1,14 @@ +package com.agfa.hap.sdo.mapper;
+
+import com.agfa.hap.sdo.DataMapper;
+import com.agfa.hap.sdo.Property;
+
+public class DummyPropertyAccessor extends AbstractPropertyAccessor {
+
+ public Object getValue(Object instance, Property property, DataMapper dataMapper) {
+ return null;
+ }
+
+ public void setValue(Object instance, Property property, Object value, DataMapper dataMapper) {
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/ExtendablePropertyAccessorBuilderTest.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/ExtendablePropertyAccessorBuilderTest.java new file mode 100644 index 0000000000..6a83adbc83 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/ExtendablePropertyAccessorBuilderTest.java @@ -0,0 +1,20 @@ +package com.agfa.hap.sdo.mapper;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.implementation.PropertyImplementation;
+import com.agfa.hap.sdo.mapper.ExtendablePropertyAccessorBuilder;
+import com.agfa.hap.sdo.mapper.PropertyAccessor;
+
+public class ExtendablePropertyAccessorBuilderTest {
+ @Test
+ public void extendedPropertyIsInSuperClass(){
+ ExtendablePropertyAccessorBuilder builder = new ExtendablePropertyAccessorBuilder(null);
+ Property superPropProperty = new PropertyImplementation("superProperty", null, null, 1);
+ PropertyAccessor accessor = builder.createPropertyAccessor(Sub.class, superPropProperty );
+ Assert.assertTrue(accessor instanceof DummyPropertyAccessor);
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/SomePojo.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/SomePojo.java new file mode 100644 index 0000000000..812ab4618d --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/SomePojo.java @@ -0,0 +1,26 @@ +package com.agfa.hap.sdo.mapper;
+
+public class SomePojo {
+ private boolean isCancelled;
+ private String someProperty;
+ private boolean someBoolean;
+ public boolean isSomeBoolean() {
+ return someBoolean;
+ }
+ public void setSomeBoolean(boolean someBoolean) {
+ this.someBoolean = someBoolean;
+ }
+ public boolean isCancelled() {
+ return isCancelled;
+ }
+ public void setCancelled(boolean isCancelled) {
+ this.isCancelled = isCancelled;
+ }
+ public String getSomeProperty() {
+ return someProperty;
+ }
+ public void setSomeProperty(String someProperty) {
+ this.someProperty = someProperty;
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/Sub.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/Sub.java new file mode 100644 index 0000000000..88aba1eeb2 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/Sub.java @@ -0,0 +1,13 @@ +package com.agfa.hap.sdo.mapper;
+
+public class Sub extends Super {
+ private String subProperty;
+
+ public String getSubProperty() {
+ return subProperty;
+ }
+
+ public void setSubProperty(String subProperty) {
+ this.subProperty = subProperty;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/Super.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/Super.java new file mode 100644 index 0000000000..e2fdd24bc1 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/mapper/Super.java @@ -0,0 +1,13 @@ +package com.agfa.hap.sdo.mapper;
+
+public class Super {
+ private String superProperty;
+
+ public String getSuperProperty() {
+ return superProperty;
+ }
+
+ public void setSuperProperty(String superProp) {
+ this.superProperty = superProp;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/A.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/A.java new file mode 100644 index 0000000000..ebb02b3b08 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/A.java @@ -0,0 +1,91 @@ +package com.agfa.hap.sdo.test;
+
+import java.net.URI;
+
+public class A {
+ private byte[] bytearrayProp;
+ private String stringProp;
+ private int intProp;
+ private B b;
+ private B containedB;
+ private long longProp;
+ private short shortProp;
+ private boolean booleanProp;
+ private double doubleProp;
+ private byte byteProp;
+ private float floatProp;
+ private URI uriProp;
+
+ public B getB() {
+ return b;
+ }
+ public void setB(B b) {
+ this.b = b;
+ }
+ public B getContainedB() {
+ return containedB;
+ }
+ public void setContainedB(B b) {
+ this.containedB = b;
+ }
+ public boolean isBooleanProp() {
+ return booleanProp;
+ }
+ public void setBooleanProp(boolean booleanProp) {
+ this.booleanProp = booleanProp;
+ }
+ public byte getByteProp() {
+ return byteProp;
+ }
+ public void setByteProp(byte byteProp) {
+ this.byteProp = byteProp;
+ }
+ public double getDoubleProp() {
+ return doubleProp;
+ }
+ public void setDoubleProp(double doubleProp) {
+ this.doubleProp = doubleProp;
+ }
+ public float getFloatProp() {
+ return floatProp;
+ }
+ public void setFloatProp(float floatProp) {
+ this.floatProp = floatProp;
+ }
+ public int getIntProp() {
+ return intProp;
+ }
+ public void setIntProp(int intProp) {
+ this.intProp = intProp;
+ }
+ public long getLongProp() {
+ return longProp;
+ }
+ public void setLongProp(long longProp) {
+ this.longProp = longProp;
+ }
+ public short getShortProp() {
+ return shortProp;
+ }
+ public void setShortProp(short shortProp) {
+ this.shortProp = shortProp;
+ }
+ public String getStringProp() {
+ return stringProp;
+ }
+ public void setStringProp(String stringProp) {
+ this.stringProp = stringProp;
+ }
+ public URI getUriProp() {
+ return uriProp;
+ }
+ public void setUriProp(URI uriProp) {
+ this.uriProp = uriProp;
+ }
+ public byte[] getBytearrayProp() {
+ return bytearrayProp;
+ }
+ public void setBytearrayProp(byte[] bytearrayProp) {
+ this.bytearrayProp = bytearrayProp;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/B.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/B.java new file mode 100644 index 0000000000..e6c04d9913 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/B.java @@ -0,0 +1,41 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class B {
+
+ private String name;
+ private List<B> children;
+ private B parent;
+ private B favouriteChild;
+
+ public B() {
+ children = new ArrayList<B>();
+ }
+
+ public List<B> getChildren() {
+ return children;
+ }
+ public void setChildren(List<B> children) {
+ this.children = children;
+ }
+ public B getFavouriteChild() {
+ return favouriteChild;
+ }
+ public void setFavouriteChild(B favouriteChild) {
+ this.favouriteChild = favouriteChild;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public B getParent() {
+ return parent;
+ }
+ public void setParent(B parent) {
+ this.parent = parent;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/C.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/C.java new file mode 100644 index 0000000000..1b9313deaf --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/C.java @@ -0,0 +1,42 @@ +package com.agfa.hap.sdo.test;
+
+import java.net.URI;
+
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.implementation.DataObjectImplementation;
+import com.agfa.hap.sdo.implementation.TypeImplementation;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+public class C extends DataObjectImplementation {
+
+ private static final long serialVersionUID = -5008889354555116408L;
+
+ public C() {
+ super(TypeHolder.type);
+ }
+
+ public C(Type type) {
+ super(type);
+ }
+
+ public String getName() {
+ return (String) super.get("name");
+ }
+
+ public void setName(String name) {
+ super.set("name", name);
+ }
+
+ public URI getUri() {
+ return (URI) super.getIdentity();
+ }
+
+ private static class TypeHolder {
+ public final static TypeImplementation type;
+ static {
+ XSDHelper.INSTANCE.define(C.class.getResourceAsStream("/sdo/test-sdo-types.xsd"), "test");
+ type = (TypeImplementation) TypeHelper.INSTANCE.getType("test", "C");
+ }
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/DataObjectCreator.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/DataObjectCreator.java new file mode 100644 index 0000000000..3b6775196e --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/DataObjectCreator.java @@ -0,0 +1,26 @@ +package com.agfa.hap.sdo.test;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.DataFactory;
+
+public class DataObjectCreator {
+
+ static DataObject createSimpleDataObject() {
+ DataObject result = DataFactory.INSTANCE.create("commonj.sdo", "Type");
+ result.set("name", "TestType");
+ result.set("dataType", Boolean.FALSE);
+ return result;
+ }
+
+ static DataObject createDataObjectWithManyValuedProperty() {
+ DataObject dataObject = createSimpleDataObject();
+ DataObject prop = dataObject.createDataObject("property");
+ prop.set("name", "prop1");
+ prop = dataObject.createDataObject("property");
+ prop.set("name", "prop2");
+ return dataObject;
+ }
+
+
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/ExampleEnum.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/ExampleEnum.java new file mode 100644 index 0000000000..362d06eef5 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/ExampleEnum.java @@ -0,0 +1,7 @@ +package com.agfa.hap.sdo.test;
+
+public enum ExampleEnum {
+
+ ONE, TWO, THREE
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/FilteringPartialDataObjectMapperTest.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/FilteringPartialDataObjectMapperTest.java new file mode 100644 index 0000000000..8ae9dfce32 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/FilteringPartialDataObjectMapperTest.java @@ -0,0 +1,78 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.PartialDataObject;
+import com.agfa.hap.sdo.ReachableDefinition;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import com.agfa.hap.sdo.implementation.TypeImplementation;
+import com.agfa.hap.sdo.mapper.FilteringPartialDataObjectMapper;
+import com.agfa.hap.sdo.mapper.PartialDataObjectMapper;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.DataFactory;
+
+public class FilteringPartialDataObjectMapperTest {
+
+ @Test
+ public void test(){
+ Type typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ DataObject stringType = DataFactory.INSTANCE.create(typeType);
+ stringType.set("name", "String");
+ stringType.set("uri", "commonj");
+
+ DataObject fTypeDO = DataFactory.INSTANCE.create(typeType);
+ fTypeDO.set("name", "TestTypeF");
+ fTypeDO.set("uri", "unittest");
+ DataObject someProp = fTypeDO.createDataObject("property");
+ someProp.set("name", "propF1");
+ someProp.set("type", stringType);
+ DataObject idProp = fTypeDO.createDataObject("property");
+ idProp.set("name", "idProp");
+ idProp.set("type", stringType);
+
+ DataObject rTypeDO = DataFactory.INSTANCE.create(typeType);
+ rTypeDO.set("name", "TestTypeR");
+ rTypeDO.set("uri", "unittest");
+ DataObject prop = rTypeDO.createDataObject("property");
+ prop.set("name", "prop1");
+ prop.set("type", fTypeDO);
+ prop = rTypeDO.createDataObject("property");
+ prop.set("name", "prop2");
+ prop.set("type", stringType);
+ List<DataObject> types = new ArrayList<DataObject>();
+ types.add(stringType);
+ types.add(fTypeDO);
+ types.add(rTypeDO);
+ TypeHelper.INSTANCE.define(types);
+ Type fType = TypeHelper.INSTANCE.getType("unittest", "TestTypeF");
+ ((TypeImplementation) fType).setIdentityProperty(fType.getProperty("idProp"));
+
+
+ List<Type> typesToBeFiltered = new ArrayList<Type>();
+
+ typesToBeFiltered.add(fType);
+
+ DataObject someF = DataFactory.INSTANCE.create("unittest", "TestTypeF");
+ someF.set("propF1", "dit is een test");
+ someF.set("idProp", "123123");
+ DataObject someR = DataFactory.INSTANCE.create("unittest", "TestTypeR");
+ someR.set("prop1", someF);
+ someR.set("prop2", "test123");
+
+ List<PartialDataObject> roots = new ArrayList<PartialDataObject>();
+ roots.add((PartialDataObject) someR);
+ Snapshot snapshot = DataAccessService.createMultiSnapShot(new FilteringPartialDataObjectMapper(typesToBeFiltered), new ReachableDefinition(), roots);
+ List<PartialDataObject> extracted = snapshot.extract(new PartialDataObjectMapper());
+ Assert.assertEquals(1, extracted.size());
+ PartialDataObject extractedR = extracted.get(0);
+ Assert.assertTrue(((PartialDataObject) extractedR.get("prop1")).isProxy());
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/InheritedB.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/InheritedB.java new file mode 100644 index 0000000000..5789e24427 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/InheritedB.java @@ -0,0 +1,14 @@ +package com.agfa.hap.sdo.test;
+
+public class InheritedB extends B {
+
+ private String nickname;
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/MyBasicObject.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/MyBasicObject.java new file mode 100644 index 0000000000..8ae1ce68ec --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/MyBasicObject.java @@ -0,0 +1,14 @@ +package com.agfa.hap.sdo.test;
+
+public class MyBasicObject {
+
+ public static MyBasicObject ONE = new MyBasicObject(1);
+ public static MyBasicObject TWO = new MyBasicObject(2);
+ public static MyBasicObject THREE = new MyBasicObject(3);
+
+ public MyBasicObject(int i) {
+ this.i = i;
+ }
+
+ public int i;
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/MyBasicObjectTypeConverter.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/MyBasicObjectTypeConverter.java new file mode 100644 index 0000000000..f7a7d7fb19 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/MyBasicObjectTypeConverter.java @@ -0,0 +1,26 @@ +package com.agfa.hap.sdo.test;
+
+import com.agfa.hap.sdo.impl.TypeConverter;
+
+public class MyBasicObjectTypeConverter extends TypeConverter<MyBasicObject> {
+
+ @Override
+ public MyBasicObject parse(String str) {
+ int i = Integer.parseInt(str);
+ switch(i) {
+ case 1:
+ return MyBasicObject.ONE;
+ case 2:
+ return MyBasicObject.TWO;
+ case 3:
+ return MyBasicObject.THREE;
+ }
+ return new MyBasicObject(i);
+ }
+
+ @Override
+ public String toString(MyBasicObject instance) {
+ return Integer.toString(instance.i);
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/ResultSetTest.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/ResultSetTest.java new file mode 100644 index 0000000000..30a03ee7ba --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/ResultSetTest.java @@ -0,0 +1,101 @@ +package com.agfa.hap.sdo.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.util.ResultSet;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+
+public class ResultSetTest {
+
+ protected Type typeType;
+
+ @Before
+ public void initializeTypes() {
+ typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ }
+
+ @Test
+ public void simpleResultSet() throws Exception {
+ List<DataObject> data = createSimpleData("t1");
+ ResultSet rs = new ResultSet(data, "name, property.name", typeType);
+ assertEquals(5, rs.getSize());
+ for (int i = 0; i < 5; i++) {
+ assertEquals("t1", rs.getValue(i, "name"));
+ Assert.assertTrue(((String) rs.getValue(i, "property.name")).startsWith("t1prop"));
+ }
+ }
+
+ protected List<DataObject> createSimpleData(String name) {
+ List<DataObject> result = new ArrayList<DataObject>();
+ DataObject t1 = DataFactory.INSTANCE.create(typeType);
+ t1.set("name", name);
+ for (int i = 0; i < 5; i++) {
+ DataObject prop = t1.createDataObject("property");
+ prop.set("name", name + "prop" + i);
+ prop.set("aliasName", name + "alias" + i);
+ }
+ result.add(t1);
+ return result;
+ }
+
+ @Test
+ public void multiResultSet() throws Exception {
+ List<DataObject> data = createSimpleData("1");
+ data.addAll(createSimpleData("2"));
+ ResultSet rs = new ResultSet(data, "name, property.name", typeType);
+ assertEquals(10, rs.getSize());
+ int one = 0;
+ int two = 0;
+ for (int i = 0; i < rs.getSize(); i++) {
+ if (rs.getValue(i, "name").equals("1")) {
+ one++;
+ }
+ if (rs.getValue(i, "name").equals("2")) {
+ two++;
+ }
+ Assert.assertTrue(((String) rs.getValue(i, "property.name")).startsWith(rs.getValue(i,"name").toString()));
+ }
+ Assert.assertEquals(5, one);
+ Assert.assertEquals(5, two);
+ }
+
+
+ @Test
+ public void twoManyValuedProperties() {
+ List<DataObject> data = createSimpleData("t1");
+ ResultSet rs = new ResultSet(data, "name, property.name, property.aliasName", typeType);
+ assertEquals(5, rs.getSize());
+ for (int i = 0; i < 5; i++) {
+ assertEquals("t1", rs.getValue(i, "name"));
+ Assert.assertEquals("t1prop"+i, rs.getValue(i, "property.name"));
+ Assert.assertEquals("t1alias"+i, rs.getValue(i, "property.aliasName"));
+ }
+ }
+
+ @Test
+ public void nullProperties() {
+ List<DataObject> data = createSimpleData("t1");
+ data.add(DataFactory.INSTANCE.create(typeType));
+ ResultSet rs = new ResultSet(data, "name, property.name", typeType);
+ assertEquals(6, rs.getSize());
+ for (int i = 0; i < rs.getSize() - 1; i++) {
+ if ("t1".equals(rs.getValue(i, "name"))) {
+ Assert.assertTrue(((String) rs.getValue(i, "property.name")).startsWith("t1prop"));
+ } else {
+ Assert.assertEquals(null, rs.getValue(i, "name"));
+ Assert.assertEquals(null, rs.getValue(i, "property.name"));
+ }
+ }
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SdoTestUtil.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SdoTestUtil.java new file mode 100644 index 0000000000..83c69a5635 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SdoTestUtil.java @@ -0,0 +1,30 @@ +package com.agfa.hap.sdo.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.junit.Assert;
+
+public class SdoTestUtil {
+
+ @SuppressWarnings("unchecked")
+ public static <T> T marshallUnmarshal(T object) {
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(bos);
+ oos.writeObject(object);
+ ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
+ return (T) is.readObject();
+ } catch (ClassNotFoundException e) {
+ Assert.fail("Exception during serialization: " + e.getMessage());
+ } catch (IOException e) {
+ Assert.fail("Exception during serialization: " + e.getMessage());
+ }
+ return null;
+ }
+
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SerializableBasicObject.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SerializableBasicObject.java new file mode 100644 index 0000000000..be0039d1a7 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SerializableBasicObject.java @@ -0,0 +1,23 @@ +package com.agfa.hap.sdo.test;
+
+import java.io.Serializable;
+
+public class SerializableBasicObject implements Serializable {
+
+ private static final long serialVersionUID = -207081518262599555L;
+
+ public SerializableBasicObject() {}
+
+ public SerializableBasicObject(int i) { this.i = i; }
+
+ public int i;
+
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof SerializableBasicObject)) {
+ return false;
+ }
+ SerializableBasicObject sbo = (SerializableBasicObject) other;
+ return sbo.i == i;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SomeType.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SomeType.java new file mode 100644 index 0000000000..39ac7dc50c --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/SomeType.java @@ -0,0 +1,192 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class SomeType {
+ private String nullStringProp = null;
+ private String nonNullStringProp = "notnull";
+ private List<String> nonNullStringPropMany = Arrays.asList(new String[]{"test1", "test2"});
+ private List<String> nullStringPropMany = null;
+ private List<String> emptyStringPropMany = Collections.<String>emptyList();
+ private TypeWithoutId nullComplexNoIdNotInSelectClauseSingle = null;
+ private TypeWithoutId nonNullComplexNoIdNotInSelectClauseSingle = new TypeWithoutId();
+ private TypeWithoutId nullComplexNoIdInSelectClauseSingle = null;
+ private TypeWithoutId nonNullComplexNoIdInSelectClauseSingle = new TypeWithoutId();
+ private TypeWithId nullComplexIdNotInSelectClauseSingle = null;
+ private TypeWithId nonNullComplexIdNotInSelectClauseSingle = new TypeWithId(13235L);
+ private TypeWithId nullComplexIdInSelectClauseSingle = null;
+ private TypeWithId nonNullComplexIdInSelectClauseSingle = new TypeWithId(123123L);
+ private TypeWithId nonNullComplexIdInSelectClauseSingleIdIsNull = new TypeWithId(null);
+ private TypeWithId nonNullComplexIdNotInSelectClauseSingleIdIsNull = new TypeWithId(null);
+ private List<TypeWithoutId> nullComplexNoIdNotInSelectClauseMany = null;
+ private List<TypeWithoutId> nonNullComplexNoIdNotInSelectClauseMany = Arrays.asList(new TypeWithoutId[]{new TypeWithoutId(), new TypeWithoutId()});
+ private List<TypeWithoutId> nullComplexNoIdInSelectClauseMany = null;
+ private List<TypeWithoutId> nonNullComplexNoIdInSelectClauseMany = Arrays.asList(new TypeWithoutId[]{new TypeWithoutId(), new TypeWithoutId()});
+ private List<TypeWithId> nullComplexIdNotInSelectClauseMany = null;
+ private List<TypeWithId> nonNullComplexIdNotInSelectClauseMany = Arrays.asList(new TypeWithId[]{new TypeWithId(1L), new TypeWithId(2L)});
+ private List<TypeWithId> nullComplexIdInSelectClauseMany = null;
+ private List<TypeWithId> nonNullComplexIdInSelectClauseMany = Arrays.asList(new TypeWithId[]{new TypeWithId(3L), new TypeWithId(4L)});
+
+
+ private List<TypeWithoutId> emptyComplexNoIdNotInSelectClauseMany = Collections.<TypeWithoutId>emptyList();
+ private List<TypeWithoutId> emptyComplexNoIdInSelectClauseMany = Collections.<TypeWithoutId>emptyList();
+ private List<TypeWithId> emptyComplexIdNotInSelectClauseMany = Collections.<TypeWithId>emptyList();
+ private List<TypeWithId> emptyComplexIdInSelectClauseMany = Collections.<TypeWithId>emptyList();
+ public String getNullStringProp() {
+ return nullStringProp;
+ }
+ public void setNullStringProp(String nullStringProp) {
+ this.nullStringProp = nullStringProp;
+ }
+ public String getNonNullStringProp() {
+ return nonNullStringProp;
+ }
+ public void setNonNullStringProp(String nonNullStringProp) {
+ this.nonNullStringProp = nonNullStringProp;
+ }
+ public TypeWithoutId getNullComplexNoIdNotInSelectClauseSingle() {
+ return nullComplexNoIdNotInSelectClauseSingle;
+ }
+ public void setNullComplexNoIdNotInSelectClauseSingle(
+ TypeWithoutId nullComplexNoIdNotInSelectClauseSingle) {
+ this.nullComplexNoIdNotInSelectClauseSingle = nullComplexNoIdNotInSelectClauseSingle;
+ }
+ public TypeWithoutId getNonNullComplexNoIdNotInSelectClauseSingle() {
+ return nonNullComplexNoIdNotInSelectClauseSingle;
+ }
+ public void setNonNullComplexNoIdNotInSelectClauseSingle(
+ TypeWithoutId nonNullComplexNoIdNotInSelectClauseSingle) {
+ this.nonNullComplexNoIdNotInSelectClauseSingle = nonNullComplexNoIdNotInSelectClauseSingle;
+ }
+ public TypeWithoutId getNullComplexNoIdInSelectClauseSingle() {
+ return nullComplexNoIdInSelectClauseSingle;
+ }
+ public void setNullComplexNoIdInSelectClauseSingle(
+ TypeWithoutId nullComplexNoIdInSelectClauseSingle) {
+ this.nullComplexNoIdInSelectClauseSingle = nullComplexNoIdInSelectClauseSingle;
+ }
+ public TypeWithoutId getNonNullComplexNoIdInSelectClauseSingle() {
+ return nonNullComplexNoIdInSelectClauseSingle;
+ }
+ public void setNonNullComplexNoIdInSelectClauseSingle(
+ TypeWithoutId nonNullComplexNoIdInSelectClauseSingle) {
+ this.nonNullComplexNoIdInSelectClauseSingle = nonNullComplexNoIdInSelectClauseSingle;
+ }
+ public TypeWithId getNullComplexIdNotInSelectClauseSingle() {
+ return nullComplexIdNotInSelectClauseSingle;
+ }
+ public void setNullComplexIdNotInSelectClauseSingle(
+ TypeWithId nullComplexIdNotInSelectClauseSingle) {
+ this.nullComplexIdNotInSelectClauseSingle = nullComplexIdNotInSelectClauseSingle;
+ }
+ public TypeWithId getNonNullComplexIdNotInSelectClauseSingle() {
+ return nonNullComplexIdNotInSelectClauseSingle;
+ }
+ public void setNonNullComplexIdNotInSelectClauseSingle(
+ TypeWithId nonNullComplexIdNotInSelectClauseSingle) {
+ this.nonNullComplexIdNotInSelectClauseSingle = nonNullComplexIdNotInSelectClauseSingle;
+ }
+ public TypeWithId getNullComplexIdInSelectClauseSingle() {
+ return nullComplexIdInSelectClauseSingle;
+ }
+ public void setNullComplexIdInSelectClauseSingle(
+ TypeWithId nullComplexIdInSelectClauseSingle) {
+ this.nullComplexIdInSelectClauseSingle = nullComplexIdInSelectClauseSingle;
+ }
+ public TypeWithId getNonNullComplexIdInSelectClauseSingle() {
+ return nonNullComplexIdInSelectClauseSingle;
+ }
+ public void setNonNullComplexIdInSelectClauseSingle(
+ TypeWithId nonNullComplexIdInSelectClauseSingle) {
+ this.nonNullComplexIdInSelectClauseSingle = nonNullComplexIdInSelectClauseSingle;
+ }
+ public List<TypeWithoutId> getNullComplexNoIdNotInSelectClauseMany() {
+ return nullComplexNoIdNotInSelectClauseMany;
+ }
+ public void setNullComplexNoIdNotInSelectClauseMany(
+ List<TypeWithoutId> nullComplexNoIdNotInSelectClauseMany) {
+ this.nullComplexNoIdNotInSelectClauseMany = nullComplexNoIdNotInSelectClauseMany;
+ }
+ public List<TypeWithoutId> getNonNullComplexNoIdNotInSelectClauseMany() {
+ return nonNullComplexNoIdNotInSelectClauseMany;
+ }
+ public void setNonNullComplexNoIdNotInSelectClauseMany(
+ List<TypeWithoutId> nonNullComplexNoIdNotInSelectClauseMany) {
+ this.nonNullComplexNoIdNotInSelectClauseMany = nonNullComplexNoIdNotInSelectClauseMany;
+ }
+ public List<TypeWithoutId> getNullComplexNoIdInSelectClauseMany() {
+ return nullComplexNoIdInSelectClauseMany;
+ }
+ public void setNullComplexNoIdInSelectClauseMany(
+ List<TypeWithoutId> nullComplexNoIdInSelectClauseMany) {
+ this.nullComplexNoIdInSelectClauseMany = nullComplexNoIdInSelectClauseMany;
+ }
+ public List<TypeWithoutId> getNonNullComplexNoIdInSelectClauseMany() {
+ return nonNullComplexNoIdInSelectClauseMany;
+ }
+ public void setNonNullComplexNoIdInSelectClauseMany(
+ List<TypeWithoutId> nonNullComplexNoIdInSelectClauseMany) {
+ this.nonNullComplexNoIdInSelectClauseMany = nonNullComplexNoIdInSelectClauseMany;
+ }
+ public List<TypeWithId> getNullComplexIdNotInSelectClauseMany() {
+ return nullComplexIdNotInSelectClauseMany;
+ }
+ public void setNullComplexIdNotInSelectClauseMany(
+ List<TypeWithId> nullComplexIdNotInSelectClauseMany) {
+ this.nullComplexIdNotInSelectClauseMany = nullComplexIdNotInSelectClauseMany;
+ }
+ public List<TypeWithId> getNonNullComplexIdNotInSelectClauseMany() {
+ return nonNullComplexIdNotInSelectClauseMany;
+ }
+ public void setNonNullComplexIdNotInSelectClauseMany(
+ List<TypeWithId> nonNullComplexIdNotInSelectClauseMany) {
+ this.nonNullComplexIdNotInSelectClauseMany = nonNullComplexIdNotInSelectClauseMany;
+ }
+ public List<TypeWithId> getNullComplexIdInSelectClauseMany() {
+ return nullComplexIdInSelectClauseMany;
+ }
+ public void setNullComplexIdInSelectClauseMany(
+ List<TypeWithId> nullComplexIdInSelectClauseMany) {
+ this.nullComplexIdInSelectClauseMany = nullComplexIdInSelectClauseMany;
+ }
+ public List<TypeWithId> getNonNullComplexIdInSelectClauseMany() {
+ return nonNullComplexIdInSelectClauseMany;
+ }
+ public void setNonNullComplexIdInSelectClauseMany(
+ List<TypeWithId> nonNullComplexIdInSelectClauseMany) {
+ this.nonNullComplexIdInSelectClauseMany = nonNullComplexIdInSelectClauseMany;
+ }
+ public List<TypeWithoutId> getEmptyComplexNoIdNotInSelectClauseMany() {
+ return emptyComplexNoIdNotInSelectClauseMany;
+ }
+ public List<TypeWithoutId> getEmptyComplexNoIdInSelectClauseMany() {
+ return emptyComplexNoIdInSelectClauseMany;
+ }
+ public List<TypeWithId> getEmptyComplexIdNotInSelectClauseMany() {
+ return emptyComplexIdNotInSelectClauseMany;
+ }
+ public List<TypeWithId> getEmptyComplexIdInSelectClauseMany() {
+ return emptyComplexIdInSelectClauseMany;
+ }
+ public TypeWithId getNonNullComplexIdInSelectClauseSingleIdIsNull() {
+ return nonNullComplexIdInSelectClauseSingleIdIsNull;
+ }
+ public List<String> getNonNullStringPropMany() {
+ return nonNullStringPropMany;
+ }
+ public List<String> getNullStringPropMany() {
+ return nullStringPropMany;
+ }
+ public List<String> getEmptyStringPropMany() {
+ return emptyStringPropMany;
+ }
+ public TypeWithId getNonNullComplexIdNotInSelectClauseSingleIdIsNull() {
+ return nonNullComplexIdNotInSelectClauseSingleIdIsNull;
+ }
+ public void setNonNullComplexIdNotInSelectClauseSingleIdIsNull(
+ TypeWithId nonNullComplexIdNotInSelectClauseSingleIdIsNull) {
+ this.nonNullComplexIdNotInSelectClauseSingleIdIsNull = nonNullComplexIdNotInSelectClauseSingleIdIsNull;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestBulkProperties.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestBulkProperties.java new file mode 100644 index 0000000000..87a7fd6445 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestBulkProperties.java @@ -0,0 +1,292 @@ +package com.agfa.hap.sdo.test;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.DataMapper;
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.ReachableDefinition;
+import com.agfa.hap.sdo.SelectClause;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.SnapshotDefinition;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import com.agfa.hap.sdo.mapper.BeanPropertyAccessorBuilder;
+import com.agfa.hap.sdo.mapper.JavaBeanMapper;
+import com.agfa.hap.sdo.mapper.PartialDataObjectMapper;
+import com.agfa.hap.sdo.mapper.PropertyAccessor;
+import com.agfa.hap.sdo.mapper.TypeMapper;
+import commonj.sdo.DataObject;
+
+public class TestBulkProperties {
+
+ private Type typeA;
+ private Type typeB;
+ private JavaBeanMapper mapper;
+
+ private Collection<Object> bulkObjects;
+ private Collection<Property> bulkProperties;
+
+ @Before
+ public void defineTypes() {
+ TestXSDHelper.defineTestTypes();
+ typeA = TypeHelper.INSTANCE.getType(TestObjectSnapShot.class.getName(), "A");
+ typeB = TypeHelper.INSTANCE.getType(TestObjectSnapShot.class.getName(), "B");
+ TypeMapper typeMapper = new TypeMapper(new BeanPropertyAccessorBuilder() {
+ @Override
+ protected PropertyAccessor createPropertyAccessor(Class cls, Property prop) {
+ PropertyAccessor result = super.createPropertyAccessor(cls, prop);
+ return new TestBulkPropertyAccessor(prop, result);
+ }
+ });
+ typeMapper.register(A.class, typeA.getURI(), typeA.getName());
+ typeMapper.register(B.class, typeB.getURI(), typeB.getName());
+ mapper = new JavaBeanMapper(typeMapper);
+ }
+
+ @Before
+ public void clearBulkObjects() {
+ bulkObjects = new ArrayList<Object>();
+ bulkProperties = new ArrayList<Property>();
+ }
+
+ @Test
+ public void simpleBulkProperty() {
+ this.bulkProperties.add(typeA.getProperty("containedB"));
+ A a = new A();
+ a.setStringProp("test");
+ B b = new B();
+ a.setContainedB(b);
+ b.setName("b1");
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeA, "containedB"), a);
+ A copyA = (A) DataAccessService.getRootObject(mapper, s);
+ Assert.assertEquals(a.getStringProp(), copyA.getStringProp());
+ Assert.assertEquals(a.getContainedB().getName(), copyA.getContainedB().getName());
+ Assert.assertEquals(1, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(a));
+ }
+
+ @Test
+ @Ignore
+ public void simpleBulkPropertyReachableDefinition() throws URISyntaxException {
+ this.bulkProperties.add(typeA.getProperty("containedB"));
+ A a = new A();
+ a.setStringProp("test");
+ a.setLongProp(1L);
+ a.setShortProp((short)2);
+ a.setBooleanProp(true);
+ a.setDoubleProp(2.0d);
+ a.setByteProp((byte) 3);
+ a.setFloatProp(5.0f);
+ a.setUriProp(new URI(""));
+ a.setBytearrayProp(new byte[]{1,2,3});
+ a.setIntProp(7);
+ B b = new B();
+ a.setContainedB(b);
+ b.setName("b1");
+ Snapshot s = DataAccessService.createSnapShot(mapper, new ReachableDefinition(), a);
+ A copyA = (A) DataAccessService.getRootObject(mapper, s);
+ Assert.assertEquals(a.getStringProp(), copyA.getStringProp());
+ Assert.assertEquals(a.getContainedB().getName(), copyA.getContainedB().getName());
+ Assert.assertEquals(1, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(a));
+ }
+
+ @Test
+ public void subselectBulkSnapshot() {
+ this.bulkProperties.add(typeA.getProperty("containedB"));
+ A a = new A();
+ B b = new B();
+ a.setContainedB(b);
+ b.setParent(new B());
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeA, "containedB.parent"), a);
+ A copyA = (A) DataAccessService.getRootObject(mapper, s);
+ Assert.assertNotNull(copyA.getContainedB().getParent());
+ Assert.assertEquals(1, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(a));
+ }
+
+ @Test
+ public void multiBulkSnapshot() {
+ this.bulkProperties.add(typeB.getProperty("parent"));
+ B b = new B();
+ B child1 = new B();
+ b.getChildren().add(child1);
+ child1.setParent(b);
+ B child2 = new B();
+ b.getChildren().add(child2);
+ child2.setParent(b);
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeB, "children.parent"), b);
+ B copyB = (B) DataAccessService.getRootObject(mapper, s);
+ Assert.assertEquals(2, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(child1));
+ Assert.assertTrue(bulkObjects.contains(child2));
+ Assert.assertEquals(2, copyB.getChildren().size());
+ for (B copyChild : copyB.getChildren()) {
+ Assert.assertEquals(copyB, copyChild.getParent());
+ }
+ }
+
+ @Test
+ public void manyValuedBulkProperty() {
+ this.bulkProperties.add(typeB.getProperty("children"));
+ B b = new B();
+ B child = new B();
+ b.getChildren().add(child);
+ child.setParent(b);
+ child = new B();
+ b.getChildren().add(child);
+ child.setParent(b);
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeB, "children.parent"), b);
+ B copyB = (B) DataAccessService.getRootObject(mapper, s);
+ Assert.assertEquals(1, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(b));
+ Assert.assertEquals(2, copyB.getChildren().size());
+ for (B copyChild : copyB.getChildren()) {
+ Assert.assertEquals(copyB, copyChild.getParent());
+ }
+ }
+
+ @Test
+ public void manyValuedDataObjectBulkProperty() {
+ this.bulkProperties.add(typeB.getProperty("children"));
+ B b = new B();
+ B child = new B();
+ b.getChildren().add(child);
+ child.setParent(b);
+ child = new B();
+ b.getChildren().add(child);
+ child.setParent(b);
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeB, "children.parent"), b);
+ Assert.assertEquals(1, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(b));
+ DataObject copyB = DataAccessService.getRootObject(new PartialDataObjectMapper() {
+
+ @Override
+ public boolean isBulkProperty(Class clazz, Property property) {
+ return bulkProperties.contains(property);
+ }
+
+ }, s);
+ Assert.assertEquals(2, copyB.getList("children").size());
+ for (Object copyChild : copyB.getList("children")) {
+ Assert.assertEquals(copyB, ((DataObject) copyChild).get("parent"));
+ }
+ }
+
+ @Test
+ public void manyValuedEmptyDataObjectBulkProperty() {
+ this.bulkProperties.add(typeB.getProperty("children"));
+ B b = new B();
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeB, "children.parent"), b);
+ Assert.assertEquals(1, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(b));
+ DataObject copyB = DataAccessService.getRootObject(new PartialDataObjectMapper() {
+
+ @Override
+ public boolean isBulkProperty(Class clazz, Property property) {
+ return bulkProperties.contains(property);
+ }
+
+ }, s);
+ Assert.assertEquals(0, copyB.getList("children").size());
+ }
+
+ @Test
+ public void dataTypeBulkProperty(){
+ this.bulkProperties.add(typeA.getProperty("stringProp"));
+ A a = new A();
+ a.setStringProp("stringpropvalue");
+ A anotherA = new A();
+ anotherA.setStringProp("somevalue");
+ List<A> as = new ArrayList<A>();
+ as.add(a);
+ as.add(anotherA);
+ Snapshot s = DataAccessService.createMultiSnapShot(mapper, new SelectClause(typeA, ""), as);
+ A copyA = (A) DataAccessService.getRootObjects(mapper, s).get(0);
+ Assert.assertEquals(a.getStringProp(), copyA.getStringProp());
+ Assert.assertEquals(2, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(a));
+ }
+
+ private class TestBulkPropertyAccessor implements PropertyAccessor {
+ private PropertyAccessor delegate;
+ private Property property;
+
+ public TestBulkPropertyAccessor(Property property, PropertyAccessor delegate) {
+ this.delegate = delegate;
+ this.property = property;
+ }
+
+ public Object getValue(Object instance, Property property, DataMapper dataMapper) {
+ Assert.assertFalse(isBulkAccessor());
+ return delegate.getValue(instance, property, dataMapper);
+ }
+
+ public Collection<?> getValues(Collection<?> instances, Property property, SnapshotDefinition def, DataMapper dataMapper) {
+ Assert.assertTrue(isBulkAccessor());
+ List<Object> result = new ArrayList<Object>();
+ for (Object a : instances) {
+ result.add(delegate.getValue(a, property, dataMapper));
+ }
+ bulkObjects.addAll(instances);
+ return result;
+ }
+
+ public boolean isBulkAccessor() {
+ return bulkProperties.contains(property);
+ }
+
+ public void setValue(Object instance, Property property, Object value, DataMapper dataMapper) {
+ delegate.setValue(instance, property, value, dataMapper);
+ }
+
+ public String fetchJoinPropertyPath(Property property) {
+ return property.getName();
+ }
+
+ }
+
+ @Test
+ public void nestedBulkProperties(){
+ this.bulkProperties.add(typeA.getProperty("b"));
+ this.bulkProperties.add(typeB.getProperty("favouriteChild"));
+ A a = new A();
+ a.setStringProp("test");
+ B b = new B();
+ a.setB(b);
+ b.setName("b1");
+ B favB = new B();
+ favB.setName("favBName");
+ b.setFavouriteChild(favB);
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeA, "b.favouriteChild"), a);
+ A copyA = (A) DataAccessService.getRootObject(mapper, s);
+ Assert.assertEquals(a.getStringProp(), copyA.getStringProp());
+ Assert.assertEquals(a.getB().getName(), copyA.getB().getName());
+ Assert.assertEquals(a.getB().getFavouriteChild().getName(), copyA.getB().getFavouriteChild().getName());
+ Assert.assertEquals(2, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(a));
+ }
+
+ @Test
+ public void nulls(){
+ this.bulkProperties.add(typeA.getProperty("containedB"));
+ A a = new A();
+ B b = new B();
+ a.setContainedB(null);
+ Snapshot s = DataAccessService.createSnapShot(mapper, new SelectClause(typeA, "containedB"), a);
+ A copyA = (A) DataAccessService.getRootObject(mapper, s);
+ Assert.assertEquals(a.getContainedB(), copyA.getContainedB());
+ Assert.assertEquals(1, bulkObjects.size());
+ Assert.assertTrue(bulkObjects.contains(a));
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestDataObjectImpl.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestDataObjectImpl.java new file mode 100644 index 0000000000..dfe8003c06 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestDataObjectImpl.java @@ -0,0 +1,173 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.PartialDataFactory;
+import com.agfa.hap.sdo.PartialDataObject;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+
+
+public class TestDataObjectImpl {
+
+ private Type propertyType;
+ private Type typeType;
+
+
+ @Before
+ public void setUp() throws Exception {
+ propertyType = TypeHelper.INSTANCE.getType("commonj.sdo", "Property");
+ typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ }
+
+ @Test
+ public void testDataFactory() {
+ DataObject property = DataFactory.INSTANCE.create(propertyType);
+ property.createDataObject(propertyType.getProperty("type").getIndex());
+ Assert.assertNotNull(property.get("type"));
+ }
+
+ @Test
+ public void testRootObject() {
+ DataObject property = DataFactory.INSTANCE.create(propertyType);
+ Assert.assertEquals(property, property.getRootObject());
+ Assert.assertNull(property.getContainer());
+ DataObject typeProperty = property.createDataObject(propertyType.getProperty("type").getIndex());
+ Assert.assertNull(typeProperty.getContainer());
+ Assert.assertEquals(typeProperty, typeProperty.getRootObject());
+ DataObject childProperty = typeProperty.createDataObject("property", "commonj.sdo", "Property");
+ Assert.assertEquals(typeProperty, childProperty.getRootObject());
+ Assert.assertEquals(typeProperty, childProperty.getContainer());
+ }
+
+ @Test
+ public void testGetSetValue() {
+ DataObject property = DataFactory.INSTANCE.create(propertyType);
+ Assert.assertFalse(property.isSet("name"));
+ property.set("name", "test");
+ Assert.assertTrue(property.isSet("name"));
+ Assert.assertEquals("test", property.get("name"));
+ property.unset("name");
+ Assert.assertNull(property.get("name"));
+ Assert.assertFalse(property.isSet("name"));
+ }
+
+ @Test
+ public void testGetSetDataObjectValue() {
+ DataObject property = DataFactory.INSTANCE.create(propertyType);
+ DataObject type = property.createDataObject("type");
+ Assert.assertEquals(typeType, type.getType());
+ Assert.assertEquals(type, property.get("type"));
+ Assert.assertEquals(type, property.getDataObject("type"));
+ }
+
+ @Test
+ public void testGetSetListValue() {
+ TestXSDHelper.defineTestTypes();
+ PartialDataObject b = PartialDataFactory.INSTANCE.create(null, "B");
+ Assert.assertTrue(b.getList("children").isEmpty());
+ for (int i = 0; i < 5; i++) {
+ DataObject child = b.createDataObject("children");
+ child.set("name", Integer.toString(i));
+ DataObject odo = (DataObject) b.getList("children").get(i);
+ Assert.assertEquals(child, odo);
+ Assert.assertEquals(Integer.toString(i), odo.get("name"));
+ Assert.assertEquals(b, child.getContainer());
+ Assert.assertEquals(b.getType().getProperty("children"), child.getContainmentProperty());
+ }
+ }
+
+ @Test
+ public void changeList() {
+ TestXSDHelper.defineTestTypes();
+ PartialDataObject b = PartialDataFactory.INSTANCE.create(null, "B");
+ List<Object> children = b.getList("children");
+ PartialDataObject child = PartialDataFactory.INSTANCE.create(b.getType().getProperty("children").getType());
+ children.add(child);
+ Assert.assertEquals(b, child.get("parent"));
+ PartialDataObject child2 = b.createDataObject("children");
+ Assert.assertEquals(2, children.size());
+ Assert.assertTrue(children.remove(child2));
+ Assert.assertEquals(1, children.size());
+ children.set(0, child2);
+ Assert.assertEquals(b, child2.get("parent"));
+ Assert.assertNull(child.get("parent"));
+ Assert.assertEquals(1, children.size());
+ }
+
+ @Test
+ public void setList() {
+ TestXSDHelper.defineTestTypes();
+ PartialDataObject b = PartialDataFactory.INSTANCE.create(null, "B");
+ PartialDataObject child = b.createDataObject("children");
+ PartialDataObject child2 = PartialDataFactory.INSTANCE.create(child.getType());
+ List<Object> properties = new ArrayList<Object>();
+ properties.add(child2);
+ b.setList("children", properties);
+ Assert.assertEquals(b, child2.get("parent"));
+ Assert.assertEquals(1, properties.size());
+ Assert.assertNull(child.get("parent"));
+ }
+
+
+ @Test
+ public void testGetSetOpposite() {
+ TestXSDHelper.defineTestTypes();
+ PartialDataObject b = PartialDataFactory.INSTANCE.create(null, "B");
+ DataObject child = b.createDataObject("children");
+ Assert.assertEquals(b, child.get("parent"));
+ Iterator<PartialDataObject> it = b.getList("children").iterator();
+ Assert.assertTrue(it.hasNext());
+ Assert.assertEquals(child, it.next());
+ Assert.assertFalse(it.hasNext());
+ PartialDataObject b2 = PartialDataFactory.INSTANCE.create(null, "B");
+ Assert.assertTrue(b2.getList("children").isEmpty());
+ child.set("parent", b2);
+ Assert.assertEquals(b2, child.get("parent"));
+ it = b2.getList("children").iterator();
+ Assert.assertTrue(it.hasNext());
+ Assert.assertEquals(child, it.next());
+ Assert.assertFalse(it.hasNext());
+ Assert.assertTrue(b.getList("children").isEmpty());
+ }
+
+ @Test
+ public void testBasicDataTypes() {
+ TestXSDHelper.defineTestTypes();
+ Type typeA = TypeHelper.INSTANCE.getType(null, "A");
+ DataObject a = DataFactory.INSTANCE.create(typeA);
+ verifyGetSetValue(a, "intProp", 5);
+ verifyGetSetValue(a, "doubleProp", 1.5);
+ verifyGetSetValue(a, "stringProp", "Test");
+ verifyGetSetValue(a, "stringProp", null);
+ verifyGetSetValue(a, "shortProp", (short) 5);
+ verifyGetSetValue(a, "longProp", 5l);
+ verifyGetSetValue(a, "byteProp", (byte) 5l);
+ verifyGetSetValue(a, "floatProp", (float) 5.23);
+ }
+
+
+ private void verifyGetSetValue(DataObject a, String prop, Object value) {
+ a.set(prop, value);
+ Assert.assertEquals(value, a.get(prop));
+ }
+
+ @Test
+ public void testSpecializedClass() {
+ TestXSDHelper.defineTestTypes();
+ C c = (C) DataFactory.INSTANCE.create(null, "C");
+ c.setName("testje");
+ Assert.assertEquals("testje", c.getName());
+ Assert.assertEquals(c.getName(), c.get("name"));
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestDefineTypeWithDataObject.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestDefineTypeWithDataObject.java new file mode 100644 index 0000000000..427ecae7bd --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestDefineTypeWithDataObject.java @@ -0,0 +1,54 @@ +package com.agfa.hap.sdo.test;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.impl.TypeProvider;
+import com.agfa.hap.sdo.model.LongIdentity;
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+
+public class TestDefineTypeWithDataObject {
+
+ @Test
+ public void define(){
+ Type typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ DataObject testType = DataFactory.INSTANCE.create(typeType);
+ testType.set("name", "test77");
+ testType.set("uri", "unittest-7");
+ DataObject prop = testType.createDataObject("property");
+ prop.set("name", "test");
+ prop.set("type", testType);
+ prop = testType.createDataObject("property");
+ prop.set("name", "primaryKey");
+ DataObject longIdentityType = DataFactory.INSTANCE.create(typeType);
+ longIdentityType.set("name", LongIdentity.class.getName());
+ prop.set("type", longIdentityType);
+ testType.set("identityProperty", "primaryKey");
+ Type newType = TypeHelper.INSTANCE.define(testType);
+ Assert.assertNotNull(newType);
+ Assert.assertEquals("test77", newType.getName());
+ Assert.assertEquals("unittest-7", newType.getURI());
+ Type lookupType = TypeHelper.INSTANCE.getType("unittest-7", "test77");
+ Assert.assertNotNull(lookupType);
+ Assert.assertEquals(newType, lookupType);
+ }
+
+ @Before
+ public void setup() {
+ TypeProvider.setInstance(new TypeProvider(){
+ public String getTypes(String uri) {
+ return null;
+ }});
+ }
+
+ @After
+ public void teardown(){
+ TypeProvider.setInstance(null);
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestEmptySnapshot.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestEmptySnapshot.java new file mode 100644 index 0000000000..85e950e9ee --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestEmptySnapshot.java @@ -0,0 +1,18 @@ +package com.agfa.hap.sdo.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.implementation.SnapshotImplementation;
+
+public class TestEmptySnapshot {
+ @Test
+ public void empty(){
+ Snapshot emptySnapshot = SnapshotImplementation.emptySnapshot();
+ Assert.assertNotNull(emptySnapshot);
+ Assert.assertTrue(DataAccessService.getRootObjects(emptySnapshot).isEmpty());
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestEqualityHelper.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestEqualityHelper.java new file mode 100644 index 0000000000..b8a84b8cfd --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestEqualityHelper.java @@ -0,0 +1,76 @@ +package com.agfa.hap.sdo.test;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.TypeHelper;
+
+public class TestEqualityHelper{
+
+ private Type typeType;
+
+ @Before
+ public void setUp() throws Exception {
+ typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ }
+
+ @Test
+ public void testNullEquality() {
+ Assert.assertTrue(EqualityHelper.INSTANCE.equalShallow(null, null));
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(null, null));
+ DataObject instance = DataFactory.INSTANCE.create(typeType);
+ instance.set("name", "a");
+ instance.createDataObject("property");
+ Assert.assertFalse(EqualityHelper.INSTANCE.equalShallow(instance, null));
+ Assert.assertFalse(EqualityHelper.INSTANCE.equal(instance, null));
+ Assert.assertFalse(EqualityHelper.INSTANCE.equalShallow(null, instance));
+ Assert.assertFalse(EqualityHelper.INSTANCE.equal(null, instance));
+ }
+
+ @Test
+ public void testShallowEquality() {
+ DataObject a = DataFactory.INSTANCE.create(typeType);
+ a.set("name", "a");
+ DataObject b = DataFactory.INSTANCE.create(typeType);
+ b.set("name", "a");
+ Assert.assertTrue(EqualityHelper.INSTANCE.equalShallow(a,b));
+ b.set("name", "b");
+ Assert.assertFalse(EqualityHelper.INSTANCE.equalShallow(a,b));
+ b.set("name", "a");
+ Assert.assertTrue(EqualityHelper.INSTANCE.equalShallow(a,b));
+ b.set("dataType", true);
+ Assert.assertFalse(EqualityHelper.INSTANCE.equalShallow(a,b));
+ a.set("dataType", true);
+ Assert.assertTrue(EqualityHelper.INSTANCE.equalShallow(a,b));
+ b.createDataObject("property");
+ Assert.assertTrue(EqualityHelper.INSTANCE.equalShallow(a,b));
+ }
+
+ @Test
+ public void testEquality() {
+ DataObject a = DataFactory.INSTANCE.create(typeType);
+ a.set("name", "a");
+ DataObject b = DataFactory.INSTANCE.create(typeType);
+ b.set("name", "a");
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(a,b));
+ b.set("name", "b");
+ Assert.assertFalse(EqualityHelper.INSTANCE.equal(a,b));
+ b.set("name", "a");
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(a,b));
+ DataObject propB = b.createDataObject("property");
+ Assert.assertFalse(EqualityHelper.INSTANCE.equal(a,b));
+ DataObject propA = a.createDataObject("property");
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(a,b));
+ propB.set("name", "propB");
+ Assert.assertFalse(EqualityHelper.INSTANCE.equal(a,b));
+ propA.set("name", "propB");
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(a,b));
+ propA.set("name", "propA");
+ Assert.assertFalse(EqualityHelper.INSTANCE.equal(a,b));
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestObjectSnapShot.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestObjectSnapShot.java new file mode 100644 index 0000000000..e0a568d8f5 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestObjectSnapShot.java @@ -0,0 +1,148 @@ +package com.agfa.hap.sdo.test;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.PartialDataObject;
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.ReachableDefinition;
+import com.agfa.hap.sdo.SelectClause;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import com.agfa.hap.sdo.mapper.JavaBeanMapper;
+import com.agfa.hap.sdo.mapper.TypeMapper;
+import commonj.sdo.DataObject;
+
+public class TestObjectSnapShot{
+
+ private Type typeA;
+ private Type typeB;
+ private JavaBeanMapper mapper;
+
+
+ @Before
+ public void setUp() throws Exception {
+ TestXSDHelper.defineTestTypes();
+ typeA = TypeHelper.INSTANCE.getType(TestObjectSnapShot.class.getName(), "A");
+ typeB = TypeHelper.INSTANCE.getType(TestObjectSnapShot.class.getName(), "B");
+ TypeMapper typeMapper = new TypeMapper();
+ typeMapper.register(A.class, typeA.getURI(), typeA.getName());
+ typeMapper.register(B.class, typeB.getURI(), typeB.getName());
+ mapper = new JavaBeanMapper(typeMapper);
+ }
+
+ @Test
+ public void testObjectToDataObject() throws Exception {
+ A a = new A();
+ a.setStringProp("acc");
+ Snapshot s = DataAccessService.createSnapShot(mapper, new ReachableDefinition(), a);
+ Assert.assertNotNull(s);
+ DataObject dao = DataAccessService.getRootObject(s);
+ Assert.assertEquals(typeA, dao.getType());
+ Assert.assertEquals(a.getStringProp(), dao.get("stringProp"));
+ }
+
+ @Test
+ public void testComplexerObjectToDataObject() throws Exception {
+ A a = new A();
+ a.setStringProp("acc");
+ B b = new B();
+ a.setB(b);
+ B child = new B();
+ child.setName("ch1");
+ child.setParent(b);
+ b.getChildren().add(child);
+ child = new B();
+ child.setName("ch2");
+ child.setParent(b);
+ b.getChildren().add(child);
+ Snapshot s = DataAccessService.createSnapShot(mapper, new ReachableDefinition(), a);
+ Assert.assertNotNull(s);
+ DataObject dao = DataAccessService.getRootObject(s);
+ Assert.assertEquals(a.getStringProp(), dao.get("stringProp"));
+ dao = dao.getDataObject("b");
+ Assert.assertNotNull(dao);
+ Assert.assertEquals(b.getName(), dao.get("name"));
+ Assert.assertEquals(b.getChildren().size(), dao.getList("children").size());
+ for (int i = 0; i < b.getChildren().size(); i++) {
+ child = b.getChildren().get(i);
+ DataObject daoChild = (DataObject) dao.getList("children").get(i);
+ Assert.assertEquals(child.getName(), daoChild.get("name"));
+ Assert.assertTrue(dao == daoChild.get("parent"));
+ }
+ }
+
+ @Test
+ public void testDataObjectMap() {
+ B b = new B();
+ b.setName("test");
+ for (Property property : typeB.getProperties()) {
+ mapper.getProperty(b, property);
+ }
+ Assert.assertEquals(b.getName(), mapper.getProperty(b, typeB.getProperty("name")));
+ }
+
+ @Test
+ public void testInheritanceInDataObjectMap() {
+ Type typeInheritedB = TypeHelper.INSTANCE.getType(TestObjectSnapShot.class.getName(), "InheritedB");
+ mapper.getTypeMapper().register(InheritedB.class, typeInheritedB.getURI(), typeInheritedB.getName());
+ InheritedB b = new InheritedB();
+ b.setName("test");
+ b.setNickname("nick");
+ Assert.assertEquals(b.getName(), mapper.getProperty(b, typeB.getProperty("name")));
+ Assert.assertEquals(b.getNickname(), mapper.getProperty(b, typeInheritedB.getProperty("nickname")));
+ }
+
+ @Test
+ public void testObjectToObject() throws Exception {
+ B b = new B();
+ b.setName("child");
+ B parent = new B();
+ parent.setName("parent");
+ b.setParent(parent);
+ Snapshot s = DataAccessService.createSnapShot(mapper, new ReachableDefinition(), b);
+ Assert.assertNotNull(s);
+ B copy = (B) DataAccessService.getRootObject(mapper, s);
+ Assert.assertEquals(b.getName(), copy.getName());
+ Assert.assertEquals(b.getParent().getName(), copy.getParent().getName());
+ }
+
+ @Test
+ public void testRoundTrip() throws Exception {
+ B b = new B();
+ b.setName("parent");
+ B child = new B();
+ child.setName("child");
+ b.getChildren().add(child);
+ child.setParent(b);
+ Snapshot snapshot = DataAccessService.createSnapShot(mapper, new ReachableDefinition(), b);
+ B copy = (B) DataAccessService.getRootObject(mapper, snapshot);
+ Assert.assertFalse(b == copy);
+ Assert.assertEquals(b.getName(), copy.getName());
+ Assert.assertEquals(b.getChildren().size(), copy.getChildren().size());
+ Assert.assertEquals(b.getChildren().get(0).getName(), copy.getChildren().get(0).getName());
+ snapshot = DataAccessService.createSnapShot(mapper, new ReachableDefinition(), b);
+ PartialDataObject bAsDataObject = DataAccessService.getRootObject(snapshot);
+ Assert.assertEquals(b.getName(), bAsDataObject.get("name"));
+ snapshot = DataAccessService.createSnapShot(new ReachableDefinition(), bAsDataObject);
+ copy = (B) DataAccessService.getRootObject(mapper, snapshot);
+ Assert.assertFalse(b == copy);
+ Assert.assertEquals(b.getName(), copy.getName());
+ Assert.assertEquals(b.getChildren().size(), copy.getChildren().size());
+ Assert.assertEquals(b.getChildren().get(0).getName(), copy.getChildren().get(0).getName());
+ }
+
+ @Test
+ public void testOppositeProperty() {
+ B b = new B();
+ B child = new B();
+ b.getChildren().add(child);
+ child.setParent(b);
+ Snapshot snapshot = DataAccessService.createSnapShot(mapper, new SelectClause(typeB, "children"), b);
+ B copy = (B) DataAccessService.getRootObject(mapper, snapshot);
+ Assert.assertEquals(copy, copy.getChildren().get(0).getParent());
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestPartialDataObject.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestPartialDataObject.java new file mode 100644 index 0000000000..ab0ada436f --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestPartialDataObject.java @@ -0,0 +1,131 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.PartialDataFactory;
+import com.agfa.hap.sdo.PartialDataObject;
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.PropertyNotAvailableException;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.implementation.TypeImplementation;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+public class TestPartialDataObject{
+
+ private Type propertyType;
+ private commonj.sdo.Type typeType;
+ private Type bType;
+
+ @Before
+ public void setUp() throws Exception {
+ propertyType = (Type) TypeHelper.INSTANCE.getType("commonj.sdo", "Property");
+ typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ XSDHelper.INSTANCE.define(this.getClass().getResourceAsStream("/sdo/test-sdo-types.xsd"), "com.agfa.hap.rcp.sdo.test");
+ bType = (TypeImplementation) TypeHelper.INSTANCE.getType("com.agfa.hap.rcp.sdo.test", "B");
+ }
+
+ @Test
+ public void testPartialDataObject() {
+ PartialDataObject property = PartialDataFactory.INSTANCE.create(propertyType);
+ Assert.assertEquals(propertyType, property.getType());
+ Assert.assertTrue(propertyType.getProperties().size() > 0);
+ for (Property p : propertyType.getProperties()) {
+ Assert.assertTrue(property.isAvailable(p));
+ property.setUnavailable(p);
+ Assert.assertFalse(property.isAvailable(p));
+ try {
+ property.get(p);
+ Assert.fail("Should not be able to access partial properties");
+ } catch (PropertyNotAvailableException e) {
+ // ok;
+ }
+ property.set(p, null);
+ Assert.assertTrue(property.isAvailable(p));
+ Assert.assertNull(property.get(p));
+ }
+ }
+
+ @Test
+ public void testGetSetPartialListValue() {
+ PartialDataObject type = PartialDataFactory.INSTANCE.create(typeType);
+ type.setUnavailable(type.getType().getProperty("property"));
+ try {
+ type.getList("property");
+ Assert.fail("Should not be able to access partial prop");
+ } catch (PropertyNotAvailableException e) {
+ // ok
+ }
+ for (int i = 0; i < 5; i++) {
+ DataObject property = type.createDataObject("property");
+ property.set("name", Integer.toString(i));
+ DataObject odo = (DataObject) type.getList("property").get(i);
+ Assert.assertEquals(property, odo);
+ Assert.assertEquals(Integer.toString(i), odo.get("name"));
+ Assert.assertEquals(type, property.getContainer());
+ Assert.assertEquals(type.getType().getProperty("property"), property.getContainmentProperty());
+ }
+ }
+
+ @Test
+ public void testSetUnavailableList() {
+ PartialDataObject type = PartialDataFactory.INSTANCE.create(typeType);
+ type.setUnavailable(type.getType().getProperty("property"));
+ type.setList("property", Collections.emptyList());
+ Assert.assertTrue(type.isAvailable(type.getType().getProperty("property")));
+ Assert.assertEquals(0, type.getList("property").size());
+ }
+
+ @Test
+ public void linkWithUnavailableOpposite() {
+ PartialDataObject parent = PartialDataFactory.INSTANCE.create(bType);
+ parent.set("name", "parent");
+ parent.setUnavailable(bType.getProperty("children"));
+ PartialDataObject child = PartialDataFactory.INSTANCE.create(bType);
+ child.set("name", "child");
+ child.set("parent", parent);
+ Assert.assertEquals(parent, child.get("parent"));
+ Assert.assertFalse(parent.isAvailable(bType.getProperty("children")));
+ Assert.assertNull(child.getContainer());
+ child.set("parent", null);
+ Assert.assertNull(child.get("parent"));
+ Assert.assertFalse(parent.isAvailable(bType.getProperty("children")));
+ }
+
+ @Test
+ public void setListWhichWasUnavailable() {
+ PartialDataObject parent = PartialDataFactory.INSTANCE.create(bType);
+ parent.set("name", "parent");
+ Property childrenProperty = bType.getProperty("children");
+ parent.setUnavailable(childrenProperty);
+ PartialDataObject child = PartialDataFactory.INSTANCE.create(bType);
+ child.set("name", "child");
+ child.set("parent", parent);
+ List<Object> children = new ArrayList<Object>();
+ children.add(child);
+ parent.setList(childrenProperty, children);
+ Assert.assertTrue(parent.isAvailable(childrenProperty));
+ Assert.assertEquals(1, parent.getList(childrenProperty).size());
+ }
+
+ @Test
+ public void testProxy() {
+ TestXSDHelper.defineTestTypes();
+ PartialDataObject proxy = PartialDataFactory.INSTANCE.createProxy(null, "C", 5);
+ Assert.assertNotNull(proxy);
+ Assert.assertTrue(proxy.isProxy());
+ Assert.assertEquals(proxy.getIdentity(), 5);
+ for (Property p : proxy.getType().getProperties()) {
+ Assert.assertEquals(p == proxy.getType().getIdentityProperty(), proxy.isAvailable(p));
+ }
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestScanner.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestScanner.java new file mode 100644 index 0000000000..021d176800 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestScanner.java @@ -0,0 +1,23 @@ +package com.agfa.hap.sdo.test;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.helper.XsdScanner;
+import commonj.sdo.Type;
+import commonj.sdo.helper.TypeHelper;
+
+public class TestScanner {
+
+ @Test
+ @Ignore("Doesn't work yet with OSGI bundles")
+ public void scanner() throws IOException {
+ XsdScanner scanner = new XsdScanner(this.getClass().getClassLoader());
+ scanner.scanClassPath("sdo/scanner");
+ Type type = TypeHelper.INSTANCE.getType("com.agfa.hap.sdo.test.scanning", "Scanner");
+ Assert.assertNotNull(type);
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSelectClause.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSelectClause.java new file mode 100644 index 0000000000..d5990720ce --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSelectClause.java @@ -0,0 +1,147 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.ObjectPropertyVisitor;
+import com.agfa.hap.sdo.PartialDataFactory;
+import com.agfa.hap.sdo.PartialDataObject;
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.SelectClause;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.SnapshotDefinition;
+import com.agfa.hap.sdo.mapper.PartialDataObjectMapper;
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+
+public class TestSelectClause {
+
+ private Type typeType;
+
+
+ @Before
+ public void setUp() throws Exception {
+ typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ }
+
+ @Test
+ public void testPropertyTree() throws Exception {
+ SelectClause s = new SelectClause(typeType, "baseType");
+ TestVisitor visitor = new TestVisitor();
+ DataObject dataObject = DataFactory.INSTANCE.create(typeType);
+ dataObject.set("name", "test");
+ dataObject.getList("baseType").add(dataObject);
+ s.visit(new PartialDataObjectMapper(), visitor, (PartialDataObject) dataObject);
+ Assert.assertEquals(10, visitor.getResults().size());
+ Assert.assertEquals(dataObject, visitor.getResults().get(0));
+ Assert.assertEquals(dataObject.getType().getProperty("baseType"), visitor.getResults().get(1));
+ Assert.assertEquals(dataObject, visitor.getResults().get(2));
+ Assert.assertEquals(dataObject.getType().getProperty("baseType").getType().getProperty("baseType"), visitor.getResults().get(3));
+ Assert.assertEquals(dataObject.getType().getProperty("baseType").getType().getProperty("property"), visitor.getResults().get(4));
+ Assert.assertEquals(dataObject.get("name"), visitor.getResults().get(5));
+ Assert.assertEquals(dataObject, visitor.getResults().get(6));
+ Assert.assertEquals(dataObject.getType().getProperty("property"), visitor.getResults().get(7));
+ Assert.assertEquals(dataObject.get("name"), visitor.getResults().get(8));
+ Assert.assertEquals(dataObject, visitor.getResults().get(9));
+ }
+
+ @Test
+ public void asCommmaSeparatedString(){
+ SelectClause selectClause = new SelectClause(typeType, "baseType, property.opposite");
+ List<String> paths = Arrays.asList(selectClause.asCommaSeparatedString().split(","));
+ Assert.assertEquals(2,paths.size());
+ Assert.assertTrue(paths.contains("baseType"));
+ Assert.assertTrue(paths.contains("property.opposite"));
+ }
+
+ @Test
+ public void asCommmaSeparatedStringEmpty(){
+ SelectClause selectClause = new SelectClause(typeType, "");
+ Assert.assertEquals("",selectClause.asCommaSeparatedString());
+ }
+
+ @Test
+ public void testStarStar() throws Exception {
+ PartialDataObject dataObject = PartialDataFactory.INSTANCE.create(typeType);
+ dataObject.set("name", "X");
+ DataObject superDO = dataObject;
+ for (int i = 0; i < 5; i++) {
+ String name = (String) superDO.get("name");
+ superDO = superDO.createDataObject("baseType");
+ superDO.set("name", "super of " + name);
+ }
+ Snapshot s = DataAccessService.createSnapShot(new SelectClause(typeType, "baseType.**"), dataObject);
+ PartialDataObject copy = DataAccessService.getRootObject(s);
+ for (int i = 0; i < 5; i++) {
+ dataObject = (PartialDataObject) dataObject.getList("baseType").get(0);
+ copy = (PartialDataObject) copy.getList("baseType").get(0);
+ Assert.assertEquals(dataObject.get("name"), copy.get("name"));
+ }
+ }
+
+ @Test
+ public void testStar() throws Exception {
+ PartialDataObject dataObject = PartialDataFactory.INSTANCE.create(typeType);
+ dataObject.set("name", "X");
+ DataObject superDO = dataObject;
+ for (int i = 0; i < 5; i++) {
+ String name = (String) superDO.get("name");
+ superDO = superDO.createDataObject("baseType");
+ superDO.set("name", "super of " + name);
+ }
+ Snapshot s = DataAccessService.createSnapShot(new SelectClause(typeType, "baseType.baseType.*"), dataObject);
+ PartialDataObject copy = DataAccessService.getRootObject(s);
+ for (int i = 0; i < 3; i++) {
+ dataObject = (PartialDataObject) dataObject.getList("baseType").get(0);
+ copy = (PartialDataObject) copy.getList("baseType").get(0);
+ Assert.assertEquals(dataObject.get("name"), copy.get("name"));
+ }
+ Assert.assertFalse(copy.isAvailable(copy.getType().getProperty("baseType")));
+ }
+
+ private static class TestVisitor implements ObjectPropertyVisitor {
+
+ private List<Object> results = new ArrayList<Object>();
+ private List<Object> bulkProperties = new ArrayList<Object>();
+
+ public List<Object> getResults() {
+ return results;
+ }
+
+ public void endDataObject(Object instance, com.agfa.hap.sdo.Type type) throws Exception {
+ results.add(instance);
+ }
+
+ public void startDataObject(Object instance, com.agfa.hap.sdo.Type type) throws Exception {
+ results.add(instance);
+ }
+
+ public void visitProxyProperty(Object instance, com.agfa.hap.sdo.Property property, Object identity) throws Exception {
+ results.add(property);
+ }
+
+ public boolean visitProperty(Object instance, com.agfa.hap.sdo.Property property, Object value) throws Exception {
+ if (property.getType().isDataType()) {
+ results.add(value);
+ return false;
+ }
+ results.add(property);
+ return true;
+ }
+
+ public void visitBulkProperty(Object instance, Property property, SnapshotDefinition subselect) {
+ this.bulkProperties.add(instance);
+ }
+
+
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSelectClauseSnapshotSerialization.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSelectClauseSnapshotSerialization.java new file mode 100644 index 0000000000..e27fa72180 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSelectClauseSnapshotSerialization.java @@ -0,0 +1,129 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.PartialDataObject;
+import com.agfa.hap.sdo.SelectClause;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.mapper.JavaBeanMapper;
+import com.agfa.hap.sdo.mapper.TypeMapper;
+import commonj.sdo.Type;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+public class TestSelectClauseSnapshotSerialization {
+ @Before
+ public void setup(){
+ XSDHelper.INSTANCE.define(TestSelectClauseSnapshotSerialization.class.getResourceAsStream("/sdo/test-sdo-selectclause.xsd"), null);
+ }
+
+ @Test
+ public void test(){
+ Type someType = TypeHelper.INSTANCE.getType("com.agfa.hap.sdo.test.selectclause", "SomeType");
+ SomeType sourceObject = new SomeType();
+
+ SelectClause selectClause = new SelectClause(someType, "nullComplexNoIdInSelectClauseSingle,nullComplexIdNotInSelectClauseSingle," +
+ "nullComplexIdInSelectClauseSingle,nonNullComplexNoIdInSelectClauseSingle,nonNullComplexIdInSelectClauseSingle,nullComplexNoIdInSelectClauseMany," +
+ "nonNullComplexNoIdInSelectClauseMany,nullComplexIdInSelectClauseMany,nonNullComplexIdInSelectClauseMany," +
+ "nonNullComplexIdInSelectClauseSingleIdIsNull, emptyComplexNoIdInSelectClauseMany, " +
+ "emptyComplexIdInSelectClauseMany");
+
+
+ TypeMapper typeMapper = new TypeMapper();
+ typeMapper.register(SomeType.class, "com.agfa.hap.sdo.test.selectclause", "SomeType");
+ typeMapper.register(TypeWithId.class, "com.agfa.hap.sdo.test.selectclause", "TypeWithId");
+ typeMapper.register(TypeWithoutId.class, "com.agfa.hap.sdo.test.selectclause", "TypeWithoutId");
+ Snapshot snapshot = DataAccessService.createSnapShot(new JavaBeanMapper(typeMapper), selectClause, sourceObject);
+ PartialDataObject target = DataAccessService.getRootObject(snapshot);
+ Assert.assertNotNull(target);
+
+ Assert.assertNull(target.get("nullStringProp"));
+
+ Assert.assertNotNull(target.get("nonNullStringProp"));
+
+ Assert.assertNotNull(target.get("nonNullStringPropMany"));
+ Assert.assertEquals("test2", target.getList("nonNullStringPropMany").get(1));
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nullStringPropMany")));
+ Assert.assertTrue(target.getList("nullStringPropMany").isEmpty());
+
+ Assert.assertNotNull(target.get("emptyStringPropMany"));
+ Assert.assertTrue(target.isAvailable(someType.getProperty("emptyStringPropMany")));
+ Assert.assertTrue(target.getList("emptyStringPropMany").isEmpty());
+
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("nullComplexNoIdNotInSelectClauseSingle")));
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("nonNullComplexNoIdNotInSelectClauseSingle")));
+
+ Assert.assertNull(target.get("nullComplexNoIdInSelectClauseSingle"));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nonNullComplexNoIdInSelectClauseSingle")));
+ Assert.assertNotNull(target.get("nonNullComplexNoIdInSelectClauseSingle"));
+
+ Assert.assertNull(target.get("nullComplexIdNotInSelectClauseSingle"));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nonNullComplexIdNotInSelectClauseSingle")));
+ Assert.assertNotNull(target.get("nonNullComplexIdNotInSelectClauseSingle"));
+ Assert.assertTrue(((PartialDataObject) target.get("nonNullComplexIdNotInSelectClauseSingle")).isProxy());
+
+ Assert.assertNull(target.get("nullComplexIdInSelectClauseSingle"));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nonNullComplexIdInSelectClauseSingle")));
+ Assert.assertNotNull(target.get("nonNullComplexIdInSelectClauseSingle"));
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("nullComplexNoIdNotInSelectClauseMany")));
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("nonNullComplexNoIdNotInSelectClauseMany")));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nullComplexNoIdInSelectClauseMany")));
+ Assert.assertNotNull("many valued props in sdo are never null SDO_2.1_DRAFT_20060726.pdf p18 par 2",
+ target.get("nullComplexNoIdInSelectClauseMany"));
+ Assert.assertTrue(((List) target.get("nullComplexNoIdInSelectClauseMany")).isEmpty());
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nonNullComplexNoIdInSelectClauseMany")));
+ Assert.assertNotNull(target.get("nonNullComplexNoIdInSelectClauseMany"));
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("nullComplexIdNotInSelectClauseMany")));
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("nonNullComplexIdNotInSelectClauseMany")));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nullComplexIdInSelectClauseMany")));
+ Assert.assertNotNull(target.get("nullComplexIdInSelectClauseMany"));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("nonNullComplexIdInSelectClauseMany")));
+ Assert.assertNotNull("many valued props in sdo are never null SDO_2.1_DRAFT_20060726.pdf p18 par 2",
+ target.get("nullComplexIdInSelectClauseMany"));
+ Assert.assertTrue(((List) target.get("nullComplexIdInSelectClauseMany")).isEmpty());
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("emptyComplexNoIdNotInSelectClauseMany")));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("emptyComplexNoIdInSelectClauseMany")));
+ Assert.assertNotNull("many valued props in sdo are never null SDO_2.1_DRAFT_20060726.pdf p18 par 2",
+ target.get("emptyComplexNoIdInSelectClauseMany"));
+ Assert.assertTrue(((List) target.get("emptyComplexNoIdInSelectClauseMany")).isEmpty());
+
+ Assert.assertFalse(target.isAvailable(someType.getProperty("emptyComplexIdNotInSelectClauseMany")));
+
+ Assert.assertTrue(target.isAvailable(someType.getProperty("emptyComplexIdInSelectClauseMany")));
+ Assert.assertNotNull("many valued props in sdo are never null SDO_2.1_DRAFT_20060726.pdf p18 par 2",
+ target.get("emptyComplexIdInSelectClauseMany"));
+ Assert.assertTrue(((List) target.get("emptyComplexIdInSelectClauseMany")).isEmpty());
+
+ Assert.assertNotNull("you could argue that since the id is null it doesn't actually exists, but that " +
+ "is not the way it currently works, so we expect it to be in the snapshot",
+ target.get("nonNullComplexIdInSelectClauseSingleIdIsNull"));
+
+ Assert.assertFalse("you could argue that since the id is null it doesn't actually exists and so" +
+ " it should be null in the snapshot, " +
+ "but that is not the way it currently works, so we expect it to be unavailable in the snapshot." +
+ " (in agility ris otherwise problems with ProcedureDefinitionType of qdoc requestedprocedures)",
+ target.isAvailable(someType.getProperty("nonNullComplexIdNotInSelectClauseSingleIdIsNull")));
+
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSerialization.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSerialization.java new file mode 100644 index 0000000000..7d44d439a0 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSerialization.java @@ -0,0 +1,76 @@ +package com.agfa.hap.sdo.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.TypeHelper;
+
+public class TestSerialization{
+ @Test
+ public void testBasicSerialization() {
+ validate(DataObjectCreator.createSimpleDataObject());
+ }
+
+ @Test
+ public void testListSerialization() {
+ validate(DataObjectCreator.createDataObjectWithManyValuedProperty());
+ }
+
+ void validate(DataObject original) {
+ DataObject copy = copy(original);
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(copy, original));
+ }
+
+ @Test
+ public void testBasicDataTypes() throws Exception {
+ TestXSDHelper.defineTestTypes();
+ Type typeA = TypeHelper.INSTANCE.getType("null", "A");
+ DataObject a = DataFactory.INSTANCE.create(typeA);
+ a.set("intProp", 5);
+ a.set("doubleProp", 1.5);
+ a.set("shortProp", (short) 5);
+ a.set("longProp", 5l);
+ a.set("stringProp", "Test");
+ a.set("uriProp", new URI("http://www.google.be/"));
+ a.set("bytearrayProp", new byte[]{-1,2,3,4,5});
+ validate(a);
+ }
+
+ @Test
+ public void testSdoRef() {
+ DataObject dataObject = DataObjectCreator.createSimpleDataObject();
+ DataObject prop1 = dataObject.createDataObject("property");
+ prop1.set("name", "prop1");
+ prop1.set("type", dataObject);
+ DataObject prop2 = dataObject.createDataObject("property");
+ prop2.set("name", "prop2");
+ prop2.set("opposite", prop1);
+ validate(dataObject);
+ }
+
+ DataObject copy(DataObject original) {
+ try {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(os);
+ oos.writeObject(original);
+ oos.close();
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(os.toByteArray()));
+ return (DataObject) ois.readObject();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSnapshot.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSnapshot.java new file mode 100644 index 0000000000..aa609b9e34 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSnapshot.java @@ -0,0 +1,194 @@ +package com.agfa.hap.sdo.test;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.PartialDataFactory;
+import com.agfa.hap.sdo.PartialDataObject;
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.PropertyNotAvailableException;
+import com.agfa.hap.sdo.ReachableDefinition;
+import com.agfa.hap.sdo.SelectClause;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import com.agfa.hap.sdo.implementation.SdoImplementationException;
+import com.agfa.hap.sdo.implementation.TypeImplementation;
+import com.agfa.hap.sdo.mapper.PartialDataObjectMapper;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.XSDHelper;
+
+public class TestSnapshot{
+
+ private Type typeType;
+ private Type bType;
+
+ @Before
+ public void setUp() throws Exception {
+ typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ XSDHelper.INSTANCE.define(this.getClass().getResourceAsStream("/sdo/test-sdo-types.xsd"), "com.agfa.hap.rcp.sdo.test");
+ bType = (TypeImplementation) TypeHelper.INSTANCE.getType("com.agfa.hap.rcp.sdo.test", "B");
+ }
+
+ @Test
+ public void testSnapshot() {
+ PartialDataObject type = PartialDataFactory.INSTANCE.create(typeType);
+ type.set("name", "test");
+ type.getList("baseType").add(type);
+ type.createDataObject("property");
+ Snapshot snapshot = DataAccessService.createSnapShot(new SelectClause(typeType, "baseType"), type);
+ snapshot = SdoTestUtil.marshallUnmarshal(snapshot);
+ PartialDataObject copy = DataAccessService.getRootObject(snapshot);
+ Assert.assertTrue(copy.isAvailable(typeType.getProperty("baseType")));
+ Assert.assertTrue(copy.isAvailable(typeType.getProperty("name")));
+ Assert.assertTrue(copy.isAvailable(typeType.getProperty("dataType")));
+ Assert.assertFalse(copy.isAvailable(typeType.getProperty("property")));
+ try {
+ copy.get("property");
+ Assert.fail("Should not be able to access property");
+ } catch (PropertyNotAvailableException e) {
+ // ok;
+ }
+ Assert.assertEquals(copy.getList("baseType").get(0), copy);
+ Assert.assertEquals(copy.get("name"), type.get("name"));
+ }
+
+ @Test
+ public void testManyInSnapshot() {
+ PartialDataObject type = PartialDataFactory.INSTANCE.create(typeType);
+ type.set("name", "test");
+ type.createDataObject("property").set("name", "prop1");
+ type.createDataObject("property").set("name", "prop2");
+ Snapshot snapshot = DataAccessService.createSnapShot(new SelectClause(typeType, "property"), type);
+ snapshot = SdoTestUtil.marshallUnmarshal(snapshot);
+ PartialDataObject copy = DataAccessService.getRootObject(snapshot);
+ Assert.assertEquals(type.get("name"), copy.get("name"));
+ Assert.assertEquals(2, copy.getList("property").size());
+ for (int i = 0; i < 2; i++) {
+ Assert.assertEquals(((DataObject) type.getList("property").get(i)).get("name"), ((DataObject) copy.getList("property").get(i)).get("name"));
+ }
+ }
+
+ @Test
+ public void testMultiSnapshot(){
+ PartialDataObject testType1 = PartialDataFactory.INSTANCE.create(typeType);
+ testType1.set("name", "test1");
+ testType1.getList("baseType").add(testType1);
+ PartialDataObject testType2 = PartialDataFactory.INSTANCE.create(typeType);
+ testType2.set("name", "test2");
+ testType2.getList("baseType").add(testType2);
+ Collection<PartialDataObject> dataObjects = new ArrayList<PartialDataObject>();
+ dataObjects.add(testType1);
+ dataObjects.add(testType2);
+ Snapshot snapshot = DataAccessService.createMultiSnapShot(new PartialDataObjectMapper(), new SelectClause(typeType, "name, baseType"), dataObjects);
+ Snapshot marshalledSnapshot = SdoTestUtil.marshallUnmarshal(snapshot);
+ List<PartialDataObject> rootObjects = DataAccessService.getRootObjects(marshalledSnapshot);
+ Assert.assertNotNull(rootObjects);
+ Assert.assertFalse(rootObjects == DataAccessService.getRootObjects(marshalledSnapshot));
+ Assert.assertEquals("test1", rootObjects.get(0).get("name"));
+ Assert.assertEquals("test2", rootObjects.get(1).get("name"));
+ try {
+ DataAccessService.getRootObject(marshalledSnapshot);
+ } catch (RuntimeException e){
+ return;
+ }
+ Assert.fail("calling getRootObject() on a snapshot with more than 1 rootobject should throw an exception");
+ }
+
+ @Test
+ public void testCompleteSnapshot() throws Exception {
+ PartialDataObject dataObject = PartialDataFactory.INSTANCE.create(typeType);
+ dataObject.set("name", "test");
+ SelectClause s = new SelectClause(typeType, "*");
+ Snapshot snapshot = DataAccessService.createSnapShot(s, dataObject);
+ PartialDataObject copy = DataAccessService.getRootObject(snapshot);
+ for (Property p : dataObject.getType().getProperties()) {
+ Assert.assertTrue(copy.isAvailable(p));
+ Assert.assertEquals(dataObject.get(p), copy.get(p));
+ }
+ }
+
+ @Test
+ public void testPartialSnapshot() throws Exception {
+ C c = new C();
+ c.setName("test");
+ C peer = new C();
+ peer.setName("peer");
+ peer.setIdentity(new URI("test"));
+ c.set("peer", peer);
+ Snapshot snapshot = DataAccessService.createSnapShot(new SelectClause(c.getType()), c);
+ PartialDataObject copy = DataAccessService.getRootObject(snapshot);
+ Assert.assertEquals(c.getName(), copy.get("name"));
+ Assert.assertTrue(((PartialDataObject) copy.get("peer")).isProxy());
+ Assert.assertEquals(peer.getIdentity(), copy.getDataObject("peer").getIdentity());
+ }
+
+ @Test
+ public void testPartialProxySnapshot() throws Exception {
+ C c = new C();
+ c.setName("test");
+ C peer = new C();
+ peer.setName("peer");
+ c.set("peer", peer);
+ Snapshot snapshot = DataAccessService.createSnapShot(new SelectClause(c.getType()), c);
+ PartialDataObject copy = DataAccessService.getRootObject(snapshot);
+ Assert.assertEquals(c.getName(), copy.get("name"));
+ Assert.assertFalse(copy.isAvailable(copy.getType().getProperty("peer")));
+ }
+
+ @Test
+ public void testProxySnapshot() throws Exception {
+ C c = new C();
+ c.setName("test");
+ c.set("peer", PartialDataFactory.INSTANCE.createProxy(c.getType(), new URI("test")));
+ try {
+ DataAccessService.createSnapShot(new SelectClause(c.getType(), "peer"), c);
+ } catch (SdoImplementationException e) {
+ // ok
+ }
+ Snapshot snapshot = DataAccessService.createSnapShot(new ReachableDefinition(), c);
+ PartialDataObject copy = DataAccessService.getRootObject(snapshot);
+ Assert.assertTrue(((PartialDataObject) copy.get("peer")).isProxy());
+ }
+
+ @Test
+ public void bidirectionalParentLinkInSnapshot() throws Exception {
+ PartialDataObject main = PartialDataFactory.INSTANCE.create(bType);
+ main.set("name", "parent");
+ PartialDataObject child1 = main.createDataObject("children");
+ child1.set("name", "child1");
+ PartialDataObject child2 = main.createDataObject("children");
+ child2.set("name", "child2");
+ List<PartialDataObject> children = new ArrayList<PartialDataObject>();
+ children.add(child1);
+ children.add(child2);
+ Snapshot snapshot = DataAccessService.createMultiSnapShot(new SelectClause(bType, "parent"), children);
+ children = DataAccessService.getRootObjects(snapshot);
+ Assert.assertEquals(2, children.size());
+ Assert.assertEquals(child1.get("name"), children.get(0).get("name"));
+ Assert.assertEquals(child2.get("name"), children.get(1).get("name"));
+ Assert.assertTrue(children.get(0).get("parent") == children.get(1).get("parent"));
+ Assert.assertEquals(main.get("name"), children.get(0).getDataObject("parent").getString("name"));
+ }
+
+ @Test
+ public void testCustomConverters() {
+ TestXSDHelper.defineBasicTestTypes();
+ Type typeBO = TypeHelper.INSTANCE.getType("com.agfa.ris.common.test.basic", "BasicObject");
+ PartialDataObject bo = PartialDataFactory.INSTANCE.create(typeBO);
+ bo.set("enum", ExampleEnum.TWO);
+ bo.set("serializable", new SerializableBasicObject(5));
+ bo.set("custom", MyBasicObject.THREE);
+ Snapshot s = DataAccessService.createSnapShot(new ReachableDefinition(), bo);
+ PartialDataObject copy = DataAccessService.getRootObject(s);
+ org.junit.Assert.assertTrue(EqualityHelper.INSTANCE.equal(bo, copy));
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSnapshotUnion.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSnapshotUnion.java new file mode 100644 index 0000000000..31e8c34039 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestSnapshotUnion.java @@ -0,0 +1,54 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.DataAccessService;
+import com.agfa.hap.sdo.PartialDataFactory;
+import com.agfa.hap.sdo.PartialDataObject;
+import com.agfa.hap.sdo.SelectClause;
+import com.agfa.hap.sdo.Snapshot;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import com.agfa.hap.sdo.implementation.SnapshotUnion;
+
+public class TestSnapshotUnion{
+
+ private Type typeType;
+
+ @Before
+ public void setUp() throws Exception {
+ typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ }
+
+ @Test
+ public void testUnion(){
+ PartialDataObject typeInFirstSnapshot = PartialDataFactory.INSTANCE.create(typeType);
+ typeInFirstSnapshot.set("name", "test1");
+ typeInFirstSnapshot.getList("baseType").add(typeInFirstSnapshot);
+ typeInFirstSnapshot.createDataObject("property");
+ Snapshot firstSnapshot = DataAccessService.createSnapShot(new SelectClause(typeType, "baseType"), typeInFirstSnapshot);
+ PartialDataObject typeInSecondSnapshot = PartialDataFactory.INSTANCE.create(typeType);
+ typeInSecondSnapshot.set("name", "test2");
+ typeInSecondSnapshot.getList("baseType").add(typeInSecondSnapshot);
+ typeInSecondSnapshot.createDataObject("property");
+ Snapshot secondSnapshot = DataAccessService.createSnapShot(new SelectClause(typeType, "baseType"), typeInSecondSnapshot);
+ Snapshot union = new SnapshotUnion(firstSnapshot, secondSnapshot);
+
+ Snapshot receivedSnapshot = SdoTestUtil.marshallUnmarshal(union);
+ List<PartialDataObject> receivedObjects= DataAccessService.getRootObjects(receivedSnapshot);
+ Assert.assertEquals(2, receivedObjects.size());
+ PartialDataObject firstObj = receivedObjects.get(0);
+ Assert.assertEquals("Type", firstObj.getType().getName());
+ Assert.assertEquals("test1", firstObj.get(typeType.getProperty("name")));
+
+ PartialDataObject secondObj = receivedObjects.get(1);
+ Assert.assertEquals("Type", secondObj.getType().getName());
+ Assert.assertEquals("test2", secondObj.get(typeType.getProperty("name")));
+ }
+
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestTypeHelper.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestTypeHelper.java new file mode 100644 index 0000000000..ed3dbdd93a --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestTypeHelper.java @@ -0,0 +1,124 @@ +package com.agfa.hap.sdo.test;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.DataFactory;
+
+public class TestTypeHelper{
+ @Test
+ public void testBasicTypes() {
+ Type type = TypeHelper.INSTANCE.getType("commonj", "String");
+ Assert.assertEquals("String", type.getName());
+ Assert.assertTrue(type.isDataType());
+ Assert.assertEquals(String.class, type.getInstanceClass());
+ }
+
+ @Test
+ public void testObjectType() {
+ Type type = TypeHelper.INSTANCE.getType("commonj", "Object");
+ Assert.assertEquals("Object", type.getName());
+ Assert.assertTrue(type.isDataType());
+ Assert.assertEquals(Object.class, type.getInstanceClass());
+ }
+
+ @Test
+ public void testMetaTypes() {
+ Type propertyType = TypeHelper.INSTANCE.getType("commonj.sdo", "Property");
+ Assert.assertNotNull(propertyType);
+ Type typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ Assert.assertNotNull(typeType);
+ Assert.assertEquals("Property", propertyType.getName());
+ Assert.assertEquals("commonj.sdo", propertyType.getURI());
+ Assert.assertFalse(propertyType.isDataType());
+ List<Property> properties = propertyType.getProperties();
+ Assert.assertEquals(8, properties.size());
+ for (int i = 0; i < properties.size(); i++) {
+ Assert.assertEquals(propertyType.getProperty(i), properties.get(i));
+ Assert.assertEquals(propertyType.getProperty(properties.get(i).getName()), properties.get(i));
+ Assert.assertEquals(propertyType, propertyType.getProperty(i).getContainingType());
+ }
+ Property nameProp = propertyType.getProperty("name");
+ Assert.assertEquals("name", nameProp.getName());
+ Assert.assertFalse(nameProp.isContainment());
+ Assert.assertFalse(nameProp.isMany());
+ Assert.assertTrue(nameProp.getType().isDataType());
+ Assert.assertFalse(propertyType.getProperty("type").getType().isDataType());
+ }
+
+ @Test
+ public void testImplementationClass() {
+ C c = new C();
+ Type typeC = TypeHelper.INSTANCE.getType(C.class);
+ Assert.assertEquals(typeC, c.getType());
+ }
+
+ @Test
+ public void testContainment() {
+ Type propertyType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ Assert.assertTrue(propertyType.getProperty("property").isContainment());
+ }
+
+// public void testOpposite() {
+// Type propertyType = TypeHelper.INSTANCE.getType("commonj.sdo", "Property");
+// Property propertyTypeProp = propertyType.getProperty("type");
+// Type typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+// Property typePropertiesProp = typeType.getProperty("property");
+// Assert.assertEquals(propertyTypeProp, typePropertiesProp.getOpposite());
+// Assert.assertEquals(typePropertiesProp, propertyTypeProp.getOpposite());
+// }
+
+ @SuppressWarnings("unchecked")
+ public void testDefineType() {
+ Type typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ DataObject stringType = DataFactory.INSTANCE.create(typeType);
+ stringType.set("name", "String");
+ stringType.set("uri", "commonj");
+ DataObject xType = DataFactory.INSTANCE.create(typeType);
+ xType.set("name", "X");
+ xType.set("uri", "test");
+ DataObject prop = xType.createDataObject("property");
+ prop.set("name", "prop1");
+ prop.set("type", xType);
+ prop = xType.createDataObject("property");
+ prop.set("name", "prop2");
+ prop.set("type", stringType);
+ List<DataObject> types = new ArrayList<DataObject>();
+ types.add(stringType);
+ types.add(xType);
+ List<Type> result = TypeHelper.INSTANCE.define(types);
+ Assert.assertEquals(2, result.size());
+ Assert.assertEquals(TypeHelper.INSTANCE.getType(String.class), result.get(0));
+ Assert.assertEquals(TypeHelper.INSTANCE.getType("test", "X"), result.get(1));
+ DataObject x = DataFactory.INSTANCE.create("test", "X");
+ x.set("prop2", "blabla");
+ Assert.assertEquals("X", x.createDataObject("prop1").getType().getName());
+ }
+
+ public void testIdentifierProperty() {
+ Type typeType = TypeHelper.INSTANCE.getType("commonj.sdo", "Type");
+ DataObject uriType = DataFactory.INSTANCE.create(typeType);
+ uriType.set("name", URI.class.getName());
+ DataObject testType = DataFactory.INSTANCE.create(typeType);
+ testType.set("name", "test");
+ testType.set("uri", "test");
+ DataObject prop = testType.createDataObject("property");
+ prop.set("name", "test");
+ prop.set("type", testType);
+ prop = testType.createDataObject("property");
+ prop.set("name", "uri");
+ prop.set("type", uriType);
+ testType.set("identityProperty", "uri");
+ Type sdoTestType = (Type) TypeHelper.INSTANCE.define(testType);
+ Assert.assertNotNull(sdoTestType.getIdentityProperty());
+ Assert.assertEquals(sdoTestType.getProperty("uri"), sdoTestType.getIdentityProperty());
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXMLHelper.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXMLHelper.java new file mode 100644 index 0000000000..27c98213f2 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXMLHelper.java @@ -0,0 +1,144 @@ +package com.agfa.hap.sdo.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import commonj.sdo.DataObject;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.XMLDocument;
+import commonj.sdo.helper.XMLHelper;
+
+public class TestXMLHelper{
+
+ @Test
+ public void testToXml() {
+ String xml = XMLHelper.INSTANCE.save(DataObjectCreator.createSimpleDataObject(), "com.agfa.ris/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ Assert.assertTrue(xml.indexOf("<test") > 0);
+ Assert.assertTrue(xml.indexOf("<name>") > 0);
+ Assert.assertTrue(xml.indexOf("<dataType>") > 0);
+ }
+
+ @Test
+ public void testManyValuedToXml() {
+ DataObject root = DataObjectCreator.createDataObjectWithManyValuedProperty();
+ String xml = XMLHelper.INSTANCE.save(root, "com.agfa.ris/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ Assert.assertTrue(xml.indexOf("<test") > 0);
+ int index = xml.indexOf("<property>");
+ Assert.assertTrue(index > 0);
+ Assert.assertTrue(xml.indexOf("<property>", index) > 0);
+ }
+
+ @Test
+ public void testFromXml() {
+ DataObject original = DataObjectCreator.createDataObjectWithManyValuedProperty();
+ String xml = XMLHelper.INSTANCE.save(original, original.getType().getURI(), "test");
+ Assert.assertNotNull(xml);
+ XMLDocument doc = XMLHelper.INSTANCE.load(xml);
+ Assert.assertEquals(original.getType().getURI(), doc.getRootElementURI());
+ Assert.assertEquals("test", doc.getRootElementName());
+ DataObject copy = doc.getRootObject();
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(original, copy));
+ }
+
+ @Test
+ public void testSdoRef() {
+ DataObject dataObject = DataObjectCreator.createSimpleDataObject();
+ DataObject prop1 = dataObject.createDataObject("property");
+ prop1.set("name", "prop1");
+ prop1.set("type", dataObject);
+ DataObject prop2 = dataObject.createDataObject("property");
+ prop2.set("name", "prop2");
+ prop2.set("opposite", prop1);
+ String xml = XMLHelper.INSTANCE.save(dataObject, "com.agfa.ris/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ Assert.assertTrue(xml.indexOf("sdo:ref") > 0);
+ XMLDocument doc = XMLHelper.INSTANCE.load(xml);
+ DataObject copy = doc.getRootObject();
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(dataObject, copy));
+ }
+
+ @Test
+ public void testSubobjectFromXml() {
+ DataObject original = DataObjectCreator.createSimpleDataObject();
+ String xml = XMLHelper.INSTANCE.save(original, "com.agfa.ris.common/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ XMLDocument doc = XMLHelper.INSTANCE.load(xml);
+ Assert.assertEquals("com.agfa.ris.common/sdo/test", doc.getRootElementURI());
+ Assert.assertEquals("test", doc.getRootElementName());
+ DataObject copy = doc.getRootObject();
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(original, copy));
+ }
+
+ @Test
+ public void testNullValue() {
+ DataObject original = DataObjectCreator.createSimpleDataObject();
+ Assert.assertTrue(original.isSet("name"));
+ original.set("name", null);
+ // Assert.assertTrue(original.isSet("name"));
+ Assert.assertNull(original.get("name"));
+ String xml = XMLHelper.INSTANCE.save(original, "com.agfa.ris.common/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ XMLDocument doc = XMLHelper.INSTANCE.load(xml);
+ DataObject copy = doc.getRootObject();
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(original, copy));
+ }
+
+ @Test
+ public void testBasicDataTypes() {
+ TestXSDHelper.defineTestTypes();
+ Type typeA = TypeHelper.INSTANCE.getType("null", "A");
+ DataObject original = DataFactory.INSTANCE.create(typeA);
+ original.set("intProp", 5);
+ original.set("doubleProp", 1.5);
+ original.set("stringProp", "Test");
+ original.set("shortProp", (short) 5);
+ original.set("longProp", 5l);
+ original.set("byteProp", (byte) 5l);
+ original.set("floatProp", (float) 3.143);
+ String xml = XMLHelper.INSTANCE.save(original, "com.agfa.ris.common/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ XMLDocument doc = XMLHelper.INSTANCE.load(xml);
+ DataObject copy = doc.getRootObject();
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(original, copy));
+ }
+
+ @Test
+ public void testCustomConverters() {
+ TestXSDHelper.defineBasicTestTypes();
+ Type typeBO = TypeHelper.INSTANCE.getType("com.agfa.ris.common.test.basic", "BasicObject");
+ DataObject bo = DataFactory.INSTANCE.create(typeBO);
+ bo.set("enum", ExampleEnum.TWO);
+ bo.set("serializable", new SerializableBasicObject(5));
+ bo.set("custom", MyBasicObject.THREE);
+ String xml = XMLHelper.INSTANCE.save(bo, "com.agfa.ris.common/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ XMLDocument doc = XMLHelper.INSTANCE.load(xml);
+ DataObject copy = doc.getRootObject();
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(bo, copy));
+ }
+
+ @Test
+ public void polymorphLink() {
+ TestXSDHelper.defineBasicTestTypes();
+ Type typeA = TypeHelper.INSTANCE.getType("com.agfa.ris.common.test.basic", "A");
+ DataObject bo = DataFactory.INSTANCE.create(typeA);
+ DataObject b = bo.createDataObject("containedB", "com.agfa.ris.common.test.basic", "InheritedB");
+ b.set("nickname", "ikke");
+ String xml = XMLHelper.INSTANCE.save(bo, "com.agfa.ris.common/sdo/test", "test");
+ Assert.assertNotNull(xml);
+ XMLDocument doc = XMLHelper.INSTANCE.load(xml);
+ DataObject copy = doc.getRootObject();
+ Assert.assertTrue(EqualityHelper.INSTANCE.equal(bo, copy));
+ }
+
+ @Test
+ public void correctNamespaceFirstType() {
+ String xml = XMLHelper.INSTANCE.save(DataObjectCreator.createSimpleDataObject(), "bla", "test");
+ Assert.assertTrue(xml.contains("sdo:Type"));
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXSDHelper.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXSDHelper.java new file mode 100644 index 0000000000..e9dab24620 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXSDHelper.java @@ -0,0 +1,179 @@ +package com.agfa.hap.sdo.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.Property;
+import com.agfa.hap.sdo.Type;
+import com.agfa.hap.sdo.helper.TypeHelper;
+import com.agfa.hap.sdo.impl.EnumTypeConverter;
+import com.agfa.hap.sdo.impl.SerializableTypeConverter;
+import com.agfa.hap.sdo.impl.TypeConverter;
+import com.agfa.hap.sdo.implementation.PropertyImplementation;
+import com.agfa.hap.sdo.implementation.TypeImplementation;
+import commonj.sdo.helper.XSDHelper;
+
+public class TestXSDHelper{
+
+ private static final String TESTURI = "com.agfa.hap.sdo.test";
+
+ public static void defineTestTypes() {
+ XSDHelper.INSTANCE.define(TestXSDHelper.class.getResourceAsStream("/sdo/test-sdo-types.xsd"), null);
+ }
+
+ public static void defineBasicTestTypes() {
+ XSDHelper.INSTANCE.define(TestXSDHelper.class.getClassLoader().getResourceAsStream("sdo/test-sdo-basictypes.xsd"), null);
+ }
+
+
+ @Before
+ public void setUp() throws Exception {
+ defineTestTypes();
+ }
+
+ @Test
+ public void testMultipleDefinition() {
+ Type typeA = TypeHelper.INSTANCE.getType(TESTURI, "A");
+ int count = typeA.getProperties().size();
+ defineTestTypes();
+ Assert.assertEquals(count, typeA.getProperties().size());
+ }
+
+ @Test
+ public void testRead() {
+ Type typeA = TypeHelper.INSTANCE.getType(TESTURI, "A");
+ Assert.assertNotNull(typeA);
+ Assert.assertEquals("String", typeA.getProperty("stringProp").getType().getName());
+ Assert.assertFalse(typeA.getProperty("stringProp").isMany());
+ Assert.assertFalse(typeA.getProperty("b").isContainment());
+ Assert.assertTrue(typeA.getProperty("containedB").isContainment());
+ Type typeB = typeA.getProperty("b").getType();
+ Assert.assertEquals("B", typeB.getName());
+ Assert.assertEquals(4, typeB.getProperties().size());
+ Assert.assertTrue(typeB.getProperty("children").isMany());
+ Assert.assertEquals(typeB, typeB.getProperty("children").getType());
+ Type typeD = TypeHelper.INSTANCE.getType(TESTURI, "E");
+ Assert.assertEquals("B", typeD.getProperty(0).getType().getName());
+
+ Type typeF = TypeHelper.INSTANCE.getType(TESTURI, "F");
+ Assert.assertNotNull(typeF);
+ Property manyStringsProp = typeF.getProperty("manyStringsProp");
+ Assert.assertTrue(manyStringsProp.isMany());
+ Assert.assertEquals("String", manyStringsProp.getType().getName());
+ Assert.assertEquals("commonj.sdo", manyStringsProp.getType().getURI());
+ }
+
+ @Test
+ public void testOppositeProperty() {
+ Type typeB = TypeHelper.INSTANCE.getType(TESTURI, "B");
+ Assert.assertNotNull(typeB.getProperty("parent"));
+ Assert.assertEquals(typeB.getProperty("parent"), typeB.getProperty("children").getOpposite());
+ Assert.assertEquals(typeB.getProperty("children"), typeB.getProperty("parent").getOpposite());
+ }
+
+ @Test
+ public void testSdoRef() {
+ Type typeB = TypeHelper.INSTANCE.getType(TESTURI, "B");
+ Property property = typeB.getProperty("favouriteChild");
+ Assert.assertNotNull(property);
+ Assert.assertEquals(typeB, property.getType());
+ Assert.assertFalse(property.isContainment());
+ }
+
+ @Test
+ public void testGenerate(){
+ List<Type> types = new ArrayList<Type>();
+ Type stringType = TypeHelper.INSTANCE.getType(String.class);
+ TypeImplementation typeF = new TypeImplementation("someotheruri", "testtypeF");
+ typeF.addProperty("someprop", stringType);
+ TypeImplementation typeE = new TypeImplementation("testuri", "testtypeE");
+ typeE.addProperty("yetanotherprop", stringType);
+ typeE.addProperty("fProp", typeF);
+ TypeImplementation typeD = new TypeImplementation("testuri", "testtypeD");
+ typeD.setBaseType(typeF);
+ typeD.normalizeTypeHierarchy();
+ typeD.addProperty("stringProp", stringType);
+ Type intType = new TypeImplementation(java.lang.Integer.class);
+ typeD.addProperty("intProp", intType);
+ PropertyImplementation manyProp = typeD.addProperty("manyprop", intType);
+ manyProp.setIsMany(true);
+ typeD.addProperty("eProp", typeE);
+ types.add(typeD);
+ String xsd = XSDHelper.INSTANCE.generate(types);
+ Assert.assertNotNull(xsd);
+ Assert.assertTrue(xsd.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
+ "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" targetNamespace=\"testuri\" xmlns:sdo=\"commonj.sdo/xml\" " +
+ "xmlns:sdoJava=\"commonj.sdo/java\" xmlns:agfaSdo=\"com.agfa.ris/sdo\" " +
+ "xmlns:tns=\"testuri\" xmlns:ns1=\"someotheruri\""));
+ Assert.assertTrue(xsd.contains("<xsd:complexType name=\"testtypeE\">\r\n" +
+ "<xsd:attribute name=\"yetanotherprop\" sdo:readOnly=\"false\" type=\"xsd:string\"/>\r\n" +
+ "<xsd:attribute name=\"fProp\" sdo:readOnly=\"false\" type=\"xsd:anyURI\" sdo:propertyType=\"ns1:testtypeF\"/>\r\n" +
+ "</xsd:complexType>"));
+ Assert.assertTrue(xsd.contains("<xsd:complexType name=\"testtypeD\">\r\n" +
+ "<xsd:complexContent>\r\n" +
+ "<xsd:extension base=\"ns1:testtypeF\"/>\r\n" +
+ "</xsd:complexContent>\r\n" +
+ "<xsd:choice maxOccurs=\"unbounded\">\r\n" +
+ "<xsd:element name=\"manyprop\" sdo:readOnly=\"false\" maxOccurs=\"unbounded\" type=\"xsd:int\"/>\r\n" +
+ "</xsd:choice>\r\n" +
+ "<xsd:attribute name=\"stringProp\" sdo:readOnly=\"false\" type=\"xsd:string\"/>\r\n" +
+ "<xsd:attribute name=\"intProp\" sdo:readOnly=\"false\" type=\"xsd:int\"/>\r\n" +
+ "<xsd:attribute name=\"eProp\" sdo:readOnly=\"false\" type=\"xsd:anyURI\" sdo:propertyType=\"tns:testtypeE\"/>\r\n" +
+ "</xsd:complexType>"));
+ Assert.assertEquals("the list will be expanded to include all types generated", 2, types.size());
+ }
+
+ @Test
+ public void testIdProperty() {
+ Type typeC = TypeHelper.INSTANCE.getType(TESTURI, "C");
+ Assert.assertNotNull(typeC.getIdentityProperty());
+ Assert.assertEquals(typeC.getProperty("uri"), typeC.getIdentityProperty());
+ }
+
+ @Test
+ public void testOppositePropertyDefinedAsAttribute() {
+ Type typeC = TypeHelper.INSTANCE.getType(TESTURI, "C");
+ Property p = typeC.getProperty("peer");
+ Assert.assertNotNull(p);
+ Assert.assertEquals(p, p.getOpposite());
+ }
+
+ @Test
+ public void testInheritance() {
+ Type typeInheritedB = TypeHelper.INSTANCE.getType(TESTURI, "InheritedB");
+ Type typeB = TypeHelper.INSTANCE.getType(TESTURI, "B");
+ Assert.assertEquals(1, typeInheritedB.getBaseTypes().size());
+ Assert.assertEquals(typeB, typeInheritedB.getBaseTypes().get(0));
+ Assert.assertEquals(typeB.getProperty("name"), typeInheritedB.getProperty("name"));
+ Assert.assertNotNull(typeInheritedB.getProperty("nickname"));
+ Assert.assertNull(typeB.getProperty("nickname"));
+ for (int i = 0; i < typeB.getProperties().size(); i++) {
+ Assert.assertEquals(typeB.getProperty(i), typeInheritedB.getProperty(i));
+ }
+ Assert.assertEquals(1, typeInheritedB.getDeclaredProperties().size());
+ Assert.assertEquals(1 + typeB.getProperties().size(), typeInheritedB.getProperties().size());
+ }
+
+ @Test
+ public void testBasicTypes() {
+ defineBasicTestTypes();
+ checkBasicType(MyBasicObject.class, MyBasicObjectTypeConverter.class);
+ checkBasicType(ExampleEnum.class, EnumTypeConverter.class);
+ checkBasicType(SerializableBasicObject.class, SerializableTypeConverter.class);
+ }
+
+ private void checkBasicType(Class clazz, Class converterClass) {
+ Type type = TypeHelper.INSTANCE.getType(clazz);
+ Assert.assertNotNull(type);
+ Assert.assertEquals("com.agfa.sdo.common.test.basic", type.getURI());
+ int index = clazz.getName().lastIndexOf('.');
+ Assert.assertEquals(clazz.getName().substring(index+1), type.getName());
+ Assert.assertTrue(type.isDataType());
+ Assert.assertEquals(clazz, type.getInstanceClass());
+ Assert.assertEquals(converterClass, TypeConverter.get(type).getClass());
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXsdHelperMultipleURI.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXsdHelperMultipleURI.java new file mode 100644 index 0000000000..cac868bf50 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TestXsdHelperMultipleURI.java @@ -0,0 +1,33 @@ +package com.agfa.hap.sdo.test;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.agfa.hap.sdo.Type;
+
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XSDHelper;
+
+
+public class TestXsdHelperMultipleURI {
+
+ @Test
+ public void multipleXsdsReferencingEatchOther(){
+ XSDHelper.INSTANCE.define(TestXSDHelper.class.getResourceAsStream("/sdo/test-sdo-types1.xsd"), null);
+ XSDHelper.INSTANCE.define(TestXSDHelper.class.getResourceAsStream("/sdo/test-sdo-types2.xsd"), null);
+ Type a1Type = (Type) TypeHelper.INSTANCE.getType("com.agfa.hap.sdo.test1", "A1");
+ Assert.assertEquals(2, a1Type.getProperties().size());
+ Type b2Type = (Type) TypeHelper.INSTANCE.getType("com.agfa.hap.sdo.test2", "B2");
+ Assert.assertEquals(2, b2Type.getProperties().size());
+ }
+
+ @Test
+ public void forwardReference(){
+ XSDHelper.INSTANCE.define(TestXSDHelper.class.getResourceAsStream("/sdo/test-sdo-types-forward.xsd"), null);
+ Type aType = (Type) TypeHelper.INSTANCE.getType("com.agfa.hap.sdo.test.forward", "Af");
+ Assert.assertEquals(2, aType.getProperties().size());
+ Type bType = (Type) TypeHelper.INSTANCE.getType("com.agfa.hap.sdo.forward", "Bf");
+ Assert.assertEquals(2, bType.getProperties().size());
+ }
+
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TypeWithId.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TypeWithId.java new file mode 100644 index 0000000000..cbccf0fe1f --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TypeWithId.java @@ -0,0 +1,26 @@ +package com.agfa.hap.sdo.test;
+
+public class TypeWithId {
+ public TypeWithId(Long id){
+ this.id = id;
+ }
+
+ private Long id;
+ private String stringProp;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getStringProp() {
+ return stringProp;
+ }
+
+ public void setStringProp(String stringProp) {
+ this.stringProp = stringProp;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TypeWithoutId.java b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TypeWithoutId.java new file mode 100644 index 0000000000..e2ca7b6a2c --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/java/com/agfa/hap/sdo/test/TypeWithoutId.java @@ -0,0 +1,13 @@ +package com.agfa.hap.sdo.test;
+
+public class TypeWithoutId {
+ private String stringProp;
+
+ public String getStringProp() {
+ return stringProp;
+ }
+
+ public void setStringProp(String stringProp) {
+ this.stringProp = stringProp;
+ }
+}
diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo-propertyaccessors.properties b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo-propertyaccessors.properties new file mode 100644 index 0000000000..8308679698 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo-propertyaccessors.properties @@ -0,0 +1 @@ +com.agfa.hap.sdo.mapper.Super.superProperty=com.agfa.hap.sdo.mapper.DummyPropertyAccessor
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/implementationclasses.properties b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/implementationclasses.properties new file mode 100644 index 0000000000..f1aa15b116 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/implementationclasses.properties @@ -0,0 +1 @@ +com.agfa.hap.sdo.test.C=com.agfa.hap.sdo.test$C
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/scanner/scan-types.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/scanner/scan-types.xsd new file mode 100644 index 0000000000..27dd4afd79 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/scanner/scan-types.xsd @@ -0,0 +1,12 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.hap.sdo.test.scanning" xmlns:tns="com.agfa.hap.sdo.test.scanning">
+
+<xsd:element name="scanner" type="tns:Scanner"/>
+<xsd:complexType name="Scanner">
+ <xsd:sequence>
+ <xsd:element name="stringProp" type="xsd:string" minOccurs="0"/>
+ </xsd:sequence>
+</xsd:complexType>
+
+</xsd:schema>
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-basictypes.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-basictypes.xsd new file mode 100644 index 0000000000..acf12da5fb --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-basictypes.xsd @@ -0,0 +1,25 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.sdo.common.test.basic" xmlns:tns="com.agfa.sdo.common.test.basic" xmlns:agfaSdoJava="com.agfa.ris/sdo">
+
+<xsd:element name="a" type="tns:BasicObject"/>
+<xsd:complexType name="BasicObject">
+ <xsd:attribute name="enum" type="tns:ExampleEnum" />
+ <xsd:attribute name="serializable" type="tns:SerializableBasicObject" />
+ <xsd:attribute name="custom" type="tns:MyBasicObject" />
+</xsd:complexType>
+
+<xsd:simpleType name="ExampleEnum" sdoJava:instanceClass="com.agfa.hap.sdo.test.ExampleEnum">
+ <xsd:restriction base="xsd:string" />
+</xsd:simpleType>
+
+<xsd:simpleType name="SerializableBasicObject" sdoJava:instanceClass="com.agfa.hap.sdo.test.SerializableBasicObject">
+ <xsd:restriction base="xsd:string" />
+</xsd:simpleType>
+
+<xsd:simpleType name="MyBasicObject" sdoJava:instanceClass="com.agfa.hap.sdo.test.MyBasicObject" agfaSdoJava:typeConverter="com.agfa.hap.sdo.test.MyBasicObjectTypeConverter">
+ <xsd:restriction base="xsd:string" />
+</xsd:simpleType>
+
+
+</xsd:schema>
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-selectclause.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-selectclause.xsd new file mode 100644 index 0000000000..f1c0b1c305 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-selectclause.xsd @@ -0,0 +1,45 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.hap.sdo.test.selectclause" xmlns:tns="com.agfa.hap.sdo.test.selectclause">
+
+<xsd:complexType name="SomeType">
+ <xsd:attribute name="nullStringProp" type="xsd:string"/>
+ <xsd:attribute name="nonNullStringProp" type="xsd:string"/>
+ <xsd:attribute name="nonNullStringPropMany" type="xsd:string" maxOccurs="unbounded"/>
+ <xsd:attribute name="nullStringPropMany" type="xsd:string" maxOccurs="unbounded"/>
+ <xsd:attribute name="emptyStringPropMany" type="xsd:string" maxOccurs="unbounded"/>
+ <xsd:attribute name="nullComplexNoIdNotInSelectClauseSingle" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nonNullComplexNoIdNotInSelectClauseSingle" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nullComplexNoIdInSelectClauseSingle" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nonNullComplexNoIdInSelectClauseSingle" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nullComplexIdNotInSelectClauseSingle" type="tns:TypeWithId"/>
+ <xsd:attribute name="nonNullComplexIdNotInSelectClauseSingle" type="tns:TypeWithId"/>
+ <xsd:attribute name="nullComplexIdInSelectClauseSingle" type="tns:TypeWithId"/>
+ <xsd:attribute name="nonNullComplexIdInSelectClauseSingle" type="tns:TypeWithId"/>
+ <xsd:attribute name="nonNullComplexIdInSelectClauseSingleIdIsNull" type="tns:TypeWithId"/>
+ <xsd:attribute name="nonNullComplexIdNotInSelectClauseSingleIdIsNull" type="tns:TypeWithId"/>
+ <xsd:attribute name="nullComplexNoIdNotInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nonNullComplexNoIdNotInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nullComplexNoIdInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nonNullComplexNoIdInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="nullComplexIdNotInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithId"/>
+ <xsd:attribute name="nonNullComplexIdNotInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithId"/>
+ <xsd:attribute name="nullComplexIdInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithId"/>
+ <xsd:attribute name="nonNullComplexIdInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithId"/>
+
+ <xsd:attribute name="emptyComplexNoIdNotInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="emptyComplexNoIdInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithoutId"/>
+ <xsd:attribute name="emptyComplexIdNotInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithId"/>
+ <xsd:attribute name="emptyComplexIdInSelectClauseMany" maxOccurs="unbounded" type="tns:TypeWithId"/>
+</xsd:complexType>
+
+<xsd:complexType name="TypeWithId" identityProperty="id">
+ <xsd:attribute name="id" type="xsd:long"/>
+ <xsd:attribute name="stringProp" type="xsd:string"/>
+</xsd:complexType>
+
+<xsd:complexType name="TypeWithoutId">
+ <xsd:attribute name="stringProp" type="xsd:string"/>
+</xsd:complexType>
+
+</xsd:schema>
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types-forward.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types-forward.xsd new file mode 100644 index 0000000000..3ac75352a5 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types-forward.xsd @@ -0,0 +1,18 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.hap.sdo.test.forward" xmlns:tns="com.agfa.hap.sdo.test.forward">
+
+<xsd:complexType name="Af">
+ <xsd:sequence>
+ <xsd:element name="bs" type="tns:Bf" sdo:readOlny="false" maxOccurs="unbounded" sdo:oppositeProperty="a"/>
+ </xsd:sequence>
+ <xsd:attribute name="anotherProperty" type="xsd:int"/>
+</xsd:complexType>
+
+<xsd:complexType name="Bf">
+ <xsd:attribute name="a" type="xsd:anyURI" sdo:propertyType="tns:Af"/>
+ <xsd:attribute name="someProperty" type="xsd:int"/>
+</xsd:complexType>
+
+
+</xsd:schema>
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types.xsd new file mode 100644 index 0000000000..b277996d04 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types.xsd @@ -0,0 +1,64 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.hap.sdo.test" xmlns:tns="com.agfa.hap.sdo.test">
+
+<xsd:element name="a" type="tns:A"/>
+<xsd:complexType name="A">
+ <xsd:sequence>
+ <xsd:element name="stringProp" type="xsd:string" minOccurs="0"/>
+ <xsd:element name="intProp" type="xsd:int" minOccurs="0"/>
+ <xsd:element name="b" type="xsd:anyURI" sdo:propertyType="tns:B"/>
+ <xsd:element name="containedB" type="tns:B"/>
+ </xsd:sequence>
+ <xsd:attribute name="longProp" type="xsd:long" />
+ <xsd:attribute name="shortProp" type="xsd:short" />
+ <xsd:attribute name="booleanProp" type="xsd:boolean" />
+ <xsd:attribute name="doubleProp" type="xsd:double" />
+ <xsd:attribute name="byteProp" type="xsd:byte" />
+ <xsd:attribute name="floatProp" type="xsd:float" />
+ <xsd:attribute name="uriProp" sdoJava:instanceClass="java.net.URI" />
+ <xsd:attribute name="bytearrayProp" type="xsd:hexBinary"/>
+</xsd:complexType>
+
+<xsd:complexType name="B">
+ <xsd:sequence>
+ <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+ <xsd:element name="children" type="tns:B" minOccurs="0" maxOccurs="unbounded" sdo:oppositeProperty="parent"/>
+ <xsd:element name="favouriteChild" type="xsd:anyURI" sdo:propertyType="tns:B" minOccurs="0" />
+ </xsd:sequence>
+</xsd:complexType>
+
+<xsd:complexType name="InheritedB">
+ <xsd:complexContent>
+ <xsd:extension base="tns:B">
+ <xsd:sequence>
+ <xsd:element name="nickname" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ </xsd:extension>
+ </xsd:complexContent>
+</xsd:complexType>
+
+<xsd:complexType name="C" identityProperty="uri">
+ <xsd:sequence>
+ <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+ </xsd:sequence>
+ <xsd:attribute name="uri" type="xsd:anyURI" />
+ <xsd:attribute name="peer" sdo:readOnly="false" type="xsd:anyURI" sdo:propertyType="tns:C" sdo:oppositeProperty="peer"/>
+</xsd:complexType>
+
+<xsd:complexType name="D">
+ <xsd:attribute name="forwardRef" sdo:readOnly="false" type="xsd:anyURI" sdo:propertyType="tns:E"/>
+</xsd:complexType>
+
+<xsd:complexType name="E">
+ <xsd:attribute name="bRef" sdo:readOnly="false" type="xsd:anyURI" sdo:propertyType="tns:B"/>
+</xsd:complexType>
+
+<xsd:complexType name="F">
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="manyStringsProp" sdo:readOnly="false" maxOccurs="unbounded" type="xsd:string"/>
+ </xsd:choice>
+</xsd:complexType>
+
+
+</xsd:schema>
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types1.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types1.xsd new file mode 100644 index 0000000000..2539d4d7d5 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types1.xsd @@ -0,0 +1,13 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.hap.sdo.test1" xmlns:tns="com.agfa.hap.sdo.test1" xmlns:test2="com.agfa.hap.sdo.test2">
+
+<xsd:complexType name="A1">
+ <xsd:sequence>
+ <xsd:element name="b2s" type="test2:B2" sdo:readOlny="false" maxOccurs="unbounded" sdo:oppositeProperty="a1"/>
+ </xsd:sequence>
+ <xsd:attribute name="anotherProperty" type="xsd:int"/>
+</xsd:complexType>
+
+
+</xsd:schema>
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types2.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types2.xsd new file mode 100644 index 0000000000..02a3b0a48d --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-sdo-types2.xsd @@ -0,0 +1,11 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.hap.sdo.test2" xmlns:tns="com.agfa.hap.sdo.test2" xmlns:test1="com.agfa.hap.sdo.test1">
+
+
+<xsd:complexType name="B2">
+ <xsd:attribute name="a1" type="xsd:anyURI" sdo:propertyType="test1:A1"/>
+ <xsd:attribute name="someProperty" type="xsd:int"/>
+</xsd:complexType>
+
+</xsd:schema>
\ No newline at end of file diff --git a/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-userrole-types.xsd b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-userrole-types.xsd new file mode 100644 index 0000000000..b659216088 --- /dev/null +++ b/sandbox/kgoodson/agfasdo/com.agfa.hap.sdo/src/test/resources/sdo/test-userrole-types.xsd @@ -0,0 +1,18 @@ +<xsd:schema xmlns="http://defaultnamespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdo="commonj.sdo/xml" xmlns:sdoJava="commonj.sdo/java"
+ targetNamespace="com.agfa.hap.sdo.test" xmlns:tns="com.agfa.hap.sdo.test.workflow">
+
+<xsd:element name="user" type="agfa.User"/>
+<xsd:complexType name="agfa.User">
+ <xsd:sequence>
+ <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+ </xsd:sequence>
+</xsd:complexType>
+
+<xsd:complexType name="agfa.Role">
+ <xsd:sequence>
+ <xsd:element name="name" type="xsd:string" minOccurs="0"/>
+ </xsd:sequence>
+</xsd:complexType>
+
+</xsd:schema>
\ No newline at end of file |