本文整理汇总了Java中org.unitils.dbunit.annotation.DataSet类的典型用法代码示例。如果您正苦于以下问题:Java DataSet类的具体用法?Java DataSet怎么用?Java DataSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataSet类属于org.unitils.dbunit.annotation包,在下文中一共展示了DataSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFirstDataSetContainsDifferentColumnsThanSecondWithDataSetsAnnotation
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSets({
@DataSet("DbunitDifferentCollumnsTest-WithOnlyOneColumn.xml"),
@DataSet("DbunitDifferentCollumnsTest-WithOnlyPersonName.xml")
})
public void testFirstDataSetContainsDifferentColumnsThanSecondWithDataSetsAnnotation() {
SqlAssert.assertCountSqlResult("select count(*) from person", dataSource, 4L);
String[][] expected = new String[][]{
new String[]{null, "Suzan"},
new String[]{null, "Mathias"},
new String[]{"14", null},
new String[]{"15", null}
};
SqlAssert.assertMultipleRowSqlResult("select * from person", expected);
}
示例2: testFirstDataSetContainsLessAttributesWithDataSetsAnnotation
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSets({
@DataSet("DbunitDifferentCollumnsTest-WithOnlyOneColumn.xml"),
@DataSet("DbunitDifferentCollumnsTest-WithAllColumns.xml")
})
public void testFirstDataSetContainsLessAttributesWithDataSetsAnnotation() {
SqlAssert.assertCountSqlResult("select count(*) from person", dataSource, 4L);
String[][] expected = new String[][]{
new String[]{"12", "Peter"},
new String[]{"13", "Stijn"},
new String[]{"14", null},
new String[]{"15", null}
};
SqlAssert.assertMultipleRowSqlResult("select * from person", expected);
}
示例3: insertDataSet
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
/**
* This method will first try to load a method level defined dataset. If no such file exists, a class level defined dataset will be
* loaded. If neither of these files exist, nothing is done. The name of the test data file at both method level and class level can be
* overridden using the {@link DataSet} annotation. If specified using this annotation but not found, a {@link UnitilsException} is
* thrown.
*
* @param testMethod The method, not null
* @param testObject The test object, not null
*/
public void insertDataSet(Method testMethod, Object testObject) {
Class<?> testClass = testObject.getClass();
try {
DataSets dataSetsAnnotation = getMethodOrClassLevelAnnotation(DataSets.class, testMethod, testClass);
if (dataSetsAnnotation != null) {
insertDataSets(dataSetsAnnotation, testObject, testMethod);
}
DataSet dataSetAnnotation = getMethodOrClassLevelAnnotation(DataSet.class, testMethod, testClass);
if (dataSetAnnotation != null) {
insertDataSet(dataSetAnnotation, testObject, testMethod);
}
} catch (Exception e) {
throw new UnitilsException("Error inserting test data from DbUnit dataset for method " + testMethod, e);
} finally {
closeJdbcConnection();
}
}
示例4: testInsertRecommendation
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet(DATA_FILENAME_ONE_LESS)
@ExpectedDataSet(DATA_FILENAME_NO_TIME)
public void testInsertRecommendation() {
RecommendationVO<Integer, Integer> recommendation = null;
try {
List<RecommendedItemVO<Integer, Integer>> recommendedItems = new ArrayList<RecommendedItemVO<Integer, Integer>>();
recommendedItems.add(new RecommendedItemVO<Integer, Integer>(
new ItemVO<Integer, Integer>(1, 33, 1), 0.89d, 1l, "x"));
recommendedItems.add(new RecommendedItemVO<Integer, Integer>(
new ItemVO<Integer, Integer>(1, 34, 1), 0.88d, 1l, "x"));
recommendation = new RecommendationVO<Integer, Integer>(1, 3, 1, 1, 1,
1, "a", "b", recommendedItems);
} catch (Exception e) {
fail("caught exception: " + e);
}
assertTrue(recommendation.getId() == null);
recommendationDAO.insertRecommendation(recommendation);
assertThat(recommendation.getId(), is(greaterThan(4)));
assertThat(recommendation.getRecommendedItems().get(0).getId(), is(greaterThan(8)));
assertThat(recommendation.getRecommendedItems().get(1).getId(), is(greaterThan(9)));
}
示例5: testInsertItemAssoc
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet(DATA_FILENAME_ONE_LESS)
@ExpectedDataSet(DATA_FILENAME_NO_CHANGEDATE)
public void testInsertItemAssoc() {
ItemAssocVO<Integer,Integer> itemAssoc = null;
try {
itemAssoc = new ItemAssocVO<Integer,Integer>(1,
new ItemVO<Integer, Integer>(1, 2, 1), 1, 0.1d,
new ItemVO<Integer, Integer>(1, 7, 1), 2, "def", 1, true);
} catch (Exception e) {
fail("caught exception: " + e);
}
assertTrue(itemAssoc.getId() == null);
itemAssocDAO.insertItemAssoc(itemAssoc);
// assertThat(itemAssoc.getId(), is(not(1)));
// assertThat(itemAssoc.getId(), is(not(2)));
// assertThat(itemAssoc.getId(), is(not(3)));
// assertThat(itemAssoc.getId(), is(not(4)));
// assertThat(itemAssoc.getId(), is(not(5)));
}
示例6: testInsertItemAssocActiveNull
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet(DATA_FILENAME_ONE_LESS)
@ExpectedDataSet(DATA_FILENAME_NO_CHANGEDATE)
public void testInsertItemAssocActiveNull() {
ItemAssocVO<Integer,Integer> itemAssoc = null;
try {
itemAssoc = new ItemAssocVO<Integer,Integer>(1,
new ItemVO<Integer, Integer>(1, 2, 1), 1, 0.1d,
new ItemVO<Integer, Integer>(1, 7, 1), 2, "def", 1, null);
} catch (Exception e) {
fail("caught exception: " + e);
}
assertTrue(itemAssoc.getId() == null);
itemAssocDAO.insertItemAssoc(itemAssoc);
// assertThat(itemAssoc.getId(), is(not(1)));
// assertThat(itemAssoc.getId(), is(not(2)));
// assertThat(itemAssoc.getId(), is(not(3)));
// assertThat(itemAssoc.getId(), is(not(4)));
// assertThat(itemAssoc.getId(), is(not(5)));
}
示例7: testInsertAction
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet(DATA_FILENAME_ONE_LESS)
@ExpectedDataSet(DATA_FILENAME_NO_ACTIONTIME)
public void testInsertAction() {
ActionVO<Integer, Integer> action = null;
try {
action = new ActionVO<>(2, 2, "abc5", "127.0.0.1",
new ItemVO<>(2, 1, 1), 1, null, null);
} catch (Exception e) {
fail("caught exception: " + e);
}
assertTrue(action.getId() == null);
actionDAO.insertAction(action, false);
assertThat(action.getId(), is(not(1l)));
assertThat(action.getId(), is(not(2l)));
assertThat(action.getId(), is(not(3l)));
assertThat(action.getId(), is(not(4l)));
assertThat(action.getId(), is(not(5l)));
}
示例8: testGetRankedItemsByActionType
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet(DATA_FILENAME_RANKINGS)
public void testGetRankedItemsByActionType() {
List<RankedItemVO<Integer, Integer>> retList = actionDAO
.getRankedItemsByActionType(1, 1, 1, 500, null, true);
assertEquals(6, retList.size());
retList = actionDAO.getRankedItemsByActionType(1, 2, 1, 500, null, true);
assertEquals(6, retList.size());
retList = actionDAO.getRankedItemsByActionType(1, 3, 1, 500, null, true);
assertEquals(5, retList.size());
retList = actionDAO.getRankedItemsByActionType(1, 4, 1, 500, null, true);
assertEquals(4, retList.size());
retList = actionDAO.getRankedItemsByActionType(1, 1, 2, 500, null, true);
assertEquals(3, retList.size());
// HINT: hardcoded check if lists equal expected lisst (Mantis Issue: #721)
}
示例9: getLogEntries_shouldReturnAllStartedAndEndedLogEntries
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet("/dbunit/pluginContainer/plugin_log+1new_ended.xml")
public void getLogEntries_shouldReturnAllStartedAndEndedLogEntries() {
List<LogEntry> logEntries = logEntryDAO.getLogEntries(0, Integer.MAX_VALUE);
assertThat(logEntries, is(not(nullValue())));
assertThat(logEntries, hasItem(matchesLogEntryWithoutId(
new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(),
date("2011-02-23 15:00:00"), date("2011-02-23 15:10:00"), 1,
waitingGenerator.newConfiguration(),
new WaitingGeneratorStats()))));
assertThat(logEntries, hasItem(matchesLogEntryWithoutId(
new LogEntry(1, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(),
date("2011-02-23 15:20:00"), null, 1, waitingGenerator.newConfiguration(), null))));
assertThat(logEntries, hasItem(matchesLogEntryWithoutId(
new LogEntry(2, waitingGenerator.getId().getUri(), waitingGenerator.getId().getVersion(),
date("2011-02-23 16:00:00"), date("2011-02-23 16:10:00"), 1,
waitingGenerator.newConfiguration(),
new WaitingGeneratorStats()))));
}
示例10: testActivateAndDeactivate
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet("/dbunit/core/dao/itemDaoTest.xml")
public void testActivateAndDeactivate() {
increaseItemId();
Item item;
Item initItem = addDummyItem(0);
itemDAO.activate(TENANT_ID, currentItemId.toString(), initItem.getItemType());
item = itemDAO.get(createRemoteTenant(TENANT_ID), currentItemId.toString(), initItem.getItemType());
Assert.assertTrue(item.isActive());
itemDAO.deactivate(TENANT_ID, currentItemId.toString(), initItem.getItemType());
item = itemDAO.get(createRemoteTenant(TENANT_ID), currentItemId.toString(), initItem.getItemType());
Assert.assertFalse(item.isActive());
itemDAO.activate(TENANT_ID, currentItemId.toString(), initItem.getItemType());
item = itemDAO.get(createRemoteTenant(TENANT_ID), currentItemId.toString(), initItem.getItemType());
Assert.assertTrue(item.isActive());
}
示例11: testCount
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet("/dbunit/core/dao/itemDaoTest.xml")
public void testCount() {
itemDAO.emptyCache();
currentItemId = 1;
Assert.assertEquals((Integer)1, itemDAO.count(TENANT_ID));
Assert.assertEquals((Integer)0, itemDAO.count(TENANT_ID_ALTERNATIVE));
Item item = addDummyItem(0);
item.setTenantId(TENANT_ID_ALTERNATIVE);
addItem(item);
increaseItemId();
item = addDummyItem(1);
Assert.assertEquals((Integer)3, itemDAO.count(TENANT_ID));
Assert.assertEquals((Integer)1, itemDAO.count(TENANT_ID_ALTERNATIVE));
Assert.assertEquals((Integer)3, itemDAO.count(TENANT_ID, ""));
Assert.assertEquals((Integer)1, itemDAO.count(TENANT_ID_ALTERNATIVE, ""));
Assert.assertEquals((Integer)1, itemDAO.count(TENANT_ID, "ITEM ONE"));
}
示例12: testGetHotItems
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet("/dbunit/core/dao/itemDaoTest.xml")
public void testGetHotItems() {
itemDAO.emptyCache();
currentItemId = 2;
Item itemToFind1 = addDummyItem(0);
increaseItemId();
Item itemToFind2 = addDummyItem(0);
currentItemId = 2;
Item itemNTF = createDummyItem(1);
itemNTF.setTenantId(TENANT_ID_ALTERNATIVE);
addItem(itemNTF);
increaseItemId();
itemNTF = createDummyItem(1);
itemNTF.setTenantId(TENANT_ID_ALTERNATIVE);
addItem(itemNTF);
List<Item> itemList = itemDAO.getHotItems(createRemoteTenant(TENANT_ID), 0, 100);
Assert.assertEquals(2, itemList.size());
Assert.assertTrue(isItemInList(itemToFind1, itemList));
}
示例13: testGetItemTypeOfItem
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet("/dbunit/core/dao/itemDaoTest.xml")
public void testGetItemTypeOfItem() {
itemDAO.emptyCache();
currentItemId = 2;
Item item1;
Item item2;
item1 = createDummyItem(0);
increaseItemId();
item2 = createDummyItem(1);
item2.setItemType("ITEM_TYPE_TEST");
addItem(item1);
addItem(item2);
Assert.assertEquals(1, itemDAO.getItemTypeIdOfItem(TENANT_ID, Integer.valueOf(item1.getItemId())));
Assert.assertEquals(2, itemDAO.getItemTypeIdOfItem(TENANT_ID, Integer.valueOf(item2.getItemId())));
}
示例14: getLogEntries_shouldReturnAtMostLimitEntries
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet("/dbunit/pluginContainer/plugin_log+1new_ended.xml")
public void getLogEntries_shouldReturnAtMostLimitEntries() {
List<LogEntry> logEntries = logEntryDAO.getLogEntries(0, 2);
assertThat(logEntries, is(not(nullValue())));
assertThat(logEntries.size(), is(lessThanOrEqualTo(2)));
}
示例15: testFindById
import org.unitils.dbunit.annotation.DataSet; //导入依赖的package包/类
@Test
@DataSet("../datasets/SinglePerson.xml")
public void testFindById() {
Session currentSession = sessionFactory.getCurrentSession();
Person userFromDb = (Person) currentSession.get(Person.class, 1L);
ReflectionAssert.assertLenientEquals(person, userFromDb);
}