@Test public void testDeleteVPCInvalidVPCID() throws Exception { long jobTimeoutMillis = 5 * 60 * 1000; JSONObject jo = new JSONObject(); jo.put("projectName", "EC-EC2-" + StringConstants.PLUGIN_VERSION); jo.put("procedureName", "API_DeleteVPC"); HashMap actualParameters = new HashMap(); actualParameters.put("config", "ec2cfg"); actualParameters.put("vpcId", "SomeRandomID"); actualParameters.put("propResult", "/myJob"); JSONArray actualParameterArray = TestUtil.getJSONActualParameterArray(actualParameters); jo.put("actualParameter", actualParameterArray); String jobId = TestUtil.callRunProcedure(jo); String response = TestUtil.waitForJob(jobId, jobTimeoutMillis); // Check job status assertEquals("Job completed without errors", "error", response); JSONObject outputProperties = TestUtil.getJobOutputProperties(jobId); JSONArray objectArray = outputProperties.getJSONArray("object"); JSONObject object = null; String failureReason = null; for (int i = 0; i < objectArray.length(); i++) { object = objectArray.getJSONObject(i); if (object .getJSONObject("property") .get("propertyName") .toString() .equalsIgnoreCase("summary")) { failureReason = object.getJSONObject("property").get("value").toString(); } } assertNotNull("No failure reason is set", failureReason); assertEquals("AWS Error: The vpc ID 'SomeRandomID' does not exist", failureReason); }
@Test(expected = AmazonServiceException.class) public void testDeleteVPC() throws Exception { // Create a VPC that can be deleted through API_DeleteVPC procedure CreateVpcResult createVpcResult = m_ec2Client.createVpc(new CreateVpcRequest("10.0.0.0/20")); Vpc vpc = createVpcResult.getVpc(); m_vpcId = vpc.getVpcId(); long jobTimeoutMillis = 5 * 60 * 1000; JSONObject jo = new JSONObject(); jo.put("projectName", "EC-EC2-" + StringConstants.PLUGIN_VERSION); jo.put("procedureName", "API_DeleteVPC"); HashMap actualParameters = new HashMap(); actualParameters.put("config", "ec2cfg"); actualParameters.put("vpcId", m_vpcId); actualParameters.put("propResult", "/myJob"); JSONArray actualParameterArray = TestUtil.getJSONActualParameterArray(actualParameters); jo.put("actualParameter", actualParameterArray); String jobId = TestUtil.callRunProcedure(jo); String response = TestUtil.waitForJob(jobId, jobTimeoutMillis); // Check job status assertEquals("Job completed with errors", "success", response); // Following method invocation must throw com.amazonaws.AmazonServiceException DescribeVpcsResult describeVpcsResult = m_ec2Client.describeVpcs(new DescribeVpcsRequest().withVpcIds(m_vpcId)); }