Search in sources :

Example 1 with SimpleNamingContextBuilder

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();
}
Also used : SimpleNamingContextBuilder(cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Example 2 with SimpleNamingContextBuilder

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();
}
Also used : SimpleNamingContextBuilder(cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Example 3 with SimpleNamingContextBuilder

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);
}
Also used : UserTransaction(jakarta.transaction.UserTransaction) SimpleNamingContextBuilder(cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder) JtaTransactionManager(cn.taketoday.transaction.jta.JtaTransactionManager) JtaTransactionManager(cn.taketoday.transaction.jta.JtaTransactionManager) TransactionManager(jakarta.transaction.TransactionManager) Test(org.junit.jupiter.api.Test)

Example 4 with SimpleNamingContextBuilder

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);
}
Also used : UserTransaction(jakarta.transaction.UserTransaction) SimpleNamingContextBuilder(cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder) JtaTransactionManager(cn.taketoday.transaction.jta.JtaTransactionManager) JtaTransactionManager(cn.taketoday.transaction.jta.JtaTransactionManager) TransactionManager(jakarta.transaction.TransactionManager) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleNamingContextBuilder (cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder)4 Test (org.junit.jupiter.api.Test)4 PathMatchingPatternResourceLoader (cn.taketoday.core.io.PathMatchingPatternResourceLoader)2 DriverManagerDataSource (cn.taketoday.jdbc.datasource.DriverManagerDataSource)2 JndiDataSourceLookup (cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup)2 JtaTransactionManager (cn.taketoday.transaction.jta.JtaTransactionManager)2 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)2 TransactionManager (jakarta.transaction.TransactionManager)2 UserTransaction (jakarta.transaction.UserTransaction)2 DataSource (javax.sql.DataSource)2