mirror of https://github.com/apache/jclouds.git
cloudservers imageextension expect tests are passing
This commit is contained in:
parent
c7469bbf4a
commit
fc159d1686
|
@ -1,71 +1,91 @@
|
||||||
|
/**
|
||||||
|
* 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.cloudservers.compute.predicates;
|
package org.jclouds.cloudservers.compute.predicates;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertFalse;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.jclouds.apis.ApiMetadata;
|
import org.jclouds.cloudservers.internal.BaseCloudServersComputeServiceExpectTest;
|
||||||
import org.jclouds.cloudservers.CloudServersApiMetadata;
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.domain.Image;
|
import org.jclouds.compute.domain.Image;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.openstack.keystone.v1_1.internal.BaseKeystoneRestClientExpectTest;
|
|
||||||
import org.jclouds.predicates.PredicateWithResult;
|
import org.jclouds.predicates.PredicateWithResult;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.net.HttpHeaders;
|
import com.google.common.net.HttpHeaders;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Module;
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author David Alves
|
||||||
|
*
|
||||||
|
*/
|
||||||
@Test(groups = "unit", testName = "GetImageWhenStatusActivePredicateWithResultExpectTest")
|
@Test(groups = "unit", testName = "GetImageWhenStatusActivePredicateWithResultExpectTest")
|
||||||
public class GetImageWhenStatusActivePredicateWithResultExpectTest extends BaseKeystoneRestClientExpectTest<Injector>
|
public class GetImageWhenStatusActivePredicateWithResultExpectTest extends
|
||||||
implements Function<ComputeServiceContext, Injector> {
|
BaseCloudServersComputeServiceExpectTest<Injector> {
|
||||||
|
|
||||||
private final HttpRequest listImagesDetail = HttpRequest
|
private final HttpRequest listImagesDetail = HttpRequest
|
||||||
.builder()
|
.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint(URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/detail?format=json"))
|
.endpoint(
|
||||||
.headers(ImmutableMultimap.<String, String> builder().put("X-Auth-Token", authToken)
|
URI.create("https://lon.servers.api.rackspacecloud.com/v1.0/10001786/images/detail?format=json&now=1257695648897"))
|
||||||
.put(HttpHeaders.ACCEPT, "application/json").build()).build();
|
.headers(ImmutableMultimap.<String, String> builder().put(HttpHeaders.ACCEPT, "application/json")
|
||||||
|
.put("X-Auth-Token", authToken).build()).build();
|
||||||
|
|
||||||
private final HttpResponse listImagesResponse = HttpResponse.builder().statusCode(200)
|
private final HttpResponse listImagesResponse = HttpResponse.builder().statusCode(200)
|
||||||
.payload(payloadFromResource("/test_list_images_detail_imageextension.json")).build();
|
.payload(payloadFromResource("/test_list_images_detail_imageextension.json")).build();
|
||||||
|
|
||||||
Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder()
|
private final Map<HttpRequest, HttpResponse> requestResponseMap = ImmutableMap.<HttpRequest, HttpResponse> builder()
|
||||||
.put(initialAuth, responseWithAuth).put(listImagesDetail, listImagesResponse).build();
|
.put(listImagesDetail, listImagesResponse).put(initialAuth, responseWithAuth).build();
|
||||||
|
|
||||||
public GetImageWhenStatusActivePredicateWithResultExpectTest() {
|
public void testReturnsFalseOnQueuedAndSavingAndTrueOnActive() {
|
||||||
provider = "cloudservers";
|
Injector injector = requestsSendResponses(requestResponseMap);
|
||||||
|
PredicateWithResult<Integer, Image> predicate = injector
|
||||||
|
.getInstance(GetImageWhenStatusActivePredicateWithResult.class);
|
||||||
|
assertTrue(predicate.apply(2));
|
||||||
|
assertFalse(predicate.apply(743));
|
||||||
|
assertFalse(predicate.apply(744));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void testFailsOnOtherStatuses() {
|
||||||
protected ApiMetadata createApiMetadata() {
|
Injector injector = requestsSendResponses(requestResponseMap);
|
||||||
return new CloudServersApiMetadata();
|
PredicateWithResult<Integer, Image> predicate = injector
|
||||||
|
.getInstance(GetImageWhenStatusActivePredicateWithResult.class);
|
||||||
|
assertTrue(illegalStateExceptionThrown(predicate, 745));
|
||||||
|
assertTrue(illegalStateExceptionThrown(predicate, 746));
|
||||||
|
assertTrue(illegalStateExceptionThrown(predicate, 747));
|
||||||
|
assertTrue(illegalStateExceptionThrown(predicate, 748));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private boolean illegalStateExceptionThrown(PredicateWithResult<Integer, Image> predicate, Integer id) {
|
||||||
protected Properties setupProperties() {
|
try {
|
||||||
Properties overrides = new Properties();
|
predicate.apply(id);
|
||||||
overrides.setProperty(PROPERTY_REGIONS, "US");
|
} catch (IllegalStateException e) {
|
||||||
overrides.setProperty(provider + ".endpoint", endpoint);
|
return true;
|
||||||
return overrides;
|
}
|
||||||
}
|
return false;
|
||||||
|
|
||||||
@Override
|
|
||||||
public Injector createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
|
|
||||||
return apply(createComputeServiceContext(fn, module, props));
|
|
||||||
}
|
|
||||||
|
|
||||||
private ComputeServiceContext createComputeServiceContext(Function<HttpRequest, HttpResponse> fn, Module module,
|
|
||||||
Properties props) {
|
|
||||||
return createInjector(fn, module, props).getInstance(ComputeServiceContext.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,10 +93,4 @@ public class GetImageWhenStatusActivePredicateWithResultExpectTest extends BaseK
|
||||||
return input.utils().injector();
|
return input.utils().injector();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testReturnsFalseOnQueuedAndSavingAndTrueOnActive() {
|
|
||||||
Injector injector = requestsSendResponses(requestResponseMap);
|
|
||||||
PredicateWithResult<Integer, Image> predicate = injector
|
|
||||||
.getInstance(GetImageWhenStatusActivePredicateWithResult.class);
|
|
||||||
assertTrue(predicate.apply(2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,103 @@
|
||||||
|
/**
|
||||||
|
* 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.cloudservers.internal;
|
||||||
|
|
||||||
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.jclouds.apis.ApiMetadata;
|
||||||
|
import org.jclouds.cloudservers.CloudServersApiMetadata;
|
||||||
|
import org.jclouds.cloudservers.config.CloudServersRestClientModule;
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.openstack.keystone.v1_1.config.AuthenticationServiceModule;
|
||||||
|
import org.jclouds.openstack.keystone.v1_1.internal.BaseKeystoneRestClientExpectTest;
|
||||||
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author David Alves
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class BaseCloudServersComputeServiceExpectTest<T> extends BaseKeystoneRestClientExpectTest<T> implements
|
||||||
|
Function<ComputeServiceContext, T> {
|
||||||
|
|
||||||
|
public BaseCloudServersComputeServiceExpectTest() {
|
||||||
|
provider = "cloudservers";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static final String CONSTANT_DATE = "2009-11-08T15:54:08.897Z";
|
||||||
|
|
||||||
|
public static class TestAuthenticationServiceModule extends AuthenticationServiceModule {
|
||||||
|
@Override
|
||||||
|
protected void configure() {
|
||||||
|
super.configure();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Module createModule() {
|
||||||
|
return new TestCloudServersRestClientModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConfiguresRestClient
|
||||||
|
protected static class TestCloudServersRestClientModule extends CloudServersRestClientModule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Supplier<Date> provideCacheBusterDate() {
|
||||||
|
return new Supplier<Date>() {
|
||||||
|
public Date get() {
|
||||||
|
return new SimpleDateFormatDateService().iso8601DateParse(CONSTANT_DATE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ApiMetadata createApiMetadata() {
|
||||||
|
return new CloudServersApiMetadata();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Properties setupProperties() {
|
||||||
|
Properties overrides = new Properties();
|
||||||
|
overrides.setProperty(PROPERTY_REGIONS, "US");
|
||||||
|
overrides.setProperty(provider + ".endpoint", endpoint);
|
||||||
|
return overrides;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T createClient(Function<HttpRequest, HttpResponse> fn, Module module, Properties props) {
|
||||||
|
return apply(createComputeServiceContext(fn, module, props));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ComputeServiceContext createComputeServiceContext(Function<HttpRequest, HttpResponse> fn, Module module,
|
||||||
|
Properties props) {
|
||||||
|
return createInjector(fn, module, props).getInstance(ComputeServiceContext.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,58 +3,63 @@
|
||||||
{
|
{
|
||||||
"id" : 2,
|
"id" : 2,
|
||||||
"name" : "CentOS 5.2",
|
"name" : "CentOS 5.2",
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2010-08-10T12:00:00Z",
|
"created" : "2010-08-10T12:00:00Z",
|
||||||
"status" : "ACTIVE"
|
"status" : "ACTIVE"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id" : 743,
|
"id" : 743,
|
||||||
"name" : "My Server Backup1",
|
"name" : "My Server Backup",
|
||||||
"serverId" : 12,
|
"serverId" : 12,
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2009-07-07T09:56:16-05:00",
|
"created" : "2009-07-07T09:56:16-05:00",
|
||||||
"status" : "SAVING",
|
"status" : "SAVING",
|
||||||
"progress" : 80
|
"progress" : 80
|
||||||
}
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"id" : 744,
|
"id" : 744,
|
||||||
"name" : "My Server Backup2",
|
"name" : "My Server Backup",
|
||||||
"serverId" : 12,
|
"serverId" : 12,
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2009-07-07T09:56:16-05:00",
|
"created" : "2009-07-07T09:56:16-05:00",
|
||||||
"status" : "UNRECOGNIZED",
|
"status" : "QUEUED"
|
||||||
}
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"id" : 745,
|
"id" : 745,
|
||||||
"name" : "My Server Backup3",
|
"name" : "My Server Backup",
|
||||||
"serverId" : 12,
|
"serverId" : 12,
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2009-07-07T09:56:16-05:00",
|
"created" : "2009-07-07T09:56:16-05:00",
|
||||||
"status" : "UNKNOWN",
|
"status" : "UNRECOGNIZED"
|
||||||
}
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"id" : 746,
|
"id" : 746,
|
||||||
"name" : "My Server Backup4",
|
"name" : "My Server Backup",
|
||||||
"serverId" : 12,
|
"serverId" : 12,
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2009-07-07T09:56:16-05:00",
|
"created" : "2009-07-07T09:56:16-05:00",
|
||||||
"status" : "PREPARING",
|
"status" : "UNKNOWN"
|
||||||
}
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"id" : 747,
|
"id" : 747,
|
||||||
"name" : "My Server Backup5",
|
"name" : "My Server Backup",
|
||||||
"serverId" : 12,
|
"serverId" : 12,
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2009-07-07T09:56:16-05:00",
|
"created" : "2009-07-07T09:56:16-05:00",
|
||||||
"status" : "QUEUED",
|
"status" : "PREPARING"
|
||||||
}
|
}
|
||||||
|
,
|
||||||
{
|
{
|
||||||
"id" : 748,
|
"id" : 748,
|
||||||
"name" : "My Server Backup6",
|
"name" : "My Server Backup",
|
||||||
"serverId" : 12,
|
"serverId" : 12,
|
||||||
"updated" : "2010-10-10T12:00:00Z",
|
"updated" : "2010-10-10T12:00:00Z",
|
||||||
"created" : "2009-07-07T09:56:16-05:00",
|
"created" : "2009-07-07T09:56:16-05:00",
|
||||||
"status" : "FAILED",
|
"status" : "FAILED"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
Loading…
Reference in New Issue