|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2010 the original author or authors. |
|
|
|
* Copyright 2002-2012 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,17 +19,24 @@ package org.springframework.jdbc.datasource.init; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.Connection; |
|
|
|
|
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.easymock.EasyMock; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.io.ClassRelativeResourceLoader; |
|
|
|
import org.springframework.core.io.ClassRelativeResourceLoader; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
|
|
|
|
import org.springframework.jdbc.datasource.DataSourceUtils; |
|
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; |
|
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; |
|
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
|
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; |
|
|
|
|
|
|
|
import org.springframework.transaction.support.TransactionSynchronizationManager; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Dave Syer |
|
|
|
* @author Dave Syer |
|
|
|
* @author Sam Brannen |
|
|
|
* @author Sam Brannen |
|
|
|
|
|
|
|
* @author Oliver Gierke |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DatabasePopulatorTests { |
|
|
|
public class DatabasePopulatorTests { |
|
|
|
|
|
|
|
|
|
|
@ -54,6 +61,12 @@ public class DatabasePopulatorTests { |
|
|
|
|
|
|
|
|
|
|
|
@After |
|
|
|
@After |
|
|
|
public void shutDown() { |
|
|
|
public void shutDown() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TransactionSynchronizationManager.isSynchronizationActive()) { |
|
|
|
|
|
|
|
TransactionSynchronizationManager.clear(); |
|
|
|
|
|
|
|
TransactionSynchronizationManager.unbindResource(db); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
db.shutdown(); |
|
|
|
db.shutdown(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -207,4 +220,22 @@ public class DatabasePopulatorTests { |
|
|
|
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); |
|
|
|
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* @see SPR-9457 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void usesBoundConnectionIfAvailable() throws SQLException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TransactionSynchronizationManager.initSynchronization(); |
|
|
|
|
|
|
|
Connection connection = DataSourceUtils.getConnection(db); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DatabasePopulator populator = EasyMock.createMock(DatabasePopulator.class); |
|
|
|
|
|
|
|
populator.populate(connection); |
|
|
|
|
|
|
|
EasyMock.expectLastCall(); |
|
|
|
|
|
|
|
EasyMock.replay(populator); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DatabasePopulatorUtils.execute(populator, db); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EasyMock.verify(populator); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|