Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/bind/marshal/8036981/Test.java
38860 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test Test.java25* @bug 803698126* @summary JAXB not preserving formatting during unmarshalling/marshalling27* @compile Good.java Main.java ObjectFactory.java Root.java28* @run main/othervm Test29*/3031import javax.xml.bind.JAXBContext;32import javax.xml.bind.Marshaller;33import javax.xml.bind.Unmarshaller;34import java.io.File;35import java.io.StringWriter;3637/**38* Test for marshalling and unmarshalling mixed and unmixed content39*/40public class Test {4142private static final String EXPECTED = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><main><Root>\n" +43" <SomeTag>\n" +44" <AChildTag>\n" +45" <AnotherChildTag/>\n" +46" <AnotherChildTag/>\n" +47" </AChildTag>\n" +48" </SomeTag>\n" +49" </Root><Good><VeryGood><TheBest><MegaSuper/><MegaSuper/>\n" +50" </TheBest>\n" +51" </VeryGood></Good></main>";5253public static void main(String[] args) throws Exception {54JAXBContext jc = JAXBContext.newInstance("testjaxbcontext");55Unmarshaller u = jc.createUnmarshaller();56Object result = u.unmarshal(new File(System.getProperty("test.src", ".") + "/test.xml"));57StringWriter sw = new StringWriter();58Marshaller m = jc.createMarshaller();59m.marshal(result, sw);60System.out.println("Expected:" + EXPECTED);61System.out.println("Observed:" + sw.toString());62if (!EXPECTED.equals(sw.toString())) {63throw new Exception("Unmarshal/Marshal generates different content");64}65}66}676869