diff --git a/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeKeyPairClientLiveTest.java b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeKeyPairClientLiveTest.java new file mode 100644 index 0000000000..f7982fe934 --- /dev/null +++ b/labs/hpcloud-compute/src/test/java/org/jclouds/hpcloud/compute/features/HPCloudComputeKeyPairClientLiveTest.java @@ -0,0 +1,34 @@ +/** + * 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.hpcloud.compute.features; + +import org.jclouds.openstack.nova.v1_1.features.KeyPairClientLiveTest; +import org.testng.annotations.Test; + +/** + * + * @author Michael Arnold + */ +@Test(groups = "live", testName = "HPCloudComputeKeyPairClientLiveTest") +public class HPCloudComputeKeyPairClientLiveTest extends KeyPairClientLiveTest { + public HPCloudComputeKeyPairClientLiveTest() { + provider = "hpcloud-compute"; + } + +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java index 12a2c50afb..c9a7b70d43 100644 --- a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/KeyPairClientExpectTest.java @@ -25,6 +25,7 @@ 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.jclouds.openstack.nova.v1_1.parse.ParseKeyPairTest; import org.testng.annotations.Test; import java.net.URI; @@ -55,15 +56,111 @@ public class KeyPairClientExpectTest extends BaseNovaRestClientExpectTest { HttpResponse listKeyPairsResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResource("/keypair_list.json")).build(); - NovaClient clientWhenFloatingIPsExist = requestsSendResponses( + NovaClient clientWhenServersExist = requestsSendResponses( keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess, listKeyPairs, listKeyPairsResponse); - assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(), + assertEquals(clientWhenServersExist.getConfiguredRegions(), ImmutableSet.of("North")); - assertEquals(clientWhenFloatingIPsExist.getKeyPairClientForRegion("North") + assertEquals(clientWhenServersExist.getKeyPairClientForRegion("North") .listKeyPairs().toString(), new ParseKeyPairListTest().expected() .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. 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. 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. 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. 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")); + } } diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientExpectTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientExpectTest.java new file mode 100644 index 0000000000..dc738036a4 --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientExpectTest.java @@ -0,0 +1,30 @@ +/** + * 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.extensions; + +import org.testng.annotations.Test; + +/** + * Tests annotation parsing of {@code SecurityGroupAsyncClient} + * + * @author Michael Arnold + */ +@Test(groups = "unit", testName = "SecurityGroupClientExpectTest") +public class SecurityGroupClientExpectTest { +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java new file mode 100644 index 0000000000..b11627b5c3 --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/extensions/SecurityGroupClientLiveTest.java @@ -0,0 +1,89 @@ +/** + * 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.extensions; + +import org.jclouds.openstack.nova.v1_1.domain.SecurityGroup; +import org.jclouds.openstack.nova.v1_1.domain.SecurityGroupRule; +import org.jclouds.openstack.nova.v1_1.extensions.SecurityGroupClient; +import org.jclouds.openstack.nova.v1_1.internal.BaseNovaClientLiveTest; +import org.testng.annotations.Test; + +import java.util.Set; + +import static org.testng.Assert.assertNotNull; + +/** + * Tests behavior of {@code SecurityGroupClient} + * + * @author Michael Arnold + */ +@Test(groups = "live", testName = "SecurityGroupClientLiveTest") +public class SecurityGroupClientLiveTest extends BaseNovaClientLiveTest { + + public static final String SECURITY_GROUP_NAME = "testsg"; + + public void listSecurityGroups() throws Exception { + for (String regionId : context.getApi().getConfiguredRegions()) { + SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); + Set securityGroupsList = client.listSecurityGroups(); + assertNotNull(securityGroupsList); + } + } + + public void createGetAndDeleteSecurityGroup() throws Exception { + for(String regionId : context.getApi().getConfiguredRegions()) { + SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); + SecurityGroup securityGroup = null; + String id; + try { + securityGroup = client.createSecurityGroup(SECURITY_GROUP_NAME, "test security group"); + assertNotNull(securityGroup); + id = securityGroup.getId(); + SecurityGroup theGroup = client.getSecurityGroup(id); + assertNotNull(theGroup); + } finally { + if (securityGroup != null) { + client.deleteSecurityGroup(securityGroup.getId()); + } + } + } + } + + public void createAndDeleteSecurityGroupRule() throws Exception { + for(String regionId : context.getApi().getConfiguredRegions()) { + SecurityGroupClient client = context.getApi().getSecurityGroupClientForRegion(regionId); + SecurityGroup securityGroup = null; + + try { + securityGroup = client.createSecurityGroup(SECURITY_GROUP_NAME, "test security group"); + assertNotNull(securityGroup); + + SecurityGroupRule rule = client.createSecurityGroupRule( + "tcp", "443", "443", "0.0.0.0/0", "", securityGroup.getId()); + assertNotNull(rule); + + } finally { + if (securityGroup != null) { + client.deleteSecurityGroup(securityGroup.getId()); + } + } + } + + } +} diff --git a/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairTest.java b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairTest.java new file mode 100644 index 0000000000..9901ba5f2d --- /dev/null +++ b/labs/openstack-nova/src/test/java/org/jclouds/openstack/nova/v1_1/parse/ParseKeyPairTest.java @@ -0,0 +1,64 @@ +/** + * 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; + +/** + * + * @author Michael Arnold + */ +@Test(groups = "unit", testName = "ParseKeyPairTest") +public class ParseKeyPairTest extends BaseItemParserTest { + + @Override + public String resource() { + return "/keypair_created.json"; + } + + @Override + @SelectJson("keypair") + @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()); + } +}