Author: amita
Date: Thu Nov 22 01:59:07 2007
New Revision: 597362

URL: http://svn.apache.org/viewvc?rev=597362&view=rev
Log:
TUSCANY-1359 implement getLowerBound() and add test for upper/lower bound check

Added:
    
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java
    incubator/tuscany/java/sdo/impl/src/test/resources/bounds.xsd
Modified:
    
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
    
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java
    
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
    
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java

Modified: 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java?rev=597362&r1=597361&r2=597362&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/SDOHelperImpl.java
 Thu Nov 22 01:59:07 2007
@@ -121,6 +121,10 @@
         return ((EStructuralFeature)property).getUpperBound();
     }
 
+    public int getLowerBound(Property property) {
+        return ((EStructuralFeature)property).getLowerBound();
+    }
+    
     public boolean isMany(Property property, DataObject context) {
         return FeatureMapUtil.isMany((EObject)context, 
(EStructuralFeature)property);
     }

Modified: 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java?rev=597362&r1=597361&r2=597362&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java
 (original)
+++ 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/AllTests.java
 Thu Nov 22 01:59:07 2007
@@ -43,6 +43,7 @@
         suite.addTestSuite(FormTestCase.class);
         suite.addTestSuite(HelperContextTestCase.class);
         suite.addTestSuite(IsManyTestCase.class);
+        suite.addTestSuite(BoundsTestCase.class);
         suite.addTestSuite(JavaSerializeDeserializeTestCase.class);
         suite.addTestSuite(MixedTypeTestCase.class);
         suite.addTestSuite(NeverStaleChangeSummaryTestCase.class);

Added: 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java?rev=597362&view=auto
==============================================================================
--- 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java
 (added)
+++ 
incubator/tuscany/java/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/BoundsTestCase.java
 Thu Nov 22 01:59:07 2007
@@ -0,0 +1,64 @@
+/**
+ *
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.tuscany.sdo.test;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.tuscany.sdo.api.SDOUtil;
+
+import junit.framework.TestCase;
+
+import commonj.sdo.*;
+import commonj.sdo.helper.*;
+
+public class BoundsTestCase extends TestCase {
+    private final String TEST_MODEL = "/bounds.xsd";
+    private final String TEST_NAMESPACE = "http://www.example.com/bounds";;
+
+    public void testBounds() {
+        Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, 
"OpenQuote");
+        DataObject quote = DataFactory.INSTANCE.create(quoteType);
+        assertEquals(2, 
SDOUtil.getUpperBound(quote.getInstanceProperty("symbol")));
+        assertEquals(0, 
SDOUtil.getLowerBound(quote.getInstanceProperty("symbol")));
+        
+        //XSD default value of maxOccurs and minOccurs is 1, unbounded returns 
-1 for maxOccurs
+        Type quoteType2 = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, 
"OpenQuote2");
+        DataObject quote2 = DataFactory.INSTANCE.create(quoteType2);
+        assertEquals(-1, 
SDOUtil.getUpperBound(quote2.getInstanceProperty("symbol")));
+        assertEquals(1, 
SDOUtil.getLowerBound(quote2.getInstanceProperty("symbol")));
+        
+        //XSD default value of maxOccurs and minOccurs is 1
+        Type quoteType3 = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, 
"OpenQuote3");
+        DataObject quote3 = DataFactory.INSTANCE.create(quoteType3);
+        assertEquals(1, 
SDOUtil.getUpperBound(quote3.getInstanceProperty("symbol")));
+        assertEquals(1, 
SDOUtil.getLowerBound(quote3.getInstanceProperty("symbol")));        
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // Populate the meta data for the test (Stock Quote) model
+        URL url = getClass().getResource(TEST_MODEL);
+        InputStream inputStream = url.openStream();
+        XSDHelper.INSTANCE.define(inputStream, url.toString());
+        inputStream.close();
+    }
+}
\ No newline at end of file

Added: incubator/tuscany/java/sdo/impl/src/test/resources/bounds.xsd
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/impl/src/test/resources/bounds.xsd?rev=597362&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/test/resources/bounds.xsd (added)
+++ incubator/tuscany/java/sdo/impl/src/test/resources/bounds.xsd Thu Nov 22 
01:59:07 2007
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+    
+    http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.    
+ -->
+<xsd:schema 
+  xmlns:bounds="http://www.example.com/bounds"; 
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
+  targetNamespace="http://www.example.com/bounds";> 
+  
+   <xsd:complexType name="OpenQuote">
+       <xsd:sequence>
+          <xsd:element name="symbol" type="xsd:string"  maxOccurs="2" 
minOccurs="0" />
+       </xsd:sequence>
+   </xsd:complexType>
+   
+   <xsd:complexType name="OpenQuote2">
+       <xsd:sequence>
+          <xsd:element name="symbol" type="xsd:string"  maxOccurs="unbounded" 
/>
+       </xsd:sequence>
+   </xsd:complexType>
+
+   <xsd:complexType name="OpenQuote3">
+       <xsd:sequence>
+          <xsd:element name="symbol" type="xsd:string"/>
+       </xsd:sequence>
+   </xsd:complexType>
+   
+</xsd:schema>

Modified: 
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java?rev=597362&r1=597361&r2=597362&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
 (original)
+++ 
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOHelper.java
 Thu Nov 22 01:59:07 2007
@@ -144,6 +144,13 @@
   public int getUpperBound(Property property);
 
   /**
+   * Return the lower bound of the specified property or 1 by default
+   * @param the property in question.
+   * @return the lower bound.
+   */
+  public int getLowerBound(Property property);
+  
+  /**
    * Returns whether the Property is many-valued given the specified context.
    * @param property The Property in question
    * @param context The context to check whether the specified Property is 
many-valued

Modified: 
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java?rev=597362&r1=597361&r2=597362&view=diff
==============================================================================
--- 
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
 (original)
+++ 
incubator/tuscany/java/sdo/lib/src/main/java/org/apache/tuscany/sdo/api/SDOUtil.java
 Thu Nov 22 01:59:07 2007
@@ -111,6 +111,14 @@
   }
 
   /**
+   * @see [EMAIL PROTECTED] 
org.apache.tuscany.sdo.api.SDOHelper#getLowerBound(Property)}.
+   */
+  public static int getLowerBound(Property property)
+  {
+    return defaultSDOHelper.getLowerBound(property);
+  }
+  
+  /**
    * @see [EMAIL PROTECTED] 
org.apache.tuscany.sdo.api.SDOHelper#isMany(Property, DataObject)}.
    */
   public static boolean isMany(Property property, DataObject context) 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to