FilePersistenceNotSerializableException,
FilePersistenceClassNotFoundException,
FilePersistenceDataCorruptedException, ProxyException,
FilePersistenceTooBigForSerializationException {
IFilePersistence filePersistence = createFilePersistence();
IDataAccessSession dataAccessSession = filePersistence
.createDataAccessSession();
dataAccessSession.open();
final Holder writeByteHolder = new Holder();
final Holder writeShortHolder = new Holder();
final Holder writeIntegerHolder = new Holder();
final Holder writeLongHolder = new Holder();
final Holder writeFloatHolder = new Holder();
final Holder writeDoubleHolder = new Holder();
final Holder writeBooleanHolder = new Holder();
final Holder writeCharacterHolder = new Holder();
/*
* use of new Integer(0) is important for the test, even if good
* practice said to use Integer.valueOf. For this test we need to manage
* two instance of integer with the same value.
*/
writeByteHolder.setObject1(new Byte((byte) 0));// NOPMD must be new for
// the test
writeByteHolder.setObject2(new Byte((byte) 0));// NOPMD must be new for
// the test
writeShortHolder.setObject1(new Short((short) 0));// NOPMD must be new
// for the test
writeShortHolder.setObject2(new Short((short) 0));// NOPMD must be new
// for the test
writeIntegerHolder.setObject1(new Integer(0));// NOPMD must be new for
// the test
writeIntegerHolder.setObject2(new Integer(0));// NOPMD must be new for
// the test
writeLongHolder.setObject1(new Long((short) 0));// NOPMD must be new for
// the test
writeLongHolder.setObject2(new Long((short) 0));// NOPMD must be new for
// the test
writeFloatHolder.setObject1(new Float(0.0));// NOPMD must be new for the
// test
writeFloatHolder.setObject2(new Float(0.0));// NOPMD must be new for the
// test
writeDoubleHolder.setObject1(new Double(0.0));// NOPMD must be new for
// the test
writeDoubleHolder.setObject2(new Double(0.0));// NOPMD must be new for
// the test
writeBooleanHolder.setObject1(new Boolean(false));// NOPMD must be new
// for the test
writeBooleanHolder.setObject2(new Boolean(false));// NOPMD must be new
// for the test
writeCharacterHolder.setObject1(new Character('a'));// NOPMD must be new
// for the test
writeCharacterHolder.setObject2(new Character('a'));// NOPMD must be new
// for the test
dataAccessSession.setObject("byte", writeByteHolder);
dataAccessSession.setObject("short", writeShortHolder);
dataAccessSession.setObject("integer", writeIntegerHolder);
dataAccessSession.setObject("long", writeLongHolder);
dataAccessSession.setObject("float", writeFloatHolder);
dataAccessSession.setObject("double", writeDoubleHolder);
dataAccessSession.setObject("boolean", writeBooleanHolder);
dataAccessSession.setObject("character", writeCharacterHolder);
dataAccessSession.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
filePersistence.close();
filePersistence = createFilePersistence();
dataAccessSession = filePersistence.createDataAccessSession();
dataAccessSession.open();
final Holder readByteHolder = (Holder) dataAccessSession
.getObject("byte");
final Holder readShortHolder = (Holder) dataAccessSession
.getObject("short");
final Holder readIntegerHolder = (Holder) dataAccessSession
.getObject("integer");
final Holder readLongHolder = (Holder) dataAccessSession
.getObject("long");
final Holder readFloatHolder = (Holder) dataAccessSession
.getObject("float");
final Holder readDoubleHolder = (Holder) dataAccessSession
.getObject("double");
final Holder readBooleanHolder = (Holder) dataAccessSession
.getObject("boolean");
final Holder readCharacterHolder = (Holder) dataAccessSession
.getObject("character");
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readByteHolder));
assertNotSame(MUST_NOT_BE_SAME, writeByteHolder, readByteHolder);
Object object1 = readByteHolder.getObject1();
assertEquals(BAD_VALUE, Byte.valueOf((byte) 0), object1);
Object object2 = readByteHolder.getObject2();
assertEquals(BAD_VALUE, Byte.valueOf((byte) 0), object2);
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readShortHolder));
assertNotSame(MUST_NOT_BE_SAME, writeShortHolder, readShortHolder);
object1 = readShortHolder.getObject1();
assertEquals(BAD_VALUE, Short.valueOf((short) 0), object1);// NOPMD
object2 = readShortHolder.getObject2();
assertEquals(BAD_VALUE, Short.valueOf((short) 0), object2);// NOPMD
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readIntegerHolder));
assertNotSame(MUST_NOT_BE_SAME, writeIntegerHolder, readIntegerHolder);
object1 = readIntegerHolder.getObject1();
assertEquals(BAD_VALUE, Integer.valueOf(0), object1);
object2 = readIntegerHolder.getObject2();
assertEquals(BAD_VALUE, Integer.valueOf(0), object2);
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readLongHolder));
assertNotSame(MUST_NOT_BE_SAME, writeLongHolder, readLongHolder);
object1 = readLongHolder.getObject1();
assertEquals(BAD_VALUE, Long.valueOf(0), object1);
object2 = readLongHolder.getObject2();
assertEquals(BAD_VALUE, Long.valueOf(0), object2);
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readFloatHolder));
assertNotSame(MUST_NOT_BE_SAME, writeFloatHolder, readFloatHolder);
object1 = readFloatHolder.getObject1();
assertEquals(BAD_VALUE, Float.valueOf((float) 0.0), object1);
object2 = readFloatHolder.getObject2();
assertEquals(BAD_VALUE, Float.valueOf((float) 0.0), object2);
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readDoubleHolder));
assertNotSame(MUST_NOT_BE_SAME, writeDoubleHolder, readDoubleHolder);
object1 = readDoubleHolder.getObject1();
assertEquals(BAD_VALUE, Double.valueOf(0.0), object1);
object2 = readDoubleHolder.getObject2();
assertEquals(BAD_VALUE, Double.valueOf(0.0), object2);
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readBooleanHolder));
assertNotSame(MUST_NOT_BE_SAME, writeBooleanHolder, readBooleanHolder);
object1 = readBooleanHolder.getObject1();
assertEquals(BAD_VALUE, Boolean.FALSE, object1);
object2 = readBooleanHolder.getObject2();
assertEquals(BAD_VALUE, Boolean.FALSE, object2);
assertTrue(MUST_BE_A_PROXY,
ProxyManager2.isProxyOrEnhanced(readCharacterHolder));
assertNotSame(MUST_NOT_BE_SAME, writeCharacterHolder,
readCharacterHolder);
object1 = readCharacterHolder.getObject1();
assertEquals(BAD_VALUE, Character.valueOf('a'), object1);
object2 = readCharacterHolder.getObject2();
assertEquals(BAD_VALUE, Character.valueOf('a'), object2);
dataAccessSession.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
filePersistence.close();
}