tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From am...@apache.org
Subject svn commit: r614489 - in /incubator/tuscany/java/sdo/impl/src: main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java
Date Wed, 23 Jan 2008 10:57:44 GMT
Author: amita
Date: Wed Jan 23 02:57:43 2008
New Revision: 614489

URL: http://svn.apache.org/viewvc?rev=614489&view=rev
Log:
TUSCANY-2009 Java SDO's EqualityHelper should compare Bytes values correctly

Modified:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java
    incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java

Modified: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java?rev=614489&r1=614488&r2=614489&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/EqualityHelperImpl.java
Wed Jan 23 02:57:43 2008
@@ -71,8 +71,23 @@
       {
         protected boolean haveEqualAttribute(EObject eObject1, EObject eObject2, EAttribute
attribute) {
             if(("ChangeSummaryType".equals(attribute.getEType().getName()) && "commonj.sdo".equals(attribute.getEType().getEPackage().getNsURI())))
{
-                throw new UnsupportedOperationException("This will be implemented when change
summary serialzation/deserialization is in place");
-            } else {
+                throw new UnsupportedOperationException("This will be implemented when change
summary serialzation/deserialization is in place"); 
+            } 
+            else if( "Bytes".equals(attribute.getEType().getName()) ) {
+                try
+                {
+                    byte [] value1 = (byte [])eObject1.eGet(attribute);
+                    byte [] value2 = (byte [])eObject2.eGet(attribute);
+                
+                    return( java.util.Arrays.equals(value1,value2) );
+                }
+                catch(Exception ex)
+                {
+                    // if any exception is thrown, assumption is they are not equal
+                    return false;
+                }
+            } 
+            else {
                 return super.haveEqualAttribute(eObject1, eObject2, attribute);
             }
         }

Modified: incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java?rev=614489&r1=614488&r2=614489&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java
Wed Jan 23 02:57:43 2008
@@ -24,10 +24,15 @@
 import java.net.URL;
 
 import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
 import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.HelperContext;
+import commonj.sdo.helper.TypeHelper;
 import commonj.sdo.helper.XMLDocument;
 import commonj.sdo.helper.XMLHelper;
 import commonj.sdo.helper.XSDHelper;
+import commonj.sdo.impl.HelperProvider;
 import junit.framework.TestCase;
 
 public class SimpleEqualityTestCase extends TestCase {
@@ -59,5 +64,28 @@
         InputStream inputStream = url.openStream();
         XSDHelper.INSTANCE.define(inputStream, url.toString());
         inputStream.close();
+    }
+    
+    public void testBytesEquality() {
+        // Dynamically create a type
+        HelperContext scope = HelperProvider.getDefaultContext();
+        TypeHelper types = scope.getTypeHelper();
+        Type BytesType = types.getType("commonj.sdo", "Bytes");
+        DataObject customerType = DataFactory.INSTANCE.create("commonj.sdo", "Type");
+        customerType.set("uri", "http://example.com/simple");
+        customerType.set("name", "Simple");
+        DataObject BytesProperty = customerType.createDataObject("property");
+        BytesProperty.set("name", "BytesVal");
+        BytesProperty.set("type", BytesType);
+        types.define(customerType);
+        
+        // Create two instances
+        DataObject obj1 = DataFactory.INSTANCE.create("http://example.com/simple", "Simple");
+        DataObject obj2 = DataFactory.INSTANCE.create("http://example.com/simple", "Simple");
+
+        obj1.setBytes("BytesVal", new byte[] {120, 80, -40});
+        obj2.setBytes("BytesVal", new byte[] {120, 80, -40});
+
+        assertTrue( scope.getEqualityHelper().equal(obj1, obj2) );
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message