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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations