Skip to content

Commit

Permalink
8264454: Jaxp unit test from open jdk needs to be improved
Browse files Browse the repository at this point in the history
Reviewed-by: joehw
  • Loading branch information
mahendrachhipa authored and JoeWang-Java committed Apr 8, 2021
1 parent 5bd6c74 commit 308f679
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 686 deletions.
40 changes: 14 additions & 26 deletions test/jaxp/javax/xml/jaxp/unittest/common/Bug6350682.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,12 +23,10 @@

package common;

import static jaxp.library.JAXPTestUtilities.runWithAllPerm;

import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;

import static jaxp.library.JAXPTestUtilities.runWithAllPerm;
import org.testng.Assert;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
Expand All @@ -46,32 +44,22 @@ public class Bug6350682 {

@Test
public void testSAXParserFactory() {
try {
runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(null));
if (Bug6350682.class.getClassLoader() == null)
System.out.println("this class loader is NULL");
else
System.out.println("this class loader is NOT NULL");
SAXParserFactory factory = SAXParserFactory.newInstance();
Assert.assertTrue(factory != null, "Failed to get an instance of a SAXParserFactory");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
// This test run in othervm so change in environment need not to be recovered at the end of test.
runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(null));
if (Bug6350682.class.getClassLoader() == null) {
System.out.println("this class loader is NULL");
} else {
System.out.println("this class loader is NOT NULL");
}
SAXParserFactory factory = SAXParserFactory.newInstance();
Assert.assertNotNull(factory, "Failed to get an instance of a SAXParserFactory");
}

@Test
public void testTransformerFactory() {
try {
runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(null));
TransformerFactory factory = TransformerFactory.newInstance();
Assert.assertTrue(factory != null, "Failed to get an instance of a TransformerFactory");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
} catch (TransformerFactoryConfigurationError error) {
error.printStackTrace();
Assert.fail(error.toString());
}
// This test run in othervm so change in environment need not to be recovered at the end of test.
runWithAllPerm(() -> Thread.currentThread().setContextClassLoader(null));
TransformerFactory factory = TransformerFactory.newInstance();
Assert.assertNotNull(factory, "Failed to get an instance of a TransformerFactory");
}
}
18 changes: 10 additions & 8 deletions test/jaxp/javax/xml/jaxp/unittest/common/Bug6723276Test.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -23,14 +23,15 @@

package common;

import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.Assert;
import java.net.URL;
import java.net.URLClassLoader;

import javax.xml.parsers.SAXParserFactory;

import org.testng.Assert;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

/*
* @test
* @bug 6723276
Expand All @@ -41,27 +42,28 @@
*/
@Listeners({jaxp.library.BasePolicy.class})
public class Bug6723276Test {
private static final String ERR_MSG = "org.apache.xerces.jaxp.SAXParserFactoryImpl not found";

@Test
public void test1() {
public void testWithDefaultContextClassLoader() {
try {
SAXParserFactory.newInstance();
} catch (Exception e) {
if (e.getMessage().indexOf("org.apache.xerces.jaxp.SAXParserFactoryImpl not found") > 0) {
if (e.getMessage().contains(ERR_MSG)) {
Assert.fail(e.getMessage());
}
}
}

@Test
public void test2() {
public void testWithGivenURLContextClassLoader() {
try {
System.out.println(Thread.currentThread().getContextClassLoader());
System.out.println(ClassLoader.getSystemClassLoader().getParent());
Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0], ClassLoader.getSystemClassLoader().getParent()));
SAXParserFactory.newInstance();
} catch (Exception e) {
if (e.getMessage().indexOf("org.apache.xerces.jaxp.SAXParserFactoryImpl not found") > 0) {
if (e.getMessage().contains(ERR_MSG)) {
Assert.fail(e.getMessage());
}
}
Expand Down
10 changes: 0 additions & 10 deletions test/jaxp/javax/xml/jaxp/unittest/common/Bug6941169.xml

This file was deleted.

11 changes: 0 additions & 11 deletions test/jaxp/javax/xml/jaxp/unittest/common/Bug6941169.xsd

This file was deleted.

1 comment on commit 308f679

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.