adding more key pair client expect-style tests

This commit is contained in:
Mike Arnold 2012-03-12 16:22:54 -05:00
parent a01d123a78
commit 6db648740b
2 changed files with 165 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient; import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest; import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairListTest; import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairListTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.net.URI; import java.net.URI;
@ -55,15 +56,111 @@ public class KeyPairClientExpectTest extends BaseNovaRestClientExpectTest {
HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(200) HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/keypair_list.json")).build(); .payload(payloadFromResource("/keypair_list.json")).build();
NovaClient clientWhenFloatingIPsExist = requestsSendResponses( NovaClient clientWhenServersExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
listKeyPairs, listKeyPairsResponse); listKeyPairs, listKeyPairsResponse);
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), assertEquals(clientWhenServersExist.getConfiguredRegions(),
ImmutableSet.of("North")); ImmutableSet.of("North"));
assertEquals(clientWhenFloatingIPsExist.getKeyPairClientForRegion("North") assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North")
.listKeyPairs().toString(), new ParseKeyPairListTest().expected() .listKeyPairs().toString(), new ParseKeyPairListTest().expected()
.toString()); .toString());
} }
public void testListKeyPairsWhenResponseIs404() throws Exception {
HttpRequest listKeyPairs = HttpRequest
.builder()
.method("GET")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-keypairs"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("Accept", "application/json")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(404)
.build();
NovaClient clientWhenNoServersExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
listKeyPairs, listKeyPairsResponse);
assertTrue(clientWhenNoServersExist.getKeyPairClientForRegion("North")
.listKeyPairs().isEmpty());
}
public void testCreateKeyPair() throws Exception {
HttpRequest createKeyPair = HttpRequest
.builder()
.method("POST")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-keypairs"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("Accept", "application/json")
.put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType("{\"keypair\":{\"name\":\"testkeypair\"}}",
"application/json")).build();
HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/keypair_created.json")).build();
NovaClient clientWhenServersExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
createKeyPair, createKeyPairResponse);
assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North")
.createKeyPair("testkeypair").toString(),
new ParseKeyPairTest().expected().toString());
}
public void testCreateKeyPairWithPublicKey() throws Exception {
HttpRequest createKeyPair = HttpRequest
.builder()
.method("POST")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-keypairs"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("Accept", "application/json")
.put("X-Auth-Token", authToken).build())
.payload(payloadFromStringWithContentType("{\"keypair\":{\"name\":\"testkeypair\",\"public_key\":\"ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n\"}}",
"application/json")).build();
HttpResponse createKeyPairResponse = HttpResponse.builder().statusCode(200)
.payload(payloadFromResource("/keypair_created.json")).build();
NovaClient clientWhenServersExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
createKeyPair, createKeyPairResponse);
assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North")
.createKeyPairWithPublicKey("testkeypair", "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n")
.toString(),
new ParseKeyPairTest().expected().toString());
}
public void testDeleteKeyPair() throws Exception {
HttpRequest deleteKeyPair = HttpRequest
.builder()
.method("DELETE")
.endpoint(
URI.create("https://compute.north.host/v1.1/3456/os-keypairs/testkeypair"))
.headers(
ImmutableMultimap.<String, String> builder()
.put("Accept", "*/*")
.put("X-Auth-Token", authToken).build()).build();
HttpResponse deleteKeyPairResponse = HttpResponse.builder().statusCode(202).build();
NovaClient clientWhenServersExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
deleteKeyPair, deleteKeyPairResponse);
assertTrue(clientWhenServersExist.getKeyPairClientForRegion("North").deleteKeyPair("testkeypair"));
}
} }

View File

@ -0,0 +1,65 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.openstack.nova.v1_1.parse;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.json.BaseItemParserTest;
import org.jclouds.json.BaseParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
import org.jclouds.openstack.nova.v1_1.domain.KeyPair;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "ParseKeyPairTest")
public class ParseKeyPairTest extends BaseItemParserTest<KeyPair> {
@Override
public String resource() {
return "/keypair_created.json";
}
@Override
@Consumes(MediaType.APPLICATION_JSON)
public KeyPair expected() {
return KeyPair
.builder()
.publicKey("ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n")
.privateKey("-----BEGIN RSA PRIVATE KEY-----\nMIICXQIAAAKBgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABAC\nE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumA\nDSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQIDAQAB\nAoGAW8Ww+KbpQK8smcgCTr/RqcmsSI8VeL2hXjJvDq0L5WbyYuFdkanDvCztUVZn\nsmyfDtwAqZXB4Ct/dN1tY7m8QpdyRaKRW4Q+hghGCAQpsG7rYDdvwdEyvMaW5RA4\ntucQyajMNyQ/tozU3wMx/v8A7RvGcE9tqoG0WK1C3kBu95UCQQDrOd+joYDkvccz\nFIVu5gNPMXEh3fGGzDxk225UlvESquYLzfz4TfmuUjH4Z1BL3wRiwfJsrrjFkm33\njIidDE8PAkEA1qHjxuaIS1yz/rfzErmcOVNlbFHMP4ihjGTTvh1ZctXlNeLwzENQ\nEDaQV3IpUY1KQR6rxcWb5AXgfF9D9PYFpwJBANucAqGAbRgh3lJgPFtXP4u2O0tF\nLPOOxmvbOdybt6KYD4LB5AXmts77SlACFMNhCXUyYaT6UuOSXDyb5gfJsB0CQQC3\nFaGXKU9Z+doQjhlq/6mjvN/nZl80Uvh7Kgb1RVPoAU1kihGeLE0/h0vZTCiyyDNv\nGRqtucMg32J+tUTi0HpBAkAwHiCZMHMeJWHUwIwlRQY/dnR86FWobRl98ViF2rCL\nDHkDVOeIser3Q6zSqU5/m99lX6an5g8pAh/R5LqnOQZC\n-----END RSA PRIVATE KEY-----\n")
.name("testkeypair")
.userId("65649731189278")
.fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4")
.build();
}
protected Injector injector() {
return Guice.createInjector(new NovaParserModule(), new GsonModule());
}
}