if (DISABLE_LOGGING) { logger.setLevel(Level.FATAL); }
assertEquals("org.castor.transactionmanager.InitializeAtRegistration",
CPAProperties.TRANSACTION_MANAGER_INIT);
AbstractProperties properties = CPAProperties.getInstance();
String memF = properties.getString(CPAProperties.TRANSACTION_MANAGER_FACTORIES, null);
String memI = properties.getString(CPAProperties.TRANSACTION_MANAGER_INIT, null);
properties.put(CPAProperties.TRANSACTION_MANAGER_FACTORIES,
TransactionManagerFactoryDummy.class.getName());
properties.put(CPAProperties.TRANSACTION_MANAGER_INIT,
Boolean.FALSE.toString());
TransactionManagerRegistry tmr = new TransactionManagerRegistry(properties);
String[] managers = tmr.getTransactionManagerNames();
assertEquals(0, managers.length);
TransactionManager manager = new TransactionManagerDummy();
try {
tmr.registerTransactionManager("m1", manager);
} catch (TransactionManagerAcquireException ex) {
fail("Unexpected TransactionManagerAcquireException.");
}
managers = tmr.getTransactionManagerNames();
assertEquals(1, managers.length);
assertEquals("m1", managers[0]);
try {
assertTrue(manager == tmr.getTransactionManager("m1"));
} catch (TransactionManagerAcquireException ex) {
fail("Unexpected TransactionManagerAcquireException.");
}
try {
tmr.registerTransactionManager("m1", new TransactionManagerDummy());
fail("A TransactionManagerAcquireException without cause "
+ "should have been thrown.");
} catch (TransactionManagerAcquireException ex) {
assertNull(ex.getCause());
}
managers = tmr.getTransactionManagerNames();
assertEquals(1, managers.length);
assertEquals("m1", managers[0]);
try {
assertTrue(manager == tmr.getTransactionManager("m1"));
} catch (TransactionManagerAcquireException ex) {
fail("Unexpected TransactionManagerAcquireException.");
}
tmr.deregisterTransactionManager("m1");
managers = tmr.getTransactionManagerNames();
assertEquals(0, managers.length);
try {
tmr.registerTransactionManager("m2", "dummy", null);
} catch (TransactionManagerAcquireException ex) {
fail("Unexpected TransactionManagerAcquireException.");
}
managers = tmr.getTransactionManagerNames();
assertEquals(1, managers.length);
assertEquals("m2", managers[0]);
WebSphereMock.init(new TransactionManagerDummy());
try {
manager = tmr.getTransactionManager("m2");
assertTrue(manager instanceof TransactionManagerDummy);
} catch (TransactionManagerAcquireException ex) {
fail("Unexpected TransactionManagerAcquireException.");
}
try {
tmr.getTransactionManager("m3");
fail("A TransactionManagerAcquireException without cause "
+ "should have been thrown.");
} catch (TransactionManagerAcquireException ex) {
assertNull(ex.getCause());
}
tmr.deregisterTransactionManager("m2");
managers = tmr.getTransactionManagerNames();
assertEquals(0, managers.length);
properties.put(CPAProperties.TRANSACTION_MANAGER_INIT, memI);
properties.put(CPAProperties.TRANSACTION_MANAGER_FACTORIES, memF);
logger.setLevel(level);
}