Skip to content

Commit

Permalink
pluggability test fix.
Browse files Browse the repository at this point in the history
Signed-off-by: Gurunandan Rao <[email protected]>
  • Loading branch information
gurunrao committed Nov 14, 2023
1 parent d2b37cd commit 16e3795
Show file tree
Hide file tree
Showing 198 changed files with 1,728 additions and 1,678 deletions.
18 changes: 17 additions & 1 deletion glassfish-runner/jpa-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@
<target>
<sql autocommit="true" classpath="${jdbc.driver.classes}" delimiter="${db.delimiter}" driver="${jakarta.persistence.jdbc.driver}" onerror="continue" password="${jakarta.persistence.jdbc.password}" url="${jakarta.persistence.jdbc.url}" userid="${jakarta.persistence.jdbc.user}">
<transaction src="${project.build.directory}/../sql/${jdbc.db}/${jdbc.db}.ddl.persistence.sql"/>
</sql>
</target>
</configuration>
</execution>
<execution>
<id>initdb-2</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<sql autocommit="true" classpath="${jdbc.driver.classes}" delimiter="${db.delimiter}" driver="${jakarta.persistence.jdbc.driver}" onerror="continue" password="${jakarta.persistence.jdbc.password}" url="${jakarta.persistence.jdbc.url}" userid="${jakarta.persistence.jdbc.user}">
<transaction src="${project.build.directory}/../sql/${jdbc.db}/${jdbc.db}.ddl.persistence.sprocs.sql"/>
</sql>
</target>
Expand Down Expand Up @@ -243,8 +256,11 @@
</goals>
<configuration>
<includes>
<include>**/jpa/core/**/*.*</include>
<include>**/*enerator*/**/*.*</include>
</includes>
<excludes>
<exclude>**/jpa/ee/**/*.*</exclude>
</excludes>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.jpa-api.jar</additionalClasspathElement>
<additionalClasspathElement>${project.build.directory}/${glassfish.toplevel.dir}/javadb/lib/derbyshared.jar</additionalClasspathElement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,6 @@ CREATE TABLE EMPLOYEE_EMBEDED_ADDRESS (ID INTEGER NOT NULL, FIRSTNAME VARCHAR(25
CREATE TABLE COLTAB_EMP_EMBEDED_ADDRESS (ADDRESS_LOCATION VARCHAR(255), STREET VARCHAR(255), STATE VARCHAR(255), ZIP VARCHAR(255), CITY VARCHAR(255), ID VARCHAR(255), EMPEMBADDRID INTEGER);
ALTER TABLE COLTAB_EMP_EMBEDED_ADDRESS ADD CONSTRAINT FK_EMPEMBADDRID FOREIGN KEY (EMPEMBADDRID) REFERENCES EMPLOYEE_EMBEDED_ADDRESS (ID) ;


DROP SEQUENCE SEQGENERATOR RESTRICT;
CREATE SEQUENCE SEQGENERATOR AS INT START WITH 10;

Expand Down
1 change: 1 addition & 0 deletions glassfish-runner/websocket-tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
</artifactItems>
</configuration>
</execution>

</executions>
</plugin>
<plugin>
Expand Down
38 changes: 32 additions & 6 deletions jpa/src/main/java/com/sun/ts/tests/jpa/common/PMClientBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.lang.System.Logger;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.charset.StandardCharsets;
import java.sql.Date;
import java.sql.Timestamp;
import java.text.ParseException;
Expand All @@ -42,6 +44,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
Expand Down Expand Up @@ -1087,10 +1090,12 @@ public String convertToURI(String path) {
public static final String STANDALONE_PERSISTENCE_XML = "com/sun/ts/tests/jpa/common/template/standalone/persistence.xml";
public static final String PERSISTENCE_ELEMENT_TAG = "persistence-unit";
public static final String CLASS_ELEMENT_TAG = "class";
public static final String MAPPING_ELEMENT_TAG = "mapping-file";
public static final String TEMP_DIR = System.getProperty("java.io.tmpdir");

public static final String PERSISTENCE_XML = "persistence.xml";

public static final String ORM_XML = "orm.xml";
public static final String MAPPING_FILE_XML = "myMappingFile.xml";

public static JavaArchive createDeploymentJar(String jarName, String packageName, String[] classes,
String persistenceFile, String[] xmlFiles) throws Exception {

Expand All @@ -1117,6 +1122,17 @@ public static JavaArchive createDeploymentJar(String jarName, String packageName
presistenceElement.item(i).appendChild(classTag);
}
}

for (int j = 0; j < xmlFiles.length; j++) {
if (!ORM_XML.equalsIgnoreCase(xmlFiles[j])) {
for (int i = 0; i < presistenceElement.getLength(); i++) {
Element mappingTag = document.createElement(MAPPING_ELEMENT_TAG);
Text mappingNode = document.createTextNode(xmlFiles[j]);
mappingTag.appendChild(mappingNode);
presistenceElement.item(i).appendChild(mappingTag);
}
}
}
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(document), new StreamResult(writer));
archive.addAsManifestResource(new StringAsset(writer.getBuffer().toString()), PERSISTENCE_XML);
Expand All @@ -1126,9 +1142,13 @@ public static JavaArchive createDeploymentJar(String jarName, String packageName
archive.addAsManifestResource(new ByteArrayAsset(xmlFileStream), PERSISTENCE_XML);
}
for (int i = 0; i < xmlFiles.length; i++) {
InputStream xmlFileStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(packageName.replace('.', '/') + "/" + xmlFiles[i]);
archive.addAsManifestResource(new ByteArrayAsset(xmlFileStream), xmlFiles[i]);
if (ORM_XML.equalsIgnoreCase(xmlFiles[i])) {
InputStream xmlFileStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(packageName.replace('.', '/') + "/" + xmlFiles[i]);
archive.addAsManifestResource(new ByteArrayAsset(xmlFileStream), xmlFiles[i]);
} else {
archive.addAsResource(packageName.replace('.', '/') + "/" + xmlFiles[i], xmlFiles[i]);
}
}

archive.as(ZipExporter.class).exportTo(new File(TEMP_DIR + File.separator + jarName), true);
Expand All @@ -1154,10 +1174,16 @@ public static JavaArchive createDeploymentJar(String jarName, String packageName

}

public static void removeDeploymentJar() throws Exception {
public static void removeTestJarFromCP() throws Exception {
URLClassLoader currentThreadClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(currentThreadClassLoader.getParent());
currentThreadClassLoader.close();
}

public static String toString(InputStream inStream) throws IOException {
try (BufferedReader bufReader = new BufferedReader(new InputStreamReader(inStream, StandardCharsets.UTF_8))) {
return bufReader.lines().collect(Collectors.joining(System.lineSeparator()));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void cleanupEmployeeData() throws Exception {
logger.log(Logger.Level.TRACE, "Cleanup data");
removeTestData();
cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

public List<List> getResultSetsFromStoredProcedure(StoredProcedureQuery spq) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public static JavaArchive createDeployment() throws Exception {

String pkgNameWithoutSuffix = Client1IT.class.getPackageName();
String pkgName = pkgNameWithoutSuffix + ".";
String[] xmlFiles = { "myMappingFile.xml" };
String[] classes = { pkgName + "Employee",
pkgName + "Employee2", pkgName + "EmployeeMappedSC" };
String[] xmlFiles = { MAPPING_FILE_XML };
String[] classes = { pkgName + "Employee", pkgName + "Employee2", pkgName + "EmployeeMappedSC" };
return createDeploymentJar("jpa_core_types_StoredProcedureQuery1.jar", pkgNameWithoutSuffix, classes, xmlFiles);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ public static JavaArchive createDeployment() throws Exception {

String pkgNameWithoutSuffix = Client2IT.class.getPackageName();
String pkgName = pkgNameWithoutSuffix + ".";
String[] xmlFiles = { "myMappingFile.xml" };
String[] classes = { pkgName + "Employee", pkgName + "Employee2",
pkgName + "EmployeeMappedSC" };
String[] xmlFiles = { MAPPING_FILE_XML };
String[] classes = { pkgName + "Employee", pkgName + "Employee2", pkgName + "EmployeeMappedSC" };
return createDeploymentJar("jpa_core_types_StoredProcedureQuery2.jar", pkgNameWithoutSuffix, classes, xmlFiles);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

protected void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Client1IT() {
public JavaArchive createDeployment() throws Exception {
String pkgNameWithoutSuffix = Client1IT.class.getPackageName();
String pkgName = pkgNameWithoutSuffix + ".";
String[] xmlFile = { "myMappingFile.xml" };
String[] xmlFile = { MAPPING_FILE_XML };
String[] classes = { pkgName + "A", pkgName + "Address", pkgName + "Customer", pkgName + "CustomerXML" };

return createDeploymentJar("jpa_core_annotations_elementcollection1.jar", pkgNameWithoutSuffix, classes,
Expand Down Expand Up @@ -163,7 +163,7 @@ public void cleanupA() throws Exception {
removeATestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeATestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Client2IT() {
public JavaArchive createDeployment() throws Exception {
String pkgNameWithoutSuffix = Client1IT.class.getPackageName();
String pkgName = pkgNameWithoutSuffix + ".";
String[] xmlFile = { "myMappingFile.xml" };
String[] xmlFile = { MAPPING_FILE_XML };

String[] classes = { pkgName + "A", pkgName + "Address", pkgName + "Customer", pkgName + "CustomerXML" };

Expand Down Expand Up @@ -194,7 +194,7 @@ public void cleanupCust() throws Exception {
removeCustTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeCustTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

protected void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public void cleanupCust() throws Exception {
removeCustTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void cleanup() throws Exception {
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeDeploymentJar();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Loading

0 comments on commit 16e3795

Please sign in to comment.