@Test(expectedExceptions = AuthorizationException.class) public void testCreateSnapshotFail() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots"); SnapshotApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET() .endpoint(endpoint) .method("POST") .payload( payloadFromResourceWithContentType( "/snapshot_create.json", MediaType.APPLICATION_JSON)) .build(), HttpResponse.builder().statusCode(401).build()) .getSnapshotApiForZone("RegionOne"); CreateSnapshotOptions options = CreateSnapshotOptions.Builder.name("jclouds-test-snapshot") .description("jclouds test snapshot") .force(); api.create("ea6f70ef-2784-40b9-9d14-d7f33c507c3f", options); }
public void testListSnapshotsInDetail() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots/detail"); SnapshotApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/snapshot_list_details.json")) .build()) .getSnapshotApiForZone("RegionOne"); Set<? extends Snapshot> snapshots = api.listInDetail().toSet(); assertEquals(snapshots, ImmutableSet.of(testSnapshot())); // double-check individual fields Snapshot snappy = Iterables.getOnlyElement(snapshots); assertEquals(snappy.getId(), "67d03df1-ce5d-4ba7-adbe-492ceb80170b"); assertEquals(snappy.getVolumeId(), "ea6f70ef-2784-40b9-9d14-d7f33c507c3f"); assertEquals(snappy.getStatus(), Volume.Status.AVAILABLE); assertEquals(snappy.getDescription(), "jclouds test snapshot"); assertEquals(snappy.getName(), "jclouds-test-snapshot"); assertEquals(snappy.getSize(), 1); }
public void testListSnapshotsFail() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots"); SnapshotApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder().statusCode(404).build()) .getSnapshotApiForZone("RegionOne"); Set<? extends Snapshot> snapshots = api.list().toSet(); assertTrue(snapshots.isEmpty()); }
public void testDeleteSnapshotNotFoundFail() { URI endpoint = URI.create( "http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots/67d03df1-ce5d-4ba7-adbe-492ceb80170b"); SnapshotApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder().statusCode(404).build()) .getSnapshotApiForZone("RegionOne"); assertFalse(api.delete("67d03df1-ce5d-4ba7-adbe-492ceb80170b")); }
public void testListSnapshots() { URI endpoint = URI.create("http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots"); SnapshotApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/snapshot_list_simple.json")) .build()) .getSnapshotApiForZone("RegionOne"); Set<? extends Snapshot> snapshots = api.list().toSet(); assertEquals(snapshots, ImmutableSet.of(testSnapshot())); }
public void testGetSnapshot() { URI endpoint = URI.create( "http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots/67d03df1-ce5d-4ba7-adbe-492ceb80170b"); SnapshotApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).build(), HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/snapshot_get.json")) .build()) .getSnapshotApiForZone("RegionOne"); Snapshot snapshot = api.get("67d03df1-ce5d-4ba7-adbe-492ceb80170b"); assertEquals(snapshot, testSnapshot()); }
@Test(expectedExceptions = IllegalStateException.class) public void testDeleteSnapshotIllegalStateFail() { URI endpoint = URI.create( "http://172.16.0.1:8776/v1/50cdb4c60374463198695d9f798fa34d/snapshots/67d03df1-ce5d-4ba7-adbe-492ceb80170b"); SnapshotApi api = requestsSendResponses( keystoneAuthWithUsernameAndPasswordAndTenantName, responseWithKeystoneAccess, authenticatedGET().endpoint(endpoint).method("DELETE").build(), HttpResponse.builder() .statusCode(400) .payload( "{\"badRequest\": {\"message\": \"Invalid volume: Volume Snapshot status must be available or error\", \"code\": 400}}") .build()) .getSnapshotApiForZone("RegionOne"); api.delete("67d03df1-ce5d-4ba7-adbe-492ceb80170b"); }