Search in sources :

Example 11 with DefaultSchemaLocationResolver

use of org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver in project eclipselink by eclipse-ee4j.

the class XSDHelperDefineAndGenerateTestCases method testDefineAndGenerate.

public void testDefineAndGenerate() throws Exception {
    InputStream is = getSchemaInputStream(getSchemaToDefine());
    List types = xsdHelper.define(is, getSchemaLocation());
    compareGeneratedTypes(getControlTypes(), types);
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(getMap());
    String generatedSchema = ((SDOXSDHelper) xsdHelper).generate(getTypesToGenerateFrom(), resolver);
    String controlSchema = getSchema(getControlGeneratedFileName());
    log("EXPECTED: \n" + controlSchema);
    log("ACTUAL: \n" + generatedSchema);
    StringReader reader = new StringReader(generatedSchema);
    InputSource inputSource = new InputSource(reader);
    Document generatedSchemaDoc = parser.parse(inputSource);
    reader.close();
    assertSchemaIdentical(getDocument(getControlGeneratedFileName()), generatedSchemaDoc);
}
Also used : InputSource(org.xml.sax.InputSource) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) InputStream(java.io.InputStream) StringReader(java.io.StringReader) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) List(java.util.List) Document(org.w3c.dom.Document)

Example 12 with DefaultSchemaLocationResolver

use of org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver in project eclipselink by eclipse-ee4j.

the class ImportBug6311853TestCases method testGenerateSchemaRoundTrip.

public void testGenerateSchemaRoundTrip() throws Exception {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(getMap());
    FileInputStream is = new FileInputStream(getControlFileName());
    List types = xsdHelper.define(is, FILE_PROTOCOL + USER_DIR + "/org/eclipse/persistence/testing/sdo/helper/xsdhelper/generate/");
    ArrayList firstType = new ArrayList(1);
    firstType.add(typeHelper.getType("my.uri2", "Person"));
    String generatedSchema = ((SDOXSDHelper) xsdHelper).generate(firstType, resolver);
    String controlSchema = getSchema(getControlFileName());
    log("EXPECTED: \n" + controlSchema);
    log("ACTUAL: \n" + generatedSchema);
    StringReader reader = new StringReader(generatedSchema);
    InputSource inputSource = new InputSource(reader);
    Document generatedSchemaDoc = parser.parse(inputSource);
    reader.close();
    assertSchemaIdentical(getDocument(getControlFileName()), generatedSchemaDoc);
}
Also used : InputSource(org.xml.sax.InputSource) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream)

Example 13 with DefaultSchemaLocationResolver

use of org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver in project eclipselink by eclipse-ee4j.

the class PurchaseOrderComplexGenerateTestCases method testGenerateSchemaRoundTrip.

public void testGenerateSchemaRoundTrip() throws Exception {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(getMap());
    List types = defineTypesFromSchema();
    String generatedSchema = ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    String controlSchema = getSchema(getControlFileNameDifferentOrder());
    log("EXPECTED: \n" + controlSchema);
    log("ACTUAL: \n" + generatedSchema);
    StringReader reader = new StringReader(generatedSchema);
    InputSource inputSource = new InputSource(reader);
    Document generatedSchemaDoc = parser.parse(inputSource);
    reader.close();
    assertSchemaIdentical(getDocument(getControlFileNameDifferentOrder()), generatedSchemaDoc);
}
Also used : InputSource(org.xml.sax.InputSource) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) StringReader(java.io.StringReader) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.w3c.dom.Document)

Example 14 with DefaultSchemaLocationResolver

use of org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver in project eclipselink by eclipse-ee4j.

the class SDODataGraphDataObjectBackPointerTest method testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithCS.

// This function will exercise the updateChangeSummaryAndDataGraph() function on SDODataObject.updateContainment()
public void testSetDOFromOtherDataGraphWithMixedContainmentNonContainmentWithoutCStoDGwithCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // Create target
    DataObject aDataObjectTarget = createRootObject(types);
    DataGraph aDataGraphTarget = dataGraph;
    aDataGraphTarget.createRootObject(aDataObjectTarget.getType());
    DataObject targetRoot = aDataGraphTarget.getRootObject();
    // Check it
    assertNotNull(targetRoot);
    assertEquals(targetRoot.getType(), aDataGraphTarget.getType(URINAME, COMPANY_TYPENAME));
    ListWrapper pOrdersTarget = (ListWrapper) targetRoot.getList(PO_PATH);
    int poSize = pOrdersTarget.size();
    assertEquals(0, poSize);
    // Add a porder (null DG source)
    // Create source
    DataObject aDataObjectSource = createRootObject(types);
    DataGraph aDataGraphSource = new SDODataGraph(aHelperContext);
    aDataGraphSource.createRootObject(aDataObjectSource.getType());
    DataObject sourceRoot = aDataGraphSource.getRootObject();
    // Check it
    assertNotNull(sourceRoot);
    assertEquals(sourceRoot.getType(), aDataGraphSource.getType(URINAME, COMPANY_TYPENAME));
    ListWrapper pOrdersSource = (ListWrapper) aDataObjectSource.getList(PO_PATH);
    int poSizeSource = pOrdersSource.size();
    assertEquals(1, poSizeSource);
    // Get source DO
    DataObject sourcePO = (DataObject) pOrdersSource.get(0);
    // DataGraph should be null before set
    assertNull(sourcePO.getDataGraph());
    // Move the root object from one null data graph to the other
    pOrdersTarget.add(sourcePO);
    // DataGraph should be not be null before set
    assertNotNull(sourcePO.getDataGraph());
    // Target dataGraph should be set on all children
    assertEquals(aDataGraphTarget, sourcePO.getDataGraph());
    DataObject copyPOshipTo = (DataObject) sourcePO.get("shipTo");
    DataObject copyPObillTo = (DataObject) sourcePO.get("billTo");
    DataObject copyPOitem1 = (DataObject) sourcePO.get("item[1]");
    DataObject copyPOitem2 = (DataObject) sourcePO.get("item[2]");
    // Check dataGraph back pointers recursively (containment only)
    List<DataObject> copyPreOrderList = preOrderTraversalDataObjectList(sourcePO);
    assertNotNull(copyPreOrderList);
    assertEquals(5, copyPreOrderList.size());
    copyPreOrderList.contains(copyPOshipTo);
    copyPreOrderList.contains(copyPObillTo);
    copyPreOrderList.contains(copyPOitem1);
    copyPreOrderList.contains(copyPOitem2);
    assertNotNull(copyPOshipTo.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOshipTo.getDataGraph());
    assertNotNull(copyPObillTo.getDataGraph());
    assertEquals(aDataGraphTarget, copyPObillTo.getDataGraph());
    // item property is unidirectional or containment=false - still in the dataGraph in this case
    assertNotNull(copyPOitem1.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOitem1.getDataGraph());
    assertNotNull(copyPOitem2.getDataGraph());
    assertEquals(aDataGraphTarget, copyPOitem2.getDataGraph());
}
Also used : QName(javax.xml.namespace.QName) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) Type(commonj.sdo.Type) DataGraph(commonj.sdo.DataGraph) SDODataGraph(org.eclipse.persistence.sdo.SDODataGraph) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) SDODataGraph(org.eclipse.persistence.sdo.SDODataGraph)

Example 15 with DefaultSchemaLocationResolver

use of org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver in project eclipselink by eclipse-ee4j.

the class SDODataGraphDataObjectBackPointerTest method testDetachNonContainmentDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS.

public void testDetachNonContainmentDOwithMixedContainmentNonContainmentWithoutCStoDGwithCS() {
    DefaultSchemaLocationResolver resolver = new DefaultSchemaLocationResolver(new HashMap<QName, String>());
    registerTypes();
    List<Type> types = getTypesToGenerateFrom();
    ((SDOXSDHelper) xsdHelper).generate(types, resolver);
    // log(generatedSchema);
    // aDataObject.getType());
    dataGraph.createRootObject(URINAME, COMPANY_TYPENAME);
    DataObject aWrappedDO = dataGraph.getRootObject();
    assertNotNull(aWrappedDO);
    // TODO
    assertEquals(aWrappedDO.getType(), dataGraph.getType(URINAME, COMPANY_TYPENAME));
    DataObject dgDO = populateRootDataGraphDataObject(dataGraph.getRootObject(), types);
    ListWrapper pOrders = (ListWrapper) dgDO.getList(PO_PATH);
    int poSize = pOrders.size();
    assertEquals(1, poSize);
    // Detach DO
    DataObject porder1DO = (DataObject) pOrders.get(0);
    int porder1ItemsSize = ((ListWrapper) porder1DO.get("item")).size();
    DataObject ncItem1DO = (DataObject) (porder1DO).get("item[1]");
    DataObject detachedDO = ncItem1DO;
    ncItem1DO.detach();
    ListWrapper pOrdersDGList = (ListWrapper) dgDO.getList(PO_PATH);
    int poSizeDG = pOrdersDGList.size();
    assertEquals(porder1ItemsSize - 1, poSizeDG);
    assertEquals(null, detachedDO.getDataGraph());
    // Remaining item
    DataObject copyPOitem2 = (DataObject) porder1DO.get("item[1]");
    /**
     * item property is unidirectional or containment=false - therefore not in the dataGraph.
     * However, if the item also has a containment=true reference to itself then it does reference the dataGraph
     */
    assertNull(ncItem1DO.getDataGraph());
    assertNotNull(copyPOitem2);
    assertNull(copyPOitem2.getDataGraph());
    // Check that the CS is not set on all nodes including non-containment ones
    assertNull(ncItem1DO.getChangeSummary());
}
Also used : Type(commonj.sdo.Type) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) DefaultSchemaLocationResolver(org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver) QName(javax.xml.namespace.QName) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper)

Aggregations

DefaultSchemaLocationResolver (org.eclipse.persistence.sdo.helper.DefaultSchemaLocationResolver)19 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)19 Type (commonj.sdo.Type)11 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)11 DataObject (commonj.sdo.DataObject)7 StringReader (java.io.StringReader)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 QName (javax.xml.namespace.QName)7 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)7 Document (org.w3c.dom.Document)7 InputSource (org.xml.sax.InputSource)7 SDOType (org.eclipse.persistence.sdo.SDOType)4 InputStream (java.io.InputStream)3 DataGraph (commonj.sdo.DataGraph)2 FileInputStream (java.io.FileInputStream)2 SDODataGraph (org.eclipse.persistence.sdo.SDODataGraph)2 Property (commonj.sdo.Property)1 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)1