19 package testsuite.clusterj;
21 import java.util.ArrayList;
22 import java.util.List;
23 import testsuite.clusterj.model.Employee;
27 private static final int NUMBER_TO_INSERT = 4;
31 createSessionFactory();
33 createEmployeeInstances(NUMBER_TO_INSERT);
39 List<Employee> insertedEmployees =
new ArrayList<Employee>();
40 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
43 insertedEmployees.add(employees.get(
i));
51 public void testSave() {
53 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
57 error(
"Employee " +
i +
" should not exist.");
60 e.setAge(NUMBER_TO_INSERT -
i);
64 error(
"Employee " +
i +
" should exist.");
67 e.setAge(NUMBER_TO_INSERT -
i);
77 for (
int i = 0;
i < NUMBER_TO_INSERT; ++
i) {
80 error(
"Failed save: employee " +
i +
" does not exist.");
83 int expected = NUMBER_TO_INSERT -
i;
84 int actual = e.getAge();
85 if (expected != actual) {
86 error(
"Failed save: for employee " + i
87 +
" expected age " + expected
88 +
" actual age " + actual);
96 public void testSaveAll() {
100 for (
int i = 0; i < NUMBER_TO_INSERT; ++
i) {
104 error(
"Employee " + i +
" should not exist.");
107 e.setAge(NUMBER_TO_INSERT - i);
111 error(
"Employee " + i +
" should exist.");
113 e = employees.get(i);
114 e.setAge(NUMBER_TO_INSERT - i);
118 expectedEmployees.add(e);
122 if (savedEmployees.size() != NUMBER_TO_INSERT) {
123 error(
"Wrong size for saved employees. Expected: " + NUMBER_TO_INSERT
124 +
" actual: " + savedEmployees.size());
126 for (
int i = 0; i < NUMBER_TO_INSERT; ++
i) {
127 Employee e = expectedEmployees.get(i);
129 Employee saved = savedEmployees.get(i);
131 error (
"Failed saveAll: employee " + i +
" did not match savedEmployees. "
132 +
"Expected: " + e.toString() +
" hashcode: " + e.hashCode()
133 +
" actual: " + saved.toString() +
" hashcode: " + saved.hashCode());
140 for (
int i = 0; i < NUMBER_TO_INSERT; ++
i) {
143 error(
"Failed saveAll: employee " + i +
" does not exist.");
146 int expected = NUMBER_TO_INSERT -
i;
147 int actual = e.getAge();
148 if (expected != actual) {
149 error(
"Failed saveAll: for employee " + i
150 +
" expected age " + expected
151 +
" actual age " + actual);