Search in sources :

Example 21 with Persister

use of org.simpleframework.xml.core.Persister in project randomizedtesting by randomizedtesting.

the class TestAntXmlReport method summary.

@Test
public void summary() throws Exception {
    super.executeTarget("antxml-summary");
    Persister p = new Persister();
    File parent = getProject().getBaseDir();
    MavenFailsafeSummaryModel_Local m1 = p.read(MavenFailsafeSummaryModel_Local.class, new File(parent, "ant-xmls2/summary1.xml"));
    assertEquals(255, (int) m1.result);
    assertEquals(5, m1.completed);
    assertEquals(2, m1.skipped);
    assertEquals(1, m1.errors);
    assertEquals(1, m1.failures);
    m1 = p.read(MavenFailsafeSummaryModel_Local.class, new File(parent, "ant-xmls2/summary2.xml"));
    assertEquals(null, m1.result);
    assertEquals(1, m1.completed);
    assertEquals(0, m1.skipped);
    assertEquals(0, m1.errors);
    assertEquals(0, m1.failures);
    m1 = p.read(MavenFailsafeSummaryModel_Local.class, new File(parent, "ant-xmls2/summary3.xml"));
    assertEquals(254, (int) m1.result);
    assertEquals(0, m1.completed);
    assertEquals(0, m1.skipped);
    assertEquals(0, m1.errors);
    assertEquals(0, m1.failures);
}
Also used : Persister(org.simpleframework.xml.core.Persister) File(java.io.File) Test(org.junit.Test)

Example 22 with Persister

use of org.simpleframework.xml.core.Persister 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)

Example 23 with Persister

use of org.simpleframework.xml.core.Persister 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 24 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class TestConfigUtil method createTestLocalConfig.

public static Config createTestLocalConfig(String machineName, TransferSettings connection) throws Exception {
    File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("client-" + machineName, connection));
    tempLocalDir.mkdirs();
    RepoTO repoTO = createRepoTO();
    // Create config TO
    ConfigTO configTO = new ConfigTO();
    configTO.setMachineName(machineName + CipherUtil.createRandomAlphabeticString(20));
    // Get Masterkey
    SaltedSecretKey masterKey = getMasterKey();
    configTO.setMasterKey(masterKey);
    LocalTransferSettings localConnection = (LocalTransferSettings) connection;
    // Create connection TO
    Map<String, String> localConnectionSettings = new HashMap<String, String>();
    localConnectionSettings.put("path", localConnection.getPath().getAbsolutePath());
    configTO.setTransferSettings(connection);
    // Create
    Config config = new Config(tempLocalDir, configTO, repoTO);
    config.setConnection(connection);
    config.getAppDir().mkdirs();
    config.getCacheDir().mkdirs();
    config.getDatabaseDir().mkdirs();
    config.getLogDir().mkdirs();
    config.getStateDir().mkdirs();
    // Write to config folder (required for some tests)
    new Persister().write(configTO, new File(config.getAppDir() + "/" + Config.FILE_CONFIG));
    new Persister().write(repoTO, new File(config.getAppDir() + "/" + Config.FILE_REPO));
    return config;
}
Also used : SaltedSecretKey(org.syncany.crypto.SaltedSecretKey) LocalTransferSettings(org.syncany.plugins.local.LocalTransferSettings) UnreliableLocalTransferSettings(org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings) HashMap(java.util.HashMap) UserConfig(org.syncany.config.UserConfig) Config(org.syncany.config.Config) ConfigTO(org.syncany.config.to.ConfigTO) Persister(org.simpleframework.xml.core.Persister) RepoTO(org.syncany.config.to.RepoTO) File(java.io.File)

Example 25 with Persister

use of org.simpleframework.xml.core.Persister in project syncany by syncany.

the class ApplicationLink method shortenLink.

private String shortenLink(String applicationLink) {
    if (!LINK_PATTERN.matcher(applicationLink).matches()) {
        throw new IllegalArgumentException("Invalid link provided, must start with syncany:// and match link pattern.");
    }
    try {
        logger.log(Level.INFO, "Shortining link " + applicationLink + " via " + LINK_SHORT_API_URL_ADD + " ...");
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("l", applicationLink));
        HttpPost postMethod = new HttpPost(LINK_SHORT_API_URL_ADD);
        postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse httpResponse = createHttpClient().execute(postMethod);
        ApplicationLinkShortenerResponse shortenerResponse = new Persister().read(ApplicationLinkShortenerResponse.class, httpResponse.getEntity().getContent());
        return String.format(LINK_SHORT_URL_FORMAT, shortenerResponse.getShortLinkId());
    } catch (Exception e) {
        logger.log(Level.WARNING, "Cannot shorten URL. Using long URL.", e);
        return applicationLink;
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Persister(org.simpleframework.xml.core.Persister) StorageException(org.syncany.plugins.transfer.StorageException) IOException(java.io.IOException)

Aggregations

Persister (org.simpleframework.xml.core.Persister)31 File (java.io.File)12 Test (org.junit.Test)11 Serializer (org.simpleframework.xml.Serializer)8 StorageException (org.syncany.plugins.transfer.StorageException)8 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)6 ConfigTO (org.syncany.config.to.ConfigTO)5 MultichunkRemoteFile (org.syncany.plugins.transfer.files.MultichunkRemoteFile)5 TransactionTO (org.syncany.plugins.transfer.to.TransactionTO)5 IOException (java.io.IOException)4 ConfigException (org.syncany.config.ConfigException)4 TestClient (org.syncany.tests.util.TestClient)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 LocalTransferSettings (org.syncany.plugins.local.LocalTransferSettings)3 Subscribe (com.google.common.eventbus.Subscribe)2 User (com.lonepulse.robozombie.model.User)2 FileOutputStream (java.io.FileOutputStream)2 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)2 BuildException (org.apache.tools.ant.BuildException)2