mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-10-23 12:19:09 +00:00
Merge pull request #1949 from sebastianmrozek/master
Test usingDatabase with a non default db
This commit is contained in:
@@ -19,21 +19,6 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestQueryUsingConnection extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void usingDatabase() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
final Database database = DB.getDefault();
|
||||
|
||||
int count =
|
||||
DB.find(Country.class)
|
||||
.usingDatabase(database)
|
||||
.findCount();
|
||||
|
||||
assertThat(count).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usingConnection() throws SQLException {
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.ESimple;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestQueryUsingDatabase {
|
||||
|
||||
private static final String SOME_OTHER_DB_NAME = "someotherdb";
|
||||
public static final ESimple RECORD1 = new ESimple();
|
||||
public static final ESimple RECORD2 = new ESimple();
|
||||
|
||||
@Before
|
||||
public void setupNonDefaultDatabase() {
|
||||
DB.byName(SOME_OTHER_DB_NAME).insert(RECORD1);
|
||||
DB.byName(SOME_OTHER_DB_NAME).insert(RECORD2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void usingNonDefaultDatabase() {
|
||||
final Database nonDefaultDb = DB.byName(SOME_OTHER_DB_NAME);
|
||||
|
||||
List<ESimple> orderList = DB.find(ESimple.class)
|
||||
.usingDatabase(nonDefaultDb)
|
||||
.findList();
|
||||
|
||||
assertThat(orderList).size().isEqualTo(2);
|
||||
assertThat(orderList).containsExactlyInAnyOrder(RECORD1, RECORD2);
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,7 @@ ebean.jodaLocalTimeMode=normal
|
||||
|
||||
#ebean.skipCacheAfterWrite=false
|
||||
|
||||
datasource.someotherdb.username=sa
|
||||
datasource.someotherdb.password=
|
||||
datasource.someotherdb.databaseUrl=jdbc:h2:mem:someotherdb
|
||||
datasource.someotherdb.databaseDriver=org.h2.Driver
|
||||
|
||||
Reference in New Issue
Block a user