Search in sources :

Example 81 with DatabaseSetup

use of com.github.springtestdbunit.annotation.DatabaseSetup in project mybatis.flying by limeng32.

the class CacheTest method test21.

@Test
@IfProfileValue(name = "CACHE", value = "true")
@DatabaseSetup(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.xml")
@ExpectedDatabase(connection = "dataSource2", assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.result.xml")
@DatabaseTearDown(connection = "dataSource2", type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/cacheTest2/test.datasource2.result.xml")
public void test21() {
    String name = "ann";
    String roleName = "user";
    String newRoleName = "admin";
    Account2_ a = new Account2_();
    Role2_ r = new Role2_();
    r.setName(roleName);
    role2Service.insert(r);
    a.setName(name);
    a.setRole(r);
    account2Service.insert(a);
    Account2_ account2_ = account2Service.select(a.getId());
    Assert.assertEquals(roleName, account2_.getRole().getName());
    Role2_ r2 = role2Service.select(r.getId());
    r2.setName(newRoleName);
    role2Service.update(r2);
    account2_ = account2Service.select(a.getId());
    Assert.assertEquals(newRoleName, account2_.getRole().getName());
}
Also used : Account2_(indi.mybatis.flying.pojo.Account2_) Role2_(indi.mybatis.flying.pojo.Role2_) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 82 with DatabaseSetup

use of com.github.springtestdbunit.annotation.DatabaseSetup in project mybatis.flying by limeng32.

the class InternalCacheTest method testCacheThread.

/**
 * 这是一个展示Junit配合Groboutils进行多线程测试的例子,在这个例子中accountInsert以子线程的方式执行多次,
 * 主线程会等待子线程全部执行完后再结束
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/internalCacheTest/testCacheThread.result.xml")
public void testCacheThread() throws Throwable {
    // 实例化 TestRunnable 类
    TestRunnable tr1, tr2;
    tr1 = new acctionSelect();
    tr2 = new acctionUpdate();
    // 把实例传递给 MTTR
    TestRunnable[] trs = { tr1, tr2 };
    MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(trs);
    // 执行MTTR和线程
    mttr.runTestRunnables();
}
Also used : TestRunnable(net.sourceforge.groboutils.junit.v1.TestRunnable) MultiThreadedTestRunner(net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 83 with DatabaseSetup

use of com.github.springtestdbunit.annotation.DatabaseSetup in project mybatis.flying by limeng32.

the class ThreadTest method testExampleThread.

/**
 * 这是一个展示Junit配合Groboutils进行多线程测试的例子,在这个例子中accountInsert以子线程的方式执行多次,
 * 主线程会等待子线程全部执行完后再结束
 */
@Test
@DatabaseSetup(type = DatabaseOperation.CLEAN_INSERT, value = "/indi/mybatis/flying/test/threadTest/testExampleThread.xml")
@ExpectedDatabase(assertionMode = DatabaseAssertionMode.NON_STRICT, value = "/indi/mybatis/flying/test/threadTest/testExampleThread.result.xml")
@DatabaseTearDown(type = DatabaseOperation.DELETE_ALL, value = "/indi/mybatis/flying/test/threadTest/testExampleThread.result.xml")
public void testExampleThread() throws Throwable {
    // 实例化 TestRunnable 类
    TestRunnable tr1, tr2;
    tr1 = new accountInsert(2L, "ann");
    tr2 = new accountInsert(3L, "ann");
    // 把实例传递给 MTTR
    TestRunnable[] trs = { tr1, tr2 };
    MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(trs);
    // 执行MTTR和线程
    mttr.runTestRunnables();
}
Also used : TestRunnable(net.sourceforge.groboutils.junit.v1.TestRunnable) MultiThreadedTestRunner(net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup) DatabaseTearDown(com.github.springtestdbunit.annotation.DatabaseTearDown)

Example 84 with DatabaseSetup

use of com.github.springtestdbunit.annotation.DatabaseSetup in project thingsboard by thingsboard.

the class JpaBasePluginDaoTest method testFindByTenantIdAndPageLink.

@Test
@DatabaseSetup("classpath:dbunit/empty_dataset.xml")
public void testFindByTenantIdAndPageLink() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    createPluginsTwoTenants(tenantId1, tenantId2, "plugin_");
    List<PluginMetaData> rules1 = pluginDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "plugin_"));
    assertEquals(20, rules1.size());
    List<PluginMetaData> rules2 = pluginDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "plugin_", rules1.get(19).getId().getId(), null));
    assertEquals(10, rules2.size());
    List<PluginMetaData> rules3 = pluginDao.findByTenantIdAndPageLink(new TenantId(tenantId1), new TextPageLink(20, "plugin_", rules2.get(9).getId().getId(), null));
    assertEquals(0, rules3.size());
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 85 with DatabaseSetup

use of com.github.springtestdbunit.annotation.DatabaseSetup in project thingsboard by thingsboard.

the class JpaBasePluginDaoTest method testFindAllTenantRulesByTenantId.

@Test
@DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml")
public void testFindAllTenantRulesByTenantId() {
    UUID tenantId1 = UUIDs.timeBased();
    UUID tenantId2 = UUIDs.timeBased();
    createTenantsAndSystemPlugins(tenantId1, tenantId2, "name_");
    List<PluginMetaData> rules1 = pluginDao.findAllTenantPluginsByTenantId(tenantId1, new TextPageLink(40, "name_"));
    assertEquals(40, rules1.size());
    List<PluginMetaData> rules2 = pluginDao.findAllTenantPluginsByTenantId(tenantId1, new TextPageLink(40, "name_", rules1.get(19).getId().getId(), null));
    assertEquals(20, rules2.size());
    List<PluginMetaData> rules3 = pluginDao.findAllTenantPluginsByTenantId(tenantId1, new TextPageLink(40, "name_", rules2.get(19).getId().getId(), null));
    assertEquals(0, rules3.size());
}
Also used : TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) UUID(java.util.UUID) AbstractJpaDaoTest(org.thingsboard.server.dao.AbstractJpaDaoTest) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Aggregations

DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)151 Test (org.junit.Test)150 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)98 DatabaseTearDown (com.github.springtestdbunit.annotation.DatabaseTearDown)92 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)78 Account_Condition (indi.mybatis.flying.pojo.condition.Account_Condition)46 Account_ (indi.mybatis.flying.pojo.Account_)43 MvcResult (org.springframework.test.web.servlet.MvcResult)26 LoginLog_ (indi.mybatis.flying.pojo.LoginLog_)25 AbstractJpaDaoTest (org.thingsboard.server.dao.AbstractJpaDaoTest)24 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)21 ArrayList (java.util.ArrayList)17 LoginLog_Condition (indi.mybatis.flying.pojo.condition.LoginLog_Condition)15 UUID (java.util.UUID)15 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)12 Role_ (indi.mybatis.flying.pojo.Role_)11 IfProfileValue (org.springframework.test.annotation.IfProfileValue)10 ExpectedDatabases (com.github.springtestdbunit.annotation.ExpectedDatabases)8 CreateStudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.CreateStudyDTO)7 Detail_ (indi.mybatis.flying.pojo.Detail_)7