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);
}
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);
}
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);
}
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;
}
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;
}
}
Aggregations