Search in sources :

Example 6 with Database

use of org.springframework.orm.jpa.vendor.Database in project spring-boot by spring-projects.

the class CustomHibernateJpaAutoConfigurationTests method testDefaultDatabaseForH2.

@Test
public void testDefaultDatabaseForH2() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.url:jdbc:h2:mem:testdb", "spring.datasource.initialize:false");
    this.context.register(TestConfiguration.class, DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, HibernateJpaAutoConfiguration.class);
    this.context.refresh();
    HibernateJpaVendorAdapter bean = this.context.getBean(HibernateJpaVendorAdapter.class);
    Database database = (Database) ReflectionTestUtils.getField(bean, "database");
    assertThat(database).isEqualTo(Database.H2);
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) Database(org.springframework.orm.jpa.vendor.Database) Test(org.junit.Test)

Example 7 with Database

use of org.springframework.orm.jpa.vendor.Database in project spring-boot by spring-projects.

the class JpaPropertiesTests method determineDatabaseWithUnknownUrl.

@Test
public void determineDatabaseWithUnknownUrl() {
    JpaProperties properties = load();
    Database database = properties.determineDatabase(mockDataSource("jdbc:unknown://localhost"));
    assertThat(database).isEqualTo(Database.DEFAULT);
}
Also used : Database(org.springframework.orm.jpa.vendor.Database) Test(org.junit.Test)

Example 8 with Database

use of org.springframework.orm.jpa.vendor.Database in project spring-boot by spring-projects.

the class JpaPropertiesTests method determineDatabaseWithKnownUrl.

@Test
public void determineDatabaseWithKnownUrl() {
    JpaProperties properties = load();
    Database database = properties.determineDatabase(mockDataSource("jdbc:h2:mem:testdb"));
    assertThat(database).isEqualTo(Database.H2);
}
Also used : Database(org.springframework.orm.jpa.vendor.Database) Test(org.junit.Test)

Example 9 with Database

use of org.springframework.orm.jpa.vendor.Database in project spring-boot by spring-projects.

the class JpaPropertiesTests method determineDatabaseNoCheckIfDatabaseIsSet.

@Test
public void determineDatabaseNoCheckIfDatabaseIsSet() throws SQLException {
    JpaProperties properties = load("spring.jpa.database=postgresql");
    DataSource dataSource = mockStandaloneDataSource();
    Database database = properties.determineDatabase(dataSource);
    assertThat(database).isEqualTo(Database.POSTGRESQL);
    verify(dataSource, never()).getConnection();
}
Also used : Database(org.springframework.orm.jpa.vendor.Database) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 10 with Database

use of org.springframework.orm.jpa.vendor.Database in project spring-boot by spring-projects.

the class CustomHibernateJpaAutoConfigurationTests method defaultDatabaseIsSet.

@Test
void defaultDatabaseIsSet() {
    this.contextRunner.withPropertyValues("spring.datasource.url:jdbc:h2:mem:testdb", "spring.datasource.initialization-mode:never").run((context) -> {
        HibernateJpaVendorAdapter bean = context.getBean(HibernateJpaVendorAdapter.class);
        Database database = (Database) ReflectionTestUtils.getField(bean, "database");
        assertThat(database).isEqualTo(Database.DEFAULT);
    });
}
Also used : HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) Database(org.springframework.orm.jpa.vendor.Database) Test(org.junit.jupiter.api.Test)

Aggregations

Database (org.springframework.orm.jpa.vendor.Database)10 Test (org.junit.Test)5 HibernateJpaVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter)4 DataSource (javax.sql.DataSource)2 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Test (org.junit.jupiter.api.Test)1 DatabaseDriver (org.springframework.boot.jdbc.DatabaseDriver)1 Bean (org.springframework.context.annotation.Bean)1 MetaDataAccessException (org.springframework.jdbc.support.MetaDataAccessException)1 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)1