Search in sources :

Example 16 with JndiDataSourceLookup

use of org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testExample2.

@Test
public void testExample2() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/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 : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) Test(org.junit.jupiter.api.Test)

Example 17 with JndiDataSourceLookup

use of org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup in project spring-framework by spring-projects.

the class PersistenceXmlParsingTests method testMetaInfCase.

@Test
public void testMetaInfCase() throws Exception {
    PersistenceUnitReader reader = new PersistenceUnitReader(new PathMatchingResourcePatternResolver(), new JndiDataSourceLookup());
    String resource = "/org/springframework/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").getURL());
    assertThat(info[0].getJarFileUrls().get(1)).isEqualTo(new ClassPathResource("order-supplemental.jar").getURL());
    assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
Also used : JndiDataSourceLookup(org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) PersistenceUnitInfo(jakarta.persistence.spi.PersistenceUnitInfo) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Aggregations

JndiDataSourceLookup (org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup)17 Test (org.junit.jupiter.api.Test)11 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)11 PersistenceUnitInfo (jakarta.persistence.spi.PersistenceUnitInfo)9 DataSource (javax.sql.DataSource)4 Bean (org.springframework.context.annotation.Bean)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 Disabled (org.junit.jupiter.api.Disabled)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 ProxyDataSource (com.haulmont.cuba.core.sys.jdbc.ProxyDataSource)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 SneakyThrows (lombok.SneakyThrows)1 lombok.val (lombok.val)1 Test (org.junit.Test)1 SimpleNamingContextBuilder (org.springframework.context.testfixture.jndi.SimpleNamingContextBuilder)1 Environment (org.springframework.core.env.Environment)1 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)1 DataSourceLookup (org.springframework.jdbc.datasource.lookup.DataSourceLookup)1 DataSourceLookupFailureException (org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException)1