mirror of https://github.com/apache/jclouds.git
adding Expect-style tests for FloatingIPClient
This commit is contained in:
parent
967926dc28
commit
e7744784f2
|
@ -0,0 +1,166 @@
|
||||||
|
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.ParseFloatingIPListTest;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.parse.ParseFloatingIPTest;
|
||||||
|
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 FloatingIPAsyncClient}
|
||||||
|
*
|
||||||
|
* @author Michael Arnold
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "FloatingIPClientExpectTest")
|
||||||
|
public class FloatingIPClientExpectTest extends BaseNovaRestClientExpectTest {
|
||||||
|
|
||||||
|
public void testListFloatingIPsWhenResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest listFloatingIPs = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("GET")
|
||||||
|
.endpoint(
|
||||||
|
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "application/json")
|
||||||
|
.put("X-Auth-Token", authToken).build()).build();
|
||||||
|
|
||||||
|
HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResource("/floatingip_list.json")).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(
|
||||||
|
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
|
||||||
|
listFloatingIPs, listFloatingIPsResponse);
|
||||||
|
|
||||||
|
assertEquals(clientWhenFloatingIPsExist.getConfiguredRegions(),
|
||||||
|
ImmutableSet.of("North"));
|
||||||
|
|
||||||
|
assertEquals(clientWhenFloatingIPsExist.getFloatingIPClientForRegion("North")
|
||||||
|
.listFloatingIPs().toString(), new ParseFloatingIPListTest().expected()
|
||||||
|
.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testListFloatingIPsWhenResponseIs404() throws Exception {
|
||||||
|
HttpRequest listFloatingIPs = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("GET")
|
||||||
|
.endpoint(
|
||||||
|
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "application/json")
|
||||||
|
.put("X-Auth-Token", authToken).build()).build();
|
||||||
|
|
||||||
|
HttpResponse listFloatingIPsResponse = HttpResponse.builder().statusCode(404)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
NovaClient clientWhenNoServersExist = requestsSendResponses(
|
||||||
|
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
|
||||||
|
listFloatingIPs, listFloatingIPsResponse);
|
||||||
|
|
||||||
|
assertTrue(clientWhenNoServersExist.getFloatingIPClientForRegion("North")
|
||||||
|
.listFloatingIPs().isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFloatingIPWhenResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest getFloatingIP = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("GET")
|
||||||
|
.endpoint(
|
||||||
|
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "application/json")
|
||||||
|
.put("X-Auth-Token", authToken).build()).build();
|
||||||
|
|
||||||
|
HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResource("/floatingip_details.json")).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(
|
||||||
|
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
|
||||||
|
getFloatingIP, getFloatingIPResponse);
|
||||||
|
|
||||||
|
assertEquals(clientWhenFloatingIPsExist.getFloatingIPClientForRegion("North")
|
||||||
|
.getFloatingIP("1").toString(),
|
||||||
|
new ParseFloatingIPTest().expected().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetFloatingIPWhenResponseIs404() throws Exception {
|
||||||
|
HttpRequest getFloatingIP = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("GET")
|
||||||
|
.endpoint(
|
||||||
|
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips/1"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "application/json")
|
||||||
|
.put("X-Auth-Token", authToken).build()).build();
|
||||||
|
|
||||||
|
HttpResponse getFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenNoServersExist = requestsSendResponses(
|
||||||
|
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
|
||||||
|
getFloatingIP, getFloatingIPResponse);
|
||||||
|
|
||||||
|
assertNull(clientWhenNoServersExist.getFloatingIPClientForRegion("North")
|
||||||
|
.getFloatingIP("1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllocateWhenResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest allocateFloatingIP = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(
|
||||||
|
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "application/json")
|
||||||
|
.put("X-Auth-Token", authToken).build())
|
||||||
|
.payload(payloadFromStringWithContentType("{}", "application/json")).build();
|
||||||
|
|
||||||
|
HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResource("/floatingip_details.json")).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenFloatingIPsExist = requestsSendResponses(
|
||||||
|
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
|
||||||
|
allocateFloatingIP, allocateFloatingIPResponse);
|
||||||
|
|
||||||
|
assertEquals(clientWhenFloatingIPsExist.getFloatingIPClientForRegion("North")
|
||||||
|
.allocate().toString(),
|
||||||
|
new ParseFloatingIPTest().expected().toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllocateWhenResponseIs404() throws Exception {
|
||||||
|
HttpRequest allocateFloatingIP = HttpRequest
|
||||||
|
.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(
|
||||||
|
URI.create("https://compute.north.host/v1.1/3456/os-floating-ips"))
|
||||||
|
.headers(
|
||||||
|
ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "application/json")
|
||||||
|
.put("X-Auth-Token", authToken).build())
|
||||||
|
.payload(payloadFromStringWithContentType("{}", "application/json")).build();
|
||||||
|
|
||||||
|
HttpResponse allocateFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
NovaClient clientWhenNoServersExist = requestsSendResponses(
|
||||||
|
keystoneAuthWithAccessKeyAndSecretKey, responseWithKeystoneAccess,
|
||||||
|
allocateFloatingIP, allocateFloatingIPResponse);
|
||||||
|
|
||||||
|
assertNull(clientWhenNoServersExist.getFloatingIPClientForRegion("North")
|
||||||
|
.allocate());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
/**
|
||||||
|
* 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.ImmutableSet;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import org.jclouds.json.BaseSetParserTest;
|
||||||
|
import org.jclouds.json.config.GsonModule;
|
||||||
|
import org.jclouds.openstack.domain.Link;
|
||||||
|
import org.jclouds.openstack.domain.Link.Relation;
|
||||||
|
import org.jclouds.openstack.domain.Resource;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||||
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Michael Arnold
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "ParseFloatingIPListTest")
|
||||||
|
public class ParseFloatingIPListTest extends BaseSetParserTest<FloatingIP> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resource() {
|
||||||
|
return "/floatingip_list.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SelectJson("floating_ips")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public Set<FloatingIP> expected() {
|
||||||
|
return ImmutableSet
|
||||||
|
.of(
|
||||||
|
FloatingIP
|
||||||
|
.builder()
|
||||||
|
.id("1")
|
||||||
|
.instanceId("12")
|
||||||
|
.ip("10.0.0.3")
|
||||||
|
.fixedIp("11.0.0.1")
|
||||||
|
.build(),
|
||||||
|
FloatingIP
|
||||||
|
.builder()
|
||||||
|
.id("2")
|
||||||
|
.instanceId(null)
|
||||||
|
.ip("10.0.0.5")
|
||||||
|
.fixedIp(null)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Injector injector() {
|
||||||
|
return Guice.createInjector(new NovaParserModule(), new GsonModule());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import org.jclouds.json.BaseItemParserTest;
|
||||||
|
import org.jclouds.json.config.GsonModule;
|
||||||
|
import org.jclouds.openstack.domain.Link;
|
||||||
|
import org.jclouds.openstack.domain.Link.Relation;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.config.NovaParserModule;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.domain.Flavor;
|
||||||
|
import org.jclouds.openstack.nova.v1_1.domain.FloatingIP;
|
||||||
|
import org.jclouds.rest.annotations.SelectJson;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jeremy Daggett
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "ParseFloatingIPTest")
|
||||||
|
public class ParseFloatingIPTest extends BaseItemParserTest<FloatingIP> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String resource() {
|
||||||
|
return "/floatingip_details.json";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SelectJson("floating_ip")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public FloatingIP expected() {
|
||||||
|
return FloatingIP
|
||||||
|
.builder()
|
||||||
|
.id("1")
|
||||||
|
.instanceId("123")
|
||||||
|
.fixedIp("10.0.0.2")
|
||||||
|
.ip("10.0.0.3")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Injector injector() {
|
||||||
|
return Guice.createInjector(new NovaParserModule(), new GsonModule());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue