/******************************************************************************* * Copyright (c) 1998, 2015 Oracle and/or its affiliates. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 * which accompanies this distribution. * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html * and the Eclipse Distribution License is available at * http://www.eclipse.org/org/documents/edl-v10.php. * * Contributors: * Oracle - initial API and implementation from Oracle TopLink ******************************************************************************/ package org.eclipse.persistence.testing.sdo.helper.xmlhelper.loadandsave; import java.io.StringReader; import java.util.ArrayList; import java.util.List; import org.w3c.dom.Document; import org.xml.sax.InputSource; import commonj.sdo.DataObject; import commonj.sdo.Type; import commonj.sdo.helper.XMLDocument; import junit.textui.TestRunner; import org.eclipse.persistence.sdo.SDOConstants; import org.eclipse.persistence.sdo.SDOType; public class LoadAndSaveXMLEncodingAndVersionTestCases extends LoadAndSaveTestCases { static String VERSION = "1.0"; private static String ENCODING = "windows-1252"; public LoadAndSaveXMLEncodingAndVersionTestCases(String name) { super(name); } protected String getSchemaName() { return "./org/eclipse/persistence/testing/sdo/helper/xmlhelper/Customer.xsd"; } protected String getControlFileName() { return ("./org/eclipse/persistence/testing/sdo/helper/xmlhelper/simpleElementEncoding.xml"); } protected String getNoSchemaControlFileName() { return ("./org/eclipse/persistence/testing/sdo/helper/xmlhelper/simpleElementEncodingNoSchema.xml"); } protected String getControlRootURI() { return NON_DEFAULT_URI; } // Override package generation based on the JAXB 2.0 algorithm in SDOUtil.java protected List<String> getPackages() { List<String> packages = new ArrayList<String>(); packages.add(NON_DEFAULT_JAVA_PACKAGE_DIR); return packages; } protected String getControlDataObjectFileName() { return ("./org/eclipse/persistence/testing/sdo/helper/xmlhelper/simpleElement.xml"); } protected String getControlRootName() { return "customer"; } protected String getRootInterfaceName() { return "CustomerType"; } public void registerTypes() { Type stringType = typeHelper.getType("commonj.sdo", "String"); SDOType propertyType = (SDOType) typeHelper.getType(SDOConstants.SDO_URL, SDOConstants.PROPERTY); // create a new Type for Customers DataObject customerType = dataFactory.create("commonj.sdo", "Type"); customerType.set("uri", getControlRootURI()); customerType.set("name", "customer"); // create a first name property addProperty(customerType, "firstName", stringType, false, false, true); // create a last name property addProperty(customerType, "lastName", stringType, false, false, true); // now define the Customer type so that customers can be made Type customerSDOType = typeHelper.define(customerType); DataObject propDO = dataFactory.create(propertyType); propDO.set("name", getControlRootName()); propDO.set("type", customerSDOType); typeHelper.defineOpenContentProperty(getControlRootURI(), propDO); } public static void main(String[] args) { String[] arguments = { "-c", "org.eclipse.persistence.testing.sdo.helper.xmlhelper.loadandsave.LoadAndSaveXMLEncodingAndVersionTestCases" }; TestRunner.main(arguments); } protected void compareXML(String controlFileName, String testString, boolean compareNodes) throws Exception { String controlString = getControlString(controlFileName); log("Expected:" + controlString); log("Actual :" + testString); assertEquals(removeWhiteSpaceFromString(controlString), removeWhiteSpaceFromString(testString)); } protected void verifyAfterLoad(XMLDocument document) { //Only check version, not encoding since some parsers don't support encoding assertTrue(document.getXMLVersion().equals(LoadAndSaveXMLEncodingAndVersionTestCases.VERSION)); } }