Skip to content
Permalink
Browse files
Updating Mock & Live tests. There was a bug due to not including /caa…
…s in path.
  • Loading branch information
trevorflanagan authored and nacx committed Apr 18, 2017
1 parent 4c6a9dd commit 92b548c2d81589f7ad9d58abcde9ca4941038810
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 32 deletions.
@@ -144,6 +144,7 @@
<test.dimensiondata-cloudcontrol.credential>
${test.dimensiondata-cloudcontrol.credential}
</test.dimensiondata-cloudcontrol.credential>
<jclouds.zones>LAB04_N2_VMWARE_1</jclouds.zones>
</systemPropertyVariables>
</configuration>
</execution>
@@ -57,6 +57,7 @@ public interface InfrastructureApi {
@GET
@Path("/datacenter")
@ResponseParser(ParseDatacenters.class)
@RequestFilters(DatacenterIdListDatacentersFilter.class)
@Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
PaginatedCollection<Datacenter> listDatacenters(PaginationOptions options);

@@ -17,11 +17,12 @@
package org.jclouds.dimensiondata.cloudcontrol.features;

import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.inject.TypeLiteral;
import org.jclouds.Fallbacks;
import org.jclouds.collect.IterableWithMarker;
import org.jclouds.collect.PagedIterable;
import org.jclouds.collect.internal.ArgsToPagedIterable;
import org.jclouds.collect.internal.Arg0ToPagedIterable;
import org.jclouds.dimensiondata.cloudcontrol.DimensionDataCloudControlApi;
import org.jclouds.dimensiondata.cloudcontrol.domain.CustomerImage;
import org.jclouds.dimensiondata.cloudcontrol.domain.CustomerImages;
@@ -46,7 +47,6 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.MediaType;
import java.util.List;

@RequestFilters({ BasicAuthentication.class, OrganisationIdFilter.class })
@Consumes(MediaType.APPLICATION_JSON)
@@ -106,7 +106,7 @@ final class ParseOsImages extends ParseJson<OsImages> {
super(json, TypeLiteral.get(OsImages.class));
}

private static class ToPagedIterable extends ArgsToPagedIterable<OsImage, ToPagedIterable> {
private static class ToPagedIterable extends Arg0ToPagedIterable<OsImage, ToPagedIterable> {

private DimensionDataCloudControlApi api;

@@ -116,7 +116,7 @@ private static class ToPagedIterable extends ArgsToPagedIterable<OsImage, ToPage
}

@Override
protected Function<Object, IterableWithMarker<OsImage>> markerToNextForArgs(List<Object> args) {
protected Function<Object, IterableWithMarker<OsImage>> markerToNextForArg0(Optional<Object> arg0) {
return new Function<Object, IterableWithMarker<OsImage>>() {
@Override
public IterableWithMarker<OsImage> apply(Object input) {
@@ -135,7 +135,7 @@ final class ParseCustomerImages extends ParseJson<CustomerImages> {
super(json, TypeLiteral.get(CustomerImages.class));
}

private static class ToPagedIterable extends ArgsToPagedIterable<CustomerImage, ToPagedIterable> {
private static class ToPagedIterable extends Arg0ToPagedIterable<CustomerImage, ToPagedIterable> {

private DimensionDataCloudControlApi api;

@@ -145,7 +145,7 @@ private static class ToPagedIterable extends ArgsToPagedIterable<CustomerImage,
}

@Override
protected Function<Object, IterableWithMarker<CustomerImage>> markerToNextForArgs(List<Object> args) {
protected Function<Object, IterableWithMarker<CustomerImage>> markerToNextForArg0(Optional<Object> arg0) {
return new Function<Object, IterableWithMarker<CustomerImage>>() {
@Override
public IterableWithMarker<CustomerImage> apply(Object input) {
@@ -30,7 +30,7 @@
*/
public class DatacenterIdFilter implements HttpRequestFilter {

protected final Supplier<Set<String>> datacenterIdsSupplier;
private final Supplier<Set<String>> datacenterIdsSupplier;

@Inject
DatacenterIdFilter(@Zone Supplier<Set<String>> datacenterIdsSupplier) {
@@ -29,9 +29,13 @@
* Adds set of Datacenter IDs as set in jclouds.zones JVM property.
*/
public class DatacenterIdListDatacentersFilter implements HttpRequestFilter {

private final Supplier<Set<String>> datacenterIdsSupplier;

@Inject
@Zone
protected Supplier<Set<String>> datacenterIdsSupplier;
DatacenterIdListDatacentersFilter(@Zone Supplier<Set<String>> datacenterIdsSupplier) {
this.datacenterIdsSupplier = datacenterIdsSupplier;
}

@Override
public HttpRequest filter(HttpRequest request) throws HttpException {
@@ -37,7 +37,7 @@
@Singleton
public class OrganisationIdFilter implements HttpRequestFilter {

private static final int ORGANIZATION_ID_INDEX = 2;
private static final int ORGANIZATION_ID_INDEX = 3;
private final Supplier<String> organisationIdSupplier;

@Inject
@@ -33,15 +33,15 @@ public void testGetAccount() throws Exception {
server.enqueue(jsonResponse("/account.json"));
Account account = api.getAccountApi().getMyAccount();
assertNotNull(account);
assertSent(HttpMethod.GET, "/" + VERSION + "/user/myUser");
assertSent(HttpMethod.GET, "/caas/" + VERSION + "/user/myUser");
}

@Test
public void testGetAccount_404() throws Exception {
server.enqueue(response404());
Account account = api.getAccountApi().getMyAccount();
assertNull(account);
assertSent(HttpMethod.GET, "/" + VERSION + "/user/myUser");
assertSent(HttpMethod.GET, "/caas/" + VERSION + "/user/myUser");
}

}
@@ -23,23 +23,33 @@
import org.testng.annotations.Test;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

@Test(groups = "live", testName = "InfrastructureApiLiveTest", singleThreaded = true)
public class InfrastructureApiLiveTest extends BaseDimensionDataCloudControlApiLiveTest {

@Test
public void testListDatacenters() {
FluentIterable<Datacenter> datacenters = api().listDatacenters().concat();
assertNotNull(datacenters);
FluentIterable<Datacenter> datacenters = getDatacenters();
assertTrue(!datacenters.isEmpty());
for (Datacenter datacenter : datacenters) {
assertNotNull(datacenter);
}
}

private FluentIterable<Datacenter> getDatacenters() {
FluentIterable<Datacenter> datacenters = api().listDatacenters().concat();
assertNotNull(datacenters);
return datacenters;
}

@Test
public void testListOperatingSystems() {
FluentIterable<OperatingSystem> operatingSystems = api().listOperatingSystems("NA9").concat();
FluentIterable<Datacenter> datacenters = getDatacenters();
FluentIterable<OperatingSystem> operatingSystems = api().listOperatingSystems(datacenters.first().get().id())
.concat();
assertNotNull(operatingSystems);
assertTrue(!operatingSystems.isEmpty());
for (OperatingSystem operatingSystem : operatingSystems) {
assertNotNull(operatingSystem);
}
@@ -65,7 +65,7 @@ public void testListDatacenters404() throws Exception {

private Uris.UriBuilder expectedListDatacentersUriBuilder() {
Uris.UriBuilder uriBuilder = Uris
.uriBuilder("/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/infrastructure/datacenter");
.uriBuilder("/caas/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/infrastructure/datacenter");
Set<String> zones = ctx.utils().injector().getInstance(ZoneIdsSupplier.class).get();
for (String zone : zones) {
uriBuilder.addQuery("id", zone);
@@ -103,7 +103,7 @@ public void testListOperatingSystems404() throws Exception {

private Uris.UriBuilder expectedListOperatingSystemsUriBuilder() {
Uris.UriBuilder uriBuilder = Uris
.uriBuilder("/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/infrastructure/operatingSystem");
.uriBuilder("/caas/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/infrastructure/operatingSystem");
uriBuilder.addQuery("datacenterId", "NA9");
return uriBuilder;
}
@@ -17,34 +17,55 @@
package org.jclouds.dimensiondata.cloudcontrol.features;

import com.google.common.collect.FluentIterable;
import org.jclouds.collect.PagedIterable;
import org.jclouds.dimensiondata.cloudcontrol.domain.CustomerImage;
import org.jclouds.dimensiondata.cloudcontrol.domain.OsImage;
import org.jclouds.dimensiondata.cloudcontrol.internal.BaseDimensionDataCloudControlApiLiveTest;
import org.testng.annotations.Test;

import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

@Test(groups = "live", testName = "ServerImageApiLiveTest", singleThreaded = true)
public class ServerImageApiLiveTest extends BaseDimensionDataCloudControlApiLiveTest {

@Test
public void testListOsImages() {
FluentIterable<OsImage> osImages = api().listOsImages().concat();
assertNotNull(osImages);
FluentIterable<OsImage> osImages = getOsImages().concat();
assertTrue(!osImages.isEmpty());
for (OsImage osImage : osImages) {
assertNotNull(osImage);
}
}

private PagedIterable<OsImage> getOsImages() {
PagedIterable<OsImage> osImages = api().listOsImages();
assertNotNull(osImages);
return osImages;
}

@Test
public void testGetOsImage() {
FluentIterable<OsImage> osImages = getOsImages().concat();
final OsImage osImage = api().getOsImage(osImages.iterator().next().id());
assertNotNull(osImage);
}

@Test
public void testListCustomerImages() {
FluentIterable<CustomerImage> customerImages = api().listCustomerImages().concat();
FluentIterable<CustomerImage> customerImages = getCustomerImages();
assertNotNull(customerImages);
for (CustomerImage customerImage : customerImages) {
assertNotNull(customerImage);
}
}

private FluentIterable<CustomerImage> getCustomerImages() {
FluentIterable<CustomerImage> customerImages = api().listCustomerImages().concat();
assertNotNull(customerImages);
return customerImages;
}

private ServerImageApi api() {
return api.getServerImageApi();
}
@@ -83,7 +83,7 @@ private Uris.UriBuilder getListOsImageUrl() {
Uris.UriBuilder uriBuilder = getOsImageUrl();
Set<String> zones = ctx.utils().injector().getInstance(ZoneIdsSupplier.class).get();
for (String zone : zones) {
uriBuilder.addQuery("datacanterId", zone);
uriBuilder.addQuery("datacenterId", zone);
}
return uriBuilder;
}
@@ -134,20 +134,20 @@ private Uris.UriBuilder getListCustomerImageUrl() {
Uris.UriBuilder uriBuilder = getCustomerImageUrl();
Set<String> zones = ctx.utils().injector().getInstance(ZoneIdsSupplier.class).get();
for (String zone : zones) {
uriBuilder.addQuery("datacanterId", zone);
uriBuilder.addQuery("datacenterId", zone);
}
return uriBuilder;
}

private Uris.UriBuilder getOsImageUrl() {
Uris.UriBuilder uriBuilder = Uris
.uriBuilder("/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/image/osImage");
.uriBuilder("/caas/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/image/osImage");
return uriBuilder;
}

private Uris.UriBuilder getCustomerImageUrl() {
Uris.UriBuilder uriBuilder = Uris
.uriBuilder("/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/image/customerImage");
.uriBuilder("/caas/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/image/customerImage");
return uriBuilder;
}

@@ -35,24 +35,24 @@ public void setup() {

@Test
public void testCaasUrl() {
String expectedPath = "/2.4/6ac1e746-b1ea-4da5-a24e-caf1a978789d/server/0896551e-4fe3-4450-a627-ad5548e7e83a?clone=trevor-test2&desc=trevor-description2";
String expectedPath = "/caas/2.4/6ac1e746-b1ea-4da5-a24e-caf1a978789d/server/0896551e-4fe3-4450-a627-ad5548e7e83a?clone=trevor-test2&desc=trevor-description2";
String updatedPath = new OrganisationIdFilter(orgIdSupplier).injectOrganisationId(
"/2.4/server/0896551e-4fe3-4450-a627-ad5548e7e83a?clone=trevor-test2&desc=trevor-description2");
"/caas/2.4/server/0896551e-4fe3-4450-a627-ad5548e7e83a?clone=trevor-test2&desc=trevor-description2");
assertEquals(updatedPath, expectedPath);
}

@Test
public void testDontAddIfAlreadyPresent() {
String expectedPath = "/2.4/6ac1e746-b1ea-4da5-a24e-caf1a978789d/server/0896551e-4fe3-4450-a627-ad5548e7e83a";
String expectedPath = "/caas/2.4/6ac1e746-b1ea-4da5-a24e-caf1a978789d/server/0896551e-4fe3-4450-a627-ad5548e7e83a";
String updatedPath = new OrganisationIdFilter(orgIdSupplier).injectOrganisationId(
"/2.4/6ac1e746-b1ea-4da5-a24e-caf1a978789d/server/0896551e-4fe3-4450-a627-ad5548e7e83a");
"/caas/2.4/6ac1e746-b1ea-4da5-a24e-caf1a978789d/server/0896551e-4fe3-4450-a627-ad5548e7e83a");
assertEquals(updatedPath, expectedPath);
}

@Test
public void testPathSegmentsLessThan2() {
String expectedPath = "/2.4";
String updatedPath = new OrganisationIdFilter(orgIdSupplier).injectOrganisationId("/2.4");
String expectedPath = "/caas/2.4";
String updatedPath = new OrganisationIdFilter(orgIdSupplier).injectOrganisationId("/caas/2.4");
assertEquals(updatedPath, expectedPath);
}

@@ -44,7 +44,7 @@ public void reset() {
@Override
protected RecordedRequest assertSent(String method, String path) throws InterruptedException {
if (!accountRetrieved) {
super.assertSent(HttpMethod.GET, "/" + VERSION + "/user/myUser");
super.assertSent(HttpMethod.GET, "/caas/" + VERSION + "/user/myUser");
accountRetrieved = true;
}
return super.assertSent(method, path);
@@ -75,7 +75,7 @@ public void start() throws IOException {
server = new MockWebServer();
server.play();
ctx = ContextBuilder.newBuilder(DimensionDataCloudControlProviderMetadata.builder().build()).credentials("", "")
.endpoint(url("")).modules(modules).overrides(overrides()).build();
.endpoint(url("/caas/")).modules(modules).overrides(overrides()).build();
json = ctx.utils().injector().getInstance(Json.class);
api = ctx.getApi();
applyAdditionalServerConfig();

0 comments on commit 92b548c

Please sign in to comment.