18 package testsuite.clusterj;
20 import java.util.ArrayList;
21 import java.util.List;
23 import testsuite.clusterj.model.LongvarbinaryPK;
27 protected int NUMBER_OF_INSTANCES = 15;
28 protected List<LongvarbinaryPK> instances =
new ArrayList<LongvarbinaryPK>();
32 createSessionFactory();
39 }
catch (Throwable t) {
63 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
64 byte[] key = getPK(
i);
66 verify(result,
i,
false);
74 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
77 instance.setName(getValue(NUMBER_OF_INSTANCES -
i));
79 verify(instance,
i,
true);
83 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
85 byte[] key = getPK(
i);
87 verify(instance,
i,
true);
94 protected void delete() {
96 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
103 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
105 byte[] key = getPK(
i);
107 errorIfNotEqual(
"Failed to delete instance: " +
i, null, instance);
116 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
118 if (
getDebug()) System.out.println(toString(instance));
119 instances.add(instance);
129 instance.setId(getPK(index));
130 instance.setNumber(index);
131 instance.setName(getValue(index));
137 result.append(
"LongvarbinaryPK[");
138 result.append(toString(instance.getId()));
139 result.append(
"]: ");
140 result.append(instance.getNumber());
141 result.append(
", \"");
142 result.append(instance.getName());
143 result.append(
"\".");
144 return result.toString();
147 protected byte[] getPK(
int index) {
148 return new byte[] {0, (byte)(index/256), (byte)(index%256)};
151 protected String getValue(
int index) {
152 return "Value " +
index;
155 protected void verify(LongvarbinaryPK instance,
int index,
boolean updated) {
156 errorIfNotEqual(
"id failed", toString(getPK(index)), toString(instance.getId()));
157 errorIfNotEqual(
"number failed", index, instance.getNumber());
159 errorIfNotEqual(
"Value failed", getValue(NUMBER_OF_INSTANCES - index), instance.getName());
161 errorIfNotEqual(
"Value failed", getValue(index), instance.getName());
166 private String toString(byte[]
id) {
167 StringBuilder builder =
new StringBuilder();
168 for (
int i = 0;
i <
id.length; ++
i) {
169 builder.append(
String.valueOf(
id[
i]));
172 return builder.toString();