Search in sources :

Example 1 with PathMatchingPatternResourceLoader

use of cn.taketoday.core.io.PathMatchingPatternResourceLoader in project today-infrastructure by TAKETODAY.

the class PersistenceXmlParsingTests method testExample2.

@Test
public void testExample2() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
    String resource = "/cn/taketoday/orm/jpa/persistence-example2.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertThat(info).isNotNull();
    assertThat(info.length).isEqualTo(1);
    assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement2");
    assertThat(info[0].getMappingFileNames().size()).isEqualTo(1);
    assertThat(info[0].getMappingFileNames().get(0)).isEqualTo("mappings.xml");
    assertThat(info[0].getProperties().keySet().size()).isEqualTo(0);
    assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
Also used : PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) Test(org.junit.jupiter.api.Test)

Example 2 with PathMatchingPatternResourceLoader

use of cn.taketoday.core.io.PathMatchingPatternResourceLoader in project today-infrastructure by TAKETODAY.

the class PersistenceXmlParsingTests method testMetaInfCase.

@Test
public void testMetaInfCase() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
    String resource = "/cn/taketoday/orm/jpa/META-INF/persistence.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertThat(info).isNotNull();
    assertThat(info.length).isEqualTo(1);
    assertThat(info[0].getPersistenceUnitName()).isEqualTo("OrderManagement");
    assertThat(info[0].getJarFileUrls().size()).isEqualTo(2);
    assertThat(info[0].getJarFileUrls().get(0)).isEqualTo(new ClassPathResource("order.jar").getLocation());
    assertThat(info[0].getJarFileUrls().get(1)).isEqualTo(new ClassPathResource("order-supplemental.jar").getLocation());
    assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
Also used : PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) ClassPathResource(cn.taketoday.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 3 with PathMatchingPatternResourceLoader

use of cn.taketoday.core.io.PathMatchingPatternResourceLoader in project today-infrastructure by TAKETODAY.

the class PersistenceXmlParsingTests method testJpa2ExcludeUnlisted.

@Test
public void testJpa2ExcludeUnlisted() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
    String resource = "/cn/taketoday/orm/jpa/persistence-exclude-2.0.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertThat(info).isNotNull();
    assertThat(info.length).as("The number of persistence units is incorrect.").isEqualTo(4);
    PersistenceUnitInfo noExclude = info[0];
    assertThat(noExclude).as("noExclude should not be null.").isNotNull();
    assertThat(noExclude.getPersistenceUnitName()).as("noExclude name is not correct.").isEqualTo("NoExcludeElement");
    assertThat(noExclude.excludeUnlistedClasses()).as("Exclude unlisted still defaults to false in 2.0.").isFalse();
    PersistenceUnitInfo emptyExclude = info[1];
    assertThat(emptyExclude).as("emptyExclude should not be null.").isNotNull();
    assertThat(emptyExclude.getPersistenceUnitName()).as("emptyExclude name is not correct.").isEqualTo("EmptyExcludeElement");
    assertThat(emptyExclude.excludeUnlistedClasses()).as("emptyExclude should be true.").isTrue();
    PersistenceUnitInfo trueExclude = info[2];
    assertThat(trueExclude).as("trueExclude should not be null.").isNotNull();
    assertThat(trueExclude.getPersistenceUnitName()).as("trueExclude name is not correct.").isEqualTo("TrueExcludeElement");
    assertThat(trueExclude.excludeUnlistedClasses()).as("trueExclude should be true.").isTrue();
    PersistenceUnitInfo falseExclude = info[3];
    assertThat(falseExclude).as("falseExclude should not be null.").isNotNull();
    assertThat(falseExclude.getPersistenceUnitName()).as("falseExclude name is not correct.").isEqualTo("FalseExcludeElement");
    assertThat(falseExclude.excludeUnlistedClasses()).as("falseExclude should be false.").isFalse();
}
Also used : PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) Test(org.junit.jupiter.api.Test)

Example 4 with PathMatchingPatternResourceLoader

use of cn.taketoday.core.io.PathMatchingPatternResourceLoader 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 5 with PathMatchingPatternResourceLoader

use of cn.taketoday.core.io.PathMatchingPatternResourceLoader in project today-infrastructure by TAKETODAY.

the class PersistenceXmlParsingTests method testJpa1ExcludeUnlisted.

@Test
public void testJpa1ExcludeUnlisted() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingPatternResourceLoader(), new JndiDataSourceLookup());
    String resource = "/cn/taketoday/orm/jpa/persistence-exclude-1.0.xml";
    PersistenceUnitInfo[] info = reader.readPersistenceUnitInfos(resource);
    assertThat(info).isNotNull();
    assertThat(info.length).as("The number of persistence units is incorrect.").isEqualTo(4);
    PersistenceUnitInfo noExclude = info[0];
    assertThat(noExclude).as("noExclude should not be null.").isNotNull();
    assertThat(noExclude.getPersistenceUnitName()).as("noExclude name is not correct.").isEqualTo("NoExcludeElement");
    assertThat(noExclude.excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
    PersistenceUnitInfo emptyExclude = info[1];
    assertThat(emptyExclude).as("emptyExclude should not be null.").isNotNull();
    assertThat(emptyExclude.getPersistenceUnitName()).as("emptyExclude name is not correct.").isEqualTo("EmptyExcludeElement");
    assertThat(emptyExclude.excludeUnlistedClasses()).as("emptyExclude should be true.").isTrue();
    PersistenceUnitInfo trueExclude = info[2];
    assertThat(trueExclude).as("trueExclude should not be null.").isNotNull();
    assertThat(trueExclude.getPersistenceUnitName()).as("trueExclude name is not correct.").isEqualTo("TrueExcludeElement");
    assertThat(trueExclude.excludeUnlistedClasses()).as("trueExclude should be true.").isTrue();
    PersistenceUnitInfo falseExclude = info[3];
    assertThat(falseExclude).as("falseExclude should not be null.").isNotNull();
    assertThat(falseExclude.getPersistenceUnitName()).as("falseExclude name is not correct.").isEqualTo("FalseExcludeElement");
    assertThat(falseExclude.excludeUnlistedClasses()).as("falseExclude should be false.").isFalse();
}
Also used : PathMatchingPatternResourceLoader(cn.taketoday.core.io.PathMatchingPatternResourceLoader) JndiDataSourceLookup(cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) Test(org.junit.jupiter.api.Test)

Aggregations

PathMatchingPatternResourceLoader (cn.taketoday.core.io.PathMatchingPatternResourceLoader)24 Test (org.junit.jupiter.api.Test)24 JndiDataSourceLookup (cn.taketoday.jdbc.datasource.lookup.JndiDataSourceLookup)22 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)20 ClassPathResource (cn.taketoday.core.io.ClassPathResource)8 DriverManagerDataSource (cn.taketoday.jdbc.datasource.DriverManagerDataSource)4 DataSource (javax.sql.DataSource)4 Disabled (org.junit.jupiter.api.Disabled)4 MapDataSourceLookup (cn.taketoday.jdbc.datasource.lookup.MapDataSourceLookup)2 SimpleNamingContextBuilder (cn.taketoday.testfixture.jndi.SimpleNamingContextBuilder)2 HashMap (java.util.HashMap)2 Properties (java.util.Properties)2