From 195774c489a1a671aca514b0afa88332bf9c6ee3 Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 10 Nov 2009 19:20:12 +0000 Subject: Moving SDO tags git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834617 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sdo/test/XMLSaveOptionsTestCase.java | 147 +++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 sdo-java/tags/1.1/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java (limited to 'sdo-java/tags/1.1/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java') diff --git a/sdo-java/tags/1.1/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java b/sdo-java/tags/1.1/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.java new file mode 100644 index 0000000000..27b750b0ff --- /dev/null +++ b/sdo-java/tags/1.1/impl/src/test/java/org/apache/tuscany/sdo/test/XMLSaveOptionsTestCase.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.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.net.URL; +import java.util.HashMap; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamWriter; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.api.SDOHelper; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.apache.tuscany.sdo.api.XMLStreamHelper; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +public class XMLSaveOptionsTestCase extends TestCase { + HelperContext hc; + private XSDHelper xsdHelper; + XMLHelper xmlh; + XMLStreamHelper xmlStreamHelper; + static final String INDENT = " ", MARGIN = " ", LINE_BREAK = "\n"; + String formatted1 = MARGIN+ "" +LINE_BREAK+ + MARGIN+ "" +LINE_BREAK+ + MARGIN+INDENT+ "FBNT" +LINE_BREAK+ + MARGIN+INDENT+ "FlyByNightTechnology" +LINE_BREAK+ + MARGIN+INDENT+ "999.0" +LINE_BREAK+ + MARGIN+INDENT+ "1000.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "1500.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "2500.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "3000.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "4000.0" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "fbnt" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "1000.0" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "2000.02000.99" +LINE_BREAK+ + MARGIN+INDENT+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+INDENT+ "" +LINE_BREAK+ + MARGIN+INDENT+ "" +LINE_BREAK+ + MARGIN+ ""; + + String formatted2 = + //MARGIN+ "" +LINE_BREAK+ + MARGIN+ "" +LINE_BREAK+ + MARGIN+INDENT+"fbnt" +LINE_BREAK+ + MARGIN+INDENT+"FlyByNightTechnology" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+INDENT+"1000.0" +LINE_BREAK+ + MARGIN+"" +LINE_BREAK; + + void define(final String model) throws IOException { + // Populate the meta data for the test model + final URL url = getClass().getResource(model); + xsdHelper.define(url.openStream(), url.toString()); + } + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + //use XMLHelper + public void testSaveXMLDocumentXMLHelper() throws IOException { + final HashMap options = new HashMap(); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK); + hc = SDOUtil.createHelperContext(false,options); + xsdHelper = hc.getXSDHelper(); + xmlh = hc.getXMLHelper(); + + // Populate the meta data for the test (Stock Quote) model + define("/simpleWithChangeSummary.xsd"); + final XMLDocument doc = xmlh.load(getClass().getResource("/simpleWithChangeSummary.xml").openStream()); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + xmlh.save(xmlh.createDocument(doc.getRootObject(), doc.getRootElementURI(), doc.getRootElementName()), baos, null); + assertEquals(formatted1, baos.toString()); + } + + //use XMLStreamHelper + public void testSaveXMLDocumentXMLStreamHelper() throws Exception { + final HashMap options = new HashMap(); + options.put(SDOHelper.XMLOptions.XML_LOAD_SCHEMA, Boolean.FALSE); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_INDENT, INDENT); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_MARGIN, MARGIN); + options.put(org.apache.tuscany.sdo.api.SDOHelper.XMLOptions.XML_SAVE_LINE_BREAK, LINE_BREAK); + final HelperContext hc = SDOUtil.createHelperContext(false, options); + xmlStreamHelper = SDOUtil.createXMLStreamHelper(hc); + + xsdHelper = hc.getXSDHelper(); + define("/simple.xsd"); + + final InputStream inStrm = getClass().getResourceAsStream("/shallowquote.xml"); + final XMLDocument document = hc.getXMLHelper().load(inStrm, null, null); + + final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); + final StringWriter writer = new StringWriter(); + final XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); + + xmlStreamHelper.save(document, streamWriter, null); + streamWriter.flush(); + assertEquals(formatted2, writer.toString()); + } +} -- cgit v1.2.3