|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2014 the original author or authors.
|
|
|
|
* Copyright 2012-2016 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -19,29 +19,82 @@ package org.springframework.boot.autoconfigure.jdbc;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link DataSourceProperties}.
|
|
|
|
* Tests for {@link DataSourceProperties}.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Maciej Walkowiak
|
|
|
|
* @author Maciej Walkowiak
|
|
|
|
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class DataSourcePropertiesTests {
|
|
|
|
public class DataSourcePropertiesTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void correctDriverClassNameFromJdbcUrlWhenDriverClassNameNotDefined() {
|
|
|
|
public void determineDriver() {
|
|
|
|
DataSourceProperties configuration = new DataSourceProperties();
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
configuration.setUrl("jdbc:mysql://mydb");
|
|
|
|
properties.setUrl("jdbc:mysql://mydb");
|
|
|
|
String driverClassName = configuration.getDriverClassName();
|
|
|
|
assertNull(properties.getDriverClassName());
|
|
|
|
assertEquals(driverClassName, "com.mysql.jdbc.Driver");
|
|
|
|
assertEquals("com.mysql.jdbc.Driver", properties.determineDriverClassName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void driverClassNameFromDriverClassNamePropertyWhenDefined() {
|
|
|
|
public void determineDriverWithExplicitConfig() {
|
|
|
|
DataSourceProperties configuration = new DataSourceProperties();
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
configuration.setUrl("jdbc:mysql://mydb");
|
|
|
|
properties.setUrl("jdbc:mysql://mydb");
|
|
|
|
configuration.setDriverClassName("org.hsqldb.jdbcDriver");
|
|
|
|
properties.setDriverClassName("org.hsqldb.jdbcDriver");
|
|
|
|
String driverClassName = configuration.getDriverClassName();
|
|
|
|
assertEquals("org.hsqldb.jdbcDriver", properties.getDriverClassName());
|
|
|
|
assertEquals(driverClassName, "org.hsqldb.jdbcDriver");
|
|
|
|
assertEquals("org.hsqldb.jdbcDriver", properties.determineDriverClassName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void determineUrl() throws Exception {
|
|
|
|
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
|
|
|
|
properties.afterPropertiesSet();
|
|
|
|
|
|
|
|
assertNull(properties.getUrl());
|
|
|
|
|
|
|
|
assertEquals(EmbeddedDatabaseConnection.H2.getUrl(), properties.determineUrl());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void determineUrlWithExplicitConfig() throws Exception {
|
|
|
|
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
|
|
|
|
properties.setUrl("jdbc:mysql://mydb");
|
|
|
|
|
|
|
|
properties.afterPropertiesSet();
|
|
|
|
|
|
|
|
assertEquals("jdbc:mysql://mydb", properties.getUrl());
|
|
|
|
|
|
|
|
assertEquals("jdbc:mysql://mydb", properties.determineUrl());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void determineUsername() throws Exception {
|
|
|
|
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
|
|
|
|
properties.afterPropertiesSet();
|
|
|
|
|
|
|
|
assertNull(properties.getUsername());
|
|
|
|
|
|
|
|
assertEquals("sa", properties.determineUsername());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void determineUsernameWithExplicitConfig() throws Exception {
|
|
|
|
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
|
|
|
|
properties.setUsername("foo");
|
|
|
|
|
|
|
|
properties.afterPropertiesSet();
|
|
|
|
|
|
|
|
assertEquals("foo", properties.getUsername());
|
|
|
|
|
|
|
|
assertEquals("foo", properties.determineUsername());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void determinePassword() throws Exception {
|
|
|
|
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
|
|
|
|
properties.afterPropertiesSet();
|
|
|
|
|
|
|
|
assertNull(properties.getPassword());
|
|
|
|
|
|
|
|
assertEquals("", properties.determinePassword());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void determinePasswordWithExplicitConfig() throws Exception {
|
|
|
|
|
|
|
|
DataSourceProperties properties = new DataSourceProperties();
|
|
|
|
|
|
|
|
properties.setPassword("bar");
|
|
|
|
|
|
|
|
properties.afterPropertiesSet();
|
|
|
|
|
|
|
|
assertEquals("bar", properties.getPassword());
|
|
|
|
|
|
|
|
assertEquals("bar", properties.determinePassword());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|