Search in sources :

Example 6 with Serializer

use of org.simpleframework.xml.Serializer in project syncany by syncany.

the class TransferSettingsTest method testRestore.

@Test
public void testRestore() throws Exception {
    final String fooTest = "foo-test";
    final String bazTest = "baz";
    final int numberTest = 1234;
    final DummyTransferSettings ts = new DummyTransferSettings();
    final LocalTransferSettings lts = new LocalTransferSettings();
    final InitOperationOptions initOperationOptions = TestConfigUtil.createTestInitOperationOptions("syncanytest");
    final ConfigTO conf = initOperationOptions.getConfigTO();
    File repoDir = ((LocalTransferSettings) initOperationOptions.getConfigTO().getTransferSettings()).getPath();
    File localDir = initOperationOptions.getLocalDir();
    conf.setTransferSettings(ts);
    ts.foo = fooTest;
    ts.baz = bazTest;
    ts.number = numberTest;
    lts.setPath(File.createTempFile("aaa", "bbb"));
    ts.subsettings = lts;
    assertTrue(ts.isValid());
    Serializer serializer = new Persister();
    serializer.write(conf, tmpFile);
    System.out.println(new String(Files.readAllBytes(Paths.get(tmpFile.toURI()))));
    ConfigTO confRestored = ConfigTO.load(tmpFile);
    TransferPlugin plugin = Plugins.get(confRestored.getTransferSettings().getType(), TransferPlugin.class);
    assertNotNull(plugin);
    TransferSettings tsRestored = confRestored.getTransferSettings();
    assertNotNull(tsRestored);
    DummyTransferManager transferManager = plugin.createTransferManager(tsRestored, config);
    assertNotNull(transferManager);
    // Tear down
    FileUtils.deleteDirectory(localDir);
    FileUtils.deleteDirectory(repoDir);
}
Also used : DummyTransferPlugin(org.syncany.plugins.dummy.DummyTransferPlugin) TransferPlugin(org.syncany.plugins.transfer.TransferPlugin) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) InitOperationOptions(org.syncany.operations.init.InitOperationOptions) DummyTransferSettings(org.syncany.plugins.dummy.DummyTransferSettings) DummyTransferManager(org.syncany.plugins.dummy.DummyTransferManager) ConfigTO(org.syncany.config.to.ConfigTO) Persister(org.simpleframework.xml.core.Persister) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) TransferSettings(org.syncany.plugins.transfer.TransferSettings) DummyTransferSettings(org.syncany.plugins.dummy.DummyTransferSettings) File(java.io.File) Serializer(org.simpleframework.xml.Serializer) Test(org.junit.Test)

Example 7 with Serializer

use of org.simpleframework.xml.Serializer in project syncany by syncany.

the class TransferSettingsTest method testDeserializeWrongClass.

@Test(expected = ElementException.class)
public void testDeserializeWrongClass() throws Exception {
    LocalTransferSettings lts = new LocalTransferSettings();
    lts.setPath(tmpFile);
    Serializer serializer = new Persister();
    serializer.write(lts, tmpFile);
    // This shouldn't blow up!
    serializer.read(DummyTransferSettings.class, tmpFile);
}
Also used : LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer) Test(org.junit.Test)

Aggregations

Serializer (org.simpleframework.xml.Serializer)7 Persister (org.simpleframework.xml.core.Persister)7 Test (org.junit.Test)3 ConfigTO (org.syncany.config.to.ConfigTO)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 InitOperationOptions (org.syncany.operations.init.InitOperationOptions)2 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 ConfigException (org.syncany.config.ConfigException)1 CipherException (org.syncany.crypto.CipherException)1 DummyTransferManager (org.syncany.plugins.dummy.DummyTransferManager)1 DummyTransferPlugin (org.syncany.plugins.dummy.DummyTransferPlugin)1 DummyTransferSettings (org.syncany.plugins.dummy.DummyTransferSettings)1 StorageException (org.syncany.plugins.transfer.StorageException)1 TransferPlugin (org.syncany.plugins.transfer.TransferPlugin)1 TransferSettings (org.syncany.plugins.transfer.TransferSettings)1