use of com.amazonaws.util.StringInputStream in project pipeline-aws-plugin by jenkinsci.
the class JSONParameterFileParserTests method parseParameters.
@Test
public void parseParameters() throws IOException {
JSONParameterFileParser parser = new JSONParameterFileParser();
String json = "[{\"ParameterKey\": \"bar\", \"ParameterValue\": \"foo\"}]";
Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withParameterValue("foo"));
}
use of com.amazonaws.util.StringInputStream in project pipeline-aws-plugin by jenkinsci.
the class JSONParameterFileParserTests method parseKeyParameters.
@Test
public void parseKeyParameters() throws IOException {
JSONParameterFileParser parser = new JSONParameterFileParser();
String json = "[{\"ParameterKey\": \"bar\", \"UsePreviousValue\": true}]";
Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withUsePreviousValue(true));
}
use of com.amazonaws.util.StringInputStream in project pipeline-aws-plugin by jenkinsci.
the class YAMLParameterFileParserTests method parseParameterCollection.
@Test
public void parseParameterCollection() throws IOException {
YAMLParameterFileParser parser = new YAMLParameterFileParser();
String json = "bar:\n - foo1\n - foo2";
Collection<Parameter> parameters = parser.parseParams(new StringInputStream(json));
Assertions.assertThat(parameters).containsExactlyInAnyOrder(new Parameter().withParameterKey("bar").withParameterValue("foo1,foo2"));
}
use of com.amazonaws.util.StringInputStream in project spring-integration-aws by spring-projects.
the class S3MessageHandlerTests method testUploadInputStream.
@Test
public void testUploadInputStream() throws IOException {
Expression actualKeyExpression = TestUtils.getPropertyValue(this.s3MessageHandler, "keyExpression", Expression.class);
this.s3MessageHandler.setKeyExpression(null);
InputStream payload = new StringInputStream("a");
Message<?> message = MessageBuilder.withPayload(payload).setHeader("s3Command", S3MessageHandler.Command.UPLOAD.name()).setHeader("key", "myStream").build();
assertThatThrownBy(() -> this.s3SendChannel.send(message)).hasCauseExactlyInstanceOf(IllegalStateException.class).hasMessageContaining("Specify a 'keyExpression' for non-java.io.File payloads");
this.s3MessageHandler.setKeyExpression(actualKeyExpression);
this.s3SendChannel.send(message);
ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
verify(this.amazonS3, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture());
PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue();
assertThat(putObjectRequest.getBucketName()).isEqualTo(S3_BUCKET_NAME);
assertThat(putObjectRequest.getKey()).isEqualTo("myStream");
assertThat(putObjectRequest.getFile()).isNull();
assertThat(putObjectRequest.getInputStream()).isNotNull();
ObjectMetadata metadata = putObjectRequest.getMetadata();
assertThat(metadata.getContentMD5()).isEqualTo(Md5Utils.md5AsBase64(payload));
assertThat(metadata.getContentLength()).isEqualTo(1);
assertThat(metadata.getContentType()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
assertThat(metadata.getContentDisposition()).isEqualTo("test.json");
}
use of com.amazonaws.util.StringInputStream in project amazon-cognito-android by aws.
the class RegisterDeviceRequestMarshaller method marshall.
public Request<RegisterDeviceRequest> marshall(RegisterDeviceRequest registerDeviceRequest) {
if (registerDeviceRequest == null) {
throw new AmazonClientException("Invalid argument passed to marshall(...)");
}
Request<RegisterDeviceRequest> request = new DefaultRequest<RegisterDeviceRequest>(registerDeviceRequest, "AmazonCognitoSync");
String target = "AWSCognitoSyncService.RegisterDevice";
request.addHeader("X-Amz-Target", target);
request.setHttpMethod(HttpMethodName.POST);
String uriResourcePath = "/identitypools/{IdentityPoolId}/identity/{IdentityId}/device";
uriResourcePath = uriResourcePath.replace("{IdentityPoolId}", (registerDeviceRequest.getIdentityPoolId() == null) ? "" : StringUtils.fromString(registerDeviceRequest.getIdentityPoolId()));
uriResourcePath = uriResourcePath.replace("{IdentityId}", (registerDeviceRequest.getIdentityId() == null) ? "" : StringUtils.fromString(registerDeviceRequest.getIdentityId()));
uriResourcePath = uriResourcePath.replaceAll("//", "/");
if (uriResourcePath.contains("?")) {
String queryString = uriResourcePath.substring(uriResourcePath.indexOf("?") + 1);
uriResourcePath = uriResourcePath.substring(0, uriResourcePath.indexOf("?"));
for (String s : queryString.split("[;&]")) {
String[] nameValuePair = s.split("=");
if (nameValuePair.length == 2) {
if (!(nameValuePair[1].isEmpty()))
request.addParameter(nameValuePair[0], nameValuePair[1]);
}
}
}
request.setResourcePath(uriResourcePath);
try {
StringWriter stringWriter = new StringWriter();
AwsJsonWriter jsonWriter = JsonUtils.getJsonWriter(stringWriter);
jsonWriter.beginObject();
if (registerDeviceRequest.getPlatform() != null) {
jsonWriter.name("Platform").value(registerDeviceRequest.getPlatform());
}
if (registerDeviceRequest.getToken() != null) {
jsonWriter.name("Token").value(registerDeviceRequest.getToken());
}
jsonWriter.endObject();
jsonWriter.close();
String snippet = stringWriter.toString();
byte[] content = snippet.getBytes(UTF8);
request.setContent(new StringInputStream(snippet));
request.addHeader("Content-Length", Integer.toString(content.length));
request.addHeader("Content-Type", "application/x-amz-json-1.0");
} catch (Throwable t) {
throw new AmazonClientException("Unable to marshall request to JSON: " + t.getMessage(), t);
}
return request;
}
Aggregations