use of cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder in project today-infrastructure by TAKETODAY.
the class PersistenceXmlParsingTests method testExample4.
@Test
public void testExample4() throws Exception {
SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
DataSource ds = new DriverManagerDataSource();
builder.bind("java:comp/env/jdbc/MyDB", ds);
PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
String resource = "/cn/taketoday/orm/jpa/persistence-example4.xml";
PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
assertThat(info).isNotNull();
assertThat(info.length).isEqualTo(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement4");
assertThat(info[0].getMappingFileNames().size()).isEqualTo(1);
assertThat(info[0].getMappingFileNames().get(0)).isEqualTo("order-mappings.xml");
assertThat(info[0].getManagedClassNames().size()).isEqualTo(3);
assertThat(info[0].getManagedClassNames().get(0)).isEqualTo("com.acme.Order");
assertThat(info[0].getManagedClassNames().get(1)).isEqualTo("com.acme.Customer");
assertThat(info[0].getManagedClassNames().get(2)).isEqualTo("com.acme.Item");
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should be true when no value.").isTrue();
assertThat(info[0].getTransactionType()).isSameAs(PersistenceUnitTransactionType.RESOURCE_LOCAL);
assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
builder.clear();
}
use of cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder in project today-framework by TAKETODAY.
the class PersistenceXmlParsingTests method testExample4.
@Test
public void testExample4() throws Exception {
SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
DataSource ds = new DriverManagerDataSource();
builder.bind("java:comp/env/jdbc/MyDB", ds);
PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
String resource = "/cn/taketoday/orm/jpa/persistence-example4.xml";
PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
assertThat(info).isNotNull();
assertThat(info.length).isEqualTo(1);
assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement4");
assertThat(info[0].getMappingFileNames().size()).isEqualTo(1);
assertThat(info[0].getMappingFileNames().get(0)).isEqualTo("order-mappings.xml");
assertThat(info[0].getManagedClassNames().size()).isEqualTo(3);
assertThat(info[0].getManagedClassNames().get(0)).isEqualTo("com.acme.Order");
assertThat(info[0].getManagedClassNames().get(1)).isEqualTo("com.acme.Customer");
assertThat(info[0].getManagedClassNames().get(2)).isEqualTo("com.acme.Item");
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should be true when no value.").isTrue();
assertThat(info[0].getTransactionType()).isSameAs(PersistenceUnitTransactionType.RESOURCE_LOCAL);
assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
builder.clear();
}
use of cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder in project today-framework by TAKETODAY.
the class JtaTransactionManagerSerializationTests method serializable.
@Test
public void serializable() throws Exception {
UserTransaction ut1 = mock(UserTransaction.class);
UserTransaction ut2 = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
JtaTransactionManager jtam = new JtaTransactionManager();
jtam.setUserTransaction(ut1);
jtam.setTransactionManager(tm);
jtam.setRollbackOnCommitFailure(true);
jtam.afterPropertiesSet();
SimpleNamingContextBuilder jndiEnv = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
jndiEnv.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut2);
JtaTransactionManager serializedJtatm = SerializationTestUtils.serializeAndDeserialize(jtam);
// should do client-side lookup
assertThat(serializedJtatm.logger).as("Logger must survive serialization").isNotNull();
assertThat(serializedJtatm.getUserTransaction() == ut2).as("UserTransaction looked up on client").isTrue();
assertThat(serializedJtatm.getTransactionManager()).as("TransactionManager didn't survive").isNull();
assertThat(serializedJtatm.isRollbackOnCommitFailure()).isEqualTo(true);
}
use of cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder in project today-infrastructure by TAKETODAY.
the class JtaTransactionManagerSerializationTests method serializable.
@Test
public void serializable() throws Exception {
UserTransaction ut1 = mock(UserTransaction.class);
UserTransaction ut2 = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
JtaTransactionManager jtam = new JtaTransactionManager();
jtam.setUserTransaction(ut1);
jtam.setTransactionManager(tm);
jtam.setRollbackOnCommitFailure(true);
jtam.afterPropertiesSet();
SimpleNamingContextBuilder jndiEnv = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
jndiEnv.bind(JtaTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut2);
JtaTransactionManager serializedJtatm = SerializationTestUtils.serializeAndDeserialize(jtam);
// should do client-side lookup
assertThat(serializedJtatm.logger).as("Logger must survive serialization").isNotNull();
assertThat(serializedJtatm.getUserTransaction() == ut2).as("UserTransaction looked up on client").isTrue();
assertThat(serializedJtatm.getTransactionManager()).as("TransactionManager didn't survive").isNull();
assertThat(serializedJtatm.isRollbackOnCommitFailure()).isEqualTo(true);
}
Aggregations