.createDataAccessSession();
/*
* create object to persist
*/
final BobForExport bobForExport = createObjectForExport();
/*
* persist
*/
dataAccessSession.open();
dataAccessSession.setObject("bob", bobForExport);
dataAccessSession.close(EnumFilePersistenceCloseAction.SAVE);
assertEquals("", 'a', bobForExport.getCharValue());
/*
* export
*/
filePersistence.xmlExport(RUNTIME, RUNTIME + "/tmp", true);
assertEquals("", 'a', bobForExport.getCharValue());
/*
* Forbidden import
*/
try {
filePersistence.xmlImport(RUNTIME, true);
fail("must fail");// NOPMD
} catch (final FilePersistenceException exception) {// NOPMD
// expected
if (!"have stored object, not empty".equals(exception.getMessage())) {
// failure
throw exception;
}
}
filePersistence.close();
assertEquals("", 'a', bobForExport.getCharValue());
/*
* test import
*/
// filePersistence = new FilePersistence(1, null, RUNTIME, true, false);
final FilePersistenceBuilder builder = new FilePersistenceBuilder();
builder.setPathName(TestConstant.getWinRamDiskRuntimeDir());
builder.setFileAccessMode(EnumFileAccessMode.MAPPED_RANDOM_FILE_ACCESS);
builder.setMaxBufferSize(8 * 1024);
builder.setMaxNumberOfBuffer(32);
builder.setProxyMode(true);
builder.setRemoveFiles(true);
builder.setGarbageManagement(false);
builder.setCrashSafeMode(false);
filePersistence = builder.build();
filePersistence.setSubstitutionOfJavaUtilCollection(true);
filePersistence.storedMutableEnum(EnumForTest.class);
HelperFileUtil.getInstance().copyFile(new File("runtime/export.xml"),
new File("runtime/tmp/export.xml"));
/* import */
filePersistence.xmlImport(RUNTIME, true);
assertEquals("", 'a', bobForExport.getCharValue());
/* do an export to visit all object graph in store */
filePersistence.xmlExport("runtime2", "runtime2", false);
assertEquals("", 'a', bobForExport.getCharValue());
dataAccessSession = filePersistence.createDataAccessSession();
dataAccessSession.open();
final BobForExport bobForExportRead = (BobForExport) dataAccessSession
.getObject("bob");
assertEquals("", 'a', bobForExport.getCharValue());
assertEquals("", 'a', bobForExportRead.getCharValue());
assertEquals("bad read value", bobForExport.toString(),
bobForExportRead.toString());
assertEquals("bad read value", bobForExport, bobForExportRead);
dataAccessSession.close(EnumFilePersistenceCloseAction.DO_NOT_SAVE);
filePersistence.close();
}