Search in sources :

Example 16 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 17 with Persister

use of org.simpleframework.xml.core.Persister in project RoboZombie by sahan.

the class DeserializerEndpointTest method testParseXml.

/**
	 * <p>Test for {@link Deserializers#XML}.
	 * 
	 * @throws Exception
	 * 			if the test terminated with an error
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testParseXml() throws Exception {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/xml";
    User user = new User(1, "Shiro", "Wretched-Egg", 17, true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Persister().write(user, baos);
    stubFor(get(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200).withBody(baos.toString())));
    User deserializedUser = deserializerEndpoint.deserializeXml();
    verify(getRequestedFor(urlEqualTo(subpath)));
    assertEquals(user.getId(), deserializedUser.getId());
    assertEquals(user.getFirstName(), deserializedUser.getFirstName());
    assertEquals(user.getLastName(), deserializedUser.getLastName());
    assertEquals(user.getAge(), deserializedUser.getAge());
    assertEquals(user.isImmortal(), deserializedUser.isImmortal());
}
Also used : User(com.lonepulse.robozombie.model.User) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Persister(org.simpleframework.xml.core.Persister) Test(org.junit.Test)

Example 18 with Persister

use of org.simpleframework.xml.core.Persister in project RoboZombie by sahan.

the class SerializerEndpointTest method testSerializeXml.

/**
	 * <p>Test for {@link Serializers#XML}.</p>
	 * 
	 * @since 1.3.0
	 */
@Test
public final void testSerializeXml() throws Exception {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    String subpath = "/xml";
    User user = new User(1, "Shiro", "Wretched-Egg", 17, true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Persister().write(user, baos);
    stubFor(put(urlEqualTo(subpath)).willReturn(aResponse().withStatus(200)));
    serializerEndpoint.serializeXml(user);
    verify(putRequestedFor(urlEqualTo(subpath)).withRequestBody(equalTo(baos.toString())));
}
Also used : User(com.lonepulse.robozombie.model.User) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Persister(org.simpleframework.xml.core.Persister) Test(org.junit.Test)

Example 19 with Persister

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

the class WatchRunner method start.

public void start() {
    watchThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                logger.log(Level.INFO, "STARTING watch at" + config.getLocalDir());
                watchOperationResult = null;
                // Write port to portFile
                File portFile = config.getPortFile();
                portFile.createNewFile();
                portFile.deleteOnExit();
                new Persister().write(portTO, portFile);
                // Start operation (blocks!)
                watchOperationResult = watchOperation.execute();
                logger.log(Level.INFO, "STOPPED watch at " + config.getLocalDir());
            } catch (Exception e) {
                logger.log(Level.SEVERE, "ERROR while running watch at " + config.getLocalDir(), e);
            }
        }
    }, "WR/" + config.getLocalDir().getName());
    watchThread.start();
}
Also used : Persister(org.simpleframework.xml.core.Persister) File(java.io.File) ConfigException(org.syncany.config.ConfigException)

Example 20 with Persister

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

the class ConfigTO method load.

public static ConfigTO load(File file) throws ConfigException {
    try {
        Registry registry = new Registry();
        Strategy strategy = new RegistryStrategy(registry);
        registry.bind(SaltedSecretKey.class, new SaltedSecretKeyConverter());
        registry.bind(String.class, new EncryptedTransferSettingsConverter());
        return new Persister(strategy).read(ConfigTO.class, file);
    } catch (ClassNotFoundException ex) {
        // Ugly hack to catch common case of non-existing plugin
        String message = ex.getMessage();
        if (!message.startsWith("org.syncany.plugins.")) {
            // Apparently there are other ClassNotFoundExceptions possible.
            throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
        }
        message = message.replaceFirst("org.syncany.plugins.", "");
        message = message.replaceAll("\\..*", "");
        throw new ConfigException("Is the " + message + " plugin installed?");
    } catch (Exception ex) {
        throw new ConfigException("Config file does not exist or is invalid: " + file, ex);
    }
}
Also used : SaltedSecretKeyConverter(org.syncany.crypto.SaltedSecretKeyConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) ConfigException(org.syncany.config.ConfigException) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) EncryptedTransferSettingsConverter(org.syncany.plugins.transfer.EncryptedTransferSettingsConverter) ConfigException(org.syncany.config.ConfigException)

Aggregations

Persister (org.simpleframework.xml.core.Persister)30 File (java.io.File)11 Test (org.junit.Test)11 StorageException (org.syncany.plugins.transfer.StorageException)8 Serializer (org.simpleframework.xml.Serializer)7 UnreliableLocalTransferSettings (org.syncany.plugins.unreliable_local.UnreliableLocalTransferSettings)6 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 ConfigTO (org.syncany.config.to.ConfigTO)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