adding KeyPairClient tests

This commit is contained in:
Mike Arnold 2012-03-09 21:47:51 -06:00
parent ce9cb23a2e
commit b322e265a5
4 changed files with 197 additions and 3 deletions

View File

@ -24,7 +24,7 @@ import org.jclouds.javax.annotation.Nullable;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
public class KeyPair { public class KeyPair implements Comparable<KeyPair>{
public static Builder builder() { public static Builder builder() {
return new Builder(); return new Builder();
} }
@ -116,6 +116,55 @@ public class KeyPair {
return this.fingerprint; return this.fingerprint;
} }
@Override
public int compareTo(KeyPair o) {
return this.fingerprint.compareTo(o.getFingerprint());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((publicKey == null) ? 0 : publicKey.hashCode());
result = prime * result + ((privateKey == null) ? 0 : privateKey.hashCode());
result = prime * result
+ ((name == null) ? 0 : name.hashCode());
result = prime * result + ((fingerprint == null) ? 0 : fingerprint.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
KeyPair other = (KeyPair) obj;
if (publicKey == null) {
if (other.publicKey != null)
return false;
} else if (!publicKey.equals(other.publicKey))
return false;
if (privateKey == null) {
if (other.privateKey != null)
return false;
} else if (!privateKey.equals(other.privateKey))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (fingerprint == null) {
if (other.fingerprint != null)
return false;
} else if (!fingerprint.equals(other.fingerprint))
return false;
return true;
}
@Override @Override
public String toString() { public String toString() {
return toStringHelper("").add("publicKey", publicKey) return toStringHelper("").add("publicKey", publicKey)

View File

@ -0,0 +1,69 @@
/**
* 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.features;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.openstack.nova.v1_1.NovaClient;
import org.jclouds.openstack.nova.v1_1.internal.BaseNovaRestClientExpectTest;
import org.jclouds.openstack.nova.v1_1.parse.ParseKeyPairListTest;
import org.testng.annotations.Test;
import java.net.URI;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
/**
* Tests annotation parsing of {@code KeyPairAsyncClient}
*
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "KeyPairClientExpectTest")
public class KeyPairClientExpectTest extends BaseNovaRestClientExpectTest {
public void testListKeyPairsWhenResponseIs2xx() 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(200)
.payload(payloadFromResource("/keypair_list.json")).build();
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
listKeyPairs, listKeyPairsResponse);
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(),
ImmutableSet.of("North"));
assertEquals(clientWhenFloatingIPsExist.getKeyPairClientForRegion("North")
.listKeyPairs().toString(), new ParseKeyPairListTest().expected()
.toString());
}
}

View File

@ -0,0 +1,76 @@
/**
* 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.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.json.BaseParserTest;
import org.jclouds.json.BaseSetParserTest;
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;
import java.util.Set;
/**
*
* @author Michael Arnold
*/
@Test(groups = "unit", testName = "ParseKeyPairListTest")
public class ParseKeyPairListTest extends BaseParserTest {
@Override
public String resource() {
return "/keypair_list.json";
}
@Override
@SelectJson("keypairs")
@Consumes(MediaType.APPLICATION_JSON)
public Set<Map<String, KeyPair>> expected() {
Map<String, KeyPair> kp1 = new HashMap<String, KeyPair>();
kp1.put("keypair", KeyPair
.builder()
.publicKey("ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQCy9EC3O7Ff80vPEfAHDQob61PGwcpYc5KE7tEZnZhrB9n0NyHPRm0E0M+ls3fcTa04HDi+R0DzmRwoyhHQJyI658v8kWZZcuvFjKCcsgsSh/dzdX0xTreLIzSOzt5U7RnZYfshP5cmxtF99yrEY3M/swdin0L+fXsTSkR1B42STQ== nova@nv-aw2az1-api0001")
.name("default")
.fingerprint("ab:0c:f4:f3:54:c0:5d:3f:ed:62:ad:d3:94:7c:79:7c")
.build());
Map<String, KeyPair> kp2 = new HashMap<String, KeyPair>();
kp2.put("keypair", KeyPair
.builder()
.publicKey("ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001")
.name("testkeypair")
.fingerprint("d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4")
.build());
return ImmutableSet.of(kp1,kp2);
}
protected Injector injector() {
return Guice.createInjector(new NovaParserModule(), new GsonModule());
}
}

View File

@ -2,14 +2,14 @@
"keypairs": [ "keypairs": [
{ {
"keypair": { "keypair": {
"public_key": "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQCy9EC3O7Ff80vPEfAHDQob61PGwcpYc5KE7tEZnZhrB9n0NyHPRm0E0M+ls3fcTa04HDi+R0DzmRwoyhHQJyI658v8kWZZcuvFjKCcsgsSh/dzdX0xTreLIzSOzt5U7RnZYfshP5cmxtF99yrEY3M/swdin0L+fXsTSkR1B42STQ== nova@nv-aw2az1-api0001\n", "public_key": "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQCy9EC3O7Ff80vPEfAHDQob61PGwcpYc5KE7tEZnZhrB9n0NyHPRm0E0M+ls3fcTa04HDi+R0DzmRwoyhHQJyI658v8kWZZcuvFjKCcsgsSh/dzdX0xTreLIzSOzt5U7RnZYfshP5cmxtF99yrEY3M/swdin0L+fXsTSkR1B42STQ== nova@nv-aw2az1-api0001",
"name": "default", "name": "default",
"fingerprint": "ab:0c:f4:f3:54:c0:5d:3f:ed:62:ad:d3:94:7c:79:7c" "fingerprint": "ab:0c:f4:f3:54:c0:5d:3f:ed:62:ad:d3:94:7c:79:7c"
} }
}, },
{ {
"keypair": { "keypair": {
"public_key": "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n", "public_key": "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001",
"name": "testkeypair", "name": "testkeypair",
"fingerprint": "d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4" "fingerprint": "d2:1f:c9:2b:d8:90:77:5f:15:64:27:e3:9f:77:1d:e4"
} }