Skip to content
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

JDK-8264454 : Jaxp unit test from open jdk needs to be improved #3274

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter
Filter file types
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -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
@@ -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;
@@ -46,32 +44,22 @@

@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));

This comment has been minimized.

@JoeWang-Java

JoeWang-Java Mar 31, 2021
Member

To address item 4 (the environment is changed), a note, something like "this test runs in othervm" can be added here or to the summary.

This comment has been minimized.

@mahendrachhipa

mahendrachhipa Apr 6, 2021
Author Contributor

Added the comment

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");
}
}
@@ -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
@@ -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
@@ -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";

This comment has been minimized.

@JoeWang-Java

JoeWang-Java Mar 31, 2021
Member

This test currently doesn't verify anything since there's no org.apache.xerces.jaxp.SAXParserFactoryImpl on the classpath. Post JDK 9, such test would require creating a dummy module.


@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());
}
}

This file was deleted.

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.