public void testSetInstanceInitiatedShutdownBehaviorForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Invokable<?, ?> method = method( InstanceApi.class, "setInstanceInitiatedShutdownBehaviorForInstanceInRegion", String.class, String.class, InstanceInitiatedShutdownBehavior.class); GeneratedHttpRequest request = processor.createRequest( method, Lists.<Object>newArrayList(null, "1", InstanceInitiatedShutdownBehavior.TERMINATE)); request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( request, setInstanceInitiatedShutdownBehavior.getPayload().getRawContent().toString(), "application/x-www-form-urlencoded", false); assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertFallbackClassEquals(method, null); checkFilters(request); }
public void testSetBlockDeviceMappingForInstanceInRegion() throws SecurityException, NoSuchMethodException, IOException { Invokable<?, ?> method = method( InstanceApi.class, "setBlockDeviceMappingForInstanceInRegion", String.class, String.class, Map.class); Map<String, BlockDevice> mapping = Maps.newLinkedHashMap(); mapping.put("/dev/sda1", new BlockDevice("vol-test1", true)); GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object>newArrayList(null, "1", mapping)); request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( request, filter.filter(setBlockDeviceMapping).getPayload().getRawContent().toString(), "application/x-www-form-urlencoded", false); checkFilters(request); }
public void testCreateSecurityGroup() throws SecurityException, NoSuchMethodException, IOException { Invokable<?, ?> method = method( AWSSecurityGroupApi.class, "createSecurityGroupInRegion", String.class, String.class, String.class); GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object>newArrayList(null, "name", "description")); request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request); assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); assertPayloadEquals( request, "Action=CreateSecurityGroup&GroupName=name&GroupDescription=description&Version=2014-02-01", "application/x-www-form-urlencoded", false); assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); assertSaxResponseParserClassEquals(method, null); assertFallbackClassEquals(method, null); checkFilters(request); }
@Test public void testGetImagesByName() throws NoSuchMethodException, IOException { Invokable<?, ?> method = method(GridImageApi.class, "getImagesByName", String[].class); GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object>of("name1", "name2")); assertRequestLineEquals( httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.5&" + "name=name1&name=name2 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class); assertSaxResponseParserClassEquals(method, null); assertFallbackClassEquals(method, null); checkFilters(httpRequest); httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); assertRequestLineEquals( httpRequest, "GET https://api.gogrid.com/api/grid/image/get?v=1.5&" + "name=name1&name=name2&" + "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity " + "HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest, null, null, false); }
public void testInitiateMultipartUpload() throws SecurityException, NegativeArraySizeException, NoSuchMethodException { Invokable<?, ?> method = method( AWSS3AsyncClient.class, "initiateMultipartUpload", String.class, ObjectMetadata.class, PutObjectOptions[].class); GeneratedHttpRequest request = processor.createRequest( method, ImmutableList.<Object>of( "bucket", ObjectMetadataBuilder.create() .key("foo") .contentMD5(new byte[] {1, 2, 3, 4}) .build())); assertRequestLineEquals(request, "POST https://bucket." + url + "/foo?uploads HTTP/1.1"); assertNonPayloadHeadersEqual( request, "Content-MD5: AQIDBA==\nContent-Type: binary/octet-stream\nHost: bucket." + url + "\n"); assertPayloadEquals(request, null, null, false); // as this is a payload-related command, but with no payload, be careful // that we check // filtering and do not ignore if this fails later. request = (GeneratedHttpRequest) request.getFilters().get(0).filter(request); assertRequestLineEquals(request, "POST https://bucket." + url + "/foo?uploads HTTP/1.1"); assertNonPayloadHeadersEqual( request, "Authorization: AWS identity:Sp1FX4svL9P2u2bFJwroaYpSANo=\nContent-MD5: AQIDBA==\n" + "Content-Type: binary/octet-stream\nDate: 2009-11-08T15:54:08.897Z\nHost: bucket." + url + "\n"); assertPayloadEquals(request, null, null, false); assertResponseParserClassEquals(method, request, UploadIdFromHttpResponseViaRegex.class); assertSaxResponseParserClassEquals(method, null); assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); checkFilters(request); }
@Test public void testGetImageListWithOptions() throws NoSuchMethodException, IOException { Invokable<?, ?> method = method(GridImageApi.class, "getImageList", GetImageListOptions[].class); GeneratedHttpRequest httpRequest = processor.createRequest( method, ImmutableList.<Object>of( new GetImageListOptions() .onlyPublic() .setState(ServerImageState.AVAILABLE) .setType(ServerImageType.WEB_APPLICATION_SERVER))); assertRequestLineEquals( httpRequest, "GET https://api.gogrid.com/api/grid/image/list?v=1.5&" + "isPublic=true&image.state=Available&" + "image.type=Web%20Server HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest, null, null, false); assertResponseParserClassEquals(method, httpRequest, ParseImageListFromJsonResponse.class); assertSaxResponseParserClassEquals(method, null); assertFallbackClassEquals(method, null); checkFilters(httpRequest); httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); assertRequestLineEquals( httpRequest, "GET https://api.gogrid.com/api/grid/image/list?" + "v=1.5&isPublic=true&image.state=Available&" + "image.type=Web%20Server&" + "sig=e9aafd0a5d4c69bb24536be4bce8a528&api_key=identity " + "HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, ""); assertPayloadEquals(httpRequest, null, null, false); }
@Override protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod) { assertEquals(httpMethod.getFilters().size(), 1); assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); }