Skip to content

Commit

Permalink
code cleanup.
Browse files Browse the repository at this point in the history
Signed-off-by: Gurunandan Rao <[email protected]>
  • Loading branch information
gurunrao committed Nov 15, 2023
1 parent 9c08aa5 commit 997c859
Show file tree
Hide file tree
Showing 30 changed files with 230 additions and 309 deletions.
27 changes: 16 additions & 11 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 @@ -87,6 +87,8 @@ abstract public class PMClientBase implements UseEntityManager, UseEntityManager

transient private boolean inContainer;

private boolean testArtifactDeployed = false;

// The following are properties specific to standalone TCK,
// not used when running tests in JakartaEE environment
transient private EntityManagerFactory emf;
Expand Down Expand Up @@ -1095,9 +1097,9 @@ public String convertToURI(String path) {
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 {

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

JavaArchive archive = ShrinkWrap.create(JavaArchive.class, jarName);

Expand Down Expand Up @@ -1157,27 +1159,30 @@ public static JavaArchive createDeploymentJar(String jarName, String packageName
URLClassLoader urlClassLoader = new URLClassLoader(
new URL[] { new File(TEMP_DIR + File.separator + jarName).toURL() }, currentThreadClassLoader);
Thread.currentThread().setContextClassLoader(urlClassLoader);
testArtifactDeployed = true;

return archive;

}

public static JavaArchive createDeploymentJar(String jarName, String packageName, String[] classes,
String[] xmlFiles) throws Exception {
public JavaArchive createDeploymentJar(String jarName, String packageName, String[] classes, String[] xmlFiles)
throws Exception {
return createDeploymentJar(jarName, packageName, classes, STANDALONE_PERSISTENCE_XML, xmlFiles);
}

public static JavaArchive createDeploymentJar(String jarName, String packageName, String[] classes)
throws Exception {
public JavaArchive createDeploymentJar(String jarName, String packageName, String[] classes) throws Exception {
String xmlFiles[] = {};
return createDeploymentJar(jarName, packageName, classes, STANDALONE_PERSISTENCE_XML, xmlFiles);

}

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

public static String toString(InputStream inStream) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Client1IT extends Client {
public Client1IT() {
}

public static JavaArchive createDeployment() throws Exception {
public JavaArchive createDeployment() throws Exception {

String pkgNameWithoutSuffix = Client1IT.class.getPackageName();
String pkgName = pkgNameWithoutSuffix + ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Client2IT extends Client {
public Client2IT() {
}

public static JavaArchive createDeployment() throws Exception {
public JavaArchive createDeployment() throws Exception {

String pkgNameWithoutSuffix = Client2IT.class.getPackageName();
String pkgName = pkgNameWithoutSuffix + ".";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public void generatorTypeSequenceTest() throws Exception {

public void createDataTypes2Data() {
try {


getEntityTransaction().begin();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ public void setup() throws Exception {
logger.log(Logger.Level.TRACE, "setup");
try {
super.setup();
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
} finally {
createDeployment();
supportSequence = Boolean.valueOf(System.getProperty("db.supports.sequence"));

Expand All @@ -87,6 +83,10 @@ public void setup() throws Exception {
throw new Exception(msg);
}
removeTestData();

} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ public JavaArchive createDeployment() throws Exception {
public void setup() throws Exception {
logger.log(Logger.Level.TRACE, "setup");
try {

super.setup();
createDeployment();
removeTestData();
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
} finally {
createDeployment();
removeTestData();
}
}

Expand Down Expand Up @@ -159,14 +157,11 @@ public void subClassInheritsCacheableTrue() throws Exception {

@AfterEach
public void cleanup() throws Exception {
try {
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
} finally {
removeTestJarFromCP();
}
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ public JavaArchive createDeployment() throws Exception {
public void setup() throws Exception {
logger.log(Logger.Level.TRACE, "setup");
try {

super.setup();

createDeployment();
removeTestData();
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
} finally {
createDeployment();
removeTestData();
}
}

Expand Down Expand Up @@ -253,14 +250,11 @@ public void subClassInheritsCacheableFalse() throws Exception {

@AfterEach
public void cleanup() throws Exception {
try {
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
} finally {
removeTestJarFromCP();
}
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ public void setup() throws Exception {
jpaprops.put("Insert_Jpa_Purchase_Order", System.getProperty("Insert_Jpa_Purchase_Order"));
jpaprops.put("Select_Jpa_Purchase_Order", System.getProperty("Select_Jpa_Purchase_Order"));
displayMap(jpaprops);
createDeployment();
removeTestData();
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
} finally {
createDeployment();
removeTestData();
}
}

Expand Down Expand Up @@ -629,14 +628,11 @@ public void createDataVIAJDBC(Properties p) {

@AfterEach
public void cleanup() throws Exception {
try {
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
} finally {
removeTestJarFromCP();
}
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ public void setup() throws Exception {
logger.log(Logger.Level.TRACE, "setup");
try {
super.setup();
createDeployment();
removeTestData();

} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
} finally {
createDeployment();
removeTestData();
}
}

Expand Down Expand Up @@ -139,14 +138,11 @@ public void containsTest() throws Exception {

@AfterEach
public void cleanup() throws Exception {
try {
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
} finally {
removeTestJarFromCP();
}
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,12 @@ public JavaArchive createDeployment() throws Exception {
public void setup() throws Exception {
logger.log(Logger.Level.TRACE, "setup");
try {

super.setup();

createDeployment();
removeTestData();
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
} finally {
createDeployment();
removeTestData();
}
}

Expand Down Expand Up @@ -154,14 +151,11 @@ public void containsTest() throws Exception {

@AfterEach
public void cleanup() throws Exception {
try {
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
} finally {
removeTestJarFromCP();
}
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,12 @@ public JavaArchive createDeployment() throws Exception {
public void setup() throws Exception {
logger.log(Logger.Level.TRACE, "setup");
try {

super.setup();

createDeployment();
removeTestData();
} catch (Exception e) {
logger.log(Logger.Level.ERROR, "Exception: ", e);
throw new Exception("Setup failed:", e);
} finally {
createDeployment();
removeTestData();

}
}

Expand Down Expand Up @@ -124,14 +120,11 @@ public void containsTest() throws Exception {

@AfterEach
public void cleanup() throws Exception {
try {
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
} finally {
removeTestJarFromCP();
}
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
logger.log(Logger.Level.TRACE, "cleanup complete, calling super.cleanup");
super.cleanup();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
16 changes: 6 additions & 10 deletions jpa/src/main/java/com/sun/ts/tests/jpa/se/descriptor/ClientIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ public JavaArchive createDeployment() throws Exception {
public void setup() throws Exception {
try {
super.setup();
} catch (Exception e) {
throw new Exception("Setup Failed!", e);
} finally {
createDeployment();
removeTestData();
createTestData();
} catch (Exception e) {
throw new Exception("Setup Failed!", e);
}
}

Expand Down Expand Up @@ -122,13 +121,10 @@ public void createTestData() {

@AfterEach
public void cleanup() throws Exception {
try {
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
super.cleanup();
} finally {
removeTestJarFromCP();
}
logger.log(Logger.Level.TRACE, "cleanup");
removeTestData();
super.cleanup();
removeTestJarFromCP();
}

private void removeTestData() {
Expand Down
Loading

0 comments on commit 997c859

Please sign in to comment.