diff options
author | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
---|---|---|
committer | dims <dims@13f79535-47bb-0310-9956-ffa450edef68> | 2008-06-17 00:23:01 +0000 |
commit | bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a (patch) | |
tree | 38a92061c0793434c4be189f1d70c3458b6bc41d /branches/sdo-java-M2/sdo/impl/src/test |
Move Tuscany from Incubator to top level.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sdo-java-M2/sdo/impl/src/test')
66 files changed, 8385 insertions, 0 deletions
diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/Quote.java b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/Quote.java new file mode 100644 index 0000000000..2855d2a67c --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/Quote.java @@ -0,0 +1,310 @@ +/** + * + * 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 com.example.simple; + +import java.math.BigDecimal; + +import java.util.List; + +/** + * <!-- begin-user-doc --> + * A representation of the model object '<em><b>Quote</b></em>'. + * <!-- end-user-doc --> + * + * <p> + * The following features are supported: + * <ul> + * <li>{@link com.example.simple.Quote#getSymbol <em>Symbol</em>}</li> + * <li>{@link com.example.simple.Quote#getCompanyName <em>Company Name</em>}</li> + * <li>{@link com.example.simple.Quote#getPrice <em>Price</em>}</li> + * <li>{@link com.example.simple.Quote#getOpen1 <em>Open1</em>}</li> + * <li>{@link com.example.simple.Quote#getHigh <em>High</em>}</li> + * <li>{@link com.example.simple.Quote#getLow <em>Low</em>}</li> + * <li>{@link com.example.simple.Quote#getVolume <em>Volume</em>}</li> + * <li>{@link com.example.simple.Quote#getChange1 <em>Change1</em>}</li> + * <li>{@link com.example.simple.Quote#getQuotes <em>Quotes</em>}</li> + * </ul> + * </p> + * + * @generated + */ +public interface Quote +{ + /** + * Returns the value of the '<em><b>Symbol</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Symbol</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Symbol</em>' attribute. + * @see #setSymbol(String) + * @generated + */ + String getSymbol(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getSymbol <em>Symbol</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Symbol</em>' attribute. + * @see #getSymbol() + * @generated + */ + void setSymbol(String value); + + /** + * Returns the value of the '<em><b>Company Name</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Company Name</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Company Name</em>' attribute. + * @see #setCompanyName(String) + * @generated + */ + String getCompanyName(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getCompanyName <em>Company Name</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Company Name</em>' attribute. + * @see #getCompanyName() + * @generated + */ + void setCompanyName(String value); + + /** + * Returns the value of the '<em><b>Price</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Price</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Price</em>' attribute. + * @see #setPrice(BigDecimal) + * @generated + */ + BigDecimal getPrice(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getPrice <em>Price</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Price</em>' attribute. + * @see #getPrice() + * @generated + */ + void setPrice(BigDecimal value); + + /** + * Returns the value of the '<em><b>Open1</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Open1</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Open1</em>' attribute. + * @see #setOpen1(BigDecimal) + * @generated + */ + BigDecimal getOpen1(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getOpen1 <em>Open1</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Open1</em>' attribute. + * @see #getOpen1() + * @generated + */ + void setOpen1(BigDecimal value); + + /** + * Returns the value of the '<em><b>High</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>High</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>High</em>' attribute. + * @see #setHigh(BigDecimal) + * @generated + */ + BigDecimal getHigh(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getHigh <em>High</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>High</em>' attribute. + * @see #getHigh() + * @generated + */ + void setHigh(BigDecimal value); + + /** + * Returns the value of the '<em><b>Low</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Low</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Low</em>' attribute. + * @see #setLow(BigDecimal) + * @generated + */ + BigDecimal getLow(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getLow <em>Low</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Low</em>' attribute. + * @see #getLow() + * @generated + */ + void setLow(BigDecimal value); + + /** + * Returns the value of the '<em><b>Volume</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Volume</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Volume</em>' attribute. + * @see #isSetVolume() + * @see #unsetVolume() + * @see #setVolume(double) + * @generated + */ + double getVolume(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getVolume <em>Volume</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Volume</em>' attribute. + * @see #isSetVolume() + * @see #unsetVolume() + * @see #getVolume() + * @generated + */ + void setVolume(double value); + + /** + * Unsets the value of the '{@link com.example.simple.Quote#getVolume <em>Volume</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #isSetVolume() + * @see #getVolume() + * @see #setVolume(double) + * @generated + */ + void unsetVolume(); + + /** + * Returns whether the value of the '{@link com.example.simple.Quote#getVolume <em>Volume</em>}' attribute is set. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return whether the value of the '<em>Volume</em>' attribute is set. + * @see #unsetVolume() + * @see #getVolume() + * @see #setVolume(double) + * @generated + */ + boolean isSetVolume(); + + /** + * Returns the value of the '<em><b>Change1</b></em>' attribute. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Change1</em>' attribute isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Change1</em>' attribute. + * @see #isSetChange1() + * @see #unsetChange1() + * @see #setChange1(double) + * @generated + */ + double getChange1(); + + /** + * Sets the value of the '{@link com.example.simple.Quote#getChange1 <em>Change1</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @param value the new value of the '<em>Change1</em>' attribute. + * @see #isSetChange1() + * @see #unsetChange1() + * @see #getChange1() + * @generated + */ + void setChange1(double value); + + /** + * Unsets the value of the '{@link com.example.simple.Quote#getChange1 <em>Change1</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #isSetChange1() + * @see #getChange1() + * @see #setChange1(double) + * @generated + */ + void unsetChange1(); + + /** + * Returns whether the value of the '{@link com.example.simple.Quote#getChange1 <em>Change1</em>}' attribute is set. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return whether the value of the '<em>Change1</em>' attribute is set. + * @see #unsetChange1() + * @see #getChange1() + * @see #setChange1(double) + * @generated + */ + boolean isSetChange1(); + + /** + * Returns the value of the '<em><b>Quotes</b></em>' containment reference list. + * The list contents are of type {@link com.example.simple.Quote}. + * <!-- begin-user-doc --> + * <p> + * If the meaning of the '<em>Quotes</em>' containment reference list isn't clear, + * there really should be more of a description here... + * </p> + * <!-- end-user-doc --> + * @return the value of the '<em>Quotes</em>' containment reference list. + * @generated + */ + List getQuotes(); + +} // Quote diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/SimpleFactory.java b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/SimpleFactory.java new file mode 100644 index 0000000000..4f33a3e19f --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/SimpleFactory.java @@ -0,0 +1,49 @@ +/** + * + * 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 com.example.simple; + + +/** + * <!-- begin-user-doc --> + * The <b>Factory</b> for the model. + * It provides a create method for each non-abstract class of the model. + * <!-- end-user-doc --> + * @generated + */ +public interface SimpleFactory +{ + /** + * The singleton instance of the factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + SimpleFactory INSTANCE = com.example.simple.impl.SimpleFactoryImpl.eINSTANCE; + + /** + * Returns a new object of class '<em>Quote</em>'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return a new object of class '<em>Quote</em>'. + * @generated + */ + Quote createQuote(); + +} //SimpleFactory diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/QuoteImpl.java b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/QuoteImpl.java new file mode 100644 index 0000000000..18c63894af --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/QuoteImpl.java @@ -0,0 +1,715 @@ +/** + * + * 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 com.example.simple.impl; + +import com.example.simple.Quote; + +import java.math.BigDecimal; + +import java.util.Collection; +import java.util.List; + +import org.apache.tuscany.sdo.impl.DataObjectImpl; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.NotificationChain; + +import org.eclipse.emf.common.util.EList; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.InternalEObject; + +import org.eclipse.emf.ecore.impl.ENotificationImpl; + +import org.eclipse.emf.ecore.util.EObjectContainmentEList; +import org.eclipse.emf.ecore.util.InternalEList; + +/** + * <!-- begin-user-doc --> + * An implementation of the model object '<em><b>Quote</b></em>'. + * <!-- end-user-doc --> + * <p> + * The following features are implemented: + * <ul> + * <li>{@link com.example.simple.impl.QuoteImpl#getSymbol <em>Symbol</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getCompanyName <em>Company Name</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getPrice <em>Price</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getOpen1 <em>Open1</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getHigh <em>High</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getLow <em>Low</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getVolume <em>Volume</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getChange1 <em>Change1</em>}</li> + * <li>{@link com.example.simple.impl.QuoteImpl#getQuotes <em>Quotes</em>}</li> + * </ul> + * </p> + * + * @generated + */ +public class QuoteImpl extends DataObjectImpl implements Quote +{ + /** + * The default value of the '{@link #getSymbol() <em>Symbol</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSymbol() + * @generated + * @ordered + */ + protected static final String SYMBOL_EDEFAULT = null; + + /** + * The cached value of the '{@link #getSymbol() <em>Symbol</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getSymbol() + * @generated + * @ordered + */ + protected String symbol = SYMBOL_EDEFAULT; + + /** + * The default value of the '{@link #getCompanyName() <em>Company Name</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getCompanyName() + * @generated + * @ordered + */ + protected static final String COMPANY_NAME_EDEFAULT = null; + + /** + * The cached value of the '{@link #getCompanyName() <em>Company Name</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getCompanyName() + * @generated + * @ordered + */ + protected String companyName = COMPANY_NAME_EDEFAULT; + + /** + * The default value of the '{@link #getPrice() <em>Price</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getPrice() + * @generated + * @ordered + */ + protected static final BigDecimal PRICE_EDEFAULT = null; + + /** + * The cached value of the '{@link #getPrice() <em>Price</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getPrice() + * @generated + * @ordered + */ + protected BigDecimal price = PRICE_EDEFAULT; + + /** + * The default value of the '{@link #getOpen1() <em>Open1</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getOpen1() + * @generated + * @ordered + */ + protected static final BigDecimal OPEN1_EDEFAULT = null; + + /** + * The cached value of the '{@link #getOpen1() <em>Open1</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getOpen1() + * @generated + * @ordered + */ + protected BigDecimal open1 = OPEN1_EDEFAULT; + + /** + * The default value of the '{@link #getHigh() <em>High</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getHigh() + * @generated + * @ordered + */ + protected static final BigDecimal HIGH_EDEFAULT = null; + + /** + * The cached value of the '{@link #getHigh() <em>High</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getHigh() + * @generated + * @ordered + */ + protected BigDecimal high = HIGH_EDEFAULT; + + /** + * The default value of the '{@link #getLow() <em>Low</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getLow() + * @generated + * @ordered + */ + protected static final BigDecimal LOW_EDEFAULT = null; + + /** + * The cached value of the '{@link #getLow() <em>Low</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getLow() + * @generated + * @ordered + */ + protected BigDecimal low = LOW_EDEFAULT; + + /** + * The default value of the '{@link #getVolume() <em>Volume</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getVolume() + * @generated + * @ordered + */ + protected static final double VOLUME_EDEFAULT = 0.0; + + /** + * The cached value of the '{@link #getVolume() <em>Volume</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getVolume() + * @generated + * @ordered + */ + protected double volume = VOLUME_EDEFAULT; + + /** + * This is true if the Volume attribute has been set. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + protected boolean volumeESet = false; + + /** + * The default value of the '{@link #getChange1() <em>Change1</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getChange1() + * @generated + * @ordered + */ + protected static final double CHANGE1_EDEFAULT = 0.0; + + /** + * The cached value of the '{@link #getChange1() <em>Change1</em>}' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getChange1() + * @generated + * @ordered + */ + protected double change1 = CHANGE1_EDEFAULT; + + /** + * This is true if the Change1 attribute has been set. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + protected boolean change1ESet = false; + + /** + * The cached value of the '{@link #getQuotes() <em>Quotes</em>}' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #getQuotes() + * @generated + * @ordered + */ + protected EList quotes = null; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected QuoteImpl() + { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected EClass eStaticClass() + { + return SimplePackageImpl.Literals.QUOTE; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String getSymbol() + { + return symbol; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setSymbol(String newSymbol) + { + String oldSymbol = symbol; + symbol = newSymbol; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__SYMBOL, oldSymbol, symbol)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String getCompanyName() + { + return companyName; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setCompanyName(String newCompanyName) + { + String oldCompanyName = companyName; + companyName = newCompanyName; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__COMPANY_NAME, oldCompanyName, companyName)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public BigDecimal getPrice() + { + return price; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setPrice(BigDecimal newPrice) + { + BigDecimal oldPrice = price; + price = newPrice; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__PRICE, oldPrice, price)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public BigDecimal getOpen1() + { + return open1; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setOpen1(BigDecimal newOpen1) + { + BigDecimal oldOpen1 = open1; + open1 = newOpen1; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__OPEN1, oldOpen1, open1)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public BigDecimal getHigh() + { + return high; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setHigh(BigDecimal newHigh) + { + BigDecimal oldHigh = high; + high = newHigh; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__HIGH, oldHigh, high)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public BigDecimal getLow() + { + return low; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setLow(BigDecimal newLow) + { + BigDecimal oldLow = low; + low = newLow; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__LOW, oldLow, low)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public double getVolume() + { + return volume; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setVolume(double newVolume) + { + double oldVolume = volume; + volume = newVolume; + boolean oldVolumeESet = volumeESet; + volumeESet = true; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__VOLUME, oldVolume, volume, !oldVolumeESet)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void unsetVolume() + { + double oldVolume = volume; + boolean oldVolumeESet = volumeESet; + volume = VOLUME_EDEFAULT; + volumeESet = false; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.UNSET, SimplePackageImpl.QUOTE__VOLUME, oldVolume, VOLUME_EDEFAULT, oldVolumeESet)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public boolean isSetVolume() + { + return volumeESet; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public double getChange1() + { + return change1; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void setChange1(double newChange1) + { + double oldChange1 = change1; + change1 = newChange1; + boolean oldChange1ESet = change1ESet; + change1ESet = true; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.SET, SimplePackageImpl.QUOTE__CHANGE1, oldChange1, change1, !oldChange1ESet)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void unsetChange1() + { + double oldChange1 = change1; + boolean oldChange1ESet = change1ESet; + change1 = CHANGE1_EDEFAULT; + change1ESet = false; + if (eNotificationRequired()) + eNotify(new ENotificationImpl(this, Notification.UNSET, SimplePackageImpl.QUOTE__CHANGE1, oldChange1, CHANGE1_EDEFAULT, oldChange1ESet)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public boolean isSetChange1() + { + return change1ESet; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public List getQuotes() + { + if (quotes == null) + { + quotes = new EObjectContainmentEList(Quote.class, this, SimplePackageImpl.QUOTE__QUOTES); + } + return quotes; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) + { + switch (featureID) + { + case SimplePackageImpl.QUOTE__QUOTES: + return ((InternalEList)getQuotes()).basicRemove(otherEnd, msgs); + } + return super.eInverseRemove(otherEnd, featureID, msgs); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Object eGet(int featureID, boolean resolve, boolean coreType) + { + switch (featureID) + { + case SimplePackageImpl.QUOTE__SYMBOL: + return getSymbol(); + case SimplePackageImpl.QUOTE__COMPANY_NAME: + return getCompanyName(); + case SimplePackageImpl.QUOTE__PRICE: + return getPrice(); + case SimplePackageImpl.QUOTE__OPEN1: + return getOpen1(); + case SimplePackageImpl.QUOTE__HIGH: + return getHigh(); + case SimplePackageImpl.QUOTE__LOW: + return getLow(); + case SimplePackageImpl.QUOTE__VOLUME: + return new Double(getVolume()); + case SimplePackageImpl.QUOTE__CHANGE1: + return new Double(getChange1()); + case SimplePackageImpl.QUOTE__QUOTES: + return getQuotes(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void eSet(int featureID, Object newValue) + { + switch (featureID) + { + case SimplePackageImpl.QUOTE__SYMBOL: + setSymbol((String)newValue); + return; + case SimplePackageImpl.QUOTE__COMPANY_NAME: + setCompanyName((String)newValue); + return; + case SimplePackageImpl.QUOTE__PRICE: + setPrice((BigDecimal)newValue); + return; + case SimplePackageImpl.QUOTE__OPEN1: + setOpen1((BigDecimal)newValue); + return; + case SimplePackageImpl.QUOTE__HIGH: + setHigh((BigDecimal)newValue); + return; + case SimplePackageImpl.QUOTE__LOW: + setLow((BigDecimal)newValue); + return; + case SimplePackageImpl.QUOTE__VOLUME: + setVolume(((Double)newValue).doubleValue()); + return; + case SimplePackageImpl.QUOTE__CHANGE1: + setChange1(((Double)newValue).doubleValue()); + return; + case SimplePackageImpl.QUOTE__QUOTES: + getQuotes().clear(); + getQuotes().addAll((Collection)newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void eUnset(int featureID) + { + switch (featureID) + { + case SimplePackageImpl.QUOTE__SYMBOL: + setSymbol(SYMBOL_EDEFAULT); + return; + case SimplePackageImpl.QUOTE__COMPANY_NAME: + setCompanyName(COMPANY_NAME_EDEFAULT); + return; + case SimplePackageImpl.QUOTE__PRICE: + setPrice(PRICE_EDEFAULT); + return; + case SimplePackageImpl.QUOTE__OPEN1: + setOpen1(OPEN1_EDEFAULT); + return; + case SimplePackageImpl.QUOTE__HIGH: + setHigh(HIGH_EDEFAULT); + return; + case SimplePackageImpl.QUOTE__LOW: + setLow(LOW_EDEFAULT); + return; + case SimplePackageImpl.QUOTE__VOLUME: + unsetVolume(); + return; + case SimplePackageImpl.QUOTE__CHANGE1: + unsetChange1(); + return; + case SimplePackageImpl.QUOTE__QUOTES: + getQuotes().clear(); + return; + } + super.eUnset(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public boolean eIsSet(int featureID) + { + switch (featureID) + { + case SimplePackageImpl.QUOTE__SYMBOL: + return SYMBOL_EDEFAULT == null ? symbol != null : !SYMBOL_EDEFAULT.equals(symbol); + case SimplePackageImpl.QUOTE__COMPANY_NAME: + return COMPANY_NAME_EDEFAULT == null ? companyName != null : !COMPANY_NAME_EDEFAULT.equals(companyName); + case SimplePackageImpl.QUOTE__PRICE: + return PRICE_EDEFAULT == null ? price != null : !PRICE_EDEFAULT.equals(price); + case SimplePackageImpl.QUOTE__OPEN1: + return OPEN1_EDEFAULT == null ? open1 != null : !OPEN1_EDEFAULT.equals(open1); + case SimplePackageImpl.QUOTE__HIGH: + return HIGH_EDEFAULT == null ? high != null : !HIGH_EDEFAULT.equals(high); + case SimplePackageImpl.QUOTE__LOW: + return LOW_EDEFAULT == null ? low != null : !LOW_EDEFAULT.equals(low); + case SimplePackageImpl.QUOTE__VOLUME: + return isSetVolume(); + case SimplePackageImpl.QUOTE__CHANGE1: + return isSetChange1(); + case SimplePackageImpl.QUOTE__QUOTES: + return quotes != null && !quotes.isEmpty(); + } + return super.eIsSet(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String toString() + { + if (eIsProxy()) return super.toString(); + + StringBuffer result = new StringBuffer(super.toString()); + result.append(" (symbol: "); + result.append(symbol); + result.append(", companyName: "); + result.append(companyName); + result.append(", price: "); + result.append(price); + result.append(", open1: "); + result.append(open1); + result.append(", high: "); + result.append(high); + result.append(", low: "); + result.append(low); + result.append(", volume: "); + if (volumeESet) result.append(volume); else result.append("<unset>"); + result.append(", change1: "); + if (change1ESet) result.append(change1); else result.append("<unset>"); + result.append(')'); + return result.toString(); + } + +} //QuoteImpl diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/SimpleFactoryImpl.java b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/SimpleFactoryImpl.java new file mode 100644 index 0000000000..5f275a94d4 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/SimpleFactoryImpl.java @@ -0,0 +1,141 @@ +/** + * + * 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 com.example.simple.impl; + +import com.example.simple.*; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; + +import org.eclipse.emf.ecore.impl.EFactoryImpl; + +import org.eclipse.emf.ecore.plugin.EcorePlugin; + +/** + * <!-- begin-user-doc --> + * An implementation of the model <b>Factory</b>. + * <!-- end-user-doc --> + * @generated + */ +public class SimpleFactoryImpl extends EFactoryImpl implements SimpleFactory +{ + /** + * The singleton instance of the factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final SimpleFactoryImpl eINSTANCE = init(); + + /** + * Creates the default factory implementation. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static SimpleFactoryImpl init() + { + try + { + SimpleFactoryImpl theSimpleFactory = (SimpleFactoryImpl)EPackage.Registry.INSTANCE.getEFactory("http://www.example.com/simple"); + if (theSimpleFactory != null) + { + return theSimpleFactory; + } + } + catch (Exception exception) + { + EcorePlugin.INSTANCE.log(exception); + } + return new SimpleFactoryImpl(); + } + + /** + * Creates an instance of the factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public SimpleFactoryImpl() + { + super(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public EObject create(EClass eClass) + { + switch (eClass.getClassifierID()) + { + case SimplePackageImpl.DOCUMENT_ROOT: return (EObject)createDocumentRoot(); + case SimplePackageImpl.QUOTE: return (EObject)createQuote(); + default: + throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier"); + } + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public EObject createDocumentRoot() + { + EObject documentRoot = super.create(SimplePackageImpl.Literals.DOCUMENT_ROOT); + return documentRoot; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Quote createQuote() + { + QuoteImpl quote = new QuoteImpl(); + return quote; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public SimplePackageImpl getSimplePackageImpl() + { + return (SimplePackageImpl)getEPackage(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @deprecated + * @generated + */ + public static SimplePackageImpl getPackage() + { + return SimplePackageImpl.eINSTANCE; + } + +} //SimpleFactoryImpl diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/SimplePackageImpl.java b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/SimplePackageImpl.java new file mode 100644 index 0000000000..50ad614fd7 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/com/example/simple/impl/SimplePackageImpl.java @@ -0,0 +1,911 @@ +/** + * + * 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 com.example.simple.impl; + +import com.example.simple.Quote; +import com.example.simple.SimpleFactory; + +import org.eclipse.emf.ecore.EAttribute; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EFactory; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EReference; + +import org.eclipse.emf.ecore.impl.EPackageImpl; + +import org.eclipse.emf.ecore.xml.type.XMLTypePackage; + +/** + * <!-- begin-user-doc --> + * The <b>Package</b> for the model. + * It contains accessors for the meta objects to represent + * <ul> + * <li>each class,</li> + * <li>each feature of each class,</li> + * <li>each enum,</li> + * <li>and each data type</li> + * </ul> + * <!-- end-user-doc --> + * @see com.example.simple.SimpleFactory + * @generated + */ +public class SimplePackageImpl extends EPackageImpl +{ + /** + * The package name. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String eNAME = "simple"; + + /** + * The package namespace URI. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String eNS_URI = "http://www.example.com/simple"; + + /** + * The package namespace name. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String eNS_PREFIX = "simple"; + + /** + * The singleton instance of the package. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final SimplePackageImpl eINSTANCE = com.example.simple.impl.SimplePackageImpl.init(); + + /** + * The meta object id for the '{@link com.example.simple.impl.DocumentRootImpl <em>Document Root</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see com.example.simple.impl.DocumentRootImpl + * @see com.example.simple.impl.SimplePackageImpl#getDocumentRoot() + * @generated + */ + public static final int DOCUMENT_ROOT = 0; + + /** + * The feature id for the '<em><b>Mixed</b></em>' attribute list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int DOCUMENT_ROOT__MIXED = 0; + + /** + * The feature id for the '<em><b>XMLNS Prefix Map</b></em>' map. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int DOCUMENT_ROOT__XMLNS_PREFIX_MAP = 1; + + /** + * The feature id for the '<em><b>XSI Schema Location</b></em>' map. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int DOCUMENT_ROOT__XSI_SCHEMA_LOCATION = 2; + + /** + * The feature id for the '<em><b>Stock Quote</b></em>' containment reference. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int DOCUMENT_ROOT__STOCK_QUOTE = 3; + + /** + * The number of structural features of the '<em>Document Root</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int DOCUMENT_ROOT_FEATURE_COUNT = 4; + + /** + * The meta object id for the '{@link com.example.simple.impl.QuoteImpl <em>Quote</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see com.example.simple.impl.QuoteImpl + * @see com.example.simple.impl.SimplePackageImpl#getQuote() + * @generated + */ + public static final int QUOTE = 1; + + /** + * The feature id for the '<em><b>Symbol</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__SYMBOL = 0; + + /** + * The feature id for the '<em><b>Company Name</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__COMPANY_NAME = 1; + + /** + * The feature id for the '<em><b>Price</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__PRICE = 2; + + /** + * The feature id for the '<em><b>Open1</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__OPEN1 = 3; + + /** + * The feature id for the '<em><b>High</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__HIGH = 4; + + /** + * The feature id for the '<em><b>Low</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__LOW = 5; + + /** + * The feature id for the '<em><b>Volume</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__VOLUME = 6; + + /** + * The feature id for the '<em><b>Change1</b></em>' attribute. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__CHANGE1 = 7; + + /** + * The feature id for the '<em><b>Quotes</b></em>' containment reference list. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE__QUOTES = 8; + + /** + * The number of structural features of the '<em>Quote</em>' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + * @ordered + */ + public static final int QUOTE_FEATURE_COUNT = 9; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private EClass documentRootEClass = null; + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private EClass quoteEClass = null; + + /** + * Creates an instance of the model <b>Package</b>, registered with + * {@link org.eclipse.emf.ecore.EPackage.Registry EPackage.Registry} by the package + * package URI value. + * <p>Note: the correct way to create the package is via the static + * factory method {@link #init init()}, which also performs + * initialization of the package, or returns the registered package, + * if one already exists. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.emf.ecore.EPackage.Registry + * @see com.example.simple.impl.SimplePackageImpl#eNS_URI + * @see #init() + * @generated + */ + private SimplePackageImpl() + { + super(eNS_URI, ((EFactory)SimpleFactory.INSTANCE)); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private static boolean isInited = false; + + /** + * Creates, registers, and initializes the <b>Package</b> for this + * model, and for any others upon which it depends. Simple + * dependencies are satisfied by calling this method on all + * dependent packages before doing anything else. This method drives + * initialization for interdependent packages directly, in parallel + * with this package, itself. + * <p>Of this package and its interdependencies, all packages which + * have not yet been registered by their URI values are first created + * and registered. The packages are then initialized in two steps: + * meta-model objects for all of the packages are created before any + * are initialized, since one package's meta-model objects may refer to + * those of another. + * <p>Invocation of this method will not affect any packages that have + * already been initialized. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see #eNS_URI + * @see #createPackageContents() + * @see #initializePackageContents() + * @generated + */ + public static SimplePackageImpl init() + { + if (isInited) return (SimplePackageImpl)EPackage.Registry.INSTANCE.getEPackage(SimplePackageImpl.eNS_URI); + + // Obtain or create and register package + SimplePackageImpl theSimplePackageImpl = (SimplePackageImpl)(EPackage.Registry.INSTANCE.getEPackage(eNS_URI) instanceof SimplePackageImpl ? EPackage.Registry.INSTANCE.getEPackage(eNS_URI) : new SimplePackageImpl()); + + isInited = true; + + // Initialize simple dependencies + XMLTypePackage.eINSTANCE.eClass(); + + // Create package meta-data objects + theSimplePackageImpl.createPackageContents(); + + // Initialize created meta-data + theSimplePackageImpl.initializePackageContents(); + + // Mark meta-data to indicate it can't be changed + theSimplePackageImpl.freeze(); + + return theSimplePackageImpl; + } + + + /** + * Returns the meta object for class '{@link org.eclipse.emf.ecore.EObject <em>Document Root</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for class '<em>Document Root</em>'. + * @see org.eclipse.emf.ecore.EObject + * @generated + */ + public EClass getDocumentRoot() + { + return documentRootEClass; + } + + /** + * Returns the meta object for the attribute list '{@link org.eclipse.emf.ecore.EObject#getMixed <em>Mixed</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute list '<em>Mixed</em>'. + * @see org.eclipse.emf.ecore.EObject#getMixed() + * @see #getDocumentRoot() + * @generated + */ + public EAttribute getDocumentRoot_Mixed() + { + return (EAttribute)documentRootEClass.getEStructuralFeatures().get(0); + } + + /** + * Returns the meta object for the map '{@link org.eclipse.emf.ecore.EObject#getXMLNSPrefixMap <em>XMLNS Prefix Map</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the map '<em>XMLNS Prefix Map</em>'. + * @see org.eclipse.emf.ecore.EObject#getXMLNSPrefixMap() + * @see #getDocumentRoot() + * @generated + */ + public EReference getDocumentRoot_XMLNSPrefixMap() + { + return (EReference)documentRootEClass.getEStructuralFeatures().get(1); + } + + /** + * Returns the meta object for the map '{@link org.eclipse.emf.ecore.EObject#getXSISchemaLocation <em>XSI Schema Location</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the map '<em>XSI Schema Location</em>'. + * @see org.eclipse.emf.ecore.EObject#getXSISchemaLocation() + * @see #getDocumentRoot() + * @generated + */ + public EReference getDocumentRoot_XSISchemaLocation() + { + return (EReference)documentRootEClass.getEStructuralFeatures().get(2); + } + + /** + * Returns the meta object for the containment reference '{@link org.eclipse.emf.ecore.EObject#getStockQuote <em>Stock Quote</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the containment reference '<em>Stock Quote</em>'. + * @see org.eclipse.emf.ecore.EObject#getStockQuote() + * @see #getDocumentRoot() + * @generated + */ + public EReference getDocumentRoot_StockQuote() + { + return (EReference)documentRootEClass.getEStructuralFeatures().get(3); + } + + /** + * Returns the meta object for class '{@link com.example.simple.Quote <em>Quote</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for class '<em>Quote</em>'. + * @see com.example.simple.Quote + * @generated + */ + public EClass getQuote() + { + return quoteEClass; + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getSymbol <em>Symbol</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Symbol</em>'. + * @see com.example.simple.Quote#getSymbol() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_Symbol() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(0); + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getCompanyName <em>Company Name</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Company Name</em>'. + * @see com.example.simple.Quote#getCompanyName() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_CompanyName() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(1); + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getPrice <em>Price</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Price</em>'. + * @see com.example.simple.Quote#getPrice() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_Price() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(2); + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getOpen1 <em>Open1</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Open1</em>'. + * @see com.example.simple.Quote#getOpen1() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_Open1() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(3); + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getHigh <em>High</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>High</em>'. + * @see com.example.simple.Quote#getHigh() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_High() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(4); + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getLow <em>Low</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Low</em>'. + * @see com.example.simple.Quote#getLow() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_Low() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(5); + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getVolume <em>Volume</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Volume</em>'. + * @see com.example.simple.Quote#getVolume() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_Volume() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(6); + } + + /** + * Returns the meta object for the attribute '{@link com.example.simple.Quote#getChange1 <em>Change1</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the attribute '<em>Change1</em>'. + * @see com.example.simple.Quote#getChange1() + * @see #getQuote() + * @generated + */ + public EAttribute getQuote_Change1() + { + return (EAttribute)quoteEClass.getEStructuralFeatures().get(7); + } + + /** + * Returns the meta object for the containment reference list '{@link com.example.simple.Quote#getQuotes <em>Quotes</em>}'. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the meta object for the containment reference list '<em>Quotes</em>'. + * @see com.example.simple.Quote#getQuotes() + * @see #getQuote() + * @generated + */ + public EReference getQuote_Quotes() + { + return (EReference)quoteEClass.getEStructuralFeatures().get(8); + } + + /** + * Returns the factory that creates the instances of the model. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @return the factory that creates the instances of the model. + * @generated + */ + public SimpleFactory getSimpleFactory() + { + return (SimpleFactory)getEFactoryInstance(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private boolean isCreated = false; + + /** + * Creates the meta-model objects for the package. This method is + * guarded to have no affect on any invocation but its first. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void createPackageContents() + { + if (isCreated) return; + isCreated = true; + + // Create classes and their features + documentRootEClass = createEClass(DOCUMENT_ROOT); + createEAttribute(documentRootEClass, DOCUMENT_ROOT__MIXED); + createEReference(documentRootEClass, DOCUMENT_ROOT__XMLNS_PREFIX_MAP); + createEReference(documentRootEClass, DOCUMENT_ROOT__XSI_SCHEMA_LOCATION); + createEReference(documentRootEClass, DOCUMENT_ROOT__STOCK_QUOTE); + + quoteEClass = createEClass(QUOTE); + createEAttribute(quoteEClass, QUOTE__SYMBOL); + createEAttribute(quoteEClass, QUOTE__COMPANY_NAME); + createEAttribute(quoteEClass, QUOTE__PRICE); + createEAttribute(quoteEClass, QUOTE__OPEN1); + createEAttribute(quoteEClass, QUOTE__HIGH); + createEAttribute(quoteEClass, QUOTE__LOW); + createEAttribute(quoteEClass, QUOTE__VOLUME); + createEAttribute(quoteEClass, QUOTE__CHANGE1); + createEReference(quoteEClass, QUOTE__QUOTES); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + private boolean isInitialized = false; + + /** + * Complete the initialization of the package and its meta-model. This + * method is guarded to have no affect on any invocation but its first. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void initializePackageContents() + { + if (isInitialized) return; + isInitialized = true; + + // Initialize package + setName(eNAME); + setNsPrefix(eNS_PREFIX); + setNsURI(eNS_URI); + + // Obtain other dependent packages + XMLTypePackage theXMLTypePackage = (XMLTypePackage)EPackage.Registry.INSTANCE.getEPackage(XMLTypePackage.eNS_URI); + + // Add supertypes to classes + + // Initialize classes and features; add operations and parameters + initEClass(documentRootEClass, null, "DocumentRoot", !IS_ABSTRACT, !IS_INTERFACE, !IS_GENERATED_INSTANCE_CLASS); + initEAttribute(getDocumentRoot_Mixed(), ecorePackage.getEFeatureMapEntry(), "mixed", null, 0, -1, null, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEReference(getDocumentRoot_XMLNSPrefixMap(), ecorePackage.getEStringToStringMapEntry(), null, "xMLNSPrefixMap", null, 0, -1, null, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEReference(getDocumentRoot_XSISchemaLocation(), ecorePackage.getEStringToStringMapEntry(), null, "xSISchemaLocation", null, 0, -1, null, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEReference(getDocumentRoot_StockQuote(), this.getQuote(), null, "stockQuote", null, 0, -2, null, IS_TRANSIENT, IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, IS_DERIVED, IS_ORDERED); + + initEClass(quoteEClass, Quote.class, "Quote", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); + initEAttribute(getQuote_Symbol(), theXMLTypePackage.getString(), "symbol", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getQuote_CompanyName(), theXMLTypePackage.getString(), "companyName", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getQuote_Price(), theXMLTypePackage.getDecimal(), "price", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getQuote_Open1(), theXMLTypePackage.getDecimal(), "open1", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getQuote_High(), theXMLTypePackage.getDecimal(), "high", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getQuote_Low(), theXMLTypePackage.getDecimal(), "low", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getQuote_Volume(), theXMLTypePackage.getDouble(), "volume", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getQuote_Change1(), theXMLTypePackage.getDouble(), "change1", null, 1, 1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_UNSETTABLE, !IS_ID, !IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEReference(getQuote_Quotes(), this.getQuote(), null, "quotes", null, 0, -1, Quote.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + + // Create resource + createResource(eNS_URI); + + // Create annotations + // http:///org/eclipse/emf/ecore/util/ExtendedMetaData + createExtendedMetaDataAnnotations(); + } + + /** + * Initializes the annotations for <b>http:///org/eclipse/emf/ecore/util/ExtendedMetaData</b>. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected void createExtendedMetaDataAnnotations() + { + String source = "http:///org/eclipse/emf/ecore/util/ExtendedMetaData"; + addAnnotation + (documentRootEClass, + source, + new String[] + { + "name", "", + "kind", "mixed" + }); + addAnnotation + (getDocumentRoot_Mixed(), + source, + new String[] + { + "kind", "elementWildcard", + "name", ":mixed" + }); + addAnnotation + (getDocumentRoot_XMLNSPrefixMap(), + source, + new String[] + { + "kind", "attribute", + "name", "xmlns:prefix" + }); + addAnnotation + (getDocumentRoot_XSISchemaLocation(), + source, + new String[] + { + "kind", "attribute", + "name", "xsi:schemaLocation" + }); + addAnnotation + (getDocumentRoot_StockQuote(), + source, + new String[] + { + "kind", "element", + "name", "stockQuote", + "namespace", "##targetNamespace" + }); + addAnnotation + (quoteEClass, + source, + new String[] + { + "name", "Quote", + "kind", "elementOnly" + }); + addAnnotation + (getQuote_Symbol(), + source, + new String[] + { + "kind", "element", + "name", "symbol" + }); + addAnnotation + (getQuote_CompanyName(), + source, + new String[] + { + "kind", "element", + "name", "companyName" + }); + addAnnotation + (getQuote_Price(), + source, + new String[] + { + "kind", "element", + "name", "price" + }); + addAnnotation + (getQuote_Open1(), + source, + new String[] + { + "kind", "element", + "name", "open1" + }); + addAnnotation + (getQuote_High(), + source, + new String[] + { + "kind", "element", + "name", "high" + }); + addAnnotation + (getQuote_Low(), + source, + new String[] + { + "kind", "element", + "name", "low" + }); + addAnnotation + (getQuote_Volume(), + source, + new String[] + { + "kind", "element", + "name", "volume" + }); + addAnnotation + (getQuote_Change1(), + source, + new String[] + { + "kind", "element", + "name", "change1" + }); + addAnnotation + (getQuote_Quotes(), + source, + new String[] + { + "kind", "element", + "name", "quotes" + }); + } + + /** + * <!-- begin-user-doc --> + * Defines literals for the meta objects that represent + * <ul> + * <li>each class,</li> + * <li>each feature of each class,</li> + * <li>each enum,</li> + * <li>and each data type</li> + * </ul> + * <!-- end-user-doc --> + * @generated + */ + public interface Literals + { + /** + * The meta object literal for the '{@link com.example.simple.impl.DocumentRootImpl <em>Document Root</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see com.example.simple.impl.DocumentRootImpl + * @see com.example.simple.impl.SimplePackageImpl#getDocumentRoot() + * @generated + */ + public static final EClass DOCUMENT_ROOT = eINSTANCE.getDocumentRoot(); + + /** + * The meta object literal for the '<em><b>Mixed</b></em>' attribute list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute DOCUMENT_ROOT__MIXED = eINSTANCE.getDocumentRoot_Mixed(); + + /** + * The meta object literal for the '<em><b>XMLNS Prefix Map</b></em>' map feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EReference DOCUMENT_ROOT__XMLNS_PREFIX_MAP = eINSTANCE.getDocumentRoot_XMLNSPrefixMap(); + + /** + * The meta object literal for the '<em><b>XSI Schema Location</b></em>' map feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EReference DOCUMENT_ROOT__XSI_SCHEMA_LOCATION = eINSTANCE.getDocumentRoot_XSISchemaLocation(); + + /** + * The meta object literal for the '<em><b>Stock Quote</b></em>' containment reference feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EReference DOCUMENT_ROOT__STOCK_QUOTE = eINSTANCE.getDocumentRoot_StockQuote(); + + /** + * The meta object literal for the '{@link com.example.simple.impl.QuoteImpl <em>Quote</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see com.example.simple.impl.QuoteImpl + * @see com.example.simple.impl.SimplePackageImpl#getQuote() + * @generated + */ + public static final EClass QUOTE = eINSTANCE.getQuote(); + + /** + * The meta object literal for the '<em><b>Symbol</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__SYMBOL = eINSTANCE.getQuote_Symbol(); + + /** + * The meta object literal for the '<em><b>Company Name</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__COMPANY_NAME = eINSTANCE.getQuote_CompanyName(); + + /** + * The meta object literal for the '<em><b>Price</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__PRICE = eINSTANCE.getQuote_Price(); + + /** + * The meta object literal for the '<em><b>Open1</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__OPEN1 = eINSTANCE.getQuote_Open1(); + + /** + * The meta object literal for the '<em><b>High</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__HIGH = eINSTANCE.getQuote_High(); + + /** + * The meta object literal for the '<em><b>Low</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__LOW = eINSTANCE.getQuote_Low(); + + /** + * The meta object literal for the '<em><b>Volume</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__VOLUME = eINSTANCE.getQuote_Volume(); + + /** + * The meta object literal for the '<em><b>Change1</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EAttribute QUOTE__CHANGE1 = eINSTANCE.getQuote_Change1(); + + /** + * The meta object literal for the '<em><b>Quotes</b></em>' containment reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final EReference QUOTE__QUOTES = eINSTANCE.getQuote_Quotes(); + + } + +} //SimplePackageImpl diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Bar1.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Bar1.java new file mode 100644 index 0000000000..4a51310cd0 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Bar1.java @@ -0,0 +1,26 @@ +/** + * + * 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.codegen; + +/** + * @version $Rev$ $Date$ + */ +public interface Bar1 { +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Bar2.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Bar2.java new file mode 100644 index 0000000000..e9151b9d46 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Bar2.java @@ -0,0 +1,26 @@ +/** + * + * 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.codegen; + +/** + * @version $Rev$ $Date$ + */ +public interface Bar2 { +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/BytecodeInterfaceGeneratorTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/BytecodeInterfaceGeneratorTestCase.java new file mode 100644 index 0000000000..218a725226 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/BytecodeInterfaceGeneratorTestCase.java @@ -0,0 +1,167 @@ +/** + * + * 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.codegen; + +import java.lang.reflect.Method; +import java.util.List; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class BytecodeInterfaceGeneratorTestCase extends TestCase { + private MockType foo; + private BytecodeInterfaceGenerator gen; + private TestClassLoader cl; + + public void testHeaderNoBaseClass() { + gen.visitType(foo); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals("Foo", c.getName()); + assertTrue(c.isInterface()); + assertEquals(0, c.getInterfaces().length); + assertEquals(0, c.getMethods().length); + } + + public void testHeaderWithPackage() { + gen.visitType(new MockType("org.apache.Foo", null)); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals("org.apache.Foo", c.getName()); + assertEquals(0, c.getInterfaces().length); + assertEquals(0, c.getMethods().length); + } + + public void testHeaderOneBaseClass() throws NoJavaImplementationException { + foo.addBaseType(new MockType("bar1", Bar1.class)); + gen.visitType(foo); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals("Foo", c.getName()); + assertEquals(1, c.getInterfaces().length); + assertEquals(Bar1.class, c.getInterfaces()[0]); + assertEquals(0, c.getMethods().length); + } + + public void testHeaderMultipleBaseClass() throws NoJavaImplementationException { + foo.addBaseType(new MockType("bar1", Bar1.class)); + foo.addBaseType(new MockType("bar2", Bar2.class)); + gen.visitType(foo); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals("Foo", c.getName()); + assertEquals(2, c.getInterfaces().length); + assertEquals(Bar1.class, c.getInterfaces()[0]); + assertEquals(Bar2.class, c.getInterfaces()[1]); + assertEquals(0, c.getMethods().length); + } + + public void testBooleanProperty() throws NoJavaImplementationException, NoSuchMethodException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("true", Boolean.TYPE, false, false)); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals(2, c.getMethods().length); + Method getter = c.getMethod("isTrue", new Class[0]); + assertEquals(boolean.class, getter.getReturnType()); + Method setter = c.getMethod("setTrue", new Class[] {boolean.class}); + assertEquals(void.class, setter.getReturnType()); + } + + public void testByteArrayProperty() throws NoJavaImplementationException, NoSuchMethodException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("bytes", byte[].class, false, false)); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals(2, c.getMethods().length); + Method getter = c.getMethod("getBytes", new Class[0]); + assertEquals(byte[].class, getter.getReturnType()); + Method setter = c.getMethod("setBytes", new Class[] {byte[].class}); + assertEquals(void.class, setter.getReturnType()); + } + + public void testObjectProperty() throws NoJavaImplementationException, NoSuchMethodException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("bar", Bar1.class, false, false)); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals(2, c.getMethods().length); + Method getter = c.getMethod("getBar", new Class[0]); + assertEquals(Bar1.class, getter.getReturnType()); + Method setter = c.getMethod("setBar", new Class[] {Bar1.class}); + assertEquals(void.class, setter.getReturnType()); + } + + public void testReadOnlyProperty() throws NoJavaImplementationException, NoSuchMethodException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("int", Integer.TYPE, false, true)); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals(1, c.getMethods().length); + Method getter = c.getMethod("getInt", new Class[0]); + assertEquals(int.class, getter.getReturnType()); + } + + public void testManyProperty() throws NoJavaImplementationException, NoSuchMethodException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("list", Integer.TYPE, true, false)); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals(1, c.getMethods().length); + Method getter = c.getMethod("getList", new Class[0]); + assertEquals(List.class, getter.getReturnType()); + } + + public void testTwoProperties() throws NoJavaImplementationException, NoSuchMethodException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("true", Boolean.TYPE, false, false)); + gen.visitProperty(new MockProperty("int", Integer.TYPE, false, false)); + gen.visitEnd(); + Class c = cl.addClass(gen.getClassData()); + assertEquals(4, c.getMethods().length); + Method getter = c.getMethod("isTrue", new Class[0]); + assertEquals(boolean.class, getter.getReturnType()); + Method setter = c.getMethod("setTrue", new Class[] {boolean.class}); + assertEquals(void.class, setter.getReturnType()); + getter = c.getMethod("getInt", new Class[0]); + assertEquals(int.class, getter.getReturnType()); + setter = c.getMethod("setInt", new Class[] {int.class}); + assertEquals(void.class, setter.getReturnType()); + } + + protected void setUp() throws Exception { + super.setUp(); + foo = new MockType("foo", null); + gen = new BytecodeInterfaceGenerator(); + cl = new TestClassLoader(); + } + + private class TestClassLoader extends ClassLoader { + public TestClassLoader() { + super(TestClassLoader.class.getClassLoader()); + } + + Class addClass(byte[] bytes) { + return defineClass(null, bytes, 0, bytes.length); + } + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Foo.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Foo.java new file mode 100644 index 0000000000..56bf6af9b4 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/Foo.java @@ -0,0 +1,26 @@ +/** + * + * 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.codegen; + +/** + * @version $Rev$ $Date$ + */ +public interface Foo { +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGeneratorTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGeneratorTestCase.java new file mode 100644 index 0000000000..6cc0529c5f --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGeneratorTestCase.java @@ -0,0 +1,129 @@ +/** + * + * 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.codegen; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class JavaInterfaceGeneratorTestCase extends TestCase { + private static final String SEP = System.getProperty("line.separator"); + + private JavaInterfaceGenerator gen; + private StringWriter writer; + private MockType foo; + + public void testHeaderNoBaseClass() { + gen.visitType(foo); + gen.visitEnd(); + assertEquals(localize("public interface Foo {\n}\n"), writer.toString()); + } + + public void testHeaderWithPackage() { + gen.visitType(new MockType("org.apache.Foo", null)); + gen.visitEnd(); + assertEquals(localize("package org.apache;\n\npublic interface Foo {\n}\n"), writer.toString()); + } + + public void testHeaderOneBaseClass() throws NoJavaImplementationException { + foo.addBaseType(new MockType("bar1", Bar1.class)); + gen.visitType(foo); + gen.visitEnd(); + assertEquals(localize("public interface Foo extends org.apache.tuscany.sdo.codegen.Bar1 {\n}\n"), writer.toString()); + } + + public void testHeaderMultipleBaseClass() throws NoJavaImplementationException { + foo.addBaseType(new MockType("bar1", Bar1.class)); + foo.addBaseType(new MockType("bar2", Bar2.class)); + gen.visitType(foo); + gen.visitEnd(); + assertEquals(localize("public interface Foo extends org.apache.tuscany.sdo.codegen.Bar1, org.apache.tuscany.sdo.codegen.Bar2 {\n}\n"), writer.toString()); + } + + public void testBooleanProperty() throws NoJavaImplementationException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("true", Boolean.TYPE, false, false)); + gen.visitEnd(); + assertEquals(localize("public interface Foo {\n\tboolean isTrue();\n\tvoid setTrue(boolean value);\n}\n"), writer.toString()); + } + + public void testByteArrayProperty() throws NoJavaImplementationException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("bytes", byte[].class, false, false)); + gen.visitEnd(); + assertEquals(localize("public interface Foo {\n\tbyte[] getBytes();\n\tvoid setBytes(byte[] value);\n}\n"), writer.toString()); + } + + public void testObjectProperty() throws NoJavaImplementationException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("bar", Bar1.class, false, false)); + gen.visitEnd(); + assertEquals(localize("public interface Foo {\n\torg.apache.tuscany.sdo.codegen.Bar1 getBar();\n\tvoid setBar(org.apache.tuscany.sdo.codegen.Bar1 value);\n}\n"), writer.toString()); + } + + public void testReadOnlyProperty() throws NoJavaImplementationException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("int", Integer.TYPE, false, true)); + gen.visitEnd(); + assertEquals(localize("public interface Foo {\n\tint getInt();\n}\n"), writer.toString()); + } + + public void testManyProperty() throws NoJavaImplementationException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("list", Integer.TYPE, true, false)); + gen.visitEnd(); + assertEquals(localize("public interface Foo {\n\tjava.util.List getList();\n}\n"), writer.toString()); + } + + public void testTwoProperties() throws NoJavaImplementationException { + gen.visitType(foo); + gen.visitProperty(new MockProperty("true", Boolean.TYPE, false, false)); + gen.visitProperty(new MockProperty("int", Integer.TYPE, false, false)); + gen.visitEnd(); + assertEquals(localize("public interface Foo {\n\tboolean isTrue();\n\tvoid setTrue(boolean value);\n\tint getInt();\n\tvoid setInt(int value);\n}\n"), writer.toString()); + } + + protected void setUp() throws Exception { + super.setUp(); + writer = new StringWriter(); + gen = new JavaInterfaceGenerator(new PrintWriter(writer)); + foo = new MockType("foo", null); + } + + private String localize(String s) { + StringBuffer b = new StringBuffer(s.length() + s.length()/10); + for (int i = 0; i < s.length(); i++) { + char ch = s.charAt(i); + if (ch == '\t') { + b.append(" "); + } else if (ch == '\n') { + b.append(SEP); + } else { + b.append(ch); + } + } + return b.toString(); + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/MockProperty.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/MockProperty.java new file mode 100644 index 0000000000..d7e70369c0 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/MockProperty.java @@ -0,0 +1,78 @@ +/** + * + * 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.codegen; + +import java.util.List; + +import commonj.sdo.Property; +import commonj.sdo.Type; + +/** + * @version $Rev$ $Date$ + */ +class MockProperty implements Property { + private final String name; + private final Type type; + private final boolean many; + private final boolean readOnly; + + public MockProperty(String name, Class type, boolean many, boolean readOnly) { + this.name = name; + this.type = new MockType(null, type); + this.many = many; + this.readOnly = readOnly; + } + + public String getName() { + return name; + } + + public Type getType() { + return type; + } + + public boolean isMany() { + return many; + } + + public boolean isContainment() { + throw new UnsupportedOperationException(); + } + + public Type getContainingType() { + throw new UnsupportedOperationException(); + } + + public Object getDefault() { + throw new UnsupportedOperationException(); + } + + public boolean isReadOnly() { + return readOnly; + } + + public Property getOpposite() { + throw new UnsupportedOperationException(); + } + + public List /*String*/ getAliasNames() { + throw new UnsupportedOperationException(); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/MockType.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/MockType.java new file mode 100644 index 0000000000..4d3ecf9799 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/codegen/MockType.java @@ -0,0 +1,96 @@ +/** + * + * 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.codegen; + +import java.util.List; +import java.util.ArrayList; + +import commonj.sdo.Type; +import commonj.sdo.Property; + +/** + * @version $Rev$ $Date$ + */ +class MockType implements Type { + private final String name; + private final Class javaClass; + private final List baseTypes = new ArrayList(); + + public MockType(String name, Class javaClass) { + this.javaClass = javaClass; + this.name = name; + } + + public void addBaseType(Type baseType) { + baseTypes.add(baseType); + } + + public String getName() { + return name; + } + + public String getURI() { + throw new UnsupportedOperationException(); + } + + public Class getInstanceClass() { + return javaClass; + } + + public boolean isInstance(Object object) { + throw new UnsupportedOperationException(); + } + + public List /*Property*/ getProperties() { + throw new UnsupportedOperationException(); + } + + public Property getProperty(String propertyName) { + throw new UnsupportedOperationException(); + } + + public boolean isDataType() { + throw new UnsupportedOperationException(); + } + + public boolean isOpen() { + throw new UnsupportedOperationException(); + } + + public boolean isSequenced() { + throw new UnsupportedOperationException(); + } + + public boolean isAbstract() { + throw new UnsupportedOperationException(); + } + + public List /*Type*/ getBaseTypes() { + return baseTypes; + } + + public List /*Property*/ getDeclaredProperties() { + throw new UnsupportedOperationException(); + } + + public List /*String*/ getAliasNames() { + throw new UnsupportedOperationException(); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java new file mode 100644 index 0000000000..e956720117 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/ChangeSummaryTestCase.java @@ -0,0 +1,92 @@ +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.ChangeSummary; +import commonj.sdo.DataGraph; +import commonj.sdo.DataObject; +import commonj.sdo.helper.XSDHelper; + + +public class ChangeSummaryTestCase extends TestCase { + private final String TEST_MODEL = "/simple.xsd"; + private final String TEST_DATA = "/simplechangesummary.xml"; + + /** + * Simple ChangeSummary test. + */ + public void testChangeSummary() throws IOException { + // Create an empty data graph and add a root object, an instance of type Quote + // + + DataGraph dataGraph = SDOUtil.createDataGraph(); + DataObject quote = dataGraph.createRootObject("http://www.example.com/simple", "Quote"); + + // Begin logging changes + // + ChangeSummary changeSummary = dataGraph.getChangeSummary(); + changeSummary.beginLogging(); + + // Modify the data graph in various fun and interesting ways + // + quote.setString("symbol", "fbnt"); + quote.setString("companyName", "FlyByNightTechnology"); + quote.setBigDecimal("price", new BigDecimal("1000.0")); + quote.setBigDecimal("open1", new BigDecimal("1000.0")); + quote.setBigDecimal("high", new BigDecimal("1000.0")); + quote.setBigDecimal("low", new BigDecimal("1000.0")); + quote.setDouble("volume", 1000); + quote.setDouble("change1", 1000); + + DataObject child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2000.0")); + + // Stop logging changes and print the resulting data graph to stdout + // + changeSummary.endLogging(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + SDOUtil.saveDataGraph(dataGraph, baos, null); + + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA))); + } + + 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(); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/CrossScopeCopyTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/CrossScopeCopyTestCase.java new file mode 100644 index 0000000000..41801685f5 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/CrossScopeCopyTestCase.java @@ -0,0 +1,469 @@ +/**
+ *
+ * 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.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Vector;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+
+public class CrossScopeCopyTestCase extends TestCase
+{
+ // Literals
+ private static final String TEST_NAMESPACE = "http://www.example.com/bank";
+ private static final String BANK_MODEL = "/bank.xsd";
+ private static final String BANK_TYPE = "bankType";
+ private static final String BRANCH_TYPE = "branchType";
+ private static final String SERVICE_TYPE = "serviceType";
+ private static final String ACCOUNT_TYPE = "accountType";
+ private static final String CUSTOMER_TYPE = "customerType";
+ private static final String ADDRESS_TYPE = "addressType";
+ private static final String DYNAMIC_TYPE = "dynamicType";
+
+ // SDO model objects
+ private TypeHelper scopeA;
+ private TypeHelper scopeB;
+
+ // SDO instance objects
+ private DataObject bankSDO;
+ private DataObject branchSDO1;
+ private DataObject branchSDO2;
+ private DataObject serviceSDO1;
+ private DataObject serviceSDO2;
+ private DataObject serviceSDO3;
+ private DataObject customerSDO1;
+ private DataObject customerSDO2;
+ private DataObject customerSDO3;
+ private DataObject customerSDO4;
+
+ private int indent = 0;
+
+ public void testCrossScopeCopy() throws IOException
+ {
+ CopyHelper copyHelperB = SDOUtil.createCrossScopeCopyHelper(scopeB);
+
+ // Perform Shallow Copy Test
+ DataObject copiedSDO = copyHelperB.copyShallow(bankSDO);
+ shallowCopyAssertions(bankSDO, copiedSDO);
+
+ // Perform Deep Copy Test
+ copiedSDO = copyHelperB.copy(bankSDO);
+ deepCopyAssertions(bankSDO, copiedSDO);
+
+ // Inter-Reference Copy
+ copiedSDO = copyHelperB.copy(customerSDO1);
+ DataObject prop = (DataObject)copiedSDO.get("HomeBranch");
+ assertTrue(prop==null);
+
+ // Perform invalid namespace test
+ DataObject sdo = SDOUtil.createDataFactory(scopeA).create(TEST_NAMESPACE, DYNAMIC_TYPE );
+ sdo.set("custNum", "099" );
+ sdo.set("firstName", "John");
+ sdo.set("lastName", "Doe");
+ boolean failed = false;
+ try
+ {
+ // In this case, we are copying an object to a scope
+ // where the object's type has not been defined. That
+ // will generate a null pointer exception what we will
+ // catch.
+ copyHelperB.copy(sdo);
+ }
+ catch(java.lang.NullPointerException ex)
+ {
+ failed = true;
+ }
+ assertTrue(failed);
+ }
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // Create Two Scopes
+ scopeA = SDOUtil.createTypeHelper();
+ scopeB = SDOUtil.createTypeHelper();
+
+ // Populate scopes with bank model now
+ URL url = getClass().getResource(BANK_MODEL);
+ InputStream inputStream = url.openStream();
+ SDOUtil.createXSDHelper(scopeA).define(inputStream, url.toString());
+ inputStream.close();
+ inputStream = url.openStream();
+ SDOUtil.createXSDHelper(scopeB).define(inputStream, url.toString());
+ inputStream.close();
+
+ // Now Populate scopeA with some dynamic models
+ populateScopeWithDynamicTypes(scopeA);
+
+ // Construct Source Tree
+ constructSourceTree(SDOUtil.createDataFactory(scopeA));
+ }
+
+ private void shallowCopyAssertions(DataObject sdo, DataObject copiedSdo)
+ {
+ assertEquals(sdo.getType().getName(), copiedSdo.getType().getName());
+ assertEquals(sdo.getType().getURI(), copiedSdo.getType().getURI());
+ assertNotSame(sdo.getType(), copiedSdo.getType());
+ assertEquals(sdo.getInstanceProperties().size(), copiedSdo
+ .getInstanceProperties().size());
+
+ for(Iterator it = sdo.getInstanceProperties().iterator(), it2 = copiedSdo
+ .getInstanceProperties().iterator(); it.hasNext();)
+ {
+ Property p1 = (Property) it.next(), p2 = (Property) it2.next();
+ assertEquals(p1.getName(), p2.getName());
+ Object o1 = sdo.get(p1), o2 = copiedSdo.get(p2);
+ if(p1.getType().isDataType())
+ {
+ assertEquals(o1, o2);
+ // TODO is there a way I can distinguish between mutable and
+ // immutable types
+ // so that I can do some "same object" tests
+ }
+ else
+ {
+ assertNotSame(p1, p2);
+ if(p2.isMany())
+ {
+ assertEquals(copiedSdo.getList(p2).size(), 0);
+ }
+ else
+ {
+ assertNull(copiedSdo.get(p2));
+ }
+ }
+ try
+ {
+ sdo.get(p2);
+ assertTrue(false);
+ }
+ catch(Exception e)
+ {
+ // expected route
+ }
+ try
+ {
+ copiedSdo.get(p1);
+ assertTrue(false);
+ }
+ catch(Exception e2)
+ {
+ // expected route
+ }
+ }
+ }
+
+ private void deepCopyAssertions(DataObject sdo, DataObject copiedSdo)
+ {
+ //indent();
+
+ //System.out.println("checking objects of types: "
+ // + sdo.getType().getName() + ", "
+ // + copiedSdo.getType().getName());
+ indent++;
+
+ assertEquals(sdo.getType().getName(), copiedSdo.getType().getName());
+ assertEquals(sdo.getType().getURI(), copiedSdo.getType().getURI());
+ assertNotSame(sdo.getType(), copiedSdo.getType());
+ assertEquals(sdo.getInstanceProperties().size(), copiedSdo
+ .getInstanceProperties().size());
+
+ for(Iterator it = sdo.getInstanceProperties().iterator(), it2 = copiedSdo
+ .getInstanceProperties().iterator(); it.hasNext();)
+ {
+ Property p1 = (Property) it.next(), p2 = (Property) it2.next();
+ assertEquals(p1.getName(), p2.getName());
+ Object o1 = sdo.get(p1), o2 = copiedSdo.get(p2);
+ if(p1.getType().isDataType())
+ {
+ assertEquals(o1, o2);
+ // TODO is there a way I can distinguish between mutable and
+ // immutable types
+ // so that I can do some "same object" tests
+ }
+ else
+ {
+ assertNotSame(p1, p2);
+ if(p2.isMany())
+ {
+ assertEquals(sdo.getList(p1).size(), copiedSdo.getList(p2)
+ .size());
+ for(Iterator it3 = sdo.getList(p1).iterator(), it4 = copiedSdo
+ .getList(p2).iterator(); it3.hasNext();)
+ {
+ deepCopyAssertions((DataObject) it3.next(),
+ (DataObject) it4.next());
+ }
+ }
+ else
+ {
+ deepCopyAssertions(sdo.getDataObject(p1), copiedSdo
+ .getDataObject(p2));
+ }
+ }
+ try
+ {
+ sdo.get(p2);
+ assertTrue(false);
+ }
+ catch(Exception e)
+ {
+ // expected route
+ }
+ try
+ {
+ copiedSdo.get(p1);
+ assertTrue(false);
+ }
+ catch(Exception e2)
+ {
+ // expected route
+ }
+ }
+
+ indent--;
+ }
+
+ /*
+ private void indent()
+ {
+ for(int i=0; i <indent; i++) System.out.print(" ");
+ }
+ */
+
+ protected void constructSourceTree(DataFactory df)
+ {
+ // Create Instances
+ bankSDO = df.create(TEST_NAMESPACE, BANK_TYPE );
+ branchSDO1 = df.create(TEST_NAMESPACE, BRANCH_TYPE );
+ branchSDO2 = df.create(TEST_NAMESPACE, BRANCH_TYPE );
+ serviceSDO1 = df.create(TEST_NAMESPACE, SERVICE_TYPE );
+ serviceSDO2 = df.create(TEST_NAMESPACE, SERVICE_TYPE );
+ serviceSDO3 = df.create(TEST_NAMESPACE, SERVICE_TYPE );
+ customerSDO1 = df.create(TEST_NAMESPACE, CUSTOMER_TYPE );
+ customerSDO2 = df.create(TEST_NAMESPACE, CUSTOMER_TYPE );
+ customerSDO3 = df.create(TEST_NAMESPACE, CUSTOMER_TYPE );
+ customerSDO4 = df.create(TEST_NAMESPACE, CUSTOMER_TYPE );
+
+ // Populate the Bank Instance
+ bankSDO.set("name", "Fourth National");
+ Vector v = new Vector();
+ v.add(branchSDO1);
+ v.add(branchSDO2);
+ bankSDO.set("Branch",v);
+ v.removeAllElements();
+ v.add(serviceSDO1);
+ v.add(serviceSDO2);
+ v.add(serviceSDO3);
+ bankSDO.set("Service",v);
+ v.removeAllElements();
+ v.add(customerSDO1);
+ v.add(customerSDO2);
+ v.add(customerSDO3);
+ v.add(customerSDO4);
+ bankSDO.set("Customer",v);
+ v.removeAllElements();
+
+ // Populate Branch Instances
+ // Branch 1
+ branchSDO1.set("ID", "BR100");
+ DataObject addr = df.create(TEST_NAMESPACE, ADDRESS_TYPE );
+ addr.set("Street", "1302 Money Street");
+ addr.set("City", "Apex");
+ addr.set("State", "NC");
+ addr.set("Zip", "27502");
+ branchSDO1.set("Address", addr);
+ v.add("If you are north, head south");
+ v.add("If you are south, head north");
+ branchSDO1.set("Directions", v);
+ v.removeAllElements();
+ DataObject account1 = df.create(TEST_NAMESPACE, ACCOUNT_TYPE );
+ account1.set("ID", "0000 1200 0001");
+ account1.set("Service", serviceSDO1 );
+ account1.setBigDecimal("Balance", new BigDecimal("3124.12"));
+ v.add(account1);
+ DataObject account2 = df.create(TEST_NAMESPACE, ACCOUNT_TYPE );
+ account2.set("ID", "0000 8899 0001");
+ account2.set("Service", serviceSDO1 );
+ account2.setBigDecimal("Balance", new BigDecimal("20.00"));
+ v.add(account2);
+ DataObject account3 = df.create(TEST_NAMESPACE, ACCOUNT_TYPE );
+ account3.set("ID", "0000 3110 0020");
+ account3.set("Service", serviceSDO3 );
+ account3.setBigDecimal("Balance", new BigDecimal("5000.00"));
+ v.add(account3);
+ branchSDO1.set("Account", v);
+ v.removeAllElements();
+ // Branch 2
+ branchSDO2.set("ID", "BR200");
+ addr = df.create(TEST_NAMESPACE, ADDRESS_TYPE );
+ addr.set("Street", "1207 Cash Court");
+ addr.set("City", "Raleigh");
+ addr.set("State", "NC");
+ addr.set("Zip", "27701");
+ branchSDO2.set("Address", addr);
+ v.add("If you are east, head west");
+ v.add("If you are west, head east");
+ branchSDO2.set("Directions", v);
+ v.removeAllElements();
+ DataObject account4 = df.create(TEST_NAMESPACE, ACCOUNT_TYPE );
+ account4.set("ID", "0000 0011 0001");
+ account4.set("Service", serviceSDO1 );
+ account4.setBigDecimal("Balance", new BigDecimal("99.12"));
+ v.add(account4);
+ DataObject account5 = df.create(TEST_NAMESPACE, ACCOUNT_TYPE );
+ account5.set("ID", "0000 9911 0001");
+ account5.set("Service", serviceSDO2 );
+ account5.setBigDecimal("Balance", new BigDecimal("820.00"));
+ v.add(account5);
+ DataObject account6 = df.create(TEST_NAMESPACE, ACCOUNT_TYPE );
+ account6.set("ID", "0000 0001 0020");
+ account6.set("Service", serviceSDO3 );
+ account6.setBigDecimal("Balance", new BigDecimal("9000.00"));
+ v.add(account6);
+ branchSDO2.set("Account", v);
+ v.removeAllElements();
+
+ // Populate Service Instances
+ serviceSDO1.set("ID", "SRV01");
+ serviceSDO1.set("Name", "Checking");
+ serviceSDO1.setBigDecimal("Fee", new BigDecimal("0.00"));
+ serviceSDO2.set("ID", "SRV02");
+ serviceSDO2.set("Name", "Savings");
+ serviceSDO2.setBigDecimal("Fee", new BigDecimal("0.00"));
+ serviceSDO3.set("ID", "SRV03");
+ serviceSDO3.set("Name", "Loan");
+ serviceSDO3.setBigDecimal("Fee", new BigDecimal("0.00"));
+
+ // Populate Customer Instances
+ // Customer 1
+ customerSDO1.set("ID", "CUST01");
+ customerSDO1.set("First", "James");
+ customerSDO1.set("Last", "Madison");
+ addr = df.create(TEST_NAMESPACE, ADDRESS_TYPE );
+ addr.set("Street", "1234 Easy Street");
+ addr.set("City", "New York");
+ addr.set("State", "NY");
+ addr.set("Zip", "27511");
+ customerSDO1.set("Address", addr);
+ customerSDO1.set("HomeBranch", branchSDO1);
+ v.add(account1);
+ customerSDO1.set("Account", v);
+ v.removeAllElements();
+ v.add(customerSDO2);
+ v.add(customerSDO3);
+ customerSDO1.set("Related", v);
+ v.removeAllElements();
+ // Customer 2
+ customerSDO2.set("ID", "CUST02");
+ customerSDO2.set("First", "George");
+ customerSDO2.set("Last", "Washington");
+ addr = df.create(TEST_NAMESPACE, ADDRESS_TYPE );
+ addr.set("Street", "1776 Potomac Avenue");
+ addr.set("City", "Washington");
+ addr.set("State", "DC");
+ addr.set("Zip", "50555");
+ customerSDO2.set("Address", addr);
+ customerSDO2.set("HomeBranch", branchSDO1);
+ v.add(account2);
+ v.add(account3);
+ customerSDO2.set("Account", v);
+ v.removeAllElements();
+ // Customer 3
+ customerSDO3.set("ID", "CUST03");
+ customerSDO3.set("First", "Thomas");
+ customerSDO3.set("Last", "Jefferson");
+ addr = df.create(TEST_NAMESPACE, ADDRESS_TYPE );
+ addr.set("Street", "1492 Columbus Avenue");
+ addr.set("City", "Charlottesville");
+ addr.set("State", "VA");
+ addr.set("Zip", "20121");
+ customerSDO3.set("Address", addr);
+ customerSDO3.set("HomeBranch", branchSDO2);
+ v.add(account4);
+ customerSDO3.set("Account", v);
+ v.removeAllElements();
+ // Customer 4
+ customerSDO4.set("ID", "CUST04");
+ customerSDO4.set("First", "Benjamin");
+ customerSDO4.set("Last", "Franklin");
+ addr = df.create(TEST_NAMESPACE, ADDRESS_TYPE );
+ addr.set("Street", "99 Light Street");
+ addr.set("City", "Philadelphia");
+ addr.set("State", "PA");
+ addr.set("Zip", "19251");
+ customerSDO4.set("Address", addr);
+ customerSDO4.set("HomeBranch", branchSDO2);
+ v.add(account5);
+ v.add(account6);
+ customerSDO4.set("Account", v);
+ v.removeAllElements();
+
+ }
+
+ private void populateScopeWithDynamicTypes(TypeHelper scope)
+ {
+ Type stringType = scope.getType("commonj.sdo", "String");
+ DataObject customerType = DataFactory.INSTANCE.create("commonj.sdo", "Type");
+ customerType.set("uri", TEST_NAMESPACE);
+ customerType.set("name", DYNAMIC_TYPE );
+ DataObject custNumProperty = customerType.createDataObject("property");
+ custNumProperty.set("name", "custNum");
+ custNumProperty.set("type", stringType);
+ DataObject firstNameProperty = customerType.createDataObject("property");
+ firstNameProperty.set("name", "firstName");
+ firstNameProperty.set("type", stringType);
+ DataObject lastNameProperty = customerType.createDataObject("property");
+ lastNameProperty.set("name", "lastName");
+ lastNameProperty.set("type", stringType);
+ scope.define(customerType);
+ }
+
+ /*
+ private void dumpObject(DataObject sdo, String node )
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SDOUtil.createXMLHelper(scopeA).save(sdo, TEST_NAMESPACE,
+ node, baos);
+ System.out.println(baos.toString());
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ */
+}
diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataTypeBaseTypeTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataTypeBaseTypeTestCase.java new file mode 100644 index 0000000000..a49b165386 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DataTypeBaseTypeTestCase.java @@ -0,0 +1,68 @@ +/** + * + * 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.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import commonj.sdo.Type; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + + +public class DataTypeBaseTypeTestCase extends TestCase { + private final String TEST_MODEL = "/datatype.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/datatype"; + + public void testSimpleSDOType() throws IOException + { + Type type = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "SimpleSDOType"); + List baseTypes = type.getBaseTypes(); + assertTrue(baseTypes.size() == 1); + } + + public void testSimpleSDOTypeInstanceClass() throws IOException + { + Type type = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "SimpleSDOTypeInstanceClass"); + List baseTypes = type.getBaseTypes(); + assertTrue(baseTypes.size() == 0); + } + + public void testSimpleSDOTypeExtendedInstanceClass() throws IOException + { + Type type = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "SimpleSDOTypeExtendedInstanceClass"); + List baseTypes = type.getBaseTypes(); + assertTrue(baseTypes.size() == 1); + } + + public void setUp() throws Exception + { + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + XSDHelper.INSTANCE.define(inputStream, url.toString()); + inputStream.close(); + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DateConversionTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DateConversionTestCase.java new file mode 100644 index 0000000000..ca345eb241 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DateConversionTestCase.java @@ -0,0 +1,366 @@ +/** + * + * 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.lang.reflect.Method; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; + +import junit.framework.TestCase; + +import commonj.sdo.helper.DataHelper; + +// DateConversionTestCase insures that the DataHelper conversions accurately +// retain the information in the specified fields (e.g. month, day or year). +// It also provides coverage for the DataHelper API. +// Note that toDate is called each time Test.initialize() is called. + +public class DateConversionTestCase extends TestCase +{ + private static Calendar test_calendar; + private static Date test_date; + private static DataHelper data_helper; + + private static final TestType TO_DATE_TIME = new TestType("toDateTime", new int [] {Calendar.YEAR, Calendar.MONTH, + Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND}); + private static final TestType TO_DURATION = new TestType("toDuration", new int [] {Calendar.YEAR, Calendar.MONTH, + Calendar.DAY_OF_MONTH, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND}); + private static final TestType TO_TIME = new TestType("toTime", new int [] {Calendar.HOUR_OF_DAY, Calendar.MINUTE, + Calendar.SECOND, Calendar.MILLISECOND}); + private static final TestType TO_DAY = new TestType("toDay", new int[] {Calendar.DAY_OF_MONTH}); + private static final TestType TO_MONTH = new TestType("toMonth", new int[] {Calendar.MONTH}); + private static final TestType TO_MONTH_DAY = new TestType("toMonthDay", new int[] {Calendar.MONTH, Calendar.DAY_OF_MONTH}); + private static final TestType TO_YEAR = new TestType("toYear", new int[] {Calendar.YEAR}); + private static final TestType TO_YEAR_MONTH= new TestType("toYearMonth", new int[] {Calendar.YEAR, Calendar.MONTH}); + private static final TestType TO_YEAR_MONTH_DAY = new TestType("toYearMonthDay", new int[] {Calendar.YEAR, + Calendar.MONTH, Calendar.DAY_OF_MONTH}); + + public DateConversionTestCase() throws Exception + { + data_helper = DataHelper.INSTANCE; + test_calendar = new GregorianCalendar(); + test_calendar.setTime(new Date(System.currentTimeMillis())); + test_date = test_calendar.getTime(); + } + + private static class TestType + { + private static final Class[] DATE_CLASS_ARRAY = {Date.class}; + private static final Class[] CALENDAR_CLASS_ARRAY = {Calendar.class}; + + Method date_method; + Method calendar_method; + int [] compare_fields; + + public TestType (String method_name, int [] compare_fields) + { + try + { + this.date_method = DataHelper.class.getMethod(method_name, DATE_CLASS_ARRAY); + } + catch (NoSuchMethodException e) + { + this.date_method = null; + } + + this.compare_fields = compare_fields; + try + { + this.calendar_method = DataHelper.class.getMethod(method_name, CALENDAR_CLASS_ARRAY); + } + catch (NoSuchMethodException e) + { + this.calendar_method = null; + } + + } + + public Method getDateMethod() + { + return this.date_method; + } + + public Method getCalendarMethod() + { + return this.calendar_method; + } + } + + private static class Test + { + String from_type; + Date from_date; + Calendar from_calendar; + Class expected_exception; + + public Test () + { + this.from_date = null; + this.from_calendar = null; + expected_exception = null; + } + + public void initialize (TestType from_type) + { + this.from_type = from_type.getDateMethod().getName(); + + try + { + String date_string = (String) from_type.getDateMethod().invoke(data_helper, new Object[] {test_date}); + this.from_date = data_helper.toDate(date_string); + date_string = (String) from_type.getCalendarMethod().invoke(data_helper, new Object[] {test_calendar}); + this.from_calendar = data_helper.toCalendar(date_string); + } + catch (Exception e) + { + this.from_date = null; + this.from_calendar = null; + } + + } + + // This method is needed because there is not a toDate(Date) method in DataHelper. + + public void initializeToDate() + { + this.from_calendar = test_calendar; + this.from_date = test_date; + this.from_type = "toDate"; + } + + public void attemptConversion (TestType to_type) throws Exception + { + executeConversion(to_type.getDateMethod(), new Object[] {this.from_date}, to_type.compare_fields); + executeConversion(to_type.getCalendarMethod(), new Object[] {this.from_calendar}, to_type.compare_fields); + } + + private void executeConversion (Method conversion, Object[] parm, int [] compare_fields) throws Exception + { + String result; + + try + { + result = (String) conversion.invoke(data_helper, parm); + } + catch (Exception e) + { + System.err.println("An unexpected exception was thrown while calling " + conversion.getName() + + " after initializing with " + this.from_type + "."); + throw e; + } + + assertTrue("The expected value did not result when calling " + conversion.getName() + + " after initializing with " + this.from_type + ".", compareFields(parm[0], result, compare_fields)); + } + + private boolean compareFields(Object compare_to, String output, int [] compare_fields) + { + Calendar result = data_helper.toCalendar(output); + Calendar expected; + + if (compare_to instanceof Calendar) + expected = (GregorianCalendar) test_calendar; + else + { + expected = new GregorianCalendar(); + expected.setTime((Date) test_date); + } + + for (int i = 0; i < compare_fields.length; i++) + { + if (expected.get(compare_fields[i]) != result.get(compare_fields[i])) + return false; + } + return true; + } + + } + + /* + public void testConversionsFromDay() throws Exception + { + Test FromDay = new Test(); + + FromDay.initialize(TO_DAY); + + FromDay.attemptConversion(TO_DAY); + } + + public void testConversionsFromDate() throws Exception + { + Test FromDate = new Test(); + + FromDate.initializeToDate(); + + FromDate.attemptConversion(TO_DATE_TIME); + FromDate.attemptConversion(TO_DURATION); + FromDate.attemptConversion(TO_TIME); + FromDate.attemptConversion(TO_DAY); + FromDate.attemptConversion(TO_MONTH); + FromDate.attemptConversion(TO_MONTH_DAY); + FromDate.attemptConversion(TO_YEAR); + FromDate.attemptConversion(TO_YEAR_MONTH); + FromDate.attemptConversion(TO_YEAR_MONTH_DAY); + } + + public void testConversionsFromDateTime() throws Exception + { + Test FromDateTime = new Test(); + + FromDateTime.initialize(TO_DATE_TIME); + + FromDateTime.attemptConversion(TO_DATE_TIME); + FromDateTime.attemptConversion(TO_DURATION); + FromDateTime.attemptConversion(TO_TIME); + FromDateTime.attemptConversion(TO_DAY); + FromDateTime.attemptConversion(TO_MONTH); + FromDateTime.attemptConversion(TO_MONTH_DAY); + FromDateTime.attemptConversion(TO_YEAR); + FromDateTime.attemptConversion(TO_YEAR_MONTH); + FromDateTime.attemptConversion(TO_YEAR_MONTH_DAY); + } + + public void testConversionsFromDuration() throws Exception + { + Test FromDuration = new Test(); + + FromDuration.initialize(TO_DURATION); + + FromDuration.attemptConversion(TO_DURATION); + FromDuration.attemptConversion(TO_DATE_TIME); + FromDuration.attemptConversion(TO_TIME); + FromDuration.attemptConversion(TO_DAY); + FromDuration.attemptConversion(TO_MONTH); + FromDuration.attemptConversion(TO_MONTH_DAY); + FromDuration.attemptConversion(TO_YEAR); + FromDuration.attemptConversion(TO_YEAR_MONTH); + FromDuration.attemptConversion(TO_YEAR_MONTH_DAY); + } + + public void testConversionsFromMonth() throws Exception + { + Test FromMonth = new Test(); + + FromMonth.initialize(TO_MONTH); + + FromMonth.attemptConversion(TO_MONTH); + } + + public void testConversionsFromMonthDay() throws Exception + { + Test FromMonthDay = new Test(); + + FromMonthDay.initialize(TO_MONTH_DAY); + FromMonthDay.attemptConversion(TO_MONTH_DAY); + FromMonthDay.attemptConversion(TO_MONTH); + FromMonthDay.attemptConversion(TO_DAY); + } + + public void testConversionsFromTime() throws Exception + { + Test FromTime = new Test(); + + FromTime.initialize(TO_TIME); + + FromTime.attemptConversion(TO_TIME); + } + + public void testConversionsFromYear() throws Exception + { + Test FromYear = new Test(); + + FromYear.initialize(TO_YEAR); + + FromYear.attemptConversion(TO_YEAR); + } + + public void testConversionsFromYearMonth() throws Exception + { + Test FromYearMonth = new Test(); + + FromYearMonth.initialize(TO_YEAR_MONTH); + + FromYearMonth.attemptConversion(TO_YEAR_MONTH); + FromYearMonth.attemptConversion(TO_MONTH); + FromYearMonth.attemptConversion(TO_YEAR); + } + + public void testConversionsFromYearMonthDay() throws Exception + { + Test FromYearMonthDay = new Test(); + + FromYearMonthDay.initialize(TO_YEAR_MONTH_DAY); + + FromYearMonthDay.attemptConversion(TO_YEAR_MONTH_DAY); + FromYearMonthDay.attemptConversion(TO_YEAR_MONTH); + FromYearMonthDay.attemptConversion(TO_MONTH_DAY); + FromYearMonthDay.attemptConversion(TO_YEAR); + FromYearMonthDay.attemptConversion(TO_MONTH); + FromYearMonthDay.attemptConversion(TO_DAY); + } + */ + + // Ensure that strings that should be recognized by toDate do not + // result in a null Date value. + + public void testToDateFormats() throws Exception + { + String[] validStrings = + { + "2006-03-31T03:30:45.123Z", + "-2006-03-31T03:30:45.1Z", + "2006-03-31T03:30:45Z", + "2006-03-31T03:30:45.123", + "2006-03-31T03:30:45.1", + "-2006-03-31T03:30:45", + "2006-03-31T03:30:45.123 EDT", + "2006-03-31T03:30:45.1 EDT", + "2006-03-31T03:30:45 EDT", + "---05 PST", + "---04", + "--12 GMT", + "--12", + "--08-08 EST", + "--08-08", + "1976-08-08 PDT", + "1976-08-08", + "88-12 CST", + "1988-12", + "2005 CDT", + "1999", + "P2006Y 08M 10D T 12H 24M 07S", + "P2006Y 10D T 12H", + "-P2006Y 08M 10D T 07S.2", + "P08M 10D T 07H", + "-P 04M 10DT12H 24S.88", + "PT12H" + }; + + for (int i = 0; i < validStrings.length; i++) + { + assertNotNull("DataHelper.toData() should not return null for '" + validStrings[i] + "'.", + data_helper.toDate(validStrings[i])); + } + + } + +} + diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java new file mode 100644 index 0000000000..e1a3e2b781 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineOpenContentPropertyTestCase.java @@ -0,0 +1,123 @@ +/**
+ *
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.math.BigDecimal;
+import java.net.URL;
+
+import org.apache.tuscany.sdo.helper.TypeHelperImpl;
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.DataObject;
+import commonj.sdo.Property;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+import junit.framework.TestCase;
+
+
+public class DefineOpenContentPropertyTestCase extends TestCase {
+ private final String TEST_MODEL = "/open.xsd";
+ private final String TEST_NAMESPACE = "http://www.example.com/open";
+ private final String TEST_DATA = "/openContentProperty.xml";
+
+ private TypeHelperImpl typeHelper;
+ private XSDHelper xsdHelper;
+ private XMLHelper xmlHelper;
+ private DataFactory dataFactory;
+
+ public void testDefineOpenContentProperty() throws IOException {
+ Type quoteType = typeHelper.getType(TEST_NAMESPACE, "OpenQuote");
+ DataObject quote = dataFactory.create(quoteType);
+
+ quote.setString("symbol", "s1");
+
+ Property companyProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "company");
+ DataObject company = quote.createDataObject(companyProperty);
+ company.setString("name", "FlyByNightTechnology");
+
+ Property priceProperty = typeHelper.getOpenContentProperty(TEST_NAMESPACE, "price");
+ quote.getList(priceProperty).add(new BigDecimal("1000.0"));
+
+ // Define a new SDO open content property with simple type
+ DataObject p = dataFactory.create("commonj.sdo", "Property");
+ p.set("type", typeHelper.getType("commonj.sdo", "Decimal"));
+ p.set("name", "highPrice");
+ Property highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
+
+ quote.setBigDecimal(highPrice, new BigDecimal("1100.0"));
+
+ // Define a new SDO open content property with complex type
+ DataObject mutualFundQuotePropertyDef = dataFactory.create("commonj.sdo", "Property");
+ mutualFundQuotePropertyDef.set("type", quoteType);
+ mutualFundQuotePropertyDef.set("name", "mutualFundQuote");
+ mutualFundQuotePropertyDef.setBoolean("containment", true);
+ Property mutualFundQuoteProperty = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, mutualFundQuotePropertyDef);
+
+ DataObject mutualFundQuote = quote.createDataObject(mutualFundQuoteProperty);
+ mutualFundQuote.setString("symbol", "mutual-1");
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ xmlHelper.save(quote, TEST_NAMESPACE, "openStockQuote", baos);
+
+ assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA)));
+
+ // validate existing property condition
+ Property duplicateProp = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
+ assertTrue(highPrice.equals(duplicateProp));
+
+ // validate error condition, where new property exists with different type
+ boolean errorCondition = false;
+ try
+ {
+ p = dataFactory.create("commonj.sdo", "Property");
+ p.set("type", typeHelper.getType("commonj.sdo", "String"));
+ p.set("name", "highPrice");
+ highPrice = typeHelper.defineOpenContentProperty(TEST_NAMESPACE, p);
+ }
+ catch( IllegalArgumentException ex )
+ {
+ errorCondition = true;
+ }
+ assertTrue(errorCondition);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ typeHelper = (TypeHelperImpl)SDOUtil.createTypeHelper();
+ xsdHelper = SDOUtil.createXSDHelper(typeHelper);
+ xmlHelper = SDOUtil.createXMLHelper(typeHelper);
+ dataFactory = SDOUtil.createDataFactory(typeHelper);
+
+ // Populate the meta data for the test (Stock Quote) model
+ URL url = getClass().getResource(TEST_MODEL);
+ InputStream inputStream = url.openStream();
+ xsdHelper.define(inputStream, url.toString());
+ inputStream.close();
+ }
+}
diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java new file mode 100644 index 0000000000..259820b2f6 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/DefineTypeTestCase.java @@ -0,0 +1,627 @@ +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.math.BigDecimal; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.helper.TypeHelperImpl; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class DefineTypeTestCase extends TestCase +{ + private static final String CUSTOMER1_XML = "/customer1.xml"; + private static final String CUSTOMER2_XML = "/customer2.xml"; + private static final String OPEN_XML = "/open2.xml"; + private static final String MIXED_XML = "/mixed2.xml"; + private static final String MIXEDOPEN_XML = "/mixedopen.xml"; + + public void testDefineTypeRoundTrip() throws Exception { + TypeHelper types = SDOUtil.createTypeHelper(); + DataFactory factory = SDOUtil.createDataFactory(types); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(types); + + Type intType = types.getType("commonj.sdo", "Int"); + Type stringType = types.getType("commonj.sdo", "String"); + + // create a new Type for Customers + DataObject customerType = factory.create("commonj.sdo", + "Type"); + customerType.set("uri", "http://example.com/customer"); + customerType.set("name", "Customer"); + + // create a customer number property + DataObject custNumProperty = customerType.createDataObject("property"); + custNumProperty.set("name", "custNum"); + custNumProperty.set("type", intType); + + // create a first name property + DataObject firstNameProperty = + customerType.createDataObject("property"); + firstNameProperty.set("name", "firstName"); + firstNameProperty.set("type", stringType); + + // create a last name property + DataObject lastNameProperty = customerType.createDataObject("property"); + lastNameProperty.set("name", "lastName"); + lastNameProperty.set("type", stringType); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save(customerType, "commonj.sdo", "type", baos); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + XMLDocument xdoc = xmlHelper.load(bais); + + customerType = xdoc.getRootObject(); + + // now define the Customer type so that customers can be made + types.define(customerType); + + DataObject customer1 = factory.create("http://example.com/customer", + "Customer"); + + customer1.setInt("custNum", 1); + customer1.set("firstName", "John"); + customer1.set("lastName", "Adams"); + DataObject customer2 = factory.create("http://example.com/customer", + "Customer"); + customer2.setInt("custNum", 2); + customer2.set("firstName", "Jeremy"); + customer2.set("lastName", "Pavick"); + + assertNotNull(customer1); + Type type = customer1.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertEquals(type.getProperty("custNum").getType(), intType); + assertEquals(type.getProperty("firstName").getType(), stringType); + assertEquals(type.getProperty("lastName").getType(), stringType); + + assertNotNull(customer2); + type = customer2.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertEquals(type.getProperty("custNum").getType(), intType); + assertEquals(type.getProperty("firstName").getType(), stringType); + assertEquals(type.getProperty("lastName").getType(), stringType); + + baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer1, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER1_XML))); + + baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer2, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER2_XML))); + } + + public void testDefineType() throws Exception + { + TypeHelper types = SDOUtil.createTypeHelper(); + DataFactory factory = SDOUtil.createDataFactory(types); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(types); + + Type intType = types.getType("commonj.sdo", "Int"); + Type stringType = types.getType("commonj.sdo", "String"); + + // create a new Type for Customers + DataObject customerType = factory.create("commonj.sdo", + "Type"); + customerType.set("uri", "http://example.com/customer"); + customerType.set("name", "Customer"); + + // create a customer number property + DataObject custNumProperty = customerType.createDataObject("property"); + custNumProperty.set("name", "custNum"); + custNumProperty.set("type", intType); + + // create a first name property + DataObject firstNameProperty = + customerType.createDataObject("property"); + firstNameProperty.set("name", "firstName"); + firstNameProperty.set("type", stringType); + + // create a last name property + DataObject lastNameProperty = customerType.createDataObject("property"); + lastNameProperty.set("name", "lastName"); + lastNameProperty.set("type", stringType); + + // now define the Customer type so that customers can be made + types.define(customerType); + + DataObject customer1 = factory.create("http://example.com/customer", + "Customer"); + customer1.setInt("custNum", 1); + customer1.set("firstName", "John"); + customer1.set("lastName", "Adams"); + DataObject customer2 = factory.create("http://example.com/customer", + "Customer"); + customer2.setInt("custNum", 2); + customer2.set("firstName", "Jeremy"); + customer2.set("lastName", "Pavick"); + + assertNotNull(customer1); + Type type = customer1.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertEquals(type.getProperty("custNum").getType(), intType); + assertEquals(type.getProperty("firstName").getType(), stringType); + assertEquals(type.getProperty("lastName").getType(), stringType); + + assertNotNull(customer2); + type = customer2.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertEquals(type.getProperty("custNum").getType(), intType); + assertEquals(type.getProperty("firstName").getType(), stringType); + assertEquals(type.getProperty("lastName").getType(), stringType); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer1, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER1_XML))); + + baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer2, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER2_XML))); + } + + public void testDefineDataType() throws Exception + { + TypeHelper types = SDOUtil.createTypeHelper(); + DataFactory factory = SDOUtil.createDataFactory(types); + XSDHelper xsdHelper = SDOUtil.createXSDHelper(types); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(types); + + Property javaClassProperty = xsdHelper.getGlobalProperty("commonj.sdo/java", "javaClass", false); + + // create a data types + DataObject intType = factory.create("commonj.sdo", "Type"); + intType.set("uri", "http://example.com/customer"); + intType.set("name", "MyIntType"); + intType.setBoolean("dataType", true); + intType.set(javaClassProperty, "int"); + + DataObject stringType = factory.create("commonj.sdo", "Type"); + stringType.set("uri", "http://example.com/customer"); + stringType.set("name", "MyStringType"); + stringType.setBoolean("dataType", true); + stringType.set(javaClassProperty, "java.lang.String"); + + // create a new Type for Customers + DataObject customerType = factory.create("commonj.sdo", + "Type"); + customerType.set("uri", "http://example.com/customer"); + customerType.set("name", "Customer"); + + // create a customer number property + DataObject custNumProperty = customerType.createDataObject("property"); + custNumProperty.set("name", "custNum"); + custNumProperty.set("type", intType); + + // create a first name property + DataObject firstNameProperty = + customerType.createDataObject("property"); + firstNameProperty.set("name", "firstName"); + firstNameProperty.set("type", stringType); + + // create a last name property + DataObject lastNameProperty = customerType.createDataObject("property"); + lastNameProperty.set("name", "lastName"); + lastNameProperty.set("type", stringType); + + // now define the Customer type so that customers can be made + types.define(customerType); + + DataObject customer1 = factory.create("http://example.com/customer", + "Customer"); + + customer1.setInt("custNum", 1); + customer1.set("firstName", "John"); + customer1.set("lastName", "Adams"); + DataObject customer2 = factory.create("http://example.com/customer", + "Customer"); + customer2.setInt("custNum", 2); + customer2.set("firstName", "Jeremy"); + customer2.set("lastName", "Pavick"); + + assertNotNull(customer1); + Type type = customer1.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + + type = type.getProperty("custNum").getType(); + assertEquals(type.getURI(), "http://example.com/customer"); + assertEquals(type.getName(), "MyIntType"); + assertTrue(type.isDataType()); + + assertNotNull(customer2); + type = customer2.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer1, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER1_XML))); + + baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer2, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER2_XML))); + } + + public void testFastDefineType() throws Exception + { + TypeHelper types = SDOUtil.createTypeHelper(); + DataFactory factory = SDOUtil.createDataFactory(types); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(types); + + Type intType = types.getType("commonj.sdo", "Int"); + Type stringType = types.getType("commonj.sdo", "String"); + + // create a new Type for Customers + Type customerType = SDOUtil.createType(types, "http://example.com/customer", "Customer", false); + + // create a customer number property + SDOUtil.createProperty(customerType, "custNum", intType); + + // create a first name property + SDOUtil.createProperty(customerType, "firstName", stringType); + + // create a last name property + SDOUtil.createProperty(customerType, "lastName", stringType); + + DataObject customer1 = factory.create("http://example.com/customer", + "Customer"); + customer1.setInt("custNum", 1); + customer1.set("firstName", "John"); + customer1.set("lastName", "Adams"); + DataObject customer2 = factory.create("http://example.com/customer", + "Customer"); + customer2.setInt("custNum", 2); + customer2.set("firstName", "Jeremy"); + customer2.set("lastName", "Pavick"); + + assertNotNull(customer1); + Type type = customer1.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertEquals(type.getProperty("custNum").getType(), intType); + assertEquals(type.getProperty("firstName").getType(), stringType); + assertEquals(type.getProperty("lastName").getType(), stringType); + + assertNotNull(customer2); + type = customer2.getType(); + assertNotNull(type.getProperty("custNum")); + assertNotNull(type.getProperty("firstName")); + assertNotNull(type.getProperty("lastName")); + assertEquals(type.getProperty("custNum").getType(), intType); + assertEquals(type.getProperty("firstName").getType(), stringType); + assertEquals(type.getProperty("lastName").getType(), stringType); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer1, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER1_XML))); + + baos = new ByteArrayOutputStream(); + xmlHelper.save( + customer2, + "http://example.com/customer", + "Customer", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(CUSTOMER2_XML))); + } + + public void testDefineSequencedType() throws Exception + { + + TypeHelper types = SDOUtil.createTypeHelper(); + DataFactory factory = SDOUtil.createDataFactory(types); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(types); + + Type stringType = types.getType("commonj.sdo", "String"); + Type decimalType = types.getType("commonj.sdo", "Decimal"); + + // Define a new mixed type - MixedQuote + DataObject mixedQuoteType = factory.create("commonj.sdo", "Type"); + mixedQuoteType.set("uri", "http://www.example.com/mixed"); + mixedQuoteType.set("name", "MixedQuote"); + mixedQuoteType.set("sequenced", Boolean.TRUE); + + DataObject symbolProperty = mixedQuoteType.createDataObject("property"); + symbolProperty.set("name", "symbol"); + symbolProperty.set("type", stringType); + + DataObject companyNameProperty = mixedQuoteType.createDataObject("property"); + companyNameProperty.set("name", "companyName"); + companyNameProperty.set("type", stringType); + + DataObject priceProperty = mixedQuoteType.createDataObject("property"); + priceProperty.set("name", "price"); + priceProperty.set("type", decimalType); + + DataObject quotesProperty = mixedQuoteType.createDataObject("property"); + quotesProperty.set("name", "quotes"); + quotesProperty.set("type", mixedQuoteType); + quotesProperty.set("many", Boolean.TRUE); + quotesProperty.set("containment", Boolean.TRUE); + + types.define(mixedQuoteType); + + DataObject quote = factory.create("http://www.example.com/mixed", "MixedQuote"); + + assertTrue(quote.getType().isSequenced()); + + Sequence sequence = quote.getSequence(); + + sequence.add("\n "); + + quote.setString("symbol", "fbnt"); + + sequence.add("\n "); + + quote.setString("companyName", "FlyByNightTechnology"); + + sequence.add("\n some text\n "); + + DataObject child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2000.0")); + + sequence.add("\n more text\n "); + + // quote.setBigDecimal("price", new BigDecimal("1000.0")); + sequence.add("price", new BigDecimal("1000.0")); + + sequence.add("\n"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save(quote, "http://www.example.com/mixed", "mixedStockQuote", baos); + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXED_XML))); + } + + public void testDefineSequencedOpenType() throws Exception + { + + TypeHelper types = SDOUtil.createTypeHelper(); + DataFactory factory = SDOUtil.createDataFactory(types); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(types); + + Type stringType = types.getType("commonj.sdo", "String"); + Type decimalType = types.getType("commonj.sdo", "Decimal"); + + // Define a new mixed type - MixedQuote + DataObject mixedQuoteType = factory.create("commonj.sdo", "Type"); + mixedQuoteType.set("uri", "http://www.example.com/mixed"); + mixedQuoteType.set("name", "MixedOpenQuote"); + mixedQuoteType.set("sequenced", Boolean.TRUE); + mixedQuoteType.set("open", Boolean.TRUE); + +// DataObject symbolProperty = mixedQuoteType.createDataObject("property"); +// symbolProperty.set("name", "symbol"); +// symbolProperty.set("type", stringType); + + DataObject companyNameProperty = mixedQuoteType.createDataObject("property"); + companyNameProperty.set("name", "companyName"); + companyNameProperty.set("type", stringType); + + DataObject priceProperty = mixedQuoteType.createDataObject("property"); + priceProperty.set("name", "price"); + priceProperty.set("type", decimalType); + + DataObject quotesProperty = mixedQuoteType.createDataObject("property"); + quotesProperty.set("name", "quotes"); + quotesProperty.set("type", mixedQuoteType); + quotesProperty.set("many", Boolean.TRUE); + quotesProperty.set("containment", Boolean.TRUE); + + types.define(mixedQuoteType); + + // Define a global type + DataObject globalType = factory.create("commonj.sdo", "Type"); + globalType.set("uri", "http://www.example.com/open"); + // Don't set the type's name - null is used for types containing global properties. + + DataObject symbolProperty = globalType.createDataObject("property"); + symbolProperty.set("name", "symbol"); + symbolProperty.set("type", stringType); + symbolProperty.set("containment", Boolean.TRUE); + + types.define(globalType); + + DataObject quote = factory.create("http://www.example.com/mixed", "MixedOpenQuote"); + + assertTrue(quote.getType().isSequenced()); + + Sequence sequence = quote.getSequence(); + + sequence.add("\n "); + + Type definedGlobalType = types.getType("http://www.example.com/open", null); + + Property definedSymbolProperty = definedGlobalType.getProperty("symbol"); + quote.setString(definedSymbolProperty, "fbnt"); + + sequence.add("\n "); + + quote.setString("companyName", "FlyByNightTechnology"); + + sequence.add("\n some text\n "); + + DataObject child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2000.0")); + + sequence.add("\n more text\n "); + + // quote.setBigDecimal("price", new BigDecimal("1000.0")); + sequence.add("price", new BigDecimal("1000.0")); + + sequence.add("\n"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save(quote, "http://www.example.com/mixed", "mixedOpenStockQuote", baos); + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(MIXEDOPEN_XML))); + } + + + public void testDefineOpenType() throws Exception + { + TypeHelperImpl types = (TypeHelperImpl)SDOUtil.createTypeHelper(); + DataFactory factory = SDOUtil.createDataFactory(types); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(types); + + Type stringType = types.getType("commonj.sdo", "String"); + Type decimalType = types.getType("commonj.sdo", "Decimal"); + + // Define a new open type - OpenQuote + DataObject openQuoteType = factory.create("commonj.sdo", "Type"); + openQuoteType.set("uri", "http://www.example.com/open"); + openQuoteType.set("name", "OpenQuote"); + openQuoteType.set("open", Boolean.TRUE); + openQuoteType.setBoolean("open", true); + + types.define(openQuoteType); + + // Define new type - CompanyType + DataObject companyType = factory.create("commonj.sdo", "Type"); + companyType.set("uri", "http://www.example.com/open"); + companyType.set("name", "CompanyType"); + + // Create CompanyType property - "name" + DataObject nameProperty = companyType.createDataObject("property"); + nameProperty.set("name", "name"); + nameProperty.set("type", stringType); + nameProperty.set("containment", Boolean.TRUE); + + types.define(companyType); + + // Define open content property - company + DataObject symbolProperty = factory.create("commonj.sdo", "Property"); + symbolProperty.set("name", "symbol"); + symbolProperty.set("type", stringType); + types.defineOpenContentProperty("http://www.example.com/open", symbolProperty); + + // Define open content property - company + DataObject companyProperty = factory.create("commonj.sdo", "Property"); + companyProperty.set("name", "company"); + companyProperty.set("type", companyType); + companyProperty.set("containment", Boolean.TRUE); + types.defineOpenContentProperty("http://www.example.com/open", companyProperty); + + // Define open content property - price + DataObject priceProperty = factory.create("commonj.sdo", "Property"); + priceProperty.set("name", "price"); + priceProperty.set("type", decimalType); + types.defineOpenContentProperty("http://www.example.com/open", priceProperty); + + // Create DataObject instances + DataObject openQuote = factory.create("http://www.example.com/open", "OpenQuote"); + assertTrue(openQuote.getType().isOpen()); + + Property definedSymbolProperty = types.getOpenContentProperty("http://www.example.com/open", "symbol"); + openQuote.set(definedSymbolProperty, "s1"); + + Property definedCompanyProperty = types.getOpenContentProperty("http://www.example.com/open", "company"); + DataObject company = openQuote.createDataObject(definedCompanyProperty); + company.setString("name", "FlyByNightTechnology"); + + Property definedPriceProperty = types.getOpenContentProperty("http://www.example.com/open", "price"); + openQuote.setBigDecimal(definedPriceProperty, new BigDecimal("1000.0")); + + assertEquals(definedPriceProperty.getType(), decimalType); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlHelper.save( + openQuote, + "http://www.example.com/open", + "openStockQuote", baos); + assertTrue( + TestUtil.equalXmlFiles( + new ByteArrayInputStream(baos.toByteArray()), + getClass().getResource(OPEN_XML))); + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/IsManyTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/IsManyTestCase.java new file mode 100644 index 0000000000..1eef4ea657 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/IsManyTestCase.java @@ -0,0 +1,65 @@ +/** + * + * 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.util.SDOUtil; + +import junit.framework.TestCase; + +import commonj.sdo.*; +import commonj.sdo.helper.*; + +public class IsManyTestCase extends TestCase { + private final String TEST_MODEL = "/open.xsd"; + private final String TEST_MODEL1ANY = "/open1any.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/open"; + private final String TEST_NAMESPACE1ANY = "http://www.example.com/open1any"; + + public void testIsMany() { + Property priceProperty = XSDHelper.INSTANCE.getGlobalProperty(TEST_NAMESPACE, "price", true); + + Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "OpenQuote"); + DataObject quote = DataFactory.INSTANCE.create(quoteType); + assertTrue( SDOUtil.isMany(priceProperty, quote)); + + quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE1ANY, "OpenQuote"); + quote = DataFactory.INSTANCE.create(quoteType); + assertFalse( SDOUtil.isMany(priceProperty, quote)); + } + + 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(); + + // Populate the meta data for the test (Stock Quote) model with maxOccurs=1 <any> + url = getClass().getResource(TEST_MODEL1ANY); + inputStream = url.openStream(); + XSDHelper.INSTANCE.define(inputStream, url.toString()); + inputStream.close(); + } +}
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JiraTestCases.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JiraTestCases.java new file mode 100644 index 0000000000..66138495ce --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/JiraTestCases.java @@ -0,0 +1,184 @@ +/** + * + * 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.util.List; + +import junit.framework.TestCase; +import commonj.sdo.*; +import commonj.sdo.helper.*; + +import org.apache.tuscany.sdo.util.SDOUtil; +import java.util.HashMap; + +/** + * The follow test cases are based upon code snipets in the SDO specification. + * They are also implemented as working samples in the sample-sdo artifact + * + * @author Robbie Minshall + * + */ +public class JiraTestCases extends TestCase { + + /** + * Bogus company namespace + */ + public static final String COMPANY_NAMESPACE = "company.xsd"; + + /** + * previously defined XSD file used + */ + public static final String COMPANY_XSD = "/company.xsd"; + + /** + * XML file containing DataGraph representing a company. This xml file + * conforms to the company model defined in 'Complete DataGraph for Company + * Example' section of the SDO specification + */ + public static final String COMPANY_DATAGRAPH_XML = "/companyDataGraphGenerated.xml"; + + /** + * Generated DataGraph + * {@link org.apache.tuscany.samples.sdo.company.CreateCompany} + */ + public static final String COMPANY_DATAOBJECT_XML = "/companyGenerated.xml"; + + /** + * Defines xsd resource contained within jar file for PurchaseOrder + * DataObject + */ + public static final String PO_XSD_RESOURCE = "/po.xsd"; + + /** + * Defines xml resource contained within jar file that is used to populate + * PurchaseOrder DataObjects + */ + public static final String PO_XML_RESOURCE = "/po.xml"; + + /** + * previously created XSD file used + */ + public static final String LETTER_XSD = "/letter.xsd"; + + /** + * JIRA Details : Add a method to SDOUtil to return all Types associated + * with a specific URI + */ + public void test_TUSCANY583() { + + // define some types + try { + XSDHelper.INSTANCE.define(getClass().getResourceAsStream( + PO_XSD_RESOURCE), null); + + XSDHelper.INSTANCE.define(getClass().getResourceAsStream( + COMPANY_XSD), null); + + createDynamicType(); + + String[] expectedPoTypeNames = {"item", "Items", + "PurchaseOrderType", "quantity", "SKU", "USAddress"}; + + String[] expectedCompanyTypeNames = {"EmployeeType", "DepartmentType", "CompanyType"}; + + String[] expectedCustomerTypeNames = {"Customer"}; + + confirmTypes("http://www.example.com/PO", expectedPoTypeNames); + confirmTypes("company.xsd", expectedCompanyTypeNames); + confirmTypes("http://example.com/customer", + expectedCustomerTypeNames); + + } catch (Exception e) { + fail("Unexpected error " + e.toString()); + e.printStackTrace(); + } + + } + + /** + * Dynamically define customer Type + */ + public static void createDynamicType() { + // get an instance of the type helper + TypeHelper typeH = TypeHelper.INSTANCE; + Type intType = typeH.getType("commonj.sdo", "Int"); + Type stringType = typeH.getType("commonj.sdo", "String"); + + // create a new Type for Customers + DataObject customerType = DataFactory.INSTANCE.create("commonj.sdo", + "Type"); + + customerType.set("uri", "http://example.com/customer"); + customerType.set("name", "Customer"); + + // create a customer number property + DataObject custNumProperty = customerType.createDataObject("property"); + custNumProperty.set("name", "custNum"); + custNumProperty.set("type", intType); + + // create a last name property + DataObject lastNameProperty = customerType.createDataObject("property"); + lastNameProperty.set("name", "lastName"); + lastNameProperty.set("type", stringType); + + // create a first name property + DataObject firstNameProperty = customerType + .createDataObject("property"); + firstNameProperty.set("name", "firstName"); + firstNameProperty.set("type", stringType); + + // now define the Customer type so that customers can be made + typeH.define(customerType); + } + + private void confirmTypes(String uri, String[] expectedTypeNames) { + + try { + + List actualTypes = SDOUtil.getTypes(TypeHelper.INSTANCE, uri); + assertNotNull("Testing that list of types for " + uri + + " is not null", actualTypes); + + // test the number of Types + assertEquals("Testing number of types for " + uri, + expectedTypeNames.length, actualTypes.size()); + + // put into a HashMap for easy lookup + HashMap typeLookup = new HashMap(); + for (int i = 0; i < actualTypes.size(); i++) { + Type type = (Type) actualTypes.get(i); + typeLookup.put(type.getName(), type); + } + + // check that we have the same types + for (int i = 0; i < expectedTypeNames.length; i++) { + assertTrue("testing that type " + expectedTypeNames[i] + + "was returned for " + uri, typeLookup + .containsKey(expectedTypeNames[i])); + } + + } catch (Exception e) { + fail("Exception caught comparing expected types to actual types for uri " + + uri + ":" + e.toString()); + e.printStackTrace(); + } + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MixedTypeTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MixedTypeTestCase.java new file mode 100644 index 0000000000..806662a83c --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/MixedTypeTestCase.java @@ -0,0 +1,89 @@ +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URL; + +import commonj.sdo.DataObject; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import junit.framework.TestCase; + + +public class MixedTypeTestCase extends TestCase { + private final String TEST_MODEL = "/mixed.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/mixed"; + private final String TEST_DATA = "/mixed.xml"; + + /** + * Sequenced type SDO 2 test. + */ + public void testSequencedType() throws IOException { + Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "MixedQuote"); + DataObject quote = DataFactory.INSTANCE.create(quoteType); + + Sequence sequence = quote.getSequence(); + + sequence.add("\n "); + + quote.setString("symbol", "fbnt"); + + sequence.add("\n "); + + quote.setString("companyName", "FlyByNightTechnology"); + + sequence.add("\n some text\n "); + + DataObject child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2000.0")); + + sequence.add("\n more text\n "); + + // quote.setBigDecimal("price", new BigDecimal("1000.0")); + sequence.add("price", new BigDecimal("1000.0")); + + sequence.add("\n"); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + XMLHelper.INSTANCE.save(quote, TEST_NAMESPACE, "mixedStockQuote", baos); + + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA))); + } + + 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(); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java new file mode 100644 index 0000000000..833ab433f1 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/OpenTypeTestCase.java @@ -0,0 +1,85 @@ +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URL; +import java.util.Iterator; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import junit.framework.TestCase; + + +public class OpenTypeTestCase extends TestCase { + private final String TEST_MODEL = "/open.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/open"; + private final String TEST_DATA = "/open.xml"; + + /** + * Open content SDO 2 test. + */ + public void testOpenType() throws IOException { + Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "OpenQuote"); + DataObject quote = DataFactory.INSTANCE.create(quoteType); + + quote.setString("symbol", "s1"); + + for (Iterator iter = quote.getInstanceProperties().iterator(); iter.hasNext();) { + Property property = (Property) iter.next(); + } + + Property companyProperty = XSDHelper.INSTANCE.getGlobalProperty(TEST_NAMESPACE, "company", true); + DataObject company = quote.createDataObject(companyProperty); + company.setString("name", "FlyByNightTechnology"); + + Property priceProperty = XSDHelper.INSTANCE.getGlobalProperty(TEST_NAMESPACE, "price", true); + quote.getList(priceProperty).add(new BigDecimal("1000.0")); + + for (Iterator iter = quote.getInstanceProperties().iterator(); iter.hasNext();) { + Property property = (Property) iter.next(); + } + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + XMLHelper.INSTANCE.save(quote, TEST_NAMESPACE, "openStockQuote", baos); + + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(TEST_DATA))); + } + + 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(); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SerializeTypesTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SerializeTypesTestCase.java new file mode 100644 index 0000000000..3ffca96f5e --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SerializeTypesTestCase.java @@ -0,0 +1,133 @@ +/**
+ *
+ * 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.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sdo.helper.TypeHelperImpl;
+import org.apache.tuscany.sdo.util.SDOUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+
+import commonj.sdo.DataGraph;
+import commonj.sdo.DataObject;
+import commonj.sdo.Type;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.TypeHelper;
+
+public class SerializeTypesTestCase extends TestCase {
+
+ public void testSerializeTypesRoundTrip() throws Exception {
+ TypeHelper types = SDOUtil.createTypeHelper();
+ DataFactory factory = SDOUtil.createDataFactory(types);
+
+ Type intType = types.getType("commonj.sdo", "Int");
+ Type stringType = types.getType("commonj.sdo", "String");
+
+ // create a new Type for Addresses
+ DataObject addressType = factory.create("commonj.sdo", "Type");
+ addressType.set("uri", "http://example.com/address");
+ addressType.set("name", "Address");
+
+ // create a address street property
+ DataObject addrStProperty = addressType.createDataObject("property");
+ addrStProperty.set("name", "addrSt");
+ addrStProperty.set("type", stringType);
+
+ // create a new Type for Customers
+ DataObject customerType = factory.create("commonj.sdo", "Type");
+ customerType.set("uri", "http://example.com/customer");
+ customerType.set("name", "Customer");
+
+ // create a customer number property
+ DataObject custNumProperty = customerType.createDataObject("property");
+ custNumProperty.set("name", "custNum");
+ custNumProperty.set("type", intType);
+
+ // create a first name property
+ DataObject firstNameProperty = customerType.createDataObject("property");
+ firstNameProperty.set("name", "firstName");
+ firstNameProperty.set("type", stringType);
+
+ // create a last name property
+ DataObject lastNameProperty = customerType.createDataObject("property");
+ lastNameProperty.set("name", "lastName");
+ lastNameProperty.set("type", stringType);
+
+ // create an address property
+ DataObject addressProperty = customerType.createDataObject("property");
+ addressProperty.set("name", "address");
+ addressProperty.set("type", addressType);
+ addressProperty.setBoolean("containment", true);
+
+ // now define the Address and Customer type so that addresses and customers can be made
+ List types2define = new ArrayList();
+ types2define.add(addressType);
+ types2define.add(customerType);
+ List typesDefined = types.define(types2define);
+
+ // Create an empty data graph and add a root object, an instance of customerType
+ //
+
+ DataGraph dataGraph = SDOUtil.createDataGraph();
+ Type customerTypeDefined = (Type) typesDefined.get(1);
+ DataObject customer1 = dataGraph.createRootObject(customerTypeDefined);
+
+ customer1.setInt("custNum", 1);
+ customer1.set("firstName", "John");
+ customer1.set("lastName", "Adams");
+ DataObject address = customer1.createDataObject("address");
+ address.set("addrSt", "577 Airport Blvd");
+
+ SDOUtil.registerDataGraphTypes(dataGraph, typesDefined);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ SDOUtil.saveDataGraph(dataGraph, baos, null);
+ //SDOUtil.saveDataGraph(dataGraph, System.out, null);
+
+ TypeHelper deserializingTypeHelper = SDOUtil.createTypeHelper();
+
+ // The following is a kludge to force deserialization of metadata into a different TypeHelper (scope)
+ // TBD figure out a proper non-EMF way to do this.
+ Map options = new HashMap();
+ Object differentFromSerializing = ((TypeHelperImpl) deserializingTypeHelper).getExtendedMetaData();
+ options.put(XMLResource.OPTION_EXTENDED_META_DATA, differentFromSerializing);
+
+ byte[] serialized = baos.toByteArray();
+ ByteArrayInputStream bais = new ByteArrayInputStream(serialized);
+ DataGraph loadedDataGraph = SDOUtil.loadDataGraph(bais, options);
+
+ DataObject loadedRootObject = loadedDataGraph.getRootObject();
+ assertNotSame(loadedRootObject.getType(), customer1.getType());
+
+ // EqualityHelper requires same Type
+ assertEquals(loadedRootObject.getInt("custNum"), customer1.getInt("custNum"));
+ assertEquals(loadedRootObject.get("firstName"), customer1.get("firstName"));
+ assertEquals(loadedRootObject.get("lastName"), customer1.get("lastName"));
+ DataObject loadedAddress = loadedRootObject.getDataObject("address");
+ assertEquals(loadedAddress.get("addrSt"), address.get("addrSt"));
+ }
+}
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleCopyTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleCopyTestCase.java new file mode 100644 index 0000000000..36f038d779 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleCopyTestCase.java @@ -0,0 +1,71 @@ +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import junit.framework.TestCase; + +public class SimpleCopyTestCase extends TestCase { + + private final String TEST_MODEL = "/simple.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/simple"; + private final String QUOTE_XML = "/quote.xml"; + private final String SHALLOW_QUOTE_XML = "/shallowquote.xml"; + + public void testSimpleCopy() throws IOException { + XMLDocument doc = XMLHelper.INSTANCE.load(getClass().getResourceAsStream(QUOTE_XML)); + DataObject sdo = doc.getRootObject(); + + DataObject copiedSdo = CopyHelper.INSTANCE.copyShallow(sdo); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + XMLHelper.INSTANCE.save(copiedSdo, TEST_NAMESPACE, "stockQuote", baos); + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(SHALLOW_QUOTE_XML))); + assertFalse(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(QUOTE_XML))); + + copiedSdo = CopyHelper.INSTANCE.copy(sdo); + + baos.reset(); + XMLHelper.INSTANCE.save(copiedSdo, TEST_NAMESPACE, "stockQuote", baos); + assertFalse(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(SHALLOW_QUOTE_XML))); + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(QUOTE_XML))); + } + + 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(); + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java new file mode 100644 index 0000000000..8c4345be46 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleDynamicTestCase.java @@ -0,0 +1,81 @@ +/** + * + * 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URL; + +import junit.framework.TestCase; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + + +public class SimpleDynamicTestCase extends TestCase { + private final String TEST_MODEL = "/simple.xsd"; + private final String TEST_NAMESPACE = "http://www.example.com/simple"; + private final String QUOTE_XML = "/quote.xml"; + + /** + * Simple Dynamic SDO 2 test. + */ + public void testDynamic() throws IOException { + Type quoteType = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "Quote"); + DataObject quote = DataFactory.INSTANCE.create(quoteType); + + quote.setString("symbol", "fbnt"); + quote.setString("companyName", "FlyByNightTechnology"); + quote.setBigDecimal("price", new BigDecimal("1000.0")); + quote.setBigDecimal("open1", new BigDecimal("1000.0")); + quote.setBigDecimal("high", new BigDecimal("1000.0")); + quote.setBigDecimal("low", new BigDecimal("1000.0")); + quote.setDouble("volume", 1000); + quote.setDouble("change1", 1000); + + DataObject child = quote.createDataObject("quotes"); + child.setBigDecimal("price", new BigDecimal("2000.0")); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + XMLHelper.INSTANCE.save(quote, TEST_NAMESPACE, "stockQuote", baos); + + assertTrue(TestUtil.equalXmlFiles(new ByteArrayInputStream(baos.toByteArray()), getClass().getResource(QUOTE_XML))); + } + + + 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(); + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java new file mode 100644 index 0000000000..c3fffa4f10 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SimpleEqualityTestCase.java @@ -0,0 +1,63 @@ +/** + * + * 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.IOException; +import java.io.InputStream; +import java.net.URL; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.EqualityHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; +import junit.framework.TestCase; + +public class SimpleEqualityTestCase extends TestCase { + private static final String TEST_MODEL = "/simple.xsd"; + private static final String QUOTE_XML = "/quote.xml"; + private static final String SHALLOW_QUOTE_XML = "/shallowquote.xml"; + + public void testEquality() throws IOException { + + XMLDocument doc = XMLHelper.INSTANCE.load(getClass().getResourceAsStream(QUOTE_XML)); + DataObject sdo = doc.getRootObject(); + + doc = XMLHelper.INSTANCE.load(getClass().getResourceAsStream(SHALLOW_QUOTE_XML)); + DataObject shallowSdo = doc.getRootObject(); + + boolean result = EqualityHelper.INSTANCE.equalShallow(sdo, shallowSdo); + assertTrue(result); + + result = EqualityHelper.INSTANCE.equal(sdo, shallowSdo); + assertFalse(result); + } + + + 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(); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SubstitutionValuesTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SubstitutionValuesTestCase.java new file mode 100644 index 0000000000..b473503122 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/SubstitutionValuesTestCase.java @@ -0,0 +1,47 @@ +/** + * + * 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.IOException; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.XSDHelper; + +public final class SubstitutionValuesTestCase extends TestCase +{ + public void test() throws IOException + { + URL url = getClass().getResource("/SubstitutionValues.xsd"); + XSDHelper.INSTANCE.define(url.openStream(), url.toString()); + + final DataObject object = DataFactory.INSTANCE.create("http://www.apache.org/tuscany/SubstitutionValues", "TestObject"); + final Type type = object.getType(); + + assertNotNull( SDOUtil.getSubstitutionValues(object, type.getProperty("groupHead"))); + assertNull( SDOUtil.getSubstitutionValues(object, type.getProperty("nonGroupHead"))); + } +}
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java new file mode 100644 index 0000000000..a7ab3f954a --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TestUtil.java @@ -0,0 +1,285 @@ +/** + * + * 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.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class TestUtil +{ + private static void getAllNodes(NodeList nodeList, List nodes) + { + int length = nodeList.getLength(); + if (length == 0) + { + return; + } + + for (int i=0; i<length; i++) + { + Node node = nodeList.item(i); + nodes.add(node); + getAllNodes(node.getChildNodes(), nodes); + } // for + } + + private static boolean equalNamedNodeMap(NamedNodeMap mapA, NamedNodeMap mapB) { + if (mapA == null) { + if (mapB == null) { + return true; + } + return false; + } + if (mapA.getLength() != mapB.getLength()) { + return false; + } + for (int i = 0; i < mapA.getLength(); i++) { + Node trialNode = mapA.item(i); + if (trialNode == null) { + return false; + } + Node checkNode = mapB.getNamedItem(trialNode.getNodeName()); + if (checkNode == null) { + return false; + } + if (!equalNode(trialNode, checkNode)) { + return false; + } + } + return true; + } + + private static boolean equalNode(Node nodeA, Node nodeB) { + if (nodeA == null) { + if (nodeB == null) { + return true; + } + return false; + } + // following is intended to provide same function as 1.5 isEqualNode() + if (nodeA.getNodeType() != nodeB.getNodeType()) { + return false; + } + if (!equalString(nodeA.getNodeName(), nodeB.getNodeName())) { + return false; + } + if (!equalString(nodeA.getLocalName(), nodeB.getLocalName())) { + return false; + } + if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) { + return false; + } + if (!equalString(nodeA.getNamespaceURI(), nodeB.getNamespaceURI())) { + return false; + } + if (!equalString(nodeA.getPrefix(), nodeB.getPrefix())) { + return false; + } + if (!equalString(nodeA.getNodeValue(), nodeB.getNodeValue())) { + return false; + } + if (!equalNamedNodeMap(nodeA.getAttributes(), nodeB.getAttributes())) { + return false; + } + if (!equalNodeList(nodeA.getChildNodes(), nodeB.getChildNodes())) { + return false; + } + if (nodeA.getNodeType() == Node.DOCUMENT_TYPE_NODE) { + DocumentType documentTypeA = (DocumentType) nodeA; + DocumentType documentTypeB = (DocumentType) nodeB; + if (!equalString(documentTypeA.getPublicId(), documentTypeB.getPublicId())) { + return false; + } + if (!equalString(documentTypeA.getSystemId(), documentTypeB.getSystemId())) { + return false; + } + if (!equalString(documentTypeA.getInternalSubset(), documentTypeB.getInternalSubset())) { + return false; + } + if (!equalNamedNodeMap(documentTypeA.getEntities(), documentTypeB.getEntities())) { + return false; + } + if (!equalNamedNodeMap(documentTypeA.getNotations(), documentTypeB.getNotations())) { + return false; + } + } + return true; + } + + private static boolean equalNodeList(NodeList nodeListA, NodeList nodeListB) { + if (nodeListA == null) { + if (nodeListB == null) { + return true; + } + return false; + } + return equalNodes(nodeListA, nodeListB); + } + + private static boolean equalString(String stringA, String stringB) { + if (stringA == null) { + if (stringB == null) { + return true; + } + return false; + } + return stringA.equals(stringB); + } + + private static boolean equalNodes(NodeList sourceNodeList, NodeList targetNodeList) + { + ArrayList sourceNodes = new ArrayList(); + ArrayList targetNodes = new ArrayList(); + + getAllNodes(sourceNodeList, sourceNodes); + getAllNodes(targetNodeList, targetNodes); + + int sourceLength = sourceNodes.size(); + int targetLength = targetNodes.size(); + + if (sourceLength != targetLength) + { + return false; + } + + for (int i=0; i<sourceLength; i++) + { + Node sourceNode = (Node)sourceNodes.get(i); + Node targetNode = (Node)targetNodes.get(i); + + /* remove comment when migrated to Java 1.5 + if (!sourceNode.isEqualNode(targetNode)) + { + return false; + } + */ + // following is intended as 1.4 equivalent of isEqualNode() + if (!equalNode(sourceNode, targetNode)) + { + return false; + } + } // for + + return true; + } + + public static boolean equalXmlFiles(URL source, URL target) + { + try { + return equalXmlFiles(source.openStream(), target.openStream()); + } + catch (IOException e) + { + return false; + } + } + + public static boolean equalXmlFiles(InputStream sourceStream, URL target) + { + try { + return equalXmlFiles(sourceStream, target.openStream()); + } + catch (IOException e) + { + return false; + } + } + + public static boolean equalXmlFiles(URL source, InputStream targetStream) + { + try { + return equalXmlFiles(source.openStream(), targetStream); + } + catch (IOException e) + { + return false; + } + } + + public static boolean equalXmlFiles(InputStream sourceStream, InputStream targetStream) + { + DocumentBuilder builder; + Document sourceDocument; + Document targetDocument; + + try { + builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + sourceDocument = builder.parse(sourceStream); + targetDocument = builder.parse(targetStream); + } + catch (FactoryConfigurationError fce) { + return false; + } + catch (ParserConfigurationException ce) { + return false; + } + catch (SAXException se) + { + return false; + } + catch (IOException ie) + { + return false; + } + + sourceDocument.normalize(); + targetDocument.normalize(); + + /* remove comment when migrated to Java 1.5 + if (!sourceDocument.getXmlVersion().equals(targetDocument.getXmlVersion())) + { + return false; + } + + String sourceXmlEncoding = sourceDocument.getXmlEncoding(); + String targetXmlEncoding = targetDocument.getXmlEncoding(); + + if (sourceXmlEncoding != null && targetXmlEncoding != null && + sourceXmlEncoding.equalsIgnoreCase(targetXmlEncoding)) + { + // continue + } + else + { + return false; + } + */ + + NodeList sourceNodes = sourceDocument.getChildNodes(); + NodeList targetNodes = targetDocument.getChildNodes(); + + return equalNodes(sourceNodes, targetNodes); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeConversionTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeConversionTestCase.java new file mode 100644 index 0000000000..278355bfd3 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeConversionTestCase.java @@ -0,0 +1,883 @@ +/** + * + * 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 junit.framework.TestCase; + + +import java.io.InputStream; +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Comparator; +import java.util.Date; +import java.util.TimeZone; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +public class TypeConversionTestCase extends TestCase +{ + // The following constants are used to get Types from XSDs + + private static final String TEST_MODEL = "/api_test.xsd"; + private static final String TEST_NAMESPACE = "http://www.example.com/api_test"; + + // The following constants describe the index for the fields in api_test.xsd. + + private static final int STRING_VAL_INDEX = 1; + private static final int BOOLEAN_VAL_INDEX = 2; + private static final int BYTE_VAL_INDEX = 4; + private static final int DECIMAL_VAL_INDEX = 6; + private static final int INT_VAL_INDEX = 8; + private static final int FLOAT_VAL_INDEX = 9; + private static final int DOUBLE_VAL_INDEX = 10; + private static final int DATE_VAL_INDEX = 11; + private static final int SHORT_VAL_INDEX = 12; + private static final int LONG_VAL_INDEX = 13; + private static final int BYTES_VAL_INDEX = 15; + private static final int INTEGER_VAL_INDEX = 16; + private static final int CHAR_VAL_INDEX = 17; + + // The following variables are Method arrays. Each array refers to a specific get<Type>, but within + // the array exist the get<Type>(index), get<Type>(property), and get<Type>(path). Rather than + // referring to each of the three in every circumstance, the more compact array appears. + + private static ConversionType TO_BOOLEAN = new ConversionType("getBoolean"); + private static ConversionType TO_BYTE = new ConversionType("getByte"); + private static ConversionType TO_CHAR = new ConversionType("getChar"); + private static ConversionType TO_DOUBLE = new ConversionType("getDouble"); + private static ConversionType TO_FLOAT = new ConversionType("getFloat"); + private static ConversionType TO_INT = new ConversionType("getInt"); + private static ConversionType TO_LONG = new ConversionType("getLong"); + private static ConversionType TO_SHORT = new ConversionType("getShort"); + private static ConversionType TO_BYTES = new ConversionType("getBytes"); + private static ConversionType TO_BIGDECIMAL = new ConversionType("getBigDecimal"); + private static ConversionType TO_BIGINTEGER = new ConversionType("getBigInteger"); + private static ConversionType TO_DATAOBJECT = new ConversionType("getDataObject"); + private static ConversionType TO_DATE = new ConversionType("getDate"); + private static ConversionType TO_STRING = new ConversionType("getString"); + private static ConversionType TO_LIST = new ConversionType("getList"); + private static ConversionType TO_SEQUENCE = new ConversionType("getSequence"); + + private static GeneralComparator COMPARE_ANY; + + // There will be several instances where a Property must be passed as a parameter. Have available the Type + // to call getProperty() as needed. + + private static Type API_TEST_TYPE; + + // The default constructor establishes each of the Method and Method[] variables. + + public TypeConversionTestCase() throws Exception + { + COMPARE_ANY = new GeneralComparator(); + + // Populate the meta data for the test model + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + XSDHelper.INSTANCE.define(inputStream, url.toString()); + inputStream.close(); + + API_TEST_TYPE = TypeHelper.INSTANCE.getType(TEST_NAMESPACE, "APITest"); + } + + private static class ConversionType + { + // The following constants are used because the getMethod function requires an Class + // array describing the parameters to the functions. + + private static final Class[] INT_CLASS_ARRAY = {int.class}; + private static final Class[] PROPERTY_CLASS_ARRAY = {Property.class}; + private static final Class[] STRING_CLASS_ARRAY = {String.class}; + + Method index_method; + Method property_method; + Method path_method; + + public ConversionType (String method_name) + { + try + { + this.index_method = DataObject.class.getMethod(method_name, INT_CLASS_ARRAY); + this.property_method = DataObject.class.getMethod(method_name, PROPERTY_CLASS_ARRAY); + this.path_method = DataObject.class.getMethod(method_name, STRING_CLASS_ARRAY); + } + catch (NoSuchMethodException e) + { + this.index_method = null; + this.property_method = null; + this.path_method = null; + } + } + + public Method getIndexMethod() + { + return this.index_method; + } + + public Method getPropertyMethod() + { + return this.property_method; + } + + public Method getPathMethod() + { + return this.path_method; + } + } + + // Each instance of Test describes a convert-from type. The index, property and path parms + // will refer to the same field, which is a field of the convert-from type. + + private static class Test + { + DataObject test_obj; + Object[] index_parm; + Object[] property_parm; + Object[] path_parm; + Object expected_value; + String from_type; + + // The constructor prepares a test DataObject and determines how to access the field + // in three different ways - index, property, and path. + + Test(String path, int index) + { + this.test_obj = DataFactory.INSTANCE.create(API_TEST_TYPE); + this.index_parm = new Object[] {new Integer(index)}; + this.property_parm = new Object[] {API_TEST_TYPE.getProperty(path)}; + this.path_parm = new Object[] {path}; + this.expected_value = null; + } + + // The initialize() function establishes the initial value of the test field. + + public void initialize(Class type, String type_name, Object initial_value) throws Exception + { + Class[] classArray = {int.class, type}; + Object[] initValueArray = new Object[] {this.index_parm[0], initial_value}; + + Method setter = DataObject.class.getMethod("set" + type_name, classArray); + setter.invoke(test_obj, initValueArray); + this.expected_value = initial_value; + this.from_type = type_name; + } + + // Attempts the conversion to the specified type, using DataObject.get____(). + // The get___() function can be called with an index, path, and property. attemptConversion() + // calls each of those three. + + public void attemptConversion(ConversionType to_type) throws Exception + { + performConversion(to_type.getIndexMethod(), this.index_parm); + performConversion(to_type.getPathMethod(), this.path_parm); + performConversion(to_type.getPropertyMethod(), this.property_parm); + } + + public void checkConversionException(ConversionType to_type, Class expected_exception) throws Exception + { + boolean index_err, path_err, property_err, consistency_err = false; + + index_err = executeExceptionCase(to_type.getIndexMethod(), this.index_parm, expected_exception); + path_err = executeExceptionCase(to_type.getPathMethod(), this.path_parm, expected_exception); + property_err = executeExceptionCase(to_type.getPropertyMethod(), this.property_parm, expected_exception); + + if (index_err != path_err || path_err != property_err) + consistency_err = true; + else if (index_err == false) + attemptConversion(to_type); + + assertFalse("An exception inconsistency exists for " + to_type.getPathMethod().getName() + " when called " + + "for a " + this.from_type + " property.", consistency_err); + } + + private void performConversion (Method convert, Object[] parm) throws Exception + { + try + { + assertTrue("Conversion did not yield expected value for " + convert.getName() + " on a " + this.from_type + " property.", + COMPARE_ANY.compare(convert.invoke(test_obj, parm), this.expected_value) == 0); + } + catch (Exception e) + { + Throwable cause = e.getCause(); + if (cause == null) + { + System.err.println("An exception of type " + e.getClass() + " occurred while performing " + convert.getName() + + " on a " + this.from_type + " property."); + } + else + { + System.err.println("An exception of type " + cause.getClass() + " occurred while performing " + convert.getName() + + " on a " + this.from_type + " property."); + } + + throw e; + } + + } + + private boolean executeExceptionCase (Method convert, Object[] parm, Class expected_exception) throws Exception + { + boolean exception_thrown = false; + try + { + convert.invoke(test_obj, parm); + } + catch (Exception e) + { + exception_thrown = true; + Throwable cause = e.getCause(); + if (cause == null) + { + assertEquals("An unexpected exception occurred while performing " + convert.getName() + + " on a " + this.from_type + " property.", expected_exception, e.getClass()); + } + else + { + assertEquals("An unexpected exception occurred while performing " + convert.getName() + + " on a " + this.from_type + " property.", expected_exception, cause.getClass()); + } + } + + return exception_thrown; + } + } + + private static class GeneralComparator implements Comparator + { + public int compare(Object obj1, Object obj2) + { + if (obj1.getClass() == obj2.getClass()) + { + if (obj1.equals(obj2)) + return 0; + else + return 1; + } + + else if (obj1.getClass() == Date.class) + { + if (obj2.getClass() == String.class) + { + try + { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy'-'MM'-'dd'T'H':'mm':'ss.S"); + + sdf.setTimeZone(TimeZone.getTimeZone("UTC")); + obj2 = sdf.parse((String) obj2); + + if (obj1.equals(obj2)) + return 0; + } + catch (Exception e) + { + System.out.println(e.getMessage()); + } + + return 1; + } + + else + { + Date temp = (Date) obj1; + + return compare(new Long(temp.getTime()), obj2); + } + + } + + else if (obj2.getClass() == Date.class) + { + return compare(obj2, obj1); + } + + else if (obj1.getClass() == Boolean.class) + { + Boolean temp = (Boolean) obj1; + + if (temp.booleanValue()) + { + if (obj2.toString().equalsIgnoreCase("true")) + return 0; + else + return 1; + } + + else + { + if (obj2.toString().equalsIgnoreCase("true")) + return 1; + else + return 0; + } + } + + else if (obj2.getClass() == Boolean.class) + return compare(obj2, obj1); + + else if (obj1.getClass() == Byte.class || obj2.getClass() == Byte.class) + { + byte b1 = (Double.valueOf(obj1.toString())).byteValue(); + byte b2 = (Double.valueOf(obj2.toString())).byteValue(); + + if (b1 == b2) + return 0; + else if (b1 < b2) + return -1; + else + return 1; + } + + else if (obj1.getClass().toString().charAt(6) == '[') + { + long result = 0; + long multiplier = 1; + + byte[] array = (byte[]) obj1; + for (int i = 0; i < array.length; i++) + { + result += array[array.length - i - 1] * multiplier; + multiplier *= 256; + } + + return compare(obj2, new Long(result)); + } + + else if (obj2.getClass().toString().charAt(6) == '[') + { + return compare(obj2, obj1); + } + + else if (obj1.getClass() == Short.class || obj2.getClass() == Short.class) + { + short s1 = (Double.valueOf(obj1.toString())).shortValue(); + short s2 = (Double.valueOf(obj2.toString())).shortValue(); + + if (s1 == s2) + return 0; + else if (s1 < s2) + return -1; + else + return 1; + } + + else if (obj1.getClass() == Integer.class || obj2.getClass() == Integer.class) + { + int i1 = (Double.valueOf(obj1.toString())).intValue(); + int i2 = (Double.valueOf(obj2.toString())).intValue(); + + if (i1 == i2) + return 0; + else if (i1 < i2) + return -1; + else + return 1; + } + + else if ( obj1.getClass() == Long.class || obj2.getClass() == Long.class + || obj1.getClass() == BigInteger.class || obj2.getClass() == BigInteger.class) + { + long l1 = (Double.valueOf(obj1.toString())).longValue(); + long l2 = (Double.valueOf(obj2.toString())).longValue(); + + if (l1 == l2) + return 0; + else if (l1 < l2) + return -1; + else + return 1; + } + + else if (obj1.getClass() == Float.class || obj2.getClass() == Float.class) + { + float f1 = (Double.valueOf(obj1.toString())).floatValue(); + float f2 = (Double.valueOf(obj2.toString())).floatValue(); + + if (f1 == f2) + return 0; + else if (f1 < f2) + return -1; + else + return 1; + } + + else if (obj1.getClass() == Double.class || obj2.getClass() == Double.class) + { + Double b1 = Double.valueOf(obj1.toString()); + Double b2 = Double.valueOf(obj2.toString()); + + return b1.compareTo(b2); + } + + else if (obj1.getClass() == BigDecimal.class || obj2.getClass() == BigDecimal.class) + { + BigDecimal b1 = new BigDecimal(obj1.toString()); + BigDecimal b2 = new BigDecimal(obj2.toString()); + + return b1.compareTo(b2); + } + + else + { + if (obj1.toString().equals(obj2.toString())) + return 0; + else + return 1; + } + } + + } + + /********************************************************** + * In the following test cases, several instances are commented out. + * For these cases, the test case currently fails. A JIRA issue (TUSCANY-581) has + * been opened to either correct the behavior (then uncomment the lines) or to + * alter the specification against which the test cases were designed (and then + * remove the lines - assuming the alteration is to remove stating the + * nature of the exception). + */ + + public void testBooleanConversion() throws Exception + { + Test FromBoolean = new Test("booleanVal", BOOLEAN_VAL_INDEX); + + FromBoolean.initialize(boolean.class, "Boolean", Boolean.valueOf(true)); + + FromBoolean.attemptConversion(TO_BOOLEAN); + FromBoolean.attemptConversion(TO_STRING); + } + + public void testBooleanExceptions() throws Exception + { + Test FromBoolean = new Test("booleanVal", BOOLEAN_VAL_INDEX); + + FromBoolean.initialize(boolean.class, "Boolean", Boolean.valueOf(true)); + +// FromBoolean.checkConversionException(TO_BYTE, ClassCastException.class); +// FromBoolean.checkConversionException(TO_CHAR, ClassCastException.class); +// FromBoolean.checkConversionException(TO_DOUBLE, ClassCastException.class); +// FromBoolean.checkConversionException(TO_FLOAT, ClassCastException.class); +// FromBoolean.checkConversionException(TO_INT, ClassCastException.class); +// FromBoolean.checkConversionException(TO_LONG, ClassCastException.class); +// FromBoolean.checkConversionException(TO_SHORT, ClassCastException.class); +// FromBoolean.checkConversionException(TO_BYTES, ClassCastException.class); +// FromBoolean.checkConversionException(TO_BIGDECIMAL, ClassCastException.class); +// FromBoolean.checkConversionException(TO_BIGINTEGER, ClassCastException.class); + FromBoolean.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromBoolean.checkConversionException(TO_DATE, ClassCastException.class); + FromBoolean.checkConversionException(TO_LIST, ClassCastException.class); + FromBoolean.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testByteConversion() throws Exception + { + Test FromByte = new Test("byteVal", BYTE_VAL_INDEX); + + FromByte.initialize(byte.class, "Byte", Byte.valueOf("-127")); + + FromByte.attemptConversion(TO_BYTE); + FromByte.attemptConversion(TO_DOUBLE); + FromByte.attemptConversion(TO_FLOAT); + FromByte.attemptConversion(TO_INT); + FromByte.attemptConversion(TO_LONG); + FromByte.attemptConversion(TO_SHORT); + FromByte.attemptConversion(TO_STRING); + } + + public void testByteExceptions() throws Exception + { + Test FromByte = new Test("byteVal", BYTE_VAL_INDEX); + + FromByte.initialize(byte.class, "Byte", Byte.valueOf("-127")); + +// FromByte.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromByte.checkConversionException(TO_CHAR, ClassCastException.class); +// FromByte.checkConversionException(TO_BYTES, ClassCastException.class); + FromByte.checkConversionException(TO_BIGDECIMAL, ClassCastException.class); + FromByte.checkConversionException(TO_BIGINTEGER, ClassCastException.class); + FromByte.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromByte.checkConversionException(TO_DATE, ClassCastException.class); + FromByte.checkConversionException(TO_LIST, ClassCastException.class); + FromByte.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testCharConversion() throws Exception + { + Test FromChar = new Test("charVal", CHAR_VAL_INDEX); + + FromChar.initialize(char.class, "Char", new Character('?')); + + FromChar.attemptConversion(TO_CHAR); + FromChar.attemptConversion(TO_STRING); + } + + public void testCharExceptions() throws Exception + { + Test FromChar = new Test("charVal", CHAR_VAL_INDEX); + + FromChar.initialize(char.class, "Char", new Character('?')); + +// FromChar.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromChar.checkConversionException(TO_BYTE, ClassCastException.class); +// FromChar.checkConversionException(TO_DOUBLE, ClassCastException.class); +// FromChar.checkConversionException(TO_FLOAT, ClassCastException.class); +// FromChar.checkConversionException(TO_INT, ClassCastException.class); +// FromChar.checkConversionException(TO_LONG, ClassCastException.class); +// FromChar.checkConversionException(TO_SHORT, ClassCastException.class); +// FromChar.checkConversionException(TO_BYTES, ClassCastException.class); +// FromChar.checkConversionException(TO_BIGDECIMAL, ClassCastException.class); +// FromChar.checkConversionException(TO_BIGINTEGER, ClassCastException.class); + FromChar.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromChar.checkConversionException(TO_DATE, ClassCastException.class); + FromChar.checkConversionException(TO_LIST, ClassCastException.class); + FromChar.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testDoubleConversion() throws Exception + { + Test FromDouble = new Test("doubleVal", DOUBLE_VAL_INDEX); + + FromDouble.initialize(double.class, "Double", new Double(Double.MAX_VALUE)); + + FromDouble.attemptConversion(TO_BYTE); + FromDouble.attemptConversion(TO_DOUBLE); + FromDouble.attemptConversion(TO_FLOAT); + FromDouble.attemptConversion(TO_INT); + FromDouble.attemptConversion(TO_LONG); + FromDouble.attemptConversion(TO_SHORT); + FromDouble.attemptConversion(TO_BIGDECIMAL); + FromDouble.attemptConversion(TO_BIGINTEGER); + FromDouble.attemptConversion(TO_STRING); + } + + public void testDoubleExceptions() throws Exception + { + Test FromDouble = new Test("doubleVal", DOUBLE_VAL_INDEX); + + FromDouble.initialize(double.class, "Double", new Double(Double.MAX_VALUE)); + +// FromDouble.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromDouble.checkConversionException(TO_CHAR, ClassCastException.class); +// FromDouble.checkConversionException(TO_BYTES, ClassCastException.class); + FromDouble.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromDouble.checkConversionException(TO_DATE, ClassCastException.class); + FromDouble.checkConversionException(TO_LIST, ClassCastException.class); + FromDouble.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testFloatConversion() throws Exception + { + Test FromFloat = new Test("floatVal", FLOAT_VAL_INDEX); + + FromFloat.initialize(float.class, "Float", new Float(Float.MIN_VALUE)); + + FromFloat.attemptConversion(TO_BYTE); + FromFloat.attemptConversion(TO_DOUBLE); + FromFloat.attemptConversion(TO_FLOAT); + FromFloat.attemptConversion(TO_INT); + FromFloat.attemptConversion(TO_LONG); + FromFloat.attemptConversion(TO_SHORT); + FromFloat.attemptConversion(TO_BIGDECIMAL); + FromFloat.attemptConversion(TO_BIGINTEGER); + FromFloat.attemptConversion(TO_STRING); + } + + public void testFloatExceptions() throws Exception + { + Test FromFloat = new Test("floatVal", FLOAT_VAL_INDEX); + + FromFloat.initialize(float.class, "Float", new Float(Float.MIN_VALUE)); + +// FromFloat.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromFloat.checkConversionException(TO_CHAR, ClassCastException.class); +// FromFloat.checkConversionException(TO_BYTES, ClassCastException.class); + FromFloat.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromFloat.checkConversionException(TO_DATE, ClassCastException.class); + FromFloat.checkConversionException(TO_LIST, ClassCastException.class); + FromFloat.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testIntConversion() throws Exception + { + Test FromInt = new Test("intVal", INT_VAL_INDEX); + + FromInt.initialize(int.class, "Int", new Integer(5)); + + FromInt.attemptConversion(TO_BYTE); + FromInt.attemptConversion(TO_DOUBLE); + FromInt.attemptConversion(TO_FLOAT); + FromInt.attemptConversion(TO_INT); + FromInt.attemptConversion(TO_LONG); + FromInt.attemptConversion(TO_SHORT); + FromInt.attemptConversion(TO_BIGDECIMAL); + FromInt.attemptConversion(TO_BIGINTEGER); + FromInt.attemptConversion(TO_STRING); + } + + public void testIntExceptions() throws Exception + { + Test FromInt = new Test("intVal", INT_VAL_INDEX); + + FromInt.initialize(int.class, "Int", new Integer(5)); + +// FromInt.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromInt.checkConversionException(TO_CHAR, ClassCastException.class); +// FromInt.checkConversionException(TO_BYTES, ClassCastException.class); + FromInt.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromInt.checkConversionException(TO_DATE, ClassCastException.class); + FromInt.checkConversionException(TO_LIST, ClassCastException.class); + FromInt.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testLongConversion() throws Exception + { + Test FromLong = new Test("longVal", LONG_VAL_INDEX); + + FromLong.initialize(long.class, "Long", new Long(7000L)); + + FromLong.attemptConversion(TO_BYTE); + FromLong.attemptConversion(TO_DOUBLE); + FromLong.attemptConversion(TO_FLOAT); + FromLong.attemptConversion(TO_INT); + FromLong.attemptConversion(TO_LONG); + FromLong.attemptConversion(TO_SHORT); + FromLong.attemptConversion(TO_BIGDECIMAL); + FromLong.attemptConversion(TO_BIGINTEGER); + FromLong.attemptConversion(TO_DATE); + FromLong.attemptConversion(TO_STRING); + } + + public void testLongExceptions() throws Exception + { + Test FromLong = new Test("longVal", LONG_VAL_INDEX); + + FromLong.initialize(long.class, "Long", new Long(7000L)); + +// FromLong.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromLong.checkConversionException(TO_CHAR, ClassCastException.class); +// FromLong.checkConversionException(TO_BYTES, ClassCastException.class); + FromLong.checkConversionException(TO_DATAOBJECT, ClassCastException.class); + FromLong.checkConversionException(TO_LIST, ClassCastException.class); + FromLong.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testShortConversion() throws Exception + { + Test FromShort = new Test("shortVal", SHORT_VAL_INDEX); + + FromShort.initialize(short.class, "Short", new Short("-8000")); + + FromShort.attemptConversion(TO_BYTE); + FromShort.attemptConversion(TO_DOUBLE); + FromShort.attemptConversion(TO_FLOAT); + FromShort.attemptConversion(TO_INT); + FromShort.attemptConversion(TO_LONG); + FromShort.attemptConversion(TO_SHORT); + FromShort.attemptConversion(TO_STRING); + } + + public void testShortExceptions() throws Exception + { + Test FromShort = new Test("shortVal", SHORT_VAL_INDEX); + + FromShort.initialize(short.class, "Short", new Short("-8000")); + +// FromShort.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromShort.checkConversionException(TO_CHAR, ClassCastException.class); +// FromShort.checkConversionException(TO_BYTES, ClassCastException.class); + FromShort.checkConversionException(TO_BIGDECIMAL, ClassCastException.class); + FromShort.checkConversionException(TO_BIGINTEGER, ClassCastException.class); + FromShort.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromShort.checkConversionException(TO_DATE, ClassCastException.class); + FromShort.checkConversionException(TO_LIST, ClassCastException.class); + FromShort.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testStringConversion() throws Exception + { + Test FromString = new Test("stringVal", STRING_VAL_INDEX); + + FromString.initialize(String.class, "String", "5"); + + FromString.attemptConversion(TO_BOOLEAN); + FromString.attemptConversion(TO_BYTE); + FromString.attemptConversion(TO_CHAR); + FromString.attemptConversion(TO_DOUBLE); + FromString.attemptConversion(TO_FLOAT); + FromString.attemptConversion(TO_INT); + FromString.attemptConversion(TO_LONG); + FromString.attemptConversion(TO_SHORT); + FromString.attemptConversion(TO_BIGDECIMAL); + FromString.attemptConversion(TO_BIGINTEGER); + FromString.attemptConversion(TO_STRING); + + FromString.initialize(String.class, "String", "1999-07-25T8:50:14.33Z"); + FromString.attemptConversion(TO_DATE); + } + + public void testStringExceptions() throws Exception + { + Test FromString = new Test("stringVal", STRING_VAL_INDEX); + + FromString.initialize(String.class, "String", "5"); + +// FromString.checkConversionException(TO_BYTES, ClassCastException.class); + FromString.checkConversionException(TO_DATAOBJECT, ClassCastException.class); + FromString.checkConversionException(TO_LIST, ClassCastException.class); + FromString.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testBytesConversion() throws Exception + { + Test FromBytes = new Test("bytesVal", BYTES_VAL_INDEX); + + FromBytes.initialize(byte[].class, "Bytes", new byte[] {10,100}); + + FromBytes.attemptConversion(TO_BYTES); + FromBytes.attemptConversion(TO_BIGINTEGER); + } + + public void testBytesExceptions() throws Exception + { + Test FromBytes = new Test("bytesVal", BYTES_VAL_INDEX); + + FromBytes.initialize(byte[].class, "Bytes", new byte[] {10,100}); + +// FromBytes.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromBytes.checkConversionException(TO_BYTE, ClassCastException.class); +// FromBytes.checkConversionException(TO_CHAR, ClassCastException.class); +// FromBytes.checkConversionException(TO_DOUBLE, ClassCastException.class); +// FromBytes.checkConversionException(TO_FLOAT, ClassCastException.class); +// FromBytes.checkConversionException(TO_INT, ClassCastException.class); +// FromBytes.checkConversionException(TO_LONG, ClassCastException.class); +// FromBytes.checkConversionException(TO_SHORT, ClassCastException.class); +// FromBytes.checkConversionException(TO_BIGDECIMAL, ClassCastException.class); + FromBytes.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromBytes.checkConversionException(TO_DATE, ClassCastException.class); +// FromBytes.checkConversionException(TO_STRING, ClassCastException.class); + FromBytes.checkConversionException(TO_LIST, ClassCastException.class); + FromBytes.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testBigDecimalConversion() throws Exception + { + Test FromBigDecimal = new Test("decimalVal", DECIMAL_VAL_INDEX); + + FromBigDecimal.initialize(BigDecimal.class, "BigDecimal", new BigDecimal("-3")); + + FromBigDecimal.attemptConversion(TO_DOUBLE); + FromBigDecimal.attemptConversion(TO_FLOAT); + FromBigDecimal.attemptConversion(TO_INT); + FromBigDecimal.attemptConversion(TO_LONG); + FromBigDecimal.attemptConversion(TO_BIGDECIMAL); + FromBigDecimal.attemptConversion(TO_BIGINTEGER); + FromBigDecimal.attemptConversion(TO_STRING); + } + + public void testBigDecimalExceptions() throws Exception + { + Test FromBigDecimal = new Test("decimalVal", DECIMAL_VAL_INDEX); + + FromBigDecimal.initialize(BigDecimal.class, "BigDecimal", new BigDecimal("-3")); + +// FromBigDecimal.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromBigDecimal.checkConversionException(TO_BYTE, ClassCastException.class); +// FromBigDecimal.checkConversionException(TO_CHAR, ClassCastException.class); +// FromBigDecimal.checkConversionException(TO_SHORT, ClassCastException.class); +// FromBigDecimal.checkConversionException(TO_BYTES, ClassCastException.class); + FromBigDecimal.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromBigDecimal.checkConversionException(TO_DATE, ClassCastException.class); + FromBigDecimal.checkConversionException(TO_LIST, ClassCastException.class); + FromBigDecimal.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testBigIntegerConversion() throws Exception + { + Test FromBigInteger = new Test("integerVal", INTEGER_VAL_INDEX); + + FromBigInteger.initialize(BigInteger.class, "BigInteger", new BigInteger("31500")); + + FromBigInteger.attemptConversion(TO_DOUBLE); + FromBigInteger.attemptConversion(TO_FLOAT); + FromBigInteger.attemptConversion(TO_INT); + FromBigInteger.attemptConversion(TO_LONG); + FromBigInteger.attemptConversion(TO_SHORT); + FromBigInteger.attemptConversion(TO_BYTES); + FromBigInteger.attemptConversion(TO_BIGDECIMAL); + FromBigInteger.attemptConversion(TO_BIGINTEGER); + FromBigInteger.attemptConversion(TO_STRING); + } + + public void testBigIntegerExceptions() throws Exception + { + Test FromBigInteger = new Test("integerVal", INTEGER_VAL_INDEX); + + FromBigInteger.initialize(BigInteger.class, "BigInteger", new BigInteger("31500")); + +// FromBigInteger.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromBigInteger.checkConversionException(TO_BYTE, ClassCastException.class); +// FromBigInteger.checkConversionException(TO_CHAR, ClassCastException.class); + FromBigInteger.checkConversionException(TO_DATAOBJECT, ClassCastException.class); +// FromBigInteger.checkConversionException(TO_DATE, ClassCastException.class); + FromBigInteger.checkConversionException(TO_LIST, ClassCastException.class); + FromBigInteger.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } + + public void testDateConversion() throws Exception + { + Test FromDate = new Test("dateVal", DATE_VAL_INDEX); + + FromDate.initialize(Date.class, "Date", new Date(System.currentTimeMillis())); + + FromDate.attemptConversion(TO_LONG); + FromDate.attemptConversion(TO_DATE); + FromDate.attemptConversion(TO_STRING); + } + + public void testDateExceptions() throws Exception + { + Test FromDate = new Test("dateVal", DATE_VAL_INDEX); + + FromDate.initialize(Date.class, "Date", new Date(System.currentTimeMillis())); + +// FromDate.checkConversionException(TO_BOOLEAN, ClassCastException.class); +// FromDate.checkConversionException(TO_BYTE, ClassCastException.class); +// FromDate.checkConversionException(TO_CHAR, ClassCastException.class); +// FromDate.checkConversionException(TO_DOUBLE, ClassCastException.class); +// FromDate.checkConversionException(TO_FLOAT, ClassCastException.class); +// FromDate.checkConversionException(TO_INT, ClassCastException.class); +// FromDate.checkConversionException(TO_SHORT, ClassCastException.class); +// FromDate.checkConversionException(TO_BYTES, ClassCastException.class); +// FromDate.checkConversionException(TO_BIGDECIMAL, ClassCastException.class); +// FromDate.checkConversionException(TO_BIGINTEGER, ClassCastException.class); + FromDate.checkConversionException(TO_DATAOBJECT, ClassCastException.class); + FromDate.checkConversionException(TO_LIST, ClassCastException.class); + FromDate.checkConversionException(TO_SEQUENCE, ClassCastException.class); + } +}
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeRoundTripTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeRoundTripTestCase.java new file mode 100644 index 0000000000..f718a3f330 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/TypeRoundTripTestCase.java @@ -0,0 +1,147 @@ +/** + * + * 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.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.Type; +import commonj.sdo.helper.DataHelper; +import commonj.sdo.helper.TypeHelper; + +public class TypeRoundTripTestCase extends TestCase { + + private static class Test { + Type type; + String value; + Object obj; + Comparator comp; + + Test(Type type, String value, Object obj) { + this.type = type; + this.value = value; + this.obj = obj; + } + + Test(Type type, String value, Object obj, Comparator comp) { + this.type = type; + this.value = value; + this.obj = obj; + this.comp = comp; + } + } + + private static class ListComparator implements Comparator { + public int compare(Object list1, Object list2) { + int answer = 1; + if (list1 instanceof List && list2 instanceof List) { + List l1 = (List) list1; + List l2 = (List) list2; + if (l1.size() == l2.size()) { + for (int n = 0; n < l1.size(); n++) { + if (!l1.get(n).equals(l2.get(n))) { + answer = 0; + break; + } + } + } else { + answer = 0; + } + } else { + answer = 0; + } + return answer; + } + } + + private static class BytesComparator implements Comparator { + public int compare(Object o1, Object o2) { + o2 = new String((byte[])o2); + if (o1.equals(o2)) return 1; + else return 0; + } + } + + public void testTypeRoundTrips() throws Exception { + String URI = "commonj.sdo"; + TypeHelper types = TypeHelper.INSTANCE; + + List list = new ArrayList(); + list.add("foo"); + list.add("bar"); + list.add("test"); + Test[] tests = { + new Test(types.getType(URI, "Boolean"), "true", new Boolean(true)), + new Test(types.getType(URI, "Byte"), "49", new Byte((byte)49)), + new Test(types.getType(URI, "Bytes"), "666F6F", "foo", new BytesComparator()), + new Test(types.getType(URI, "Character"), "a", new Character('a')), + new Test(types.getType(URI, "Date"), "2005-12-12T12:12:12.012Z", DataHelper.INSTANCE.toDate("2005-12-12T12:12:12.012Z")), + new Test(types.getType(URI, "DateTime"), "2005-12-12T12:12:12zz", "2005-12-12T12:12:12zz"), + new Test(types.getType(URI, "Day"), "---12", "---12"), + new Test(types.getType(URI, "Decimal"), "12.12", new BigDecimal("12.12")), + new Test(types.getType(URI, "Double"), "12.12", new Double(12.12)), + new Test(types.getType(URI, "Duration"), "P5Y2M10D", "P5Y2M10D"), + new Test(types.getType(URI, "Float"), "12.12", new Float(12.12f)), + new Test(types.getType(URI, "Int"), "12", new Integer(12)), + new Test(types.getType(URI, "Integer"), "12", new BigInteger("12")), + new Test(types.getType(URI, "Long"), "12", new Long(12l)), + new Test(types.getType(URI, "Month"), "--12", "--12"), + new Test(types.getType(URI, "MonthDay"), "--12-12", "--12-12"), + new Test(types.getType(URI, "Object"), "test", "test"), + new Test(types.getType(URI, "Short"), "12", new Short((short)12)), + new Test(types.getType(URI, "String"), "test", "test"), + new Test(types.getType(URI, "Strings"), "foo bar test", list, new ListComparator()), + new Test(types.getType(URI, "Time"), "12:12:12.12", "12:12:12.12"), + new Test(types.getType(URI, "URI"), "http://example.org", "http://example.org"), + new Test(types.getType(URI, "Year"), "2005", "2005"), + new Test(types.getType(URI, "YearMonth"), "2005-12", "2005-12"), + new Test(types.getType(URI, "YearMonthDay"), "2005-12-12", "2005-12-12") + }; + + for (int n = 0; n < tests.length; n++) { + assertEquals( + SDOUtil.convertToString(tests[n].type, SDOUtil.createFromString(tests[n].type, tests[n].value)), + tests[n].value + ); + + //System.out.print("."); + + if (tests[n].comp == null) { + assertEquals( + SDOUtil.createFromString(tests[n].type, SDOUtil.convertToString(tests[n].type, tests[n].obj)), + tests[n].obj + ); + } else { + String o1 = SDOUtil.convertToString(tests[n].type, tests[n].obj); + Object o2 = SDOUtil.createFromString(tests[n].type, o1); + assertEquals(tests[n].comp.compare(tests[n].obj, o2), 1); + } + } + + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLDocumentTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLDocumentTestCase.java new file mode 100644 index 0000000000..1cf59757ef --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLDocumentTestCase.java @@ -0,0 +1,110 @@ +/** + * + * 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.IOException; + +import junit.framework.TestCase; + +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + + +public class XMLDocumentTestCase extends TestCase +{ + private final String TEST_XML_DOCUMENT = "/XMLDocumentTestCase.xml"; + + // remember that NS1... and NS2... items are expected in sorted order by name + private final String NS1_SCHEMA_NAME = "http://www.example.com/open"; + + private final String NS1_SCHEMA_LOCATION = "/open.xsd"; + + private final String NS2_SCHEMA_NAME = "http://www.example.com/xmlDocumentSchemaLocation"; + + private final String NS2_SCHEMA_LOCATION = "/XMLDocumentSchemaLocation.xsd"; + + private final String NS_SET_NAME_LOCATION = "namespace schemaLocation"; + + //private final String NNS_SCHEMA_LOCATION = "http://www.example.com/XMLDocumentNoNamespaceSchemaLocation.xsd"; + private final String NNS_SCHEMA_LOCATION = "/XMLDocumentNoNamespaceSchemaLocation.xsd"; + + private final String NNS_SET_LOCATION = "noNamespaceSchemaLocation"; + + /** + * This method will load an xml document consisting of a xsi:schemaLocation and + * xsi:noNamespaceSchemaLocation defined. It will then use the XMLDocument API to get and + * set the schemaLocation property. + * + * @throws IOException + */ + public void testSchemaLocation() throws IOException + { + // load the xml document which has xsi:noNamespaceSchemaLocation and xsi:schemaLocation defined + XMLDocument doc = XMLHelper.INSTANCE.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT)); + + // get the schemaLocation + assertEquals(NS1_SCHEMA_NAME + " " + NS1_SCHEMA_LOCATION + " " + NS2_SCHEMA_NAME + " " + NS2_SCHEMA_LOCATION, doc.getSchemaLocation()); + + // set the schemaLocation to another value and test to see if the value was set + doc.setSchemaLocation(NS_SET_NAME_LOCATION); + assertEquals(NS_SET_NAME_LOCATION, doc.getSchemaLocation()); + + // remove the schemaLocation and ensure it returns null + doc.setSchemaLocation(null); + assertNull(doc.getSchemaLocation()); + + // ensure changes to schemaLocation have not changed noNamespaceSchemaLocation + assertEquals(NNS_SCHEMA_LOCATION, doc.getNoNamespaceSchemaLocation()); + } + + /** + * This method will load an xml document consisting of a xsi:schemaLocation and + * xsi:noNamespaceSchemaLocation defined. It will then use the XMLDocument API to get and + * set the noNamespaceSchemaLocation property. + * + * @throws IOException + */ + public void testNoNamespaceSchemaLocation() throws IOException + { + // load the xml document which has xsi:noNamespaceSchemaLocation and xsi:schemaLocation defined + XMLDocument doc = XMLHelper.INSTANCE.load(getClass().getResourceAsStream(TEST_XML_DOCUMENT)); + + // get the noNamespaceSchemaLocation + assertEquals(NNS_SCHEMA_LOCATION, doc.getNoNamespaceSchemaLocation()); + + // set the noNameSpaceSchemaLocation to another value and test to see if the value was set + doc.setNoNamespaceSchemaLocation(NNS_SET_LOCATION); + assertEquals(NNS_SET_LOCATION, doc.getNoNamespaceSchemaLocation()); + + // remove the noNameSpaceSchemaLocation and ensure it returns null + doc.setNoNamespaceSchemaLocation(null); + assertNull(doc.getNoNamespaceSchemaLocation()); + + // ensure changes to noNameSpaceSchemaLocation have not changed schemaLocation + assertEquals(NS1_SCHEMA_NAME + " " + NS1_SCHEMA_LOCATION + " " + NS2_SCHEMA_NAME + " " + NS2_SCHEMA_LOCATION, doc.getSchemaLocation()); + } + + protected void setUp() throws Exception + { + super.setUp(); + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLStreamHelperTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLStreamHelperTestCase.java new file mode 100644 index 0000000000..4afbbf6137 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XMLStreamHelperTestCase.java @@ -0,0 +1,144 @@ +/** + * + * 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.IOException; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.URL; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class XMLStreamHelperTestCase extends TestCase { + + private XSDHelper xsdHelper = XSDHelper.INSTANCE; + + private TypeHelper typeHelper = TypeHelper.INSTANCE; + + private XMLStreamHelper streamHelper; + + private XMLInputFactory inputFactory; + + private XMLOutputFactory outputFactory; + + private QName module = new QName("http://foo", "module"); + + private QName name = new QName("http://bar", "implementation.mock"); + + private String testName = "foo-ext"; + // private String testName = "complex"; + + private String xml; + + // = "<module name=\"m\" xmlns=\"http://foo\" xmlns:bar=\"http://bar\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" + // xsi:schemaLocation=\"http://bar foo-ext.xsd http://foo foo.xsd \"><component name=\"c\"><bar:implementation.mock + // myAttr=\"helloworld.HelloWorldImpl\" listAttr=\"1 2\">1<bar:myElement>Dummy</bar:myElement>2</bar:implementation.mock></component></module>"; + + protected void setUp() throws Exception { + super.setUp(); + streamHelper = SDOUtil.createXMLStreamHelper(typeHelper); + URL url = getClass().getClassLoader().getResource(testName + ".xsd"); + xsdHelper.define(url.openStream(), url.toExternalForm()); + inputFactory = XMLInputFactory.newInstance(); + outputFactory = XMLOutputFactory.newInstance(); + url = getClass().getClassLoader().getResource(testName + ".xml"); + InputStreamReader reader = new InputStreamReader(url.openStream()); + StringBuffer stringBuffer = new StringBuffer(); + char buf[] = new char[1024]; + int size; + while ((size = reader.read(buf)) != -1) + stringBuffer.append(buf, 0, size); + xml = stringBuffer.toString(); + reader.close(); + } + + public void testLoadObject() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml)); + int event = reader.getEventType(); + while (!(event == XMLStreamConstants.START_ELEMENT && reader.getName().equals(name)) && reader.hasNext()) { + event = reader.next(); + } + DataObject dataObject = streamHelper.loadObject(reader); + Assert.assertNotNull(dataObject); + Assert.assertTrue(dataObject.getString("myAttr").equals("helloworld.HelloWorldImpl")); + } + + public void testLoad() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(xml)); + XMLDocument document = streamHelper.load(reader); + Assert.assertNotNull(document); + Assert.assertEquals(document.getRootElementURI(), module.getNamespaceURI()); + Assert.assertEquals(document.getRootElementName(), module.getLocalPart()); + DataObject moduleObject = document.getRootObject(); + List components = moduleObject.getList("component"); + DataObject componentObject = (DataObject) components.get(0); + // componentObject.getDataObject("implementation.mock"); + DataObject implObject = (DataObject) componentObject.getSequence(0).getValue(0); + Assert.assertTrue(implObject.getString("myAttr").equals("helloworld.HelloWorldImpl")); + } + + public void testSave() throws XMLStreamException { + XMLDocument document = XMLHelper.INSTANCE.load(xml); + StringWriter writer = new StringWriter(); + XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); + streamHelper.save(document, streamWriter); + streamWriter.flush(); + String xmlStr = writer.toString(); + // System.out.println(xmlStr); + Assert.assertTrue(xmlStr.indexOf("myAttr=\"helloworld.HelloWorldImpl\"")!=-1); + } + + public void testSaveObject() throws XMLStreamException { + XMLDocument document = XMLHelper.INSTANCE.load(xml); + DataObject moduleObject = document.getRootObject(); + List components = moduleObject.getList("component"); + DataObject componentObject = (DataObject) components.get(0); + StringWriter writer = new StringWriter(); + XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); + streamHelper.saveObject(componentObject, streamWriter); + streamWriter.flush(); + Assert.assertTrue(writer.toString().indexOf("myAttr=\"helloworld.HelloWorldImpl\"")!=-1); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XPathTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XPathTestCase.java new file mode 100644 index 0000000000..4012ee7d3f --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XPathTestCase.java @@ -0,0 +1,128 @@ +/** + * + * 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.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import junit.framework.TestCase; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class XPathTestCase extends TestCase { + + private final String TEST_MODEL = "/xpath.xsd"; + private final String XPATH_XML = "/xpath.xml"; + + /** + * The presence or absence of the @ sign in a path has no meaning. + * Properties are always matched by name independent of their XML representation. + * @throws IOException + */ + public void testAtSignProperty() throws IOException { + TypeHelper typeHelper = SDOUtil.createTypeHelper(); + XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + xsdHelper.define(inputStream, url.toString()); + + inputStream.close(); + + XMLDocument doc = xmlHelper.load(getClass().getResourceAsStream(XPATH_XML)); + + DataObject drive = doc.getRootObject(); + DataObject folder1 = (DataObject) drive.get("Folder.1"); + String value = folder1.getString("@creation_date"); + + assertEquals(value, "2000-03-23"); + } + + public void testListIndexing() throws Exception { + TypeHelper typeHelper = SDOUtil.createTypeHelper(); + XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper); + XMLHelper xmlHelper = SDOUtil.createXMLHelper(typeHelper); + + URL url = getClass().getResource(TEST_MODEL); + InputStream inputStream = url.openStream(); + xsdHelper.define(inputStream, url.toString()); + + inputStream.close(); + + XMLDocument doc = xmlHelper.load(getClass().getResourceAsStream(XPATH_XML)); + + DataObject root = doc.getRootObject(); + DataObject folder1 = root.getDataObject("Folder[1]"); + assertNotNull(folder1); + DataObject folder1a = root.getDataObject("Folder.0"); + assertEquals(folder1, folder1a); + folder1a = root.getDataObject("Folder[FolderName=Folder00000000000]"); + assertEquals(folder1, folder1a); + + DataObject noFolder = null; + + try { + noFolder = root.getDataObject("Folder[3]"); + assertFalse("bad indexing passed", true); + } catch (IndexOutOfBoundsException iobe) { + // as expected + } catch (Exception e) { + assertFalse("bad indexing generated wrong exception" + e, true); + } + + try { + noFolder = root.getDataObject("Folder[0]"); + assertFalse("bad indexing passed", true); + } catch (IndexOutOfBoundsException iobe) { + // as expected + } catch (Exception e) { + assertFalse("bad indexing generated wrong exception" + e, true); + } + + try { + noFolder = root.getDataObject("Folder.2"); + assertFalse("bad indexing passed", true); + } catch (IndexOutOfBoundsException iobe) { + // as expected + } catch (Exception e) { + assertFalse("bad indexing generated wrong exception" + e, true); + } + + try { + noFolder = root.getDataObject("Folder.-1"); + assertFalse("bad indexing passed", true); + } catch (IndexOutOfBoundsException iobe) { + // as expected + } catch (Exception e) { + assertFalse("bad indexing generated wrong exception" + e, true); + } + + noFolder = root.getDataObject("Folder[FolderName=foo]"); + assertNull(noFolder); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XSDHelperTestCase.java b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XSDHelperTestCase.java new file mode 100644 index 0000000000..557fa12d87 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/java/org/apache/tuscany/sdo/test/XSDHelperTestCase.java @@ -0,0 +1,192 @@ +/** + * + * 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.IOException; +import java.net.URL; +import java.util.Hashtable; +import java.util.List; +import java.util.Vector; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + +import com.example.simple.impl.SimpleFactoryImpl; +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.TypeHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * @version $Rev$ $Date$ + */ +public class XSDHelperTestCase extends TestCase { + private static final String TEST_MODEL = "/simple.xsd"; + private URL modelURL; + + public void testDefineWithLocation() throws IOException { + XSDHelper xsdHelper = SDOUtil.createXSDHelper(SDOUtil.createTypeHelper()); + List types = xsdHelper.define(modelURL.openStream(), modelURL.toString()); + assertEquals(2, types.size()); + } + + public void testDefineWithNoLocation() { + XSDHelper xsdHelper = SDOUtil.createXSDHelper(SDOUtil.createTypeHelper()); + List types = xsdHelper.define(getClass().getResourceAsStream(TEST_MODEL), null); + assertEquals(2, types.size()); + } + + public void testDuplicateDefineWithLocation() throws IOException { + XSDHelper xsdHelper = SDOUtil.createXSDHelper(SDOUtil.createTypeHelper()); + List types = xsdHelper.define(modelURL.openStream(), modelURL.toString()); + assertEquals(2, types.size()); + + List types2 = xsdHelper.define(modelURL.openStream(), modelURL.toString()); + assertEquals(0, types2.size()); + } + + public void testXSDGeneration_staticSDOType() throws IOException + { + //test for static sdo type. The test succeeds if the IllegalArgumentException is thrown + //by XSDHelper.generate method in which case the string xsd must be null; + XSDHelper xsdHelper = SDOUtil.createXSDHelper(SDOUtil.createTypeHelper()); + DataObject quoteSDO = (DataObject)SimpleFactoryImpl.INSTANCE.createQuote(); + List typeList = new Vector(); + typeList.add(quoteSDO.getType()); + String xsd = null; + + try + { + xsd = xsdHelper.generate(typeList); + xsd = ""; + } + catch ( IllegalArgumentException e ) + { + } + assertNull(xsd); + } + + public void testXSDGeneration_DynamicSDOType() throws IOException + { + //test for dynamic SDOs that have no XSD model. Here the testcase succeeds only if the + //xsd is generated by XSDHelper in which case xsd must not be null + XSDHelper xsdHelper = SDOUtil.createXSDHelper(SDOUtil.createTypeHelper()); + DataObject quoteType = DataFactory.INSTANCE.create("commonj.sdo", "Type"); + quoteType.set("uri", "http://www.example.com/dynamic"); + quoteType.set("name", "DynamicQuote"); + + DataObject aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "symbol"); + aProperty.set("type", TypeHelper.INSTANCE.getType("commonj.sdo", "String")); + + aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "price"); + aProperty.set("type", TypeHelper.INSTANCE.getType("commonj.sdo", "Decimal")); + + aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "volume"); + aProperty.set("type", TypeHelper.INSTANCE.getType("commonj.sdo", "Double")); + + TypeHelper.INSTANCE.define(quoteType); + + Type dynamicQuoteType = + TypeHelper.INSTANCE.getType("http://www.example.com/dynamic", "DynamicQuote"); + + Vector types = new Vector(); + types.add(dynamicQuoteType); + String xsd = null; + + try + { + xsd = xsdHelper.generate(types); + //System.out.println(xsd); + } + catch ( IllegalArgumentException e ) + { + } + assertNotNull(xsd); + + } + + public void testXSDGeneration_DynamicWithNestedStaticSDOType() throws IOException + { + //testing static SDO with XSD Model being contained in a Dynamic SDO not having an XSD Model. + //the schema must be generated with imports / includes for the XSD corresponding to the static + //sdo types. + TypeHelper typeHelper = SDOUtil.createTypeHelper(); + XSDHelper xsdHelper = SDOUtil.createXSDHelper(typeHelper); + + DataObject quoteSDO = (DataObject)SimpleFactoryImpl.INSTANCE.createQuote(); + + + DataObject quoteType = DataFactory.INSTANCE.create("commonj.sdo", "Type"); + quoteType.set("uri", "http://www.example.com/dynamic"); + quoteType.set("name", "DynamicQuote"); + + DataObject aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "symbol"); + aProperty.set("type", typeHelper.getType("commonj.sdo", "String")); + + aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "price"); + aProperty.set("type", typeHelper.getType("commonj.sdo", "Decimal")); + + aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "volume"); + aProperty.set("type", typeHelper.getType("commonj.sdo", "Double")); + + aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "containedQuotes"); + aProperty.set("type", typeHelper.getType(quoteSDO.getType().getURI(), quoteSDO.getType().getName())); + aProperty.set("containment", new Boolean(true)); + + aProperty = quoteType.createDataObject("property"); + aProperty.set("name", "referredQuotes"); + aProperty.set("type", typeHelper.getType(quoteSDO.getType().getURI(), quoteSDO.getType().getName())); + + typeHelper.define(quoteType); + + Type dynamicQuoteType = + typeHelper.getType("http://www.example.com/dynamic", "DynamicQuote"); + Vector types = new Vector(); + types.add(dynamicQuoteType); + String xsd = null; + + try + { + Hashtable schemaLocationMap = new Hashtable(); + schemaLocationMap.put("http://www.example.com/simple", "http://www.example.com/simple/xsd"); + xsd = xsdHelper.generate(types, schemaLocationMap); + //System.out.println(xsd); + } + catch ( IllegalArgumentException e ) + { + } + assertNotNull(xsd); + + } + + protected void setUp() throws Exception { + super.setUp(); + modelURL = getClass().getResource(TEST_MODEL); + } +} diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/SubstitutionValues.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/SubstitutionValues.xsd new file mode 100644 index 0000000000..7aee02c032 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/SubstitutionValues.xsd @@ -0,0 +1,30 @@ +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.apache.org/tuscany/SubstitutionValues" + xmlns:sv="http://www.apache.org/tuscany/SubstitutionValues"> + <!-- + 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. + --> + <element name="groupHead" type="string"/> + <complexType name="TestObject"> + <sequence> + <element ref="sv:groupHead"/> + <element name="nonGroupHead" type="string"/> + </sequence> + </complexType> + <element name="groupMember" type="string" substitutionGroup="sv:groupHead"/> +</schema>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentNoNamespaceSchemaLocation.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentNoNamespaceSchemaLocation.xsd new file mode 100644 index 0000000000..7718cb424f --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentNoNamespaceSchemaLocation.xsd @@ -0,0 +1,31 @@ +<?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:xsd="http://www.w3.org/2001/XMLSchema"> + + <xsd:element name="aNoNamespaceSchemaLocationElement"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="anElement" type="xsd:string" minOccurs="1" maxOccurs="unbounded"/> + </xsd:sequence> + <xsd:attribute name="date" type="xsd:date"/> + </xsd:complexType> + </xsd:element> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentSchemaLocation.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentSchemaLocation.xsd new file mode 100644 index 0000000000..c48fab79f1 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentSchemaLocation.xsd @@ -0,0 +1,35 @@ +<?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:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.example.com/xmlDocumentSchemaLocation" + xmlns:sl="http://www.example.com/xmlDocumentSchemaLocation"> + + <xsd:element name="schemaLocationElement" type="xsd:string" /> + + <xsd:element name="purchaseReport"> + <xsd:complexType> + <xsd:sequence> + <xsd:any minOccurs="1" maxOccurs="unbounded"/> + </xsd:sequence> + <xsd:attribute name="periodEnding" type="xsd:date"/> + </xsd:complexType> + </xsd:element> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentTestCase.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentTestCase.xml new file mode 100644 index 0000000000..88160e0b2f --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/XMLDocumentTestCase.xml @@ -0,0 +1,14 @@ +<sl:purchaseReport + xmlns:sl="http://www.example.com/xmlDocumentSchemaLocation" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.example.com/xmlDocumentSchemaLocation + /XMLDocumentSchemaLocation.xsd + http://www.example.com/open + /open.xsd" + xsi:noNamespaceSchemaLocation="/XMLDocumentNoNamespaceSchemaLocation.xsd" + periodEnding="2007-12-31"> + <sl:schemaLocationElement>some string</sl:schemaLocationElement> + <aNoNamespaceSchemaLocationElement date="2006-04-01"> + <anElement>another string</anElement> + </aNoNamespaceSchemaLocationElement> +</sl:purchaseReport> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/api_test.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/api_test.xsd new file mode 100644 index 0000000000..3ccaebdd57 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/api_test.xsd @@ -0,0 +1,46 @@ +<?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:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sdo="commonj.sdo" xmlns:simple="http://www.example.com/api_test" targetNamespace="http://www.example.com/api_test">
+ <xsd:import namespace="commonj.sdo" schemaLocation="sdoModel.xsd"/>
+ <xsd:element name="apiTestElem" type="simple:APITest"/>
+
+ <xsd:complexType mixed="true" name="APITest">
+ <xsd:sequence>
+ <xsd:element name="stringVal" type="sdo:String"/>
+ <xsd:element name="booleanVal" type="sdo:Boolean"/>
+ <xsd:element name="booleanVal2" type="sdo:Boolean"/>
+ <xsd:element name="byteVal" type="sdo:Byte"/>
+ <xsd:element name="stringVal2" type="sdo:String"/>
+ <xsd:element name="decimalVal" type="sdo:Decimal"/>
+ <xsd:element name="decimalVal2" type="sdo:Decimal"/>
+ <xsd:element name="intVal" type="sdo:Int"/>
+ <xsd:element name="floatVal" type="sdo:Float"/>
+ <xsd:element name="doubleVal" type="sdo:Double"/>
+ <xsd:element name="dateVal" type="sdo:Date"/>
+ <xsd:element name="shortVal" type="sdo:Short"/>
+ <xsd:element name="longVal" type="sdo:Long"/>
+ <xsd:element maxOccurs="unbounded" minOccurs="0" name="children" type="simple:APITest"/>
+ <xsd:element name="bytesVal" type="sdo:Bytes"/>
+ <xsd:element name="integerVal" type="sdo:Integer"/>
+ <xsd:element name="charVal" type="sdo:Character"/>
+ <xsd:element name="xsdDate" type="xsd:date"/>
+ </xsd:sequence>
+ </xsd:complexType>
+</xsd:schema>
diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/bank.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/bank.xsd new file mode 100644 index 0000000000..ae23feefa3 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/bank.xsd @@ -0,0 +1,78 @@ +<?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 targetNamespace="http://www.example.com/bank"
+ xmlns:bank="http://www.example.com/bank"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:sdoXML="commonj.sdo/xml">
+
+ <xsd:element name="bank" type="bank:bankType"/>
+
+ <xsd:complexType name="bankType">
+ <xsd:sequence>
+ <xsd:element name="Branch" type="bank:branchType" maxOccurs="unbounded" />
+ <xsd:element name="Service" type="bank:serviceType" maxOccurs="unbounded" />
+ <xsd:element name="Customer" type="bank:customerType" maxOccurs="unbounded" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="branchType">
+ <xsd:sequence>
+ <xsd:element name="Address" type="bank:addressType"/>
+ <xsd:element name="Directions" type="xsd:string" maxOccurs="unbounded" />
+ <xsd:element name="Account" type="bank:accountType" maxOccurs="unbounded" />
+ </xsd:sequence>
+ <xsd:attribute name="ID" type="xsd:ID"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="serviceType">
+ <xsd:attribute name="ID" type="xsd:ID"/>
+ <xsd:attribute name="Name" type="xsd:string"/>
+ <xsd:attribute name="Fee" type="xsd:decimal"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="accountType">
+ <xsd:attribute name="ID" type="xsd:ID"/>
+ <xsd:attribute name="Service" type="xsd:IDREF" sdoXML:propertyType="bank:serviceType" />
+ <xsd:attribute name="Balance" type="xsd:decimal" />
+ </xsd:complexType>
+
+ <xsd:complexType name="customerType">
+ <xsd:sequence>
+ <xsd:element name="First" type="xsd:string" />
+ <xsd:element name="Last" type="xsd:string" />
+ <xsd:element name="Address" type="bank:addressType"/>
+ <xsd:element name="HomeBranch" type="xsd:IDREF" sdoXML:propertyType="bank:branchType" />
+ <xsd:element name="Account" type="xsd:IDREF" sdoXML:propertyType="bank:accountType" maxOccurs="unbounded" />
+ </xsd:sequence>
+ <xsd:attribute name="ID" type="xsd:ID"/>
+ <xsd:attribute name="Related" type="xsd:IDREFS" sdoXML:propertyType="bank:customerType" />
+ </xsd:complexType>
+
+ <xsd:complexType name="addressType">
+ <xsd:sequence>
+ <xsd:element name="Street" type="xsd:string"/>
+ <xsd:element name="City" type="xsd:string"/>
+ <xsd:element name="State" type="xsd:string"/>
+ <xsd:element name="Zip" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ </xsd:schema>
diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/company.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/company.xsd new file mode 100644 index 0000000000..18e99352be --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/company.xsd @@ -0,0 +1,44 @@ +<?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:company="company.xsd" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="company.xsd"> + <xsd:element name="company" type="company:CompanyType"/> + <xsd:complexType name="CompanyType"> + <xsd:sequence> + <xsd:element name="departments" type="company:DepartmentType" maxOccurs="unbounded"/> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="employeeOfTheMonth" type="xsd:string"/> + </xsd:complexType> + <xsd:complexType name="DepartmentType"> + <xsd:sequence> + <xsd:element name="employees" type="company:EmployeeType" maxOccurs="unbounded"/> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="location" type="xsd:string"/> + <xsd:attribute name="number" type="xsd:int"/> + </xsd:complexType> + <xsd:complexType name="EmployeeType"> + <xsd:attribute name="name" type="xsd:string"/> + <xsd:attribute name="SN" type="xsd:ID"/> + <xsd:attribute name="manager" type="xsd:boolean"/> + </xsd:complexType> + </xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/customer1.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/customer1.xml new file mode 100644 index 0000000000..5a29e30a3c --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/customer1.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="ASCII"?> +<customer:Customer + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:customer="http://example.com/customer" + xsi:type="customer:Customer" + custNum="1" + firstName="John" + lastName="Adams"/>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/customer2.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/customer2.xml new file mode 100644 index 0000000000..e9ebb92677 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/customer2.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="ASCII"?> +<customer:Customer + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:customer="http://example.com/customer" + xsi:type="customer:Customer" + custNum="2" + firstName="Jeremy" + lastName="Pavick"/>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/datatype.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/datatype.xsd new file mode 100644 index 0000000000..9c03964367 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/datatype.xsd @@ -0,0 +1,34 @@ +<?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:xsd="http://www.w3.org/2001/XMLSchema" xmlns:datatype="http://www.example.com/datatype" xmlns:sdoJava="commonj.sdo/java" targetNamespace="http://www.example.com/datatype"> + + <xsd:simpleType name="SimpleSDOType"> + <xsd:restriction base="xsd:string"/> + </xsd:simpleType> + + <xsd:simpleType name="SimpleSDOTypeInstanceClass" sdoJava:instanceClass="java.lang.Integer"> + <xsd:restriction base="xsd:string"/> + </xsd:simpleType> + + <xsd:simpleType name="SimpleSDOTypeExtendedInstanceClass" sdoJava:extendedInstanceClass="java.lang.String"> + <xsd:restriction base="xsd:string"/> + </xsd:simpleType> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/foo-ext.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/foo-ext.xml new file mode 100644 index 0000000000..000909a52e --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/foo-ext.xml @@ -0,0 +1,9 @@ +<module name="m" xmlns="http://foo" xmlns:bar="http://bar" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://bar foo-ext.xsd http://foo foo.xsd "> + <component name="c"> + <bar:implementation.mock myAttr="helloworld.HelloWorldImpl" + listAttr="1 2">1<bar:myElement>Dummy</bar:myElement>2 + </bar:implementation.mock> + </component> +</module>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/foo-ext.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/foo-ext.xsd new file mode 100644 index 0000000000..8bad6f9307 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/foo-ext.xsd @@ -0,0 +1,44 @@ +<?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. + --> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://bar" + elementFormDefault="qualified" + xmlns:foo="http://foo" xmlns:bar="http://bar"> + + <import namespace="http://foo" + schemaLocation="foo.xsd" /> + + <element name="implementation.mock" type="bar:MockImplementation" + substitutionGroup="foo:implementation" /> + <complexType name="MockImplementation" mixed="true"> + <complexContent> + <extension base="foo:Implementation"> + <sequence> + <element name="myElement" type="string"/> + <any namespace="##other" processContents="lax" + minOccurs="0" maxOccurs="unbounded" /> + </sequence> + <attribute name="myAttr" type="NCName" use="required" /> + <attribute name="listAttr" type="NMTOKENS" use="optional" /> + <anyAttribute namespace="##any" processContents="lax" /> + </extension> + </complexContent> + </complexType> +</schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/foo.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/foo.xsd new file mode 100644 index 0000000000..27a8e3644c --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/foo.xsd @@ -0,0 +1,232 @@ +<?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. + --> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://foo" + elementFormDefault="qualified" xmlns:foo="http://foo"> + + <element name="componentType" type="foo:ComponentType"/> + <complexType name="ComponentType"> + <sequence> + <element minOccurs="0" maxOccurs="unbounded" name="service" type="foo:Service"/> + <element minOccurs="0" maxOccurs="unbounded" name="reference" type="foo:Reference"/> + <element minOccurs="0" maxOccurs="unbounded" name="property" type="foo:Property"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="Service"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="foo:interface"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <element name="interface" type="foo:Interface"/> + <complexType name="Interface"/> + + <complexType name="Reference"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="foo:interface"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="multiplicity" type="foo:Multiplicity" use="optional" default="1..1"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="Property"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="type" type="QName" use="required"/> + <attribute name="many" type="boolean" default="false" use="optional"/> + <attribute name="required" type="boolean" default="false" use="optional"/> + <attribute name="default" type="string" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + + <element name="moduleFragment" type="foo:ModuleFragment"/> + <complexType name="ModuleFragment"> + <sequence> + <element minOccurs="0" maxOccurs="unbounded" name="entryPoint" type="foo:EntryPoint"/> + <element minOccurs="0" maxOccurs="unbounded" name="component" type="foo:Component"/> + <element minOccurs="0" maxOccurs="unbounded" name="externalService" type="foo:ExternalService"/> + <element minOccurs="0" maxOccurs="unbounded" name="wire" type="foo:ModuleWire"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <element name="module" type="foo:Module"/> + <complexType name="Module"> + <complexContent> + <extension base="foo:ModuleFragment"/> + </complexContent> + </complexType> + + <complexType name="EntryPoint"> + <sequence> + <element minOccurs="0" maxOccurs="1" ref="foo:interface"/> + <element minOccurs="1" maxOccurs="unbounded" ref="foo:binding"/> + <element minOccurs="1" maxOccurs="unbounded" name="reference" type="anyURI"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="multiplicity" type="foo:Multiplicity" use="optional" default="1..1"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + <!-- a multiplicity 1..1 or 0..n sample + <reference>StockQuoteComponent</reference> - type must be URI + a multiplicity 1..n or 0..n sample + <reference>StockQuoteComponent1</reference> - type must be URI + <reference>StockQuoteComponent2</reference> + --> + + <element name="binding" type="foo:Binding"/> + <complexType name="Binding"> + <attribute name="uri" type="anyURI" use="optional"/> + </complexType> + + <complexType name="Component"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="foo:implementation"/> + <element minOccurs="0" maxOccurs="1" name="properties" type="foo:PropertyValues"/> + <element minOccurs="0" maxOccurs="1" name="references" type="foo:ReferenceValues"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + <!-- a multiplicity 1..1 or 0..1 sample + <references> + <v:stockQuote>StockQuoteComponent</v:stockquote> - type must be URI + </references> + a multiplicity 1..n or 0..n sample + <references> + <v:stockQuote>StockQuoteComponent1</v:stockQuote> - type must be URI + <v:stockQuote>StockQuoteComponent2</v:stockQuote> + </references> + --> + + <element name="implementation" type="foo:Implementation"/> + <complexType name="Implementation"/> + + <complexType name="PropertyValues"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="ReferenceValues"> + <sequence> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + + <complexType name="ExternalService"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="foo:interface"/> + <element minOccurs="0" maxOccurs="unbounded" ref="foo:binding"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="overridable" type="foo:OverrideOptions" default="may" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + + <complexType name="ModuleWire"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="foo:source.uri"/> + <element minOccurs="1" maxOccurs="1" ref="foo:target.uri"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <element name="source"/> + <element name="target"/> + + <element name="source.uri" type="anyURI" substitutionGroup="foo:source"/> + <element name="target.uri" type="anyURI" substitutionGroup="foo:target"/> + + <element name="subsystem" type="foo:Subsystem"/> + <complexType name="Subsystem"> + <sequence> + <element minOccurs="0" maxOccurs="unbounded" name="entryPoint" type="foo:EntryPoint"/> + <element minOccurs="0" maxOccurs="unbounded" name="moduleComponent" type="foo:ModuleComponent"/> + <element minOccurs="0" maxOccurs="unbounded" name="externalService" type="foo:ExternalService"/> + <element minOccurs="0" maxOccurs="unbounded" name="wire" type="foo:SystemWire"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="uri" type="anyURI" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="ModuleComponent"> + <sequence> + <element minOccurs="0" maxOccurs="1" name="properties" type="foo:PropertyValues"/> + <element minOccurs="0" maxOccurs="1" name="references" type="foo:ReferenceValues"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + <attribute name="name" type="NCName" use="required"/> + <attribute name="module" type="NCName" use="required"/> + <attribute name="uri" type="anyURI" use="optional"/> + <anyAttribute namespace="##any" processContents="lax"/> + </complexType> + + <complexType name="SystemWire"> + <sequence> + <element minOccurs="1" maxOccurs="1" ref="foo:source"/> + <element minOccurs="1" maxOccurs="1" ref="foo:target"/> + <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> + </sequence> + </complexType> + + <element name="source.epr" substitutionGroup="foo:source"/> + <element name="target.epr" substitutionGroup="foo:target"/> + + <simpleType name="Multiplicity"> + <restriction base="string"> + <enumeration value="0..1"/> + <enumeration value="1..1"/> + <enumeration value="0..n"/> + <enumeration value="1..n"/> + </restriction> + </simpleType> + + <simpleType name="OverrideOptions"> + <restriction base="string"> + <enumeration value="no"/> + <enumeration value="may"/> + <enumeration value="must"/> + </restriction> + </simpleType> + +</schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed.xml new file mode 100644 index 0000000000..42ff3a3a5b --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="ASCII"?> +<mixed:mixedStockQuote xmlns:mixed="http://www.example.com/mixed"> + <symbol>fbnt</symbol> + <companyName>FlyByNightTechnology</companyName> + some text + <quotes><price>2000.0</price></quotes> + more text + <price>1000.0</price> +</mixed:mixedStockQuote>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed.xsd new file mode 100644 index 0000000000..b9a8487559 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed.xsd @@ -0,0 +1,41 @@ +<?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 + targetNamespace="http://www.example.com/mixed" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:simple="http://www.example.com/mixed"> + + <xsd:element name="mixedStockQuote" type="simple:MixedQuote"/> + + <xsd:complexType name="MixedQuote" mixed="true"> + <xsd:sequence> + <xsd:element name="symbol" type="xsd:string"/> + <xsd:element name="companyName" type="xsd:string"/> + <xsd:element name="price" type="xsd:decimal"/> + <xsd:element name="open1" type="xsd:decimal"/> + <xsd:element name="high" type="xsd:decimal"/> + <xsd:element name="low" type="xsd:decimal"/> + <xsd:element name="volume" type="xsd:double"/> + <xsd:element name="change1" type="xsd:double"/> + <xsd:element name="quotes" type="simple:MixedQuote" minOccurs="0" maxOccurs="unbounded"/> + </xsd:sequence> + </xsd:complexType> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed2.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed2.xml new file mode 100644 index 0000000000..d95d179478 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixed2.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="ASCII"?> +<mixed:mixedStockQuote + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:mixed="http://www.example.com/mixed" + xsi:type="mixed:MixedQuote"> + <symbol>fbnt</symbol> + <companyName>FlyByNightTechnology</companyName> + some text + <quotes><price>2000.0</price></quotes> + more text + <price>1000.0</price> +</mixed:mixedStockQuote>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/mixedopen.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixedopen.xml new file mode 100644 index 0000000000..21a62ef2d0 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/mixedopen.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="ASCII"?> +<mixed:mixedOpenStockQuote + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:mixed="http://www.example.com/mixed" + xmlns:open="http://www.example.com/open" + xsi:type="mixed:MixedOpenQuote"> + <open:symbol>fbnt</open:symbol> + <companyName>FlyByNightTechnology</companyName> + some text + <quotes><price>2000.0</price></quotes> + more text + <price>1000.0</price> +</mixed:mixedOpenStockQuote> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/names.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/names.xsd new file mode 100644 index 0000000000..97b57c1741 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/names.xsd @@ -0,0 +1,33 @@ +<?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 + targetNamespace="http://www.example.com/names" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:names="http://www.example.com/names"> + + <xsd:element name="class" type="names:class"/> + <xsd:element name="test.element" type="names:test.element" /> + <xsd:element name="void" type="names:void" /> + + <xsd:complexType name="class" /> + <xsd:complexType name="test.element" /> + <xsd:complexType name="void" /> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/open.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/open.xml new file mode 100644 index 0000000000..d4a5b92e0c --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/open.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="ASCII"?> +<open:openStockQuote xmlns:open="http://www.example.com/open"> + <symbol>s1</symbol> + <open:company> + <name>FlyByNightTechnology</name> + </open:company> + <open:price>1000.0</open:price> +</open:openStockQuote>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/open.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/open.xsd new file mode 100644 index 0000000000..d100d58fc6 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/open.xsd @@ -0,0 +1,44 @@ +<?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:simple="http://www.example.com/open" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.example.com/open"> + + <xsd:element name="openStockQuote" type="simple:OpenQuote"/> + + <xsd:element name="price" type="xsd:decimal"/> + + <xsd:element name="company"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="name" type="xsd:string"/> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:complexType name="OpenQuote"> + <xsd:sequence> + <xsd:element name="symbol" type="xsd:string"/> + <xsd:any maxOccurs="unbounded" namespace="##any"/> + </xsd:sequence> + </xsd:complexType> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/open1any.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/open1any.xsd new file mode 100644 index 0000000000..00efaef5e0 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/open1any.xsd @@ -0,0 +1,44 @@ +<?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:simple="http://www.example.com/open1any" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://www.example.com/open1any"> + + <xsd:element name="openStockQuote" type="simple:OpenQuote"/> + + <xsd:element name="price" type="xsd:decimal"/> + + <xsd:element name="company"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="name" type="xsd:string"/> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + + <xsd:complexType name="OpenQuote"> + <xsd:sequence> + <xsd:element name="symbol" type="xsd:string"/> + <xsd:any namespace="##any"/> + </xsd:sequence> + </xsd:complexType> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/open2.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/open2.xml new file mode 100644 index 0000000000..ab992ccf74 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/open2.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="ASCII"?> +<open:openStockQuote + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:open="http://www.example.com/open" + xsi:type="open:OpenQuote"> + <open:symbol>s1</open:symbol> + <open:company name="FlyByNightTechnology"/> + <open:price>1000.0</open:price> +</open:openStockQuote> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/openContentProperty.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/openContentProperty.xml new file mode 100644 index 0000000000..03608365c0 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/openContentProperty.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="ASCII"?>
+<open:openStockQuote xmlns:open="http://www.example.com/open">
+ <symbol>s1</symbol>
+ <open:company>
+ <name>FlyByNightTechnology</name>
+ </open:company>
+ <open:price>1000.0</open:price>
+ <open:highPrice>1100.0</open:highPrice>
+ <open:mutualFundQuote>
+ <symbol>mutual-1</symbol>
+ </open:mutualFundQuote>
+</open:openStockQuote>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/po.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/po.xsd new file mode 100644 index 0000000000..5c53ac1905 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/po.xsd @@ -0,0 +1,62 @@ +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns="http://www.example.com/PO" targetNamespace="http://www.example.com/PO"> + + <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> + <xsd:element name="comment" type="xsd:string"/> + + <xsd:complexType name="PurchaseOrderType"> + <xsd:sequence> + <xsd:element name="shipTo" type="USAddress"/> + <xsd:element name="billTo" type="USAddress"/> + <xsd:element ref="comment" minOccurs="0"/> + <xsd:element name="items" type="Items"/> + + </xsd:sequence> + <xsd:attribute name="orderDate" type="xsd:date"/> + </xsd:complexType> + + <xsd:complexType name="USAddress"> + <xsd:sequence> + <xsd:element name="name" type="xsd:string"/> + + <xsd:element name="street" type="xsd:string"/> + <xsd:element name="city" type="xsd:string"/> + <xsd:element name="state" type="xsd:string"/> + <xsd:element name="zip" type="xsd:decimal"/> + </xsd:sequence> + <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/> + + </xsd:complexType> + + <xsd:complexType name="Items"> + <xsd:sequence> + <xsd:element name="item" minOccurs="0" maxOccurs="unbounded"> + <xsd:complexType> + <xsd:sequence> + + <xsd:element name="productName" type="xsd:string"/> + <xsd:element name="price" type="xsd:decimal"/> + <xsd:element name="quantity"> + <xsd:simpleType> + <xsd:restriction base="xsd:positiveInteger"> + <xsd:maxExclusive value="100"/> + </xsd:restriction> + + </xsd:simpleType> + </xsd:element> + <xsd:element ref="comment" minOccurs="0"/> + <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/> + </xsd:sequence> + + <xsd:attribute name="partNum" type="SKU" use="required"/> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + </xsd:complexType> + <xsd:simpleType name="SKU"> + + <xsd:restriction base="xsd:string"> + <xsd:pattern value="\d{3}-[A-Z]{2}"/> + </xsd:restriction> + </xsd:simpleType> + </xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/quote.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/quote.xml new file mode 100644 index 0000000000..d7b5969e23 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/quote.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="ASCII"?> +<simple:stockQuote xmlns:simple="http://www.example.com/simple"> + <symbol>fbnt</symbol> + <companyName>FlyByNightTechnology</companyName> + <price>1000.0</price> + <open1>1000.0</open1> + <high>1000.0</high> + <low>1000.0</low> + <volume>1000.0</volume> + <change1>1000.0</change1> + <quotes> + <price>2000.0</price> + </quotes> +</simple:stockQuote>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/sdoannotations.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/sdoannotations.xsd new file mode 100644 index 0000000000..98be3a57d7 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/sdoannotations.xsd @@ -0,0 +1,60 @@ +<?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 + targetNamespace="http://www.example.com/sdoannotations" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:sdoa="http://www.example.com/sdoannotations" + xmlns:sdo="commonj.sdo/xml" + xmlns:sdoj="commonj.sdo/java"> + + <!-- simple element with no annotations --> + <xsd:element name="foo0" type="xsd:string" /> + + <!-- simple element with sdo:name --> + <xsd:element name="foo1" type="xsd:string" sdo:name="foo2" /> + + <!-- simple element with sdo:type --> + <xsd:element + name="foo3" type="xsd:int" + sdo:dataType="xsd:string" + sdo:aliasName="foo4" + sdo:readOnly="true" /> + + <xsd:element + name="foo5" type="sdoa:foo6" /> + + <!-- complex type with no annotations --> + <xsd:complexType name="foo6"> + <xsd:sequence> + <xsd:element name="bar1" type="xsd:int" /> + </xsd:sequence> + <xsd:attribute name="bar2" type="xsd:int" /> + </xsd:complexType> + + <xsd:element + name="foo7" type="sdoa:foo8" /> + + <xsd:complexType name="foo8" sdo:name="foo9" sdoj:instanceClass="org.apache.tuscany.sdo.test.XSDHelperTestCase"> + <xsd:sequence> + <xsd:element name="bar3" type="xsd:int" sdo:string="true" /> + </xsd:sequence> + </xsd:complexType> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/sdotypes.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/sdotypes.xsd new file mode 100644 index 0000000000..f206c86013 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/sdotypes.xsd @@ -0,0 +1,71 @@ +<?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 + targetNamespace="http://www.example.com/sdotypes" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:sdot="http://www.example.com/sdotypes"> + + <xsd:element name="foo0" type="xsd:anySimpleType"/> + <xsd:element name="foo2" type="xsd:anyURI"/> + <xsd:element name="foo3" type="xsd:base64Binary"/> + <xsd:element name="foo4" type="xsd:boolean"/> + <xsd:element name="foo5" type="xsd:byte"/> + <xsd:element name="foo6" type="xsd:date"/> + <xsd:element name="foo7" type="xsd:dateTime"/> + <xsd:element name="foo8" type="xsd:decimal"/> + <xsd:element name="foo9" type="xsd:double"/> + <xsd:element name="foo10" type="xsd:duration"/> + <xsd:element name="foo11" type="xsd:ENTITIES"/> + <xsd:element name="foo12" type="xsd:ENTITY"/> + <xsd:element name="foo13" type="xsd:float"/> + <xsd:element name="foo14" type="xsd:gDay"/> + <xsd:element name="foo15" type="xsd:gMonth"/> + <xsd:element name="foo16" type="xsd:gMonthDay"/> + <xsd:element name="foo17" type="xsd:gYear"/> + <xsd:element name="foo18" type="xsd:gYearMonth"/> + <xsd:element name="foo19" type="xsd:hexBinary"/> + <xsd:element name="foo20" type="xsd:ID"/> + <xsd:element name="foo21" type="xsd:IDREF"/> + <xsd:element name="foo22" type="xsd:IDREFS"/> + <xsd:element name="foo23" type="xsd:int"/> + <xsd:element name="foo24" type="xsd:integer"/> + <xsd:element name="foo25" type="xsd:language"/> + <xsd:element name="foo26" type="xsd:long"/> + <xsd:element name="foo27" type="xsd:Name"/> + <xsd:element name="foo28" type="xsd:NCName"/> + <xsd:element name="foo29" type="xsd:negativeInteger"/> + <xsd:element name="foo30" type="xsd:NMTOKEN"/> + <xsd:element name="foo31" type="xsd:NMTOKENS"/> + <xsd:element name="foo32" type="xsd:nonNegativeInteger"/> + <xsd:element name="foo33" type="xsd:nonPositiveInteger"/> + <xsd:element name="foo34" type="xsd:normalizedString"/> + <xsd:element name="foo35" type="xsd:NOTATION"/> + <xsd:element name="foo36" type="xsd:positiveInteger"/> + <xsd:element name="foo37" type="xsd:QName"/> + <xsd:element name="foo38" type="xsd:short"/> + <xsd:element name="foo39" type="xsd:string"/> + <xsd:element name="foo40" type="xsd:time"/> + <xsd:element name="foo41" type="xsd:token"/> + <xsd:element name="foo42" type="xsd:unsignedByte"/> + <xsd:element name="foo43" type="xsd:unsignedInt"/> + <xsd:element name="foo44" type="xsd:unsignedLong"/> + <xsd:element name="foo45" type="xsd:unsignedShort"/> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/shallowquote.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/shallowquote.xml new file mode 100644 index 0000000000..a56f2fe2b7 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/shallowquote.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="ASCII"?> +<simple:stockQuote xmlns:simple="http://www.example.com/simple"> + <symbol>fbnt</symbol> + <companyName>FlyByNightTechnology</companyName> + <price>1000.0</price> + <open1>1000.0</open1> + <high>1000.0</high> + <low>1000.0</low> + <volume>1000.0</volume> + <change1>1000.0</change1> +</simple:stockQuote>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/simple.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/simple.xsd new file mode 100644 index 0000000000..46a2b1f4df --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/simple.xsd @@ -0,0 +1,41 @@ +<?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 + targetNamespace="http://www.example.com/simple" + xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns:simple="http://www.example.com/simple"> + + <xsd:element name="stockQuote" type="simple:Quote"/> + + <xsd:complexType name="Quote"> + <xsd:sequence> + <xsd:element name="symbol" type="xsd:string"/> + <xsd:element name="companyName" type="xsd:string"/> + <xsd:element name="price" type="xsd:decimal"/> + <xsd:element name="open1" type="xsd:decimal"/> + <xsd:element name="high" type="xsd:decimal"/> + <xsd:element name="low" type="xsd:decimal"/> + <xsd:element name="volume" type="xsd:double"/> + <xsd:element name="change1" type="xsd:double"/> + <xsd:element name="quotes" type="simple:Quote" minOccurs="0" maxOccurs="unbounded"/> + </xsd:sequence> + </xsd:complexType> + +</xsd:schema> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/simplechangesummary.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/simplechangesummary.xml new file mode 100644 index 0000000000..1a34e0bf80 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/simplechangesummary.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="ASCII"?> +<sdo:datagraph xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sdo="commonj.sdo" + xmlns:sdo_1="http://www.apache.org/tuscany/2005/SDO" xmlns:simple="http://www.example.com/simple"> + <changeSummary xmlns="" + logging="false"> + <objectChanges key="#//@eRootObject"> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="symbol" set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="companyName" set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="price" set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="open1" set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="high" set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="low" set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="volume" dataValue="0.0" + set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="change1" dataValue="0.0" + set="false"/> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="quotes" set="false"/> + </objectChanges> + <objectChanges key="#//@eRootObject/@quotes.0"> + <value xsi:type="sdo_1:ChangeSummarySetting" featureName="price" set="false"/> + </objectChanges> + </changeSummary> + <simple:Quote> + <symbol>fbnt</symbol> + <companyName>FlyByNightTechnology</companyName> + <price>1000.0</price> + <open1>1000.0</open1> + <high>1000.0</high> + <low>1000.0</low> + <volume>1000.0</volume> + <change1>1000.0</change1> + <quotes> + <price>2000.0</price> + </quotes> + </simple:Quote> +</sdo:datagraph> diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/xpath.xml b/branches/sdo-java-M2/sdo/impl/src/test/resources/xpath.xml new file mode 100644 index 0000000000..3b3e2ffbb4 --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/xpath.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="ASCII"?> +<xpath:drive xmlns:xpath="http://www.example.com/xpath" id="0"> + <Folder creation_date="1999-10-20" creator="Hasan" type="FolderType"> + <FolderName>Folder00000000000</FolderName> + <description>marries inflamed apprehended beseeming bustle</description> + <SecurityObject name="secure1"> + <Allows> + <Allow> + <User>Brian</User> + <Permissions>rw</Permissions> + </Allow> + <Allow> + <User>Fuhwei</User> + <Permissions>r</Permissions> + </Allow> + </Allows> + <Denies> + <Deny> + <User>Hasan</User> + </Deny> + <Deny> + <User>Frank</User> + </Deny> + </Denies> + </SecurityObject> + </Folder> + <Folder creation_date="2000-03-23" creator="Kapil" type="FileType"> + <FolderName>Folder00000000011</FolderName> + <description>Mumbling Jumblin Pink Panther goofs it up</description> + <SecurityObject name="secure2"> + <Allows> + <Allow> + <User>Imad</User> + <Permissions>x</Permissions> + </Allow> + <Allow> + <User>Robbie</User> + <Permissions>rwx</Permissions> + </Allow> + </Allows> + <Denies> + <Deny> + <User>Yang</User> + </Deny> + <Deny> + <User>Art</User> + </Deny> + </Denies> + </SecurityObject> + </Folder> +</xpath:drive>
\ No newline at end of file diff --git a/branches/sdo-java-M2/sdo/impl/src/test/resources/xpath.xsd b/branches/sdo-java-M2/sdo/impl/src/test/resources/xpath.xsd new file mode 100644 index 0000000000..0b817d425d --- /dev/null +++ b/branches/sdo-java-M2/sdo/impl/src/test/resources/xpath.xsd @@ -0,0 +1,75 @@ +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" + xmlns="http://www.example.com/xpath" targetNamespace="http://www.example.com/xpath"> + <!-- + 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:element name="drive" type="DriveType"/> + + <xsd:complexType name="DriveType"> + <xsd:sequence> + <xsd:element name="Folder" type="FolderType" minOccurs="0" maxOccurs="unbounded"/> + </xsd:sequence> + <xsd:attribute name="id" type="xsd:int"/> + </xsd:complexType> + + <xsd:complexType name="FolderType"> + <xsd:sequence> + <xsd:element name="FolderName" type="xsd:string"/> + <xsd:element name="description" type="xsd:string"/> + <xsd:element name="SecurityObject" type="SecurityObjectType"/> + </xsd:sequence> + <xsd:attribute name="creation_date" type="xsd:date" minOccurs="0"/> + <xsd:attribute name="creator" type="xsd:string" minOccurs="0"/> + <xsd:attribute name="type" type="xsd:string" minOccurs="0"/> + + </xsd:complexType> + + <xsd:complexType name="AllowsObjectType"> + <xsd:sequence> + <xsd:element name="Allow" minOccurs="0" maxOccurs="unbounded"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="User" type="xsd:string"/> + <xsd:element name="Permissions" type="xsd:string"/> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + </xsd:complexType> + + <xsd:complexType name="DeniesObjectType"> + <xsd:sequence> + <xsd:element name="Deny" minOccurs="0" maxOccurs="unbounded"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="User" type="xsd:string"/> + </xsd:sequence> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + </xsd:complexType> + + <xsd:complexType name="SecurityObjectType"> + <xsd:sequence> + <xsd:element name="Allows" type="AllowsObjectType"/> + <xsd:element name="Denies" type="DeniesObjectType"/> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string"/> + </xsd:complexType> + +</xsd:schema> |