Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/bind/marshal/8134111/UnmarshalTest.java
38861 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 8134111
27
* @summary test that elements without namespace is ignored by unmarshaller
28
* when elementFormDefault is set to QUALIFIED.
29
* @compile testTypes/package-info.java testTypes/Root.java
30
* testTypes/WhenType.java testTypes/ObjectFactory.java
31
* @run testng/othervm UnmarshalTest
32
*/
33
34
import java.io.StringReader;
35
import javax.xml.bind.JAXBContext;
36
import javax.xml.bind.Unmarshaller;
37
import org.testng.annotations.Test;
38
import static org.testng.Assert.assertNull;
39
import org.xml.sax.InputSource;
40
import testTypes.Root;
41
42
public class UnmarshalTest {
43
44
@Test
45
public void unmarshalUnexpectedNsTest() throws Exception {
46
JAXBContext context;
47
Unmarshaller unm;
48
// Create JAXB context from testTypes package
49
context = JAXBContext.newInstance("testTypes");
50
// Create unmarshaller from JAXB context
51
unm = context.createUnmarshaller();
52
// Unmarshall xml document with unqualified dtime element
53
Root r = (Root) unm.unmarshal(new InputSource(new StringReader(DOC)));
54
// Print dtime value and check if it is null
55
System.out.println("dtime is:"+r.getWhen().getDtime());
56
assertNull(r.getWhen().getDtime());
57
}
58
59
//Xml document to unmarshall with unqualified dtime element
60
private final String DOC =
61
"<tns:root xmlns:tns=\"http://www.example.org/testNamespace/\">" +
62
"<tns:when>" +
63
"<dtime>2015-06-24T13:16:14.933-04:00</dtime>" +
64
"</tns:when>" +
65
"</tns:root>";
66
}
67
68