use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestJsonParcels method testSerializedHttpCustomClass.
@Test
public void testSerializedHttpCustomClass() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
GarbageTruck gt = new GarbageTruck();
gt.setCapacity(120);
gt.setUsage(90);
oos.writeObject(gt);
oos.flush();
byte[] content = baos.toByteArray();
String lmod = wiremock.org.apache.http.client.utils.DateUtils.formatDate(new Date());
stubFor(get(urlEqualTo("/sample.ser")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", lmod).withBody(content)));
URIParcel<GarbageTruck> myDoc = new URIParcel<GarbageTruck>(GarbageTruck.class, new URI("http://localhost:28187/sample.ser"));
GarbageTruck received = myDoc.call();
Assert.assertEquals(gt.getCapacity(), received.getCapacity());
Assert.assertEquals(gt.getUsage(), received.getUsage());
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestJsonParcels method testJsonHttpCustomClass.
@Test
public void testJsonHttpCustomClass() throws Exception {
Gson gson = new Gson();
GarbageTruck gt = new GarbageTruck();
gt.setCapacity(100);
gt.setUsage(50);
String doc = gson.toJson(gt);
String lmod = wiremock.org.apache.http.client.utils.DateUtils.formatDate(new Date());
stubFor(get(urlEqualTo("/sample.json")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", lmod).withBody(doc)));
URIParcel<GarbageTruck> myDoc = new URIParcel<GarbageTruck>(GarbageTruck.class, new URI("http://localhost:28187/sample.json"));
GarbageTruck received = myDoc.call();
Assert.assertEquals(gt.getCapacity(), received.getCapacity());
Assert.assertEquals(gt.getUsage(), received.getUsage());
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestKeys method testCertificate.
@Test
public void testCertificate() throws Exception {
URI keyLoc = new URI("mem:myCertificate");
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(2048);
KeyPair keyPair = generator.generateKeyPair();
X509v3CertificateBuilder certBuilder = new X509v3CertificateBuilder(new X500Name("CN=Some authority, OU=DATG, O=Disney, C=US"), new BigInteger(64, new SecureRandom()), // yesterday
new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000), // 10 years
new Date(System.currentTimeMillis() + 10 * 365 * 24 * 60 * 60 * 1000), new X500Name("DN=mySubject"), SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
JcaContentSignerBuilder builder = new JcaContentSignerBuilder("SHA256withRSA");
ContentSigner signer = builder.build(keyPair.getPrivate());
byte[] certBytes = certBuilder.build(signer).getEncoded();
Certificate cert = CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(certBytes));
URIParcel<Certificate> certParcel = new URIParcel<Certificate>(Certificate.class, keyLoc);
certParcel.put(cert);
byte[] rawBytes = URIParcel.get(keyLoc, byte[].class);
Assert.assertTrue("Expected X509 certificate", new String(rawBytes).startsWith("-----BEGIN CERTIFICATE-----"));
Certificate rc = URIParcel.get(keyLoc, Certificate.class);
Assert.assertEquals(keyPair.getPublic(), rc.getPublicKey());
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestKeys method testPublicKey.
@Test
public void testPublicKey() throws Exception {
URI keyLoc = new URI("mem:myPublicKey");
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
generator.initialize(2048);
KeyPair keyPair = generator.generateKeyPair();
URIParcel<PublicKey> myParcel = new URIParcel<PublicKey>(PublicKey.class, keyLoc);
myParcel.put(keyPair.getPublic());
URIParcel<byte[]> rawParcel = new URIParcel<byte[]>(byte[].class, keyLoc);
Assert.assertTrue("Expected PKCS8 public key file", new String(rawParcel.call()).startsWith("-----BEGIN PUBLIC KEY-----"));
myParcel = new URIParcel<PublicKey>(PublicKey.class, keyLoc);
PublicKey copy = myParcel.call();
Assert.assertEquals(keyPair.getPublic(), copy);
}
use of com.disney.uriparcel.URIParcel in project groovity by disney.
the class TestKeyStoreKeyLoader method setupKeyLoader.
private KeyChainKeyLoader setupKeyLoader(String keystorePassword) {
Map<String, Object> config = new HashMap<String, Object>();
config.put(KeyStoreValueHandler.KEYSTORE_PASSWORD, keystorePassword);
config.put(KeyStoreValueHandler.KEYSTORE_TYPE, "JCEKS");
URIParcel<KeyStore> parcel = new URIParcel<KeyStore>(KeyStore.class, new File("src/test/resources/testKey.store").toURI(), config);
KeyChain chain = new KeyStoreKeyChainImpl(parcel, "".toCharArray());
KeyChainKeyLoader loader = new KeyChainKeyLoader(chain);
return loader;
}
Aggregations