use of org.simpleframework.xml.core.Persister in project syncany by syncany.
the class UploadInterruptedTest method testUnreliableUpload_Test3_FailsAtDatabaseFile.
@Test
public void testUnreliableUpload_Test3_FailsAtDatabaseFile() throws Exception {
/*
* This test fails when trying to upload the first database file, but succeeds on retry
*
* 1. upload(action-up-987, actions/action-up-987)
* 2. upload(transaction-123, transactions/transaction-123)
* 3. upload(multichunk-1, temp-1)
* 5. upload(database-123, temp-2) <<< FAILS HERE
* 6. move(temp-1, multichunks/multichunk-1)
* 8. move(temp-2, databases/database-123)
*/
// Setup
UnreliableLocalTransferSettings testConnection = TestConfigUtil.createTestUnreliableLocalConnection(Arrays.asList(new String[] { "rel=[456].+upload.+database" }));
TestClient clientA = new TestClient("A", testConnection);
// 1. First upload fails
clientA.createNewFile("A-original", 10);
boolean upFailed = false;
try {
clientA.up();
} catch (StorageException e) {
upFailed = true;
logger.log(Level.INFO, e.getMessage());
}
assertTrue(upFailed);
assertEquals(0, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/transactions/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/temporary/").listFiles().length);
File transactionFile = new File(testConnection.getPath() + "/transactions/").listFiles()[0];
TransactionTO transactionTO = new Persister().read(TransactionTO.class, transactionFile);
assertEquals(2, transactionTO.getActions().size());
assertTrue(transactionTO.getActions().get(0).getRemoteFile().getName().contains("multichunk-"));
assertTrue(transactionTO.getActions().get(1).getRemoteFile().getName().contains("database-"));
// 2. Second try succeeds and must clean up the transactions
clientA.up();
assertEquals(1, new File(testConnection.getPath() + "/databases/").listFiles().length);
assertEquals(1, new File(testConnection.getPath() + "/multichunks/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/actions/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/transactions/").listFiles().length);
assertEquals(0, new File(testConnection.getPath() + "/temporary/").listFiles().length);
// Tear down
clientA.deleteTestData();
}
use of org.simpleframework.xml.core.Persister in project project1-ICS372 by sandip-rai.
the class XmlHandler method readXMLFile.
/**
* Read XML file.
*
* @param path
* the file
* @return true, if successful
* @throws Exception
*/
public boolean readXMLFile(String path) throws Exception {
// Decide how to handle unknown patients and readings based on system settings
boolean addPatients = clinicalTrial.getSettings().xmlAddUnknownPatients();
boolean addReadings = clinicalTrial.getSettings().xmlAddUnknownReadings();
File file = new File(path);
Serializer serializer = new Persister();
ReadingSet readingSet = serializer.read(ReadingSet.class, file);
// Convert from a reading set to an ArrayList of FileReadings so that the data
// can be processed
ArrayList<FileReading> fileReadings = getFileReading(readingSet);
// Attempt to add the clinics to the trial
addClinicToTrial(fileReadings);
// the trial
if (addPatients) {
addPatientsToTrial(fileReadings, addReadings);
}
// Add readings from input file to Patient's readings ArrayList
AddReadingToPatient(fileReadings);
return true;
}
use of org.simpleframework.xml.core.Persister in project project1-ICS372 by sandip-rai.
the class XmlHandler method readXMLFile.
/**
* Read XML file.
*
* @param file
* the file
* @return true, if successful
* @throws Exception
*/
public boolean readXMLFile(String path) throws Exception {
// Decide how to handle unknown patients and readings based on system settings
boolean addPatients = clinicalTrial.getSettings().xmlAddUnknownPatients();
boolean addReadings = clinicalTrial.getSettings().xmlAddUnknownReadings();
try {
File file = new File(path);
Serializer serializer = new Persister();
ReadingSet readingSet = serializer.read(ReadingSet.class, file);
// Convert from a reading set to an ArrayList of FileReadings so that the data
// can be processed
ArrayList<FileReading> fileReadings = getFileReading(readingSet);
// Attempt to add the clinics to the trial
addClinicToTrial(fileReadings);
// the trial
if (addPatients) {
addPatientsToTrial(fileReadings, addReadings);
}
// Add readings from input file to Patient's readings ArrayList
AddReadingToPatient(fileReadings);
return true;
} catch (JAXBException e) {
e.printStackTrace();
}
return false;
}
use of org.simpleframework.xml.core.Persister in project applause by applause.
the class JobByIdProvider method extractItem.
protected JobOffer extractItem(Reader reader) throws Exception {
Serializer serializer = new Persister();
Jobs root = serializer.read(Jobs.class, reader);
return root.getJobOffer();
}
use of org.simpleframework.xml.core.Persister in project applause by applause.
the class CareerDataProvider method extractItem.
protected Career extractItem(Reader reader) throws Exception {
Serializer serializer = new Persister();
Data root = serializer.read(Data.class, reader);
return root.getCareer();
}
Aggregations