modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java | 16
++++++----
1 file changed, 11 insertions(+), 5 deletions(-)
New commits:
commit a07dc82e8347ce2f1e7e42f9520fb3d4d5f7f3b6
Author: John Mazzitelli <mazz(a)redhat.com>
Date: Thu Jul 28 15:33:05 2011 -0400
[coverity] closing the initial context explicitly
diff --git
a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
index 57ec318..85fb5b8 100644
--- a/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
+++ b/modules/core/domain/src/test/java/org/rhq/core/domain/test/AbstractEJB3Test.java
@@ -35,15 +35,13 @@ import javax.transaction.TransactionManager;
import org.testng.AssertJUnit;
import org.testng.annotations.AfterGroups;
-import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeGroups;
-import org.testng.annotations.BeforeSuite;
import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
public abstract class AbstractEJB3Test extends AssertJUnit {
-// @BeforeSuite(groups = "integration.ejb3")
+ // @BeforeSuite(groups = "integration.ejb3")
@BeforeGroups(groups = "integration.ejb3")
public static void startupEmbeddedJboss() {
System.out.println("Starting ejb3...");
@@ -84,7 +82,7 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
}
}
-// @AfterSuite
+ // @AfterSuite
@AfterGroups(groups = "integration.ejb3")
public static void shutdownEmbeddedJboss() {
EJB3StandaloneBootstrap.shutdown();
@@ -93,12 +91,20 @@ public abstract class AbstractEJB3Test extends AssertJUnit {
private TransactionManager tm;
public TransactionManager getTransactionManager() {
+ InitialContext initialContext = null;
try {
- tm = (TransactionManager)
getInitialContext().lookup("java:/TransactionManager");
+ initialContext = getInitialContext();
+ tm = (TransactionManager)
initialContext.lookup("java:/TransactionManager");
return tm;
} catch (NamingException e) {
e.printStackTrace();
throw new RuntimeException("Failed to load transaction manager",
e);
+ } finally {
+ try {
+ initialContext.close();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to close the initial context -
why did this happen?", e);
+ }
}
}
Show replies by date