This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
/
DataSetBuilderTest.java
134 lines (107 loc) · 4.31 KB
/
DataSetBuilderTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package org.dbunit.dataset.builder;
import static org.junit.Assert.*;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.ITable;
import org.junit.Test;
public class DataSetBuilderTest {
@Test
public void ignoringCaseByDefault() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
builder.ensureTableIsPresent("PeRsoN");
assertTrue(builder.containsTable("Person"));
}
@Test
public void notIgnoringCaseWhenSpecified() throws Exception {
DataSetBuilder builder = new DataSetBuilder(false);
builder.ensureTableIsPresent("PeRsoN");
assertFalse(builder.containsTable("Person"));
assertTrue(builder.containsTable("PeRsoN"));
}
@Test
public void ensuringPresenceOfExistingTableMakesNoHarm() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
builder.newRow("person").add();
builder.ensureTableIsPresent("PeRsoN");
assertTrue(builder.containsTable("Person"));
}
@Test
public void tablesAreKeptInOrder() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
builder.newRow("PERSON").add();
builder.newRow("ADDRESS").add();
builder.newRow("_TABLE_").add();
IDataSet dataSet = builder.build();
assertArrayEquals(new String[]{"PERSON", "ADDRESS", "_TABLE_"}, dataSet.getTableNames());
}
@Test
public void addsDataForSingleRow() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
builder.newRow("PERSON").with("NAME", "Bob").with("AGE", 18).add();
IDataSet dataSet = builder.build();
ITable table = dataSet.getTable("PERSON");
assertEquals(1, table.getRowCount());
assertEquals("Bob", table.getValue(0, "NAME"));
assertEquals(18, table.getValue(0, "AGE"));
}
@Test
public void addsDataWithColumnSpec() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
ColumnSpec<String> name = ColumnSpec.newColumn("NAME");
ColumnSpec<Integer> age = ColumnSpec.newColumn("AGE");
builder.newRow("PERSON").with(name, "Bob").with(age, 18).add();
IDataSet dataSet = builder.build();
ITable table = dataSet.getTable("PERSON");
assertEquals(1, table.getRowCount());
assertEquals("Bob", table.getValue(0, "NAME"));
assertEquals(18, table.getValue(0, "AGE"));
}
@Test
public void addsDataForMultipleRowsOfDifferentTables() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
builder.newRow("PERSON").with("NAME", "Bob").with("AGE", 18).add();
builder.newRow("ADDRESS").with("STREET", "Main Street").with("NUMBER", 42).add();
builder.newRow("PERSON").with("NAME", "Alice").with("AGE", 23).add();
IDataSet dataSet = builder.build();
ITable table = dataSet.getTable("PERSON");
assertEquals(2, table.getRowCount());
assertEquals("Bob", table.getValue(0, "NAME"));
assertEquals(18, table.getValue(0, "AGE"));
assertEquals("Alice", table.getValue(1, "NAME"));
assertEquals(23, table.getValue(1, "AGE"));
table = dataSet.getTable("ADDRESS");
assertEquals(1, table.getRowCount());
assertEquals("Main Street", table.getValue(0, "STREET"));
assertEquals(42, table.getValue(0, "NUMBER"));
}
@Test
public void addsNewColumnsOnTheFly() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
builder.newRow("PERSON").with("NAME", "Bob").add();
builder.newRow("PERSON").with("AGE", 18).add();
IDataSet dataSet = builder.build();
ITable table = dataSet.getTable("PERSON");
assertEquals(2, table.getRowCount());
assertEquals("Bob", table.getValue(0, "NAME"));
assertNull(table.getValue(0, "AGE"));
assertNull(table.getValue(1, "NAME"));
assertEquals(18, table.getValue(1, "AGE"));
}
@Test
public void addDataSet() throws Exception {
DataSetBuilder builder = new DataSetBuilder();
builder.newRow("PERSON").with("NAME", "Bob").with("AGE", 18).add();
IDataSet dataSet = builder.build();
ITable table = dataSet.getTable("PERSON");
assertEquals(1, table.getRowCount());
builder = new DataSetBuilder();
builder.newRow("PERSON").with("NAME", "John").with("AGE", 19).add();
builder.addDataSet(dataSet);
IDataSet dataSet2 = builder.build();
ITable table2 = dataSet2.getTable("PERSON");
assertEquals(2, table2.getRowCount());
assertEquals("John", table2.getValue(0, "NAME"));
assertEquals(19, table2.getValue(0, "AGE"));
assertEquals("Bob", table2.getValue(1, "NAME"));
assertEquals(18, table2.getValue(1, "AGE"));
}
}