mirror of https://github.com/apache/jclouds.git
replace ExpectTests with MockWebServerTests
refactor AccountApiExpectedTest to AccountApiMockTest refactor DatacenterApiExpectTest to DatacenterApiMockTest refactor SoftwareDescriptionApiExpectTest to SoftwareDescriptionApiMockTest refactor VirtualGuestApiExpectTest to VirtualGuestApiMockTest refactor VirtualGuestBlockDeviceTemplateGroupApiExpectTest to VirtualGuestBlockDeviceTemplateGroupApiMockTest
This commit is contained in:
parent
cc3167c3f4
commit
a0ada77eec
|
@ -66,6 +66,11 @@
|
||||||
<artifactId>jclouds-compute</artifactId>
|
<artifactId>jclouds-compute</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.auto.value</groupId>
|
||||||
|
<artifactId>auto-value</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.jclouds</groupId>
|
<groupId>org.apache.jclouds</groupId>
|
||||||
<artifactId>jclouds-core</artifactId>
|
<artifactId>jclouds-core</artifactId>
|
||||||
|
@ -97,6 +102,18 @@
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp</groupId>
|
||||||
|
<artifactId>mockwebserver</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<!-- Already provided by jclouds-sshj -->
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.bouncycastle</groupId>
|
||||||
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.auto.service</groupId>
|
<groupId>com.google.auto.service</groupId>
|
||||||
<artifactId>auto-service</artifactId>
|
<artifactId>auto-service</artifactId>
|
||||||
|
|
|
@ -16,14 +16,14 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.domain;
|
package org.jclouds.softlayer.domain;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
|
||||||
import com.google.inject.name.Named;
|
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
|
||||||
|
|
||||||
import java.beans.ConstructorProperties;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Strings.emptyToNull;
|
import static com.google.common.base.Strings.emptyToNull;
|
||||||
|
import java.beans.ConstructorProperties;
|
||||||
|
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.inject.name.Named;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Address
|
* Class Address
|
||||||
|
|
|
@ -24,7 +24,7 @@ import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.Fallbacks;
|
import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.Fallback;
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
|
@ -54,7 +54,7 @@ public interface AccountApi {
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Account/VirtualGuests")
|
@Path("/SoftLayer_Account/VirtualGuests")
|
||||||
@QueryParams(keys = "objectMask", values = LIST_GUEST_MASK)
|
@QueryParams(keys = "objectMask", values = LIST_GUEST_MASK)
|
||||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
@Fallback(EmptySetOnNotFoundOr404.class)
|
||||||
Set<VirtualGuest> listVirtualGuests();
|
Set<VirtualGuest> listVirtualGuests();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +65,7 @@ public interface AccountApi {
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Account/getBlockDeviceTemplateGroups")
|
@Path("/SoftLayer_Account/getBlockDeviceTemplateGroups")
|
||||||
@QueryParams(keys = "objectMask", values = GUEST_MASK)
|
@QueryParams(keys = "objectMask", values = GUEST_MASK)
|
||||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
@Fallback(EmptySetOnNotFoundOr404.class)
|
||||||
Set<VirtualGuestBlockDeviceTemplateGroup> getBlockDeviceTemplateGroups();
|
Set<VirtualGuestBlockDeviceTemplateGroup> getBlockDeviceTemplateGroups();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.features;
|
package org.jclouds.softlayer.features;
|
||||||
|
|
||||||
|
import static org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
||||||
|
import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
|
@ -24,7 +26,6 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.Fallbacks;
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.Fallback;
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
|
@ -47,7 +48,7 @@ public interface DatacenterApi {
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Location_Datacenter/Datacenters")
|
@Path("/SoftLayer_Location_Datacenter/Datacenters")
|
||||||
@QueryParams(keys = "objectMask", values = "locationAddress;regions")
|
@QueryParams(keys = "objectMask", values = "locationAddress;regions")
|
||||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
@Fallback(EmptySetOnNotFoundOr404.class)
|
||||||
Set<Datacenter> listDatacenters();
|
Set<Datacenter> listDatacenters();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,6 +59,6 @@ public interface DatacenterApi {
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Location_Datacenter/{id}")
|
@Path("/SoftLayer_Location_Datacenter/{id}")
|
||||||
@QueryParams(keys = "objectMask", values = "locationAddress;regions")
|
@QueryParams(keys = "objectMask", values = "locationAddress;regions")
|
||||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
Datacenter getDatacenter(@PathParam("id") long id);
|
Datacenter getDatacenter(@PathParam("id") long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.features;
|
package org.jclouds.softlayer.features;
|
||||||
|
|
||||||
|
import static org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
||||||
|
import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
|
import static org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -27,7 +30,6 @@ import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.Fallbacks;
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.BinderParam;
|
import org.jclouds.rest.annotations.BinderParam;
|
||||||
import org.jclouds.rest.annotations.Fallback;
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
@ -78,7 +80,7 @@ public interface VirtualGuestApi {
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest/{id}/getObject")
|
@Path("/SoftLayer_Virtual_Guest/{id}/getObject")
|
||||||
@QueryParams(keys = "objectMask", values = GUEST_MASK)
|
@QueryParams(keys = "objectMask", values = GUEST_MASK)
|
||||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
VirtualGuest getVirtualGuest(@PathParam("id") long id);
|
VirtualGuest getVirtualGuest(@PathParam("id") long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,7 +92,7 @@ public interface VirtualGuestApi {
|
||||||
@Named("VirtualGuests:delete")
|
@Named("VirtualGuests:delete")
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest/{id}/deleteObject")
|
@Path("/SoftLayer_Virtual_Guest/{id}/deleteObject")
|
||||||
@Fallback(Fallbacks.FalseOnNotFoundOr404.class)
|
@Fallback(FalseOnNotFoundOr404.class)
|
||||||
boolean deleteVirtualGuest(@PathParam("id") long id);
|
boolean deleteVirtualGuest(@PathParam("id") long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,7 +102,7 @@ public interface VirtualGuestApi {
|
||||||
@Named("VirtualGuests:getCreateObjectOptions")
|
@Named("VirtualGuests:getCreateObjectOptions")
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest/getCreateObjectOptions")
|
@Path("/SoftLayer_Virtual_Guest/getCreateObjectOptions")
|
||||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
ContainerVirtualGuestConfiguration getCreateObjectOptions();
|
ContainerVirtualGuestConfiguration getCreateObjectOptions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +114,7 @@ public interface VirtualGuestApi {
|
||||||
@Named("VirtualGuest:rebootHard")
|
@Named("VirtualGuest:rebootHard")
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest/{id}/rebootHard.json")
|
@Path("/SoftLayer_Virtual_Guest/{id}/rebootHard.json")
|
||||||
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
|
@Fallback(VoidOnNotFoundOr404.class)
|
||||||
void rebootHardVirtualGuest(@PathParam("id") long id);
|
void rebootHardVirtualGuest(@PathParam("id") long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,7 +126,7 @@ public interface VirtualGuestApi {
|
||||||
@Named("VirtualGuest:pause")
|
@Named("VirtualGuest:pause")
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest/{id}/pause.json")
|
@Path("/SoftLayer_Virtual_Guest/{id}/pause.json")
|
||||||
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
|
@Fallback(VoidOnNotFoundOr404.class)
|
||||||
void pauseVirtualGuest(@PathParam("id") long id);
|
void pauseVirtualGuest(@PathParam("id") long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,7 +138,7 @@ public interface VirtualGuestApi {
|
||||||
@Named("VirtualGuest:resume")
|
@Named("VirtualGuest:resume")
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest/{id}/resume.json")
|
@Path("/SoftLayer_Virtual_Guest/{id}/resume.json")
|
||||||
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
|
@Fallback(VoidOnNotFoundOr404.class)
|
||||||
void resumeVirtualGuest(@PathParam("id") long id);
|
void resumeVirtualGuest(@PathParam("id") long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,6 +151,7 @@ public interface VirtualGuestApi {
|
||||||
@POST
|
@POST
|
||||||
@Path("/SoftLayer_Virtual_Guest/{id}/setTags")
|
@Path("/SoftLayer_Virtual_Guest/{id}/setTags")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Fallback(FalseOnNotFoundOr404.class)
|
||||||
boolean setTags(@PathParam("id") long id, @BinderParam(TagToJson.class) Set<String> tags);
|
boolean setTags(@PathParam("id") long id, @BinderParam(TagToJson.class) Set<String> tags);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,6 +180,6 @@ public interface VirtualGuestApi {
|
||||||
@Path("/SoftLayer_Virtual_Guest/{id}/getObject")
|
@Path("/SoftLayer_Virtual_Guest/{id}/getObject")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@QueryParams(keys = "objectMask", values = NOTES_MASK)
|
@QueryParams(keys = "objectMask", values = NOTES_MASK)
|
||||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
VirtualGuest getNotes(@PathParam("id") long id);
|
VirtualGuest getNotes(@PathParam("id") long id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.softlayer.features;
|
package org.jclouds.softlayer.features;
|
||||||
|
|
||||||
|
import static org.jclouds.Fallbacks.EmptySetOnNotFoundOr404;
|
||||||
|
import static org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
@ -25,7 +27,6 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.Fallbacks;
|
|
||||||
import org.jclouds.http.filters.BasicAuthentication;
|
import org.jclouds.http.filters.BasicAuthentication;
|
||||||
import org.jclouds.rest.annotations.Fallback;
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
import org.jclouds.rest.annotations.QueryParams;
|
import org.jclouds.rest.annotations.QueryParams;
|
||||||
|
@ -53,7 +54,7 @@ public interface VirtualGuestBlockDeviceTemplateGroupApi {
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages")
|
@Path("/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages")
|
||||||
@QueryParams(keys = "objectMask", values = MASK)
|
@QueryParams(keys = "objectMask", values = MASK)
|
||||||
@Fallback(Fallbacks.EmptySetOnNotFoundOr404.class)
|
@Fallback(EmptySetOnNotFoundOr404.class)
|
||||||
Set<VirtualGuestBlockDeviceTemplateGroup> getPublicImages();
|
Set<VirtualGuestBlockDeviceTemplateGroup> getPublicImages();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,6 +69,6 @@ public interface VirtualGuestBlockDeviceTemplateGroupApi {
|
||||||
@GET
|
@GET
|
||||||
@Path("/SoftLayer_Virtual_Guest_Block_Device_Template_Group/{id}/getObject")
|
@Path("/SoftLayer_Virtual_Guest_Block_Device_Template_Group/{id}/getObject")
|
||||||
@QueryParams(keys = "objectMask", values = MASK)
|
@QueryParams(keys = "objectMask", values = MASK)
|
||||||
@Fallback(Fallbacks.NullOnNotFoundOr404.class)
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
VirtualGuestBlockDeviceTemplateGroup getObject(@PathParam("id") String id);
|
VirtualGuestBlockDeviceTemplateGroup getObject(@PathParam("id") String id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF 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.softlayer.features;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.softlayer.SoftLayerApi;
|
|
||||||
import org.jclouds.softlayer.parse.GetVirtualGuestBlockDeviceTemplateGroupsResponseTest;
|
|
||||||
import org.jclouds.softlayer.parse.ListVirtualGuestsResponseTest;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "AccountApiExpectTest")
|
|
||||||
public class AccountApiExpectTest extends BaseSoftLayerApiExpectTest {
|
|
||||||
|
|
||||||
public void testListVirtualGuestsWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest listVirtualGuestsRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse listVirtualGuestsResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/account_list.json")).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(listVirtualGuestsRequest, listVirtualGuestsResponse);
|
|
||||||
|
|
||||||
assertEquals(api.getAccountApi().listVirtualGuests(),
|
|
||||||
new ListVirtualGuestsResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testListVirtualGuestsWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest listVirtualGuestsRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse listVirtualGuestsResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(listVirtualGuestsRequest, listVirtualGuestsResponse);
|
|
||||||
|
|
||||||
assertTrue(Iterables.isEmpty(api.getAccountApi().listVirtualGuests()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetBlockDeviceTemplateGroupsWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest getVirtualGuestBlockDeviceTemplateGroup = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getVirtualGuestBlockDeviceTemplateGroupResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/account_get_block_devices_template_groups.json")).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(getVirtualGuestBlockDeviceTemplateGroup, getVirtualGuestBlockDeviceTemplateGroupResponse);
|
|
||||||
|
|
||||||
assertEquals(api.getAccountApi().getBlockDeviceTemplateGroups(),
|
|
||||||
new GetVirtualGuestBlockDeviceTemplateGroupsResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetBlockDeviceTemplateGroupsWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest getObjectRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse);
|
|
||||||
|
|
||||||
assertTrue(Iterables.isEmpty(api.getAccountApi().getBlockDeviceTemplateGroups()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF 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.softlayer.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
import org.jclouds.softlayer.SoftLayerApi;
|
||||||
|
import org.jclouds.softlayer.config.SoftLayerParserModule;
|
||||||
|
import org.jclouds.softlayer.internal.BaseSoftLayerMockTest;
|
||||||
|
import org.jclouds.softlayer.parse.VirtualGuestBlockDeviceTemplateGroupsParseTest;
|
||||||
|
import org.jclouds.softlayer.parse.VirtualGuestsParseTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock tests for the {@link org.jclouds.softlayer.features.AccountApi} class.
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "AccountApiMockTest")
|
||||||
|
public class AccountApiMockTest extends BaseSoftLayerMockTest {
|
||||||
|
|
||||||
|
public void testListVirtualGuests() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/account_list.json")));
|
||||||
|
AccountApi api = getAccountApi(server);
|
||||||
|
try {
|
||||||
|
assertEquals(api.listVirtualGuests(), new VirtualGuestsParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEmptyListVirtualGuests() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
AccountApi api = getAccountApi(server);
|
||||||
|
try {
|
||||||
|
assertTrue(api.listVirtualGuests().isEmpty());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Account/VirtualGuests?objectMask=powerState%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem%3BblockDevices.diskImage%3BtagReferences");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetBlockDeviceTemplateGroups() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/account_get_block_devices_template_groups.json")));
|
||||||
|
AccountApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getAccountApi();
|
||||||
|
try {
|
||||||
|
assertEquals(api.getBlockDeviceTemplateGroups(), new VirtualGuestBlockDeviceTemplateGroupsParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEmptyBlockDeviceTemplateGroups() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
AccountApi api = getAccountApi(server);
|
||||||
|
try {
|
||||||
|
assertTrue(api.getBlockDeviceTemplateGroups().isEmpty());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Account/getBlockDeviceTemplateGroups?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private AccountApi getAccountApi(MockWebServer server) {
|
||||||
|
return api(SoftLayerApi.class, server.getUrl("/").toString(), new
|
||||||
|
JavaUrlHttpCommandExecutorServiceModule(), new SoftLayerParserModule()).getAccountApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,93 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF 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.softlayer.features;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertNull;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.softlayer.parse.GetDatacenterResponseTest;
|
|
||||||
import org.jclouds.softlayer.parse.ListDatacentersResponseTest;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "DatacenterApiExpectTest")
|
|
||||||
public class DatacenterApiExpectTest extends BaseSoftLayerApiExpectTest {
|
|
||||||
|
|
||||||
public void testListDatacentersWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest listDatacentersRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse listDatacentersResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/datacenter_list.json")).build();
|
|
||||||
|
|
||||||
DatacenterApi api = requestSendsResponse(listDatacentersRequest, listDatacentersResponse).getDatacenterApi();
|
|
||||||
|
|
||||||
assertEquals(api.listDatacenters(),
|
|
||||||
new ListDatacentersResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testListDatacenterWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest listDatacentersRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse listDatacentersResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
|
|
||||||
DatacenterApi api = requestSendsResponse(listDatacentersRequest, listDatacentersResponse).getDatacenterApi();
|
|
||||||
|
|
||||||
assertTrue(Iterables.isEmpty(api.listDatacenters()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetDatacenterWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest getDatacenterRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getDatacenterResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/datacenter_get.json")).build();
|
|
||||||
|
|
||||||
DatacenterApi api = requestSendsResponse(getDatacenterRequest, getDatacenterResponse).getDatacenterApi();
|
|
||||||
|
|
||||||
assertEquals(api.getDatacenter(265592),
|
|
||||||
new GetDatacenterResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetDatacenterWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest getDatacenterRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getDatacenterResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
|
|
||||||
DatacenterApi api = requestSendsResponse(getDatacenterRequest, getDatacenterResponse).getDatacenterApi();
|
|
||||||
|
|
||||||
assertNull(api.getDatacenter(265592));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF 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.softlayer.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.jclouds.softlayer.SoftLayerApi;
|
||||||
|
import org.jclouds.softlayer.internal.BaseSoftLayerMockTest;
|
||||||
|
import org.jclouds.softlayer.parse.DatacenterParseTest;
|
||||||
|
import org.jclouds.softlayer.parse.DatacentersParseTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock tests for the {@link org.jclouds.softlayer.features.DatacenterApi} class.
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "DatacenterApiMockTest")
|
||||||
|
public class DatacenterApiMockTest extends BaseSoftLayerMockTest {
|
||||||
|
|
||||||
|
public void testListDatacenters() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_list.json")));
|
||||||
|
DatacenterApi api = getDatacenterApi(server);
|
||||||
|
try {
|
||||||
|
assertEquals(api.listDatacenters(), new DatacentersParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void testEmptyListDatacenters() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
DatacenterApi api = getDatacenterApi(server);
|
||||||
|
try {
|
||||||
|
assertTrue(api.listDatacenters().isEmpty());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Location_Datacenter/Datacenters?objectMask=locationAddress%3Bregions");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetDatacenter() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_get.json")));
|
||||||
|
DatacenterApi api = getDatacenterApi(server);
|
||||||
|
try {
|
||||||
|
assertEquals(api.getDatacenter(265592), new DatacenterParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetNullDatacenter() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
DatacenterApi api = getDatacenterApi(server);
|
||||||
|
try {
|
||||||
|
assertNull(api.getDatacenter(265592));
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Location_Datacenter/265592?objectMask=locationAddress%3Bregions");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private DatacenterApi getDatacenterApi(MockWebServer server) {
|
||||||
|
return api(SoftLayerApi.class, server.getUrl("/").toString()).getDatacenterApi();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,55 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF 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.softlayer.features;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.softlayer.parse.GetAllObjectsResponseTest;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "SoftwareDescriptionApiExpectTest")
|
|
||||||
public class SoftwareDescriptionApiExpectTest extends BaseSoftLayerApiExpectTest {
|
|
||||||
|
|
||||||
public void testGetAllObjectsWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest getAllObjectsRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Software_Description/getAllObjects?objectMask=id%3Bname%3Bversion%3BoperatingSystem%3BlongDescription%3BreferenceCode")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
HttpResponse getAllObjectsResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/software_description_list.json")).build();
|
|
||||||
SoftwareDescriptionApi api = requestSendsResponse(getAllObjectsRequest, getAllObjectsResponse).getSoftwareDescriptionApi();
|
|
||||||
assertEquals(api.getAllObjects(), new GetAllObjectsResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetAllObjectsWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest getAllObjectsRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Software_Description/getAllObjects?objectMask=id%3Bname%3Bversion%3BoperatingSystem%3BlongDescription%3BreferenceCode")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
HttpResponse getAllObjectsResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftwareDescriptionApi api = requestSendsResponse(getAllObjectsRequest, getAllObjectsResponse).getSoftwareDescriptionApi();
|
|
||||||
assertTrue(Iterables.isEmpty(api.getAllObjects()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF 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.softlayer.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.jclouds.softlayer.SoftLayerApi;
|
||||||
|
import org.jclouds.softlayer.internal.BaseSoftLayerMockTest;
|
||||||
|
import org.jclouds.softlayer.parse.SoftwareDescriptionsParseTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock tests for the {@link org.jclouds.softlayer.features.SoftwareDescriptionApi} class.
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "SoftwareDescriptionApiMockTest")
|
||||||
|
public class SoftwareDescriptionApiMockTest extends BaseSoftLayerMockTest {
|
||||||
|
|
||||||
|
public void testGetAllObjects() throws Exception {
|
||||||
|
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/software_description_list.json")));
|
||||||
|
SoftwareDescriptionApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getSoftwareDescriptionApi();
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertEquals(api.getAllObjects(), new SoftwareDescriptionsParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Software_Description/getAllObjects?objectMask=id%3Bname%3Bversion%3BoperatingSystem%3BlongDescription%3BreferenceCode");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,263 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF 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.softlayer.features;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertFalse;
|
|
||||||
import static org.testng.Assert.assertNull;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.softlayer.SoftLayerApi;
|
|
||||||
import org.jclouds.softlayer.domain.Datacenter;
|
|
||||||
import org.jclouds.softlayer.domain.OperatingSystem;
|
|
||||||
import org.jclouds.softlayer.domain.VirtualGuest;
|
|
||||||
import org.jclouds.softlayer.parse.CreateVirtualGuestResponseTest;
|
|
||||||
import org.jclouds.softlayer.parse.GetCreateObjectOptionsResponseTest;
|
|
||||||
import org.jclouds.softlayer.parse.GetVirtualGuestResponseTest;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "VirtualGuestApiExpectTest")
|
|
||||||
public class VirtualGuestApiExpectTest extends BaseSoftLayerApiExpectTest {
|
|
||||||
|
|
||||||
public void testGetVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest getVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences%3BprivateNetworkOnlyFlag%3BsshKeys")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getVirtualGuestResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/virtual_guest_get.json")).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(getVirtualGuest, getVirtualGuestResponse);
|
|
||||||
|
|
||||||
assertEquals(api.getVirtualGuestApi().getVirtualGuest(3001812),
|
|
||||||
new GetVirtualGuestResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetVirtualGuestWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest getObjectRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences%3BprivateNetworkOnlyFlag%3BsshKeys")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse);
|
|
||||||
assertNull(api.getVirtualGuestApi().getVirtualGuest(3001812));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCreateVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest createVirtualGuest = HttpRequest.builder().method("POST")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
|
||||||
.payload(payloadFromResourceWithContentType("/virtual_guest_create.json", MediaType.APPLICATION_JSON))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse createVirtualGuestResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/virtual_guest_create_response.json")).build();
|
|
||||||
|
|
||||||
VirtualGuestApi api = requestSendsResponse(createVirtualGuest, createVirtualGuestResponse).getVirtualGuestApi();
|
|
||||||
VirtualGuest virtualGuest = createVirtualGuest();
|
|
||||||
VirtualGuest result = api.createVirtualGuest(virtualGuest);
|
|
||||||
assertEquals(result, new CreateVirtualGuestResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest deleteVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/deleteObject")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse deleteVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
|
|
||||||
|
|
||||||
VirtualGuestApi api = requestSendsResponse(deleteVirtualGuest, deleteVirtualGuestResponse).getVirtualGuestApi();
|
|
||||||
assertTrue(api.deleteVirtualGuest(1301396));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteVirtualGuestWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest deleteVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/deleteObject")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse deleteVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
VirtualGuestApi api = requestSendsResponse(deleteVirtualGuest, deleteVirtualGuestResponse).getVirtualGuestApi();
|
|
||||||
assertFalse(api.deleteVirtualGuest(1301396));
|
|
||||||
}
|
|
||||||
|
|
||||||
private VirtualGuest createVirtualGuest() {
|
|
||||||
return VirtualGuest.builder()
|
|
||||||
.domain("example.com")
|
|
||||||
.hostname("host1")
|
|
||||||
.id(1301396)
|
|
||||||
.maxMemory(1024)
|
|
||||||
.startCpus(1)
|
|
||||||
.localDiskFlag(true)
|
|
||||||
.operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST")
|
|
||||||
.operatingSystemReferenceCode("UBUNTU_LATEST")
|
|
||||||
.build())
|
|
||||||
.datacenter(Datacenter.builder().name("test").build())
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetCreateObjectOptionsWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest getVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getVirtualGuestResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/container_virtual_guest_configuration.json")).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(getVirtualGuest, getVirtualGuestResponse);
|
|
||||||
|
|
||||||
assertEquals(api.getVirtualGuestApi().getCreateObjectOptions(),
|
|
||||||
new GetCreateObjectOptionsResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetCreateObjectOptionsWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest getObjectRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/getCreateObjectOptions")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse);
|
|
||||||
assertNull(api.getVirtualGuestApi().getCreateObjectOptions());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testRebootHardVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest rebootHardVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/rebootHard.json")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse rebootHardVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(rebootHardVirtualGuest, rebootHardVirtualGuestResponse);
|
|
||||||
api.getVirtualGuestApi().rebootHardVirtualGuest(1301396);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testRebootHardVirtualGuestWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest rebootHardVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/rebootHard.json")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse rebootHardVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(rebootHardVirtualGuest, rebootHardVirtualGuestResponse);
|
|
||||||
api.getVirtualGuestApi().rebootHardVirtualGuest(1301396);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPauseVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest pauseVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/pause.json")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse pauseVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(pauseVirtualGuest, pauseVirtualGuestResponse);
|
|
||||||
api.getVirtualGuestApi().pauseVirtualGuest(1301396);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPauseVirtualGuestWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest pauseVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/pause.json")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse pauseVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(pauseVirtualGuest, pauseVirtualGuestResponse);
|
|
||||||
api.getVirtualGuestApi().pauseVirtualGuest(1301396);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testResumeVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest resumeVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/resume.json")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse resumeVirtualGuestResponse = HttpResponse.builder().statusCode(200).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(resumeVirtualGuest, resumeVirtualGuestResponse);
|
|
||||||
api.getVirtualGuestApi().resumeVirtualGuest(1301396);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testResumeVirtualGuestWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest resumeVirtualGuest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/resume.json")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse resumeVirtualGuestResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(resumeVirtualGuest, resumeVirtualGuestResponse);
|
|
||||||
api.getVirtualGuestApi().resumeVirtualGuest(1301396);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSetTagsOnVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest setTagsOnVirtualGuest = HttpRequest.builder().method("POST")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/setTags")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
|
||||||
.payload(payloadFromResourceWithContentType("/virtual_guest_set_tags.json", MediaType.APPLICATION_JSON))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse setTagsOnVirtualGuestResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/virtual_guest_set_tags_response.json")).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(setTagsOnVirtualGuest, setTagsOnVirtualGuestResponse);
|
|
||||||
VirtualGuest virtualGuest = createVirtualGuest();
|
|
||||||
assertTrue(api.getVirtualGuestApi().setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSetNotesOnVirtualGuestWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest setNodesOnVirtualGuest = HttpRequest.builder().method("POST")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1301396/editObject")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==")
|
|
||||||
.payload(payloadFromResourceWithContentType("/virtual_guest_set_notes.json", MediaType.APPLICATION_JSON))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
HttpResponse setNotesOnVirtualGuestResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload("true").build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(setNodesOnVirtualGuest, setNotesOnVirtualGuestResponse);
|
|
||||||
VirtualGuest virtualGuest = createVirtualGuest();
|
|
||||||
assertTrue(api.getVirtualGuestApi().setNotes(virtualGuest.getId(), "some notes"));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,234 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF 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.softlayer.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
import org.jclouds.softlayer.SoftLayerApi;
|
||||||
|
import org.jclouds.softlayer.config.SoftLayerParserModule;
|
||||||
|
import org.jclouds.softlayer.domain.Datacenter;
|
||||||
|
import org.jclouds.softlayer.domain.OperatingSystem;
|
||||||
|
import org.jclouds.softlayer.domain.VirtualGuest;
|
||||||
|
import org.jclouds.softlayer.internal.BaseSoftLayerMockTest;
|
||||||
|
import org.jclouds.softlayer.parse.GetCreateObjectOptionsParseTest;
|
||||||
|
import org.jclouds.softlayer.parse.VirtualGuestParseTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock tests for the {@link org.jclouds.softlayer.features.VirtualGuestApi} class.
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "VirtualGuestApiMockTest")
|
||||||
|
public class VirtualGuestApiMockTest extends BaseSoftLayerMockTest {
|
||||||
|
|
||||||
|
public void testGetVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/virtual_guest_get.json")));
|
||||||
|
VirtualGuestApi api = getVirtualGuestApi(server);
|
||||||
|
|
||||||
|
try {
|
||||||
|
assertEquals(api.getVirtualGuest(3001812), new VirtualGuestParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences%3BprivateNetworkOnlyFlag%3BsshKeys");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetNullVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestApi api = getVirtualGuestApi(server);
|
||||||
|
try {
|
||||||
|
assertNull(api.getVirtualGuest(3001812));
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/3001812/getObject?objectMask=id%3Bhostname%3Bdomain%3BfullyQualifiedDomainName%3BpowerState%3BmaxCpu%3BmaxMemory%3BstatusId%3BoperatingSystem.passwords%3BprimaryBackendIpAddress%3BprimaryIpAddress%3BactiveTransactionCount%3BblockDevices.diskImage%3Bdatacenter%3BtagReferences%3BprivateNetworkOnlyFlag%3BsshKeys");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCreateVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/virtual_guest_get.json")));
|
||||||
|
VirtualGuestApi api = getVirtualGuestApi(server);
|
||||||
|
VirtualGuest virtualGuest = createVirtualGuest();
|
||||||
|
try {
|
||||||
|
assertEquals(api.createVirtualGuest(virtualGuest), new VirtualGuestParseTest().expected());
|
||||||
|
assertSent(server, "POST", "/SoftLayer_Virtual_Guest");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse());
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
assertTrue(api.deleteVirtualGuest(1301396));
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/deleteObject");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteNonExistingVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
assertFalse(api.deleteVirtualGuest(1301396));
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/deleteObject");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetCreateObjectOptions() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/container_virtual_guest_configuration.json")));
|
||||||
|
VirtualGuestApi api = getVirtualGuestApi(server);
|
||||||
|
try {
|
||||||
|
assertEquals(api.getCreateObjectOptions(), new GetCreateObjectOptionsParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/getCreateObjectOptions");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetNullCreateObjectOptions() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
assertNull(api.getCreateObjectOptions());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/getCreateObjectOptions");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRebootHardVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_get.json")));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
api.rebootHardVirtualGuest(1301396);
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/rebootHard.json");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testRebootNonExistingVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
api.rebootHardVirtualGuest(1301396);
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/rebootHard.json");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPauseVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_get.json")));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
api.pauseVirtualGuest(1301396);
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/pause.json");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPauseNonExistingVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
api.pauseVirtualGuest(1301396);
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/pause.json");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResumeVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/datacenter_get.json")));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
api.resumeVirtualGuest(1301396);
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/resume.json");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResumeNonExistingVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
try {
|
||||||
|
api.resumeVirtualGuest(1301396);
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest/1301396/resume.json");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSetTagsOnVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/virtual_guest_set_tags_response.json")));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
VirtualGuest virtualGuest = createVirtualGuest();
|
||||||
|
try {
|
||||||
|
assertTrue(api.setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3")));
|
||||||
|
assertSent(server, "POST", "/SoftLayer_Virtual_Guest/1301396/setTags");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSetTagsOnNonExistingVirtualGuest() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestApi api = api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestApi();
|
||||||
|
VirtualGuest virtualGuest = createVirtualGuest();
|
||||||
|
try {
|
||||||
|
assertFalse(api.setTags(virtualGuest.getId(), ImmutableSet.of("test1", "test2", "test3")));
|
||||||
|
assertSent(server, "POST", "/SoftLayer_Virtual_Guest/1301396/setTags");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualGuest createVirtualGuest() {
|
||||||
|
return VirtualGuest.builder()
|
||||||
|
.domain("example.com")
|
||||||
|
.hostname("host1")
|
||||||
|
.id(1301396)
|
||||||
|
.maxMemory(1024)
|
||||||
|
.startCpus(1)
|
||||||
|
.localDiskFlag(true)
|
||||||
|
.operatingSystem(OperatingSystem.builder().id("UBUNTU_LATEST")
|
||||||
|
.operatingSystemReferenceCode("UBUNTU_LATEST")
|
||||||
|
.build())
|
||||||
|
.datacenter(Datacenter.builder().name("test").build())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualGuestApi getVirtualGuestApi(MockWebServer server) {
|
||||||
|
return api(SoftLayerApi.class, server.getUrl("/").toString(), new
|
||||||
|
JavaUrlHttpCommandExecutorServiceModule(), new SoftLayerParserModule()).getVirtualGuestApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,91 +0,0 @@
|
||||||
/*
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright ownership.
|
|
||||||
* The ASF 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.softlayer.features;
|
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
|
||||||
import static org.testng.Assert.assertNull;
|
|
||||||
import static org.testng.Assert.assertTrue;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
|
||||||
import org.jclouds.http.HttpResponse;
|
|
||||||
import org.jclouds.softlayer.SoftLayerApi;
|
|
||||||
import org.jclouds.softlayer.parse.GetVirtualGuestBlockDeviceTemplateGroupResponseTest;
|
|
||||||
import org.jclouds.softlayer.parse.ListPublicImagesResponseTest;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
@Test(groups = "unit", testName = "VirtualGuestBlockDeviceTemplateGroupApiExpectTest")
|
|
||||||
public class VirtualGuestBlockDeviceTemplateGroupApiExpectTest extends BaseSoftLayerApiExpectTest {
|
|
||||||
|
|
||||||
public void testListPublicImagesWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest listPublicImagesRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse listPublicImagesResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/virtual_guest_block_device_template_group_get_public_images.json")).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(listPublicImagesRequest, listPublicImagesResponse);
|
|
||||||
|
|
||||||
assertEquals(api.getVirtualGuestBlockDeviceTemplateGroupApi().getPublicImages(),
|
|
||||||
new ListPublicImagesResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testListPublicImagesWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest listPublicImagesRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse listPublicImagesResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(listPublicImagesRequest, listPublicImagesResponse);
|
|
||||||
assertTrue(Iterables.isEmpty(api.getVirtualGuestBlockDeviceTemplateGroupApi().getPublicImages()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetObjectWhenResponseIs2xx() {
|
|
||||||
|
|
||||||
HttpRequest getObject = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/3001812/getObject?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getObjectResponse = HttpResponse.builder().statusCode(200)
|
|
||||||
.payload(payloadFromResource("/virtual_guest_block_device_template_group_get.json")).build();
|
|
||||||
|
|
||||||
SoftLayerApi api = requestSendsResponse(getObject, getObjectResponse);
|
|
||||||
|
|
||||||
assertEquals(api.getVirtualGuestBlockDeviceTemplateGroupApi().getObject("3001812"),
|
|
||||||
new GetVirtualGuestBlockDeviceTemplateGroupResponseTest().expected());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetObjectWhenResponseIs4xx() {
|
|
||||||
|
|
||||||
HttpRequest getObjectRequest = HttpRequest.builder().method("GET")
|
|
||||||
.endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest_Block_Device_Template_Group/3001812/getObject?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription")
|
|
||||||
.addHeader("Accept", "application/json")
|
|
||||||
.addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build();
|
|
||||||
|
|
||||||
HttpResponse getObjectResponse = HttpResponse.builder().statusCode(404).build();
|
|
||||||
SoftLayerApi api = requestSendsResponse(getObjectRequest, getObjectResponse);
|
|
||||||
assertNull(api.getVirtualGuestBlockDeviceTemplateGroupApi().getObject("3001812"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF 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.softlayer.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.jclouds.softlayer.SoftLayerApi;
|
||||||
|
import org.jclouds.softlayer.internal.BaseSoftLayerMockTest;
|
||||||
|
import org.jclouds.softlayer.parse.PublicImagesParseTest;
|
||||||
|
import org.jclouds.softlayer.parse.VirtualGuestBlockDeviceTemplateGroupParseTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockResponse;
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock tests for the {@link VirtualGuestBlockDeviceTemplateGroupApi} class.
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "VirtualGuestBlockDeviceTemplateGroupApiMockTest")
|
||||||
|
public class VirtualGuestBlockDeviceTemplateGroupApiMockTest extends BaseSoftLayerMockTest {
|
||||||
|
|
||||||
|
public void testListPublicImages() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/virtual_guest_block_device_template_group_get_public_images.json")));
|
||||||
|
VirtualGuestBlockDeviceTemplateGroupApi api = getVirtualGuestBlockDeviceTemplateGroupApi(server);
|
||||||
|
try {
|
||||||
|
assertEquals(api.getPublicImages(), new PublicImagesParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testEmptyListImages() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestBlockDeviceTemplateGroupApi api = getVirtualGuestBlockDeviceTemplateGroupApi(server);
|
||||||
|
try {
|
||||||
|
assertTrue(api.getPublicImages().isEmpty());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest_Block_Device_Template_Group/getPublicImages?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetObject() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/virtual_guest_block_device_template_group_get.json")));
|
||||||
|
VirtualGuestBlockDeviceTemplateGroupApi api = getVirtualGuestBlockDeviceTemplateGroupApi(server);
|
||||||
|
try {
|
||||||
|
assertEquals(api.getObject("3001812"), new VirtualGuestBlockDeviceTemplateGroupParseTest().expected());
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest_Block_Device_Template_Group/3001812/getObject?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetNullObject() throws Exception {
|
||||||
|
MockWebServer server = mockWebServer(new MockResponse().setResponseCode(404));
|
||||||
|
VirtualGuestBlockDeviceTemplateGroupApi api = getVirtualGuestBlockDeviceTemplateGroupApi(server);
|
||||||
|
try {
|
||||||
|
assertNull(api.getObject("3001812"));
|
||||||
|
assertSent(server, "GET", "/SoftLayer_Virtual_Guest_Block_Device_Template_Group/3001812/getObject?objectMask=children.blockDevices.diskImage.softwareReferences.softwareDescription");
|
||||||
|
} finally {
|
||||||
|
server.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private VirtualGuestBlockDeviceTemplateGroupApi getVirtualGuestBlockDeviceTemplateGroupApi(MockWebServer server) {
|
||||||
|
return api(SoftLayerApi.class, server.getUrl("/").toString()).getVirtualGuestBlockDeviceTemplateGroupApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF 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.softlayer.internal;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.jclouds.Constants.PROPERTY_CREDENTIAL;
|
||||||
|
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||||
|
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||||
|
import static org.jclouds.util.Strings2.toStringAndClose;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.http.BaseMockWebServerTest;
|
||||||
|
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
|
||||||
|
import org.jclouds.softlayer.SoftLayerApiMetadata;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.inject.Module;
|
||||||
|
import com.squareup.okhttp.mockwebserver.MockWebServer;
|
||||||
|
import com.squareup.okhttp.mockwebserver.RecordedRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all SoftLayer mock tests.
|
||||||
|
*/
|
||||||
|
public class BaseSoftLayerMockTest extends BaseMockWebServerTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addOverrideProperties(Properties properties) {
|
||||||
|
properties.setProperty(PROPERTY_IDENTITY, "uuid");
|
||||||
|
properties.setProperty(PROPERTY_CREDENTIAL, "apikey");
|
||||||
|
properties.setProperty(PROPERTY_API_VERSION, "3");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Module createConnectionModule() {
|
||||||
|
return new JavaUrlHttpCommandExecutorServiceModule();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] payloadFromResource(String resource) {
|
||||||
|
try {
|
||||||
|
return toStringAndClose(getClass().getResourceAsStream(resource)).getBytes(Charsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw Throwables.propagate(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected RecordedRequest assertSent(MockWebServer server, String method, String path) throws InterruptedException {
|
||||||
|
RecordedRequest request = server.takeRequest();
|
||||||
|
assertThat(request.getMethod()).isEqualTo(method);
|
||||||
|
assertThat(request.getPath()).isEqualTo("/v" + new SoftLayerApiMetadata().getVersion() + path);
|
||||||
|
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo(MediaType.APPLICATION_JSON);
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,7 +28,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class GetDatacenterResponseTest extends BaseSoftLayerParseTest<Datacenter> {
|
public class DatacenterParseTest extends BaseSoftLayerParseTest<Datacenter> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resource() {
|
public String resource() {
|
|
@ -28,7 +28,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ListDatacentersResponseTest extends BaseSoftLayerParseTest<Set<Datacenter>> {
|
public class DatacentersParseTest extends BaseSoftLayerParseTest<Set<Datacenter>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resource() {
|
public String resource() {
|
|
@ -30,7 +30,7 @@ import org.jclouds.softlayer.internal.BaseSoftLayerParseTest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
public class GetCreateObjectOptionsResponseTest extends BaseSoftLayerParseTest<ContainerVirtualGuestConfiguration> {
|
public class GetCreateObjectOptionsParseTest extends BaseSoftLayerParseTest<ContainerVirtualGuestConfiguration> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resource() {
|
public String resource() {
|
|
@ -32,7 +32,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ListPublicImagesResponseTest extends
|
public class PublicImagesParseTest extends
|
||||||
BaseSoftLayerParseTest<Set<VirtualGuestBlockDeviceTemplateGroup>> {
|
BaseSoftLayerParseTest<Set<VirtualGuestBlockDeviceTemplateGroup>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -28,7 +28,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class GetAllObjectsResponseTest extends BaseSoftLayerParseTest<Set<SoftwareDescription>> {
|
public class SoftwareDescriptionsParseTest extends BaseSoftLayerParseTest<Set<SoftwareDescription>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resource() {
|
public String resource() {
|
|
@ -31,7 +31,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class
|
public class
|
||||||
GetVirtualGuestBlockDeviceTemplateGroupResponseTest extends
|
VirtualGuestBlockDeviceTemplateGroupParseTest extends
|
||||||
BaseSoftLayerParseTest<VirtualGuestBlockDeviceTemplateGroup> {
|
BaseSoftLayerParseTest<VirtualGuestBlockDeviceTemplateGroup> {
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -33,7 +33,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class
|
public class
|
||||||
GetVirtualGuestBlockDeviceTemplateGroupsResponseTest extends
|
VirtualGuestBlockDeviceTemplateGroupsParseTest extends
|
||||||
BaseSoftLayerParseTest<Set<VirtualGuestBlockDeviceTemplateGroup>> {
|
BaseSoftLayerParseTest<Set<VirtualGuestBlockDeviceTemplateGroup>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
|
@ -25,7 +25,7 @@ import org.jclouds.softlayer.internal.BaseSoftLayerParseTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class GetVirtualGuestResponseTest extends BaseSoftLayerParseTest<VirtualGuest> {
|
public class VirtualGuestParseTest extends BaseSoftLayerParseTest<VirtualGuest> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resource() {
|
public String resource() {
|
|
@ -29,7 +29,7 @@ import org.testng.annotations.Test;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
@Test(groups = "unit")
|
@Test(groups = "unit")
|
||||||
public class ListVirtualGuestsResponseTest extends BaseSoftLayerParseTest<Set<VirtualGuest>> {
|
public class VirtualGuestsParseTest extends BaseSoftLayerParseTest<Set<VirtualGuest>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resource() {
|
public String resource() {
|
Loading…
Reference in New Issue