@Singleton @Provides @Named("CreateNodeService") String provideCreateNodeService() throws IOException { return Strings2.toStringAndClose(getClass().getResourceAsStream("/CreateNodeService.xml")); }
public <V> V apply(final InputStream stream, final Class<V> type) throws IOException { try { return xml.fromXML(Strings2.toStringAndClose(stream), type); } finally { if (stream != null) { stream.close(); } } }
@Singleton @Provides @Named("CreateNodeService") String provideInstantiateVAppTemplateParams() throws IOException { InputStream is = getClass().getResourceAsStream("/CreateNodeService.xml"); return Strings2.toStringAndClose(is); } });
public Payload payloadFromResourceWithContentType(String resource, String contentType) { try { return payloadFromStringWithContentType(Strings2.toStringAndClose(getClass().getResourceAsStream(resource)), contentType); } catch (IOException e) { throw Throwables.propagate(e); } }
public void testParseUsers() throws JsonSyntaxException, IOException { String json = Strings2.toStringAndClose(getClass().getResourceAsStream("/user_list.json")); Users users = gson.fromJson(json, Users.class); assertEquals(users.toSet(), expectedUsers); } }
@Test public void testPrivateKeyMatchesSha1String() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); assert privateKeyHasSha1(privKey, expectedSha1); }
private Payload payloadFromResource(String resource) { try { return payloadFromStringWithContentType(toStringAndClose(getClass().getResourceAsStream(resource)), "application/xml"); } catch (IOException e) { throw propagate(e); } } }
@Test public void testPrivateKeyMatchesPublicKeyTyped() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); RSAPrivateCrtKeySpec privateKey = (RSAPrivateCrtKeySpec) Pems.privateKeySpec(privKey); String pubKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test.pub")); RSAPublicKeySpec publicKey = publicKeySpecFromOpenSSH(pubKey); assert privateKeyMatchesPublicKey(privateKey, publicKey); }
@Test(expectedExceptions = IOException.class) public void testDefaultAccessPolicy() throws Exception { String bucketName = getContainerName(); try { URL url = new URL(String.format("https://%s.s3.amazonaws.com", bucketName)); Strings2.toStringAndClose(url.openStream()); } finally { returnContainer(bucketName); } }
@Test public void testEncodeAsOpenSSH() throws IOException, InvalidKeySpecException, NoSuchAlgorithmException { String encoded = SshKeys.encodeAsOpenSSH((RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic( SshKeys.publicKeySpecFromOpenSSH(Payloads.newPayload(getClass().getResourceAsStream("/test.pub"))))); assertEquals(encoded, Strings2.toStringAndClose(getClass().getResourceAsStream("/test.pub")).trim()); }
@Test void testCreateStringToSign() throws IOException { String expects = Strings2.toStringAndClose(getClass().getResourceAsStream("/hashstring.txt")); HttpRequest request = newRequest(preconstructedHeaders().build()); String toSign = filter.createStringToSign(request); assertEquals(toSign, expects); }
public void testInputInputStreamSynch() throws Exception { HttpWire wire = setUpSynch(); InputStream in = wire.input(new ByteArrayInputStream("foo".getBytes())); String compare = Strings2.toStringAndClose(in); assertEquals(compare, "foo"); assertEquals(((BufferLogger) wire.getWireLog()).buff.toString(), "<< \"foo\""); }
public void testDefault() throws Exception { String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); BindCloneVAppParamsToXmlPayload binder = injector.getInstance(BindCloneVAppParamsToXmlPayload.class); Map<String, Object> map = Maps.newHashMap(); map.put("newName", "my-vapp"); map.put("vApp", "https://vcloud.safesecureweb.com/api/v0.8/vapp/4181"); assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); } }
public void testComplete() throws IOException { Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( Strings2.toStringAndClose(MapToDriveInfoTest.class.getResourceAsStream("/drive.txt"))).get(0); assertEquals(MAP_TO_DRIVE.apply(input), ONE); } }
public void test() throws IOException { Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( Strings2.toStringAndClose(MapToVLANInfoTest.class.getResourceAsStream("/vlan.txt"))).get(0); assertEquals(MAP_TO_VLAN.apply(input), ONE); } }
public void testNew() throws IOException { Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( Strings2.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server.txt"))).get(0); assertEquals(MAP_TO_DRIVE.apply(input), NEW); } }
public void testComplete() throws IOException { Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( Strings2.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/servers.txt"))).get(0); assertEquals(MAP_TO_DRIVE.apply(input), ONE); }
public void testNew2() throws IOException { Map<String, String> input = new ListOfKeyValuesDelimitedByBlankLinesToListOfMaps().apply( Strings2.toStringAndClose(MapToServerInfoTest.class.getResourceAsStream("/new_server2.txt"))).get(0); assertEquals(MAP_TO_DRIVE_2_0.apply(input), NEW); } }
public void testWithDescription() throws IOException { String expected = toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate.xml")); CloneVAppTemplateOptions options = new CloneVAppTemplateOptions() .description("The description of the new vAppTemplate"); GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(options)); BindCloneVAppTemplateParamsToXmlPayload binder = injector .getInstance(BindCloneVAppTemplateParamsToXmlPayload.class); Builder<String, Object> map = ImmutableMap.builder(); map.put("name", "new-linux-server"); map.put("Source", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201"); assertEquals(binder.bindToRequest(request, map.build()).getPayload().getRawContent(), expected); }
@Test public void testCanReadRsaAndCompareFingerprintOnPrivateRSAKey() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); RSAPrivateCrtKeySpec key = (RSAPrivateCrtKeySpec) Pems.privateKeySpec(privKey); String fingerPrint = fingerprint(key.getPublicExponent(), key.getModulus()); assertEquals(fingerPrint, expectedFingerprint); }