Search in sources :

Example 1 with URIParcel

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();
    }
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) FileWriter(java.io.FileWriter) Properties(java.util.Properties) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 2 with URIParcel

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());
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 3 with URIParcel

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);
}
Also used : HashMap(java.util.HashMap) URIParcel(com.disney.uriparcel.URIParcel) SecretKeySpec(javax.crypto.spec.SecretKeySpec) KeyStore(java.security.KeyStore) URI(java.net.URI) Key(java.security.Key) Test(org.junit.Test)

Example 4 with URIParcel

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());
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) URI(java.net.URI) Test(org.junit.Test)

Example 5 with URIParcel

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);
}
Also used : URIParcel(com.disney.uriparcel.URIParcel) URI(java.net.URI) MemoryPayload(com.disney.uriparcel.MemoryPayload) Test(org.junit.Test)

Aggregations

URIParcel (com.disney.uriparcel.URIParcel)24 URI (java.net.URI)18 Test (org.junit.Test)17 HashMap (java.util.HashMap)11 File (java.io.File)8 KeyStore (java.security.KeyStore)8 KeyStoreKeyChainImpl (com.disney.http.auth.keychain.KeyStoreKeyChainImpl)7 KeyChainKeyLoader (com.disney.http.auth.client.keyloader.KeyChainKeyLoader)5 KeyPair (java.security.KeyPair)5 Date (java.util.Date)5 KeyChain (com.disney.http.auth.keychain.KeyChain)4 Key (java.security.Key)4 KeyPairGenerator (java.security.KeyPairGenerator)4 KeyObjectKeyLoader (com.disney.http.auth.client.keyloader.KeyObjectKeyLoader)3 HttpSignatureSigner (com.disney.http.auth.client.signer.HttpSignatureSigner)3 URL (java.net.URL)3 PublicKey (java.security.PublicKey)3 Map (java.util.Map)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 MemoryPayload (com.disney.uriparcel.MemoryPayload)2