use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestParcels method testPropsFileParcel.
@Test
public void testPropsFileParcel() throws Exception {
File myMapFile = File.createTempFile("testMapParcel", ".json");
try {
FileWriter fw = new FileWriter(myMapFile);
try {
fw.write("a=1\nb=foo\ncom.abc.def=xyz mno");
} finally {
fw.close();
}
URI myUri = myMapFile.toURI();
URIParcel<Properties> myParcel = new URIParcel<Properties>(Properties.class, myUri);
Properties result = myParcel.call();
// System.out.println("Got "+result);
Properties compareTo = new Properties();
compareTo.put("a", "1");
compareTo.put("b", "foo");
compareTo.put("com.abc.def", "xyz mno");
Assert.assertEquals(compareTo, result);
} finally {
myMapFile.delete();
}
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestParcels method testXml.
@Test
public void testXml() throws Exception {
String doc = "<a><b>123</b><c>456</c></a>";
String lmod = wiremock.org.apache.http.client.utils.DateUtils.formatDate(new Date());
stubFor(get(urlEqualTo("/sample.xml")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", lmod).withBody(doc)));
URIParcel<Document> myDoc = new URIParcel<Document>(Document.class, new URI("http://localhost:28187/sample.xml"));
Element rootElem = myDoc.call().getDocumentElement();
Assert.assertEquals(2, rootElem.getChildNodes().getLength());
Assert.assertEquals("123", rootElem.getChildNodes().item(0).getTextContent());
Assert.assertEquals("456", rootElem.getChildNodes().item(1).getTextContent());
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestParcels method testMem.
@Test
public void testMem() throws Exception {
String password = "sled";
SecretKeySpec secretKey = new SecretKeySpec("rosebud".getBytes(), "DES");
KeyStore orig = KeyStore.getInstance("JCEKS");
orig.load(null);
orig.setKeyEntry("kane", secretKey, password.toCharArray(), null);
// MemoryPayload payload = MemoryPayload.serialize(orig,password.toCharArray());
// MemoryContext.put(keystoreURI, payload);
Map<String, Object> config = new HashMap<>();
config.put(KeyStoreValueHandler.KEYSTORE_TYPE, "JCEKS");
config.put(KeyStoreValueHandler.KEYSTORE_PASSWORD, password);
URI keystoreURI = new URI("mem:/user/citizen.jceks");
URIParcel<KeyStore> myParcel = new URIParcel<KeyStore>(KeyStore.class, keystoreURI, config);
myParcel.put(orig);
// now dereference
myParcel = new URIParcel<KeyStore>(KeyStore.class, keystoreURI, config);
KeyStore result = myParcel.call();
Key rkey = result.getKey("kane", password.toCharArray());
Assert.assertEquals(secretKey, rkey);
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestParcels method testClasspathObject.
@Test
public void testClasspathObject() throws Exception {
URI uri = new URI("classpath:someData.txt");
URIParcel<String> parcel = new URIParcel<String>(String.class, uri);
Assert.assertEquals("This is some really good data", parcel.call());
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestParcels method testString.
@Test
public void testString() throws Exception {
String val = "TEN FOUR OK \u201c";
URI uri = new URI("mem:stringTest");
MemoryContext.put(uri, new MemoryPayload(val.getBytes("UTF-8"), "text/plain;charset=UTF-8"));
URIParcel<String> parcel = new URIParcel<String>(String.class, uri);
String rval = parcel.call();
Assert.assertFalse(rval == val);
Assert.assertEquals(rval, val);
}
Aggregations