@Test(expectedExceptions = ResourceNotFoundException.class) public void testCreateInstanceFail() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET() .endpoint( endpoint) // bad naming convention, you should not be able to change the // method to POST .method("POST") .payload( payloadFromResourceWithContentType( "/instance_create_request.json", MediaType.APPLICATION_JSON)) .build(), HttpResponse.builder() .statusCode(404) .payload(payloadFromResource("/instance_create.json")) .build() // response ) .getInstanceApi("RegionOne"); api.create("1", 2, "json_rack_instance"); }
public void testGetInstanceFail() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances/12312"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build()) .getInstanceApi("RegionOne"); assertNull(api.get("12312")); }
public void testListInstancesFail() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build()) .getInstanceApi("RegionOne"); Set<? extends Instance> instances = api.list().toSet(); assertTrue(instances.isEmpty()); }
public void testDeleteInstance() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances/098653ba-218b-47ce-936a-e0b749101f81"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder().statusCode(202).build() // response ) .getInstanceApi("RegionOne"); assertTrue(api.delete("098653ba-218b-47ce-936a-e0b749101f81")); }
public void testListInstances() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/instance_list.json")) .build()) .getInstanceApi("RegionOne"); Set<? extends Instance> instances = api.list().toSet(); assertEquals(instances.size(), 2); assertEquals(instances.iterator().next().getSize(), 2); }
public void testIsRootInstanceFalse() { URI endpoint = URI.create( "http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7/root"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/instance_is_rooted_false.json")) .build()) .getInstanceApi("RegionOne"); Boolean rooted = api.isRooted("44b277eb-39be-4921-be31-3d61b43651d7"); assertEquals(rooted.booleanValue(), false); }
public void testEnableRootOnInstanceFail() { URI endpoint = URI.create( "http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7/root"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().method("POST").endpoint(endpoint).build(), HttpResponse.builder() .statusCode(404) .payload(payloadFromResource("/instance_root.json")) .build()) .getInstanceApi("RegionOne"); String password = api.enableRoot("44b277eb-39be-4921-be31-3d61b43651d7"); assertEquals(password, null); }
@Test(expectedExceptions = ResourceNotFoundException.class) public void testIsRootInstanceFail() { URI endpoint = URI.create( "http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7/root"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder() .statusCode(404) .payload(payloadFromResource("/instance_is_rooted.json")) .build()) .getInstanceApi("RegionOne"); Boolean rooted = api.isRooted("44b277eb-39be-4921-be31-3d61b43651d7"); assertNull(rooted); }
public void testGetInstance() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/3456/instances/44b277eb-39be-4921-be31-3d61b43651d7"); InstanceApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/instance_get.json")) .build()) .getInstanceApi("RegionOne"); Instance instance = api.get("44b277eb-39be-4921-be31-3d61b43651d7"); assertEquals(instance.getName(), "json_rack_instance"); assertEquals(instance.getId(), "44b277eb-39be-4921-be31-3d61b43651d7"); assertEquals(instance.getLinks().size(), 2); assertEquals( instance.getHostname(), "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com"); }