Skip to content
Permalink
Browse files
network and image tests / correct zones configuration
  • Loading branch information
Boris Trishkin authored and nacx committed Dec 20, 2017
1 parent 889b34b commit 9c74d22bb8723df1b31113265fef504272c66b23
Showing 11 changed files with 384 additions and 84 deletions.
@@ -47,6 +47,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.Set;

@RequestFilters({ BasicAuthentication.class, OrganisationIdFilter.class })
@Consumes(MediaType.APPLICATION_JSON)
@@ -75,7 +76,7 @@ public interface InfrastructureApi {
@Path("/operatingSystem")
@ResponseParser(ParseOperatingSystems.class)
@Fallback(Fallbacks.EmptyIterableWithMarkerOnNotFoundOr404.class)
PaginatedCollection<OperatingSystem> listOperatingSystems(@QueryParam("datacenterId") String datacenterId,
PaginatedCollection<OperatingSystem> listOperatingSystems(@QueryParam("datacenterId") Set<String> datacenterId,
PaginationOptions options);

@Named("infrastructure:operatingSystem")
@@ -84,7 +85,7 @@ PaginatedCollection<OperatingSystem> listOperatingSystems(@QueryParam("datacente
@Transform(ParseOperatingSystems.ToPagedIterable.class)
@ResponseParser(ParseOperatingSystems.class)
@Fallback(Fallbacks.EmptyPagedIterableOnNotFoundOr404.class)
PagedIterable<OperatingSystem> listOperatingSystems(@QueryParam("datacenterId") String datacenterId);
PagedIterable<OperatingSystem> listOperatingSystems(@QueryParam("datacenterId") Set<String> datacenterId);

final class ParseDatacenters extends ParseJson<Datacenters> {

@@ -138,7 +139,7 @@ protected Function<Object, IterableWithMarker<OperatingSystem>> markerToNextForA
@Override
public IterableWithMarker<OperatingSystem> apply(Object input) {
PaginationOptions paginationOptions = PaginationOptions.class.cast(input);
return api.getInfrastructureApi().listOperatingSystems(arg.get().toString(), paginationOptions);
return api.getInfrastructureApi().listOperatingSystems((Set<String>) arg.get(), paginationOptions);
}
};
}
@@ -37,7 +37,6 @@
import org.jclouds.dimensiondata.cloudcontrol.domain.Placement;
import org.jclouds.dimensiondata.cloudcontrol.domain.PublicIpBlock;
import org.jclouds.dimensiondata.cloudcontrol.domain.PublicIpBlocks;
import org.jclouds.dimensiondata.cloudcontrol.domain.Response;
import org.jclouds.dimensiondata.cloudcontrol.domain.Vlan;
import org.jclouds.dimensiondata.cloudcontrol.domain.Vlans;
import org.jclouds.dimensiondata.cloudcontrol.filters.OrganisationIdFilter;
@@ -165,7 +164,8 @@ PaginatedCollection<Vlan> listVlans(@QueryParam("networkDomainId") String networ
@Path("/addPublicIpBlock")
@Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindToJsonPayload.class)
Response addPublicIpBlock(@PayloadParam("networkDomainId") String networkDomainId);
@ResponseParser(ParsePublicIpBlockId.class)
String addPublicIpBlock(@PayloadParam("networkDomainId") String networkDomainId);

@Named("networkDomain:listPublicIPv4AddressBlocks")
@GET
@@ -203,7 +203,8 @@ PaginatedCollection<PublicIpBlock> listPublicIPv4AddressBlocks(@QueryParam("netw
@Produces(MediaType.APPLICATION_JSON)
@MapBinder(BindToJsonPayload.class)
@Fallback(Fallbacks.VoidOnNotFoundOr404.class)
Response createNatRule(@PayloadParam("networkDomainId") String networkDomainId,
@ResponseParser(ParseNatRuleId.class)
String createNatRule(@PayloadParam("networkDomainId") String networkDomainId,
@PayloadParam("internalIp") String internalIp, @PayloadParam("externalIp") String externalIp);

@Named("networkDomain:listNatRules")
@@ -483,5 +484,24 @@ final class FirewallRuleId extends ParseResponse {
super(json, "firewallRuleId");
}
}

@Singleton
final class ParsePublicIpBlockId extends ParseResponse {

@Inject
ParsePublicIpBlockId(Json json) {
super(json, "ipBlockId");
}
}

@Singleton
final class ParseNatRuleId extends ParseResponse {

@Inject
ParseNatRuleId(Json json) {
super(json, "natRuleId");
}
}

}

@@ -22,6 +22,9 @@
import org.jclouds.dimensiondata.cloudcontrol.internal.BaseDimensionDataCloudControlApiLiveTest;
import org.testng.annotations.Test;

import java.util.Set;
import java.util.HashSet;

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

@@ -45,9 +48,11 @@ private FluentIterable<Datacenter> getDatacenters() {

@Test
public void testListOperatingSystems() {
FluentIterable<Datacenter> datacenters = getDatacenters();
FluentIterable<OperatingSystem> operatingSystems = api().listOperatingSystems(datacenters.first().get().id())
.concat();
Set<String> datacenterIds = new HashSet<String>();
for (Datacenter dc : getDatacenters()) {
datacenterIds.add(dc.id());
}
FluentIterable<OperatingSystem> operatingSystems = api().listOperatingSystems(datacenterIds).concat();
assertNotNull(operatingSystems);
assertTrue(!operatingSystems.isEmpty());
for (OperatingSystem operatingSystem : operatingSystems) {
@@ -16,15 +16,14 @@
*/
package org.jclouds.dimensiondata.cloudcontrol.features;

import com.google.common.collect.Sets;
import org.jclouds.dimensiondata.cloudcontrol.domain.Datacenter;
import org.jclouds.dimensiondata.cloudcontrol.domain.OperatingSystem;
import org.jclouds.dimensiondata.cloudcontrol.internal.BaseAccountAwareCloudControlMockTest;
import org.jclouds.http.Uris;
import org.jclouds.location.suppliers.ZoneIdsSupplier;
import org.testng.annotations.Test;

import javax.ws.rs.HttpMethod;
import java.util.Set;

import static com.google.common.collect.Iterables.size;
import static org.testng.Assert.assertEquals;
@@ -43,7 +42,7 @@ public void testListDatacenters() throws Exception {
assertEquals(size(datacenters), 1); // Force the PagedIterable to advance
assertEquals(server.getRequestCount(), 2);

assertSent(HttpMethod.GET, expectedListDatacentersUriBuilder().toString());
assertSent(HttpMethod.GET, addZonesToUriBuilder(expectedListDatacentersUriBuilder()).toString());
}

public void testListDatacentersWithPagination() throws Exception {
@@ -53,29 +52,32 @@ public void testListDatacentersWithPagination() throws Exception {

consumeIterableAndAssertAdditionalPagesRequested(datacenters, 2, 1);

assertSent(HttpMethod.GET, expectedListDatacentersUriBuilder().toString());
assertSent(HttpMethod.GET, addPageNumberToUriBuilder(expectedListDatacentersUriBuilder(), 2).toString());
assertSent(HttpMethod.GET, addZonesToUriBuilder(expectedListDatacentersUriBuilder()).toString());
assertSent(HttpMethod.GET, addZonesToUriBuilder(expectedListDatacentersWithPaginationUriBuilder(2)).toString());
}

public void testListDatacenters404() throws Exception {
server.enqueue(response404());
assertTrue(api.getInfrastructureApi().listDatacenters().concat().isEmpty());
assertSent(HttpMethod.GET, expectedListDatacentersUriBuilder().toString());
assertSent(HttpMethod.GET, addZonesToUriBuilder(expectedListDatacentersUriBuilder()).toString());
}

private Uris.UriBuilder expectedListDatacentersUriBuilder() {
Uris.UriBuilder uriBuilder = Uris
.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);
}
return uriBuilder;
return addZonesToUriBuilder(uriBuilder);
}

private Uris.UriBuilder expectedListDatacentersWithPaginationUriBuilder(int pageNumber) {
Uris.UriBuilder uriBuilder = Uris
.uriBuilder("/caas/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/infrastructure/datacenter");
return addZonesToUriBuilder(addPageNumberToUriBuilder(uriBuilder, pageNumber, true));
}

public void testListOperatingSystems() throws Exception {
server.enqueue(jsonResponse("/operatingSystems.json"));
Iterable<OperatingSystem> operatingSystems = api.getInfrastructureApi().listOperatingSystems("NA9").concat();
Iterable<OperatingSystem> operatingSystems = api.getInfrastructureApi()
.listOperatingSystems(Sets.newHashSet("NA1", "NA9")).concat();

assertEquals(size(operatingSystems), 33);
assertEquals(server.getRequestCount(), 2);
@@ -86,26 +88,32 @@ public void testListOperatingSystems() throws Exception {
public void testListOperatingSystemsWithPagination() throws Exception {
server.enqueue(jsonResponse("/operatingSystems-page1.json"));
server.enqueue(jsonResponse("/operatingSystems-page2.json"));
Iterable<OperatingSystem> operatingSystems = api.getInfrastructureApi().listOperatingSystems("NA9").concat();
Iterable<OperatingSystem> operatingSystems = api.getInfrastructureApi()
.listOperatingSystems(Sets.newHashSet("NA1", "NA9")).concat();

consumeIterableAndAssertAdditionalPagesRequested(operatingSystems, 33, 1);

assertSent(HttpMethod.GET, expectedListOperatingSystemsUriBuilder().toString());
assertSent(HttpMethod.GET, addPageNumberToUriBuilder(expectedListOperatingSystemsUriBuilder(), 2).toString());
assertSent(HttpMethod.GET, expectedListOperatingSystemsWithPaginationUriBuilder(2).toString());

}

public void testListOperatingSystems404() throws Exception {
server.enqueue(response404());
assertTrue(api.getInfrastructureApi().listOperatingSystems("NA9").concat().isEmpty());
assertTrue(api.getInfrastructureApi().listOperatingSystems(Sets.newHashSet("NA1", "NA9")).concat().isEmpty());
assertSent(HttpMethod.GET, expectedListOperatingSystemsUriBuilder().toString());
}

private Uris.UriBuilder expectedListOperatingSystemsUriBuilder() {
Uris.UriBuilder uriBuilder = Uris
.uriBuilder("/caas/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/infrastructure/operatingSystem");
uriBuilder.addQuery("datacenterId", "NA9");
uriBuilder.addQuery("datacenterId", "NA1", "NA9");
return uriBuilder;
}

private Uris.UriBuilder expectedListOperatingSystemsWithPaginationUriBuilder(int pageNumber) {
Uris.UriBuilder uriBuilder = Uris
.uriBuilder("/caas/" + VERSION + "/6ac1e746-b1ea-4da5-a24e-caf1a978789d/infrastructure/operatingSystem");
return addPageNumberToUriBuilder(uriBuilder.addQuery("datacenterId", "NA1", "NA9"), pageNumber, false);
}
}

0 comments on commit 9c74d22

Please sign in to comment.