-
Notifications
You must be signed in to change notification settings - Fork 604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JAX-WS: JAXB: backup with parent namespace test #30566
Merged
BerksanAtes
merged 3 commits into
OpenLiberty:integration
from
BerksanAtes:JAXB_BackupWithParentNamespace_Test
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
dev/com.ibm.ws.jaxb_fat/fat/src/com/ibm/ws/jaxb/fat/LibertyJAXBSpecTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package com.ibm.ws.jaxb.fat; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.BufferedReader; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.ibm.websphere.simplicity.ShrinkHelper; | ||
|
||
import componenttest.annotation.Server; | ||
import componenttest.annotation.SkipForRepeat; | ||
import componenttest.custom.junit.runner.FATRunner; | ||
import componenttest.topology.impl.LibertyServer; | ||
import componenttest.topology.utils.HttpUtils; | ||
|
||
@RunWith(FATRunner.class) | ||
public class LibertyJAXBSpecTest { | ||
|
||
private static final String APP_NAME = "jaxbSpecApp"; | ||
|
||
@Server("jaxbspec_fat") | ||
public static LibertyServer server; | ||
|
||
private static final int CONN_TIMEOUT = 5; | ||
|
||
@BeforeClass | ||
public static void setUp() throws Exception { | ||
ShrinkHelper.defaultDropinApp(server, APP_NAME, "jaxb.web", "jaxb.xmlnsform.unqualified", "jaxb.xmlnsform.qualified", "jaxb.xmlnsform.servlet"); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDown() throws Exception { | ||
server.stopServer(); | ||
} | ||
|
||
@After | ||
public void afterTest() throws Exception { | ||
server.stopServer(); | ||
} | ||
|
||
/* | ||
* Test com.sun.xml.bind.backupWithParentNamespace which is introduced to JAXB 2.3.9 | ||
* Skipping EE9 and EE10 because they don't use this JAXB version. | ||
* This property doesn't work for them. | ||
*/ | ||
@Test | ||
@SkipForRepeat({ SkipForRepeat.EE9_FEATURES, SkipForRepeat.EE10_FEATURES }) | ||
public void testBackupWithParentNamespaceTrue_Servlet() throws Exception { | ||
Map<String, String> map = server.getJvmOptionsAsMap(); | ||
map.put("-Dcom.sun.xml.bind.backupWithParentNamespace", "true"); | ||
server.setJvmOptions(map); | ||
server.startServer(); | ||
server.waitForStringInLog("CWWKZ0001I:.*" + APP_NAME); | ||
|
||
String testResultString = runTestServlet(); | ||
if (testResultString != null) { | ||
assertTrue("When backupWithParentNamespace property is applied, an element with a prefix from a XmlNsForm.QUALIFIED package should not be null", | ||
testResultString.contains("qpwp:value")); // qpwp: Qualified Person With Prefix | ||
assertTrue("When backupWithParentNamespace property is applied, an element without a prefix from a XmlNsForm.QUALIFIED package should not be null", | ||
testResultString.contains("qpnp:value")); // qpnp: Qualified Person No Prefix | ||
assertTrue("When backupWithParentNamespace property is applied, an element with a prefix from a XmlNsForm.UNQUALIFIED package should be null", | ||
testResultString.contains("upwp:null")); // upwp: Unqualified Person With Prefix | ||
assertTrue("When backupWithParentNamespace property is applied, an element without a prefix from a XmlNsForm.UNQUALIFIED package should not be null", | ||
testResultString.contains("upnp:value")); // upnp: Unqualified Person No Prefix | ||
} | ||
} | ||
|
||
/* | ||
* Tests JAXB specs to see if ElementFormDefault setting is honored | ||
*/ | ||
@Test | ||
public void testBackupWithParentNamespaceFalse() throws Exception { | ||
Map<String, String> map = server.getJvmOptionsAsMap(); | ||
map.clear(); | ||
server.setJvmOptions(map); | ||
server.startServer(); | ||
server.waitForStringInLog("CWWKZ0001I:.*" + APP_NAME); | ||
|
||
String testResultString = runTestServlet(); | ||
if (testResultString != null) { | ||
assertTrue("Violation of JAXB spec, an element with a prefix from a XmlNsForm.QUALIFIED package should not be null", | ||
testResultString.contains("qpwp:value")); // qpwp: Qualified Person With Prefix | ||
assertTrue("Violation of JAXB spec, an element without a prefix from a XmlNsForm.QUALIFIED package should be null", | ||
testResultString.contains("qpnp:null")); // qpnp: Qualified Person No Prefix | ||
assertTrue("Violation of JAXB spec, an element with a prefix from a XmlNsForm.UNQUALIFIED package should be null", | ||
testResultString.contains("upwp:null")); // upwp: Unqualified Person With Prefix | ||
assertTrue("Violation of JAXB spec, an element without a prefix from a XmlNsForm.UNQUALIFIED package should not be null", | ||
testResultString.contains("upnp:value")); // upnp: Unqualified Person No Prefix | ||
} | ||
} | ||
|
||
/* | ||
* Runs the test servlet and return all results in a string with specific keys | ||
*/ | ||
private String runTestServlet() throws Exception { | ||
server.copyFileToLibertyServerRoot("Person.xml"); //Read the XML file to unmarshall | ||
|
||
String servletUrl = new StringBuilder("http://").append(server.getHostname()) | ||
.append(":") | ||
.append(server.getHttpDefaultPort()) | ||
.append("/") | ||
.append(APP_NAME) | ||
.append("/JaxbSpecTest") | ||
.toString(); // Build servlet url | ||
HttpURLConnection con = HttpUtils.getHttpConnection(new URL(servletUrl), HttpURLConnection.HTTP_OK, CONN_TIMEOUT); | ||
BufferedReader br = HttpUtils.getConnectionStream(con); | ||
String result = br.readLine(); | ||
if (result != null && result.contains("XML not found")) { | ||
assertTrue("Person.xml file is not found", false); | ||
result = null; | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<ns:Person xmlns:ns="http://a"> | ||
<ns:firstNameWithPrefix>John</ns:firstNameWithPrefix> | ||
<LastNameWithOutPrefix>Doe</LastNameWithOutPrefix> | ||
</ns:Person> |
1 change: 1 addition & 0 deletions
1
dev/com.ibm.ws.jaxb_fat/publish/servers/jaxbspec_fat/bootstrap.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bootstrap.include=../testports.properties |
9 changes: 9 additions & 0 deletions
9
dev/com.ibm.ws.jaxb_fat/publish/servers/jaxbspec_fat/server.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<server> | ||
<featureManager> | ||
<feature>servlet-3.1</feature> | ||
<feature>componenttest-1.0</feature> | ||
<feature>jaxb-2.2</feature> | ||
</featureManager> | ||
|
||
<include location="../fatTestPorts.xml"/> | ||
</server> |
50 changes: 50 additions & 0 deletions
50
dev/com.ibm.ws.jaxb_fat/test-applications/jaxbApp/src/jaxb/xmlnsform/qualified/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package jaxb.xmlnsform.qualified; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement(name = "Person", namespace = "http://a") | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class Person { | ||
@XmlElement | ||
private String firstNameWithPrefix; | ||
|
||
@XmlElement | ||
private String LastNameWithOutPrefix; | ||
|
||
public String getFirstNameWithPrefix() { | ||
return firstNameWithPrefix; | ||
} | ||
|
||
public void setFirstNameWithPrefix(String firstNameWithPrefix) { | ||
this.firstNameWithPrefix = firstNameWithPrefix; | ||
} | ||
|
||
public String getLastNameWithOutPrefix() { | ||
return LastNameWithOutPrefix; | ||
} | ||
|
||
public void setLastNameWithOutPrefix(String lastNameWithOutPrefix) { | ||
LastNameWithOutPrefix = lastNameWithOutPrefix; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Person{nameWithPrefix='" + firstNameWithPrefix + "', nameWithOutPrefix=" + LastNameWithOutPrefix + '}'; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
....ibm.ws.jaxb_fat/test-applications/jaxbApp/src/jaxb/xmlnsform/qualified/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
@javax.xml.bind.annotation.XmlSchema(namespace = "http://a", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) | ||
package jaxb.xmlnsform.qualified; |
83 changes: 83 additions & 0 deletions
83
...ws.jaxb_fat/test-applications/jaxbApp/src/jaxb/xmlnsform/servlet/JaxbSpecTestServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package jaxb.xmlnsform.servlet; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.xml.bind.JAXBContext; | ||
import javax.xml.bind.Unmarshaller; | ||
|
||
/** | ||
* | ||
*/ | ||
@WebServlet("/JaxbSpecTest") | ||
public class JaxbSpecTestServlet extends HttpServlet { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
doWorker(req, resp); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
doWorker(req, resp); | ||
} | ||
|
||
private void doWorker(HttpServletRequest req, HttpServletResponse resp) { | ||
PrintWriter writer = null; | ||
try { | ||
writer = resp.getWriter(); | ||
File personXml = new File("Person.xml"); | ||
|
||
if (!personXml.exists()) { | ||
writer.write("XML not found"); | ||
return; | ||
} | ||
JAXBContext jaxbContextQualified = JAXBContext.newInstance(jaxb.xmlnsform.qualified.Person.class); | ||
Unmarshaller unmarshallerQualified = jaxbContextQualified.createUnmarshaller(); | ||
jaxb.xmlnsform.qualified.Person qualifiedPerson = (jaxb.xmlnsform.qualified.Person) unmarshallerQualified.unmarshal(personXml); | ||
writeNullStatus(writer, "qpwp", qualifiedPerson.getFirstNameWithPrefix()); // qpwp: Qualified Person With Prefix | ||
writeNullStatus(writer, "qpnp", qualifiedPerson.getLastNameWithOutPrefix()); // qpnp: Qualified Person No Prefix | ||
|
||
JAXBContext jaxbContextUnQualified = JAXBContext.newInstance(jaxb.xmlnsform.unqualified.Person.class); | ||
Unmarshaller unmarshallerUnQualified = jaxbContextUnQualified.createUnmarshaller(); | ||
jaxb.xmlnsform.unqualified.Person unQualifiedPerson = (jaxb.xmlnsform.unqualified.Person) unmarshallerUnQualified.unmarshal(personXml); | ||
writeNullStatus(writer, "upwp", unQualifiedPerson.getFirstNameWithPrefix()); // upwp: Unqualified Person With Prefix | ||
writeNullStatus(writer, "upnp", unQualifiedPerson.getLastNameWithOutPrefix()); // upnp: Unqualified Person No Prefix | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* @param key key to mark which assertion it's related to | ||
* @param value value to test if it's null | ||
* @return | ||
*/ | ||
private void writeNullStatus(PrintWriter writer, String key, String value) { | ||
writer.write(key + (value == null ? ":null |" : ":value |")); | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
dev/com.ibm.ws.jaxb_fat/test-applications/jaxbApp/src/jaxb/xmlnsform/unqualified/Person.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package jaxb.xmlnsform.unqualified; | ||
|
||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlElement; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement(name = "Person", namespace = "http://a") | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class Person { | ||
@XmlElement | ||
private String firstNameWithPrefix; | ||
|
||
@XmlElement | ||
private String LastNameWithOutPrefix; | ||
|
||
public String getFirstNameWithPrefix() { | ||
return firstNameWithPrefix; | ||
} | ||
|
||
public void setFirstNameWithPrefix(String firstNameWithPrefix) { | ||
this.firstNameWithPrefix = firstNameWithPrefix; | ||
} | ||
|
||
public String getLastNameWithOutPrefix() { | ||
return LastNameWithOutPrefix; | ||
} | ||
|
||
public void setLastNameWithOutPrefix(String lastNameWithOutPrefix) { | ||
LastNameWithOutPrefix = lastNameWithOutPrefix; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Person{nameWithPrefix='" + firstNameWithPrefix + "', nameWithOutPrefix=" + LastNameWithOutPrefix + '}'; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...bm.ws.jaxb_fat/test-applications/jaxbApp/src/jaxb/xmlnsform/unqualified/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 IBM Corporation and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
@javax.xml.bind.annotation.XmlSchema(namespace = "http://a") | ||
package jaxb.xmlnsform.unqualified; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright needs to be