You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2014/03/31 09:13:53 UTC
[40/52] [partial] Moving jclouds dependencies to accurate parent
directories
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/FlavorInZoneToHardwareTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/FlavorInZoneToHardwareTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/FlavorInZoneToHardwareTest.java
new file mode 100644
index 0000000..b3a0e30
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/FlavorInZoneToHardwareTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.openstack.nova.v2_0.domain.Flavor;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.FlavorInZone;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests the function used to transform Flavor objects into Hardware objects
+ *
+ * @author Matt Stephenson, Adrian Cole
+ */
+@Test(testName = "FlavorInZoneToHardwareTest")
+public class FlavorInZoneToHardwareTest {
+ Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
+ "openstack-nova").build();
+ Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
+ LocationScope.ZONE).parent(provider).build();
+ Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
+ .<String, Location> of("az-1.region-a.geo-1", zone));
+
+ @Test
+ public void testConversionWhereLocationFound() {
+
+ UUID id = UUID.randomUUID();
+
+ FlavorInZone flavorInZoneToConvert = new FlavorInZone(Flavor.builder().id(id.toString())
+ .name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "az-1.region-a.geo-1");
+
+ Hardware converted = new FlavorInZoneToHardware(locationIndex).apply(flavorInZoneToConvert);
+
+ Flavor flavorToConvert = flavorInZoneToConvert.getFlavor();
+ assertEquals(converted.getName(), flavorToConvert.getName());
+ assertEquals(converted.getId(), flavorInZoneToConvert.slashEncode());
+ assertEquals(converted.getProviderId(), flavorToConvert.getId());
+ assertEquals(converted.getLocation(), locationIndex.get().get("az-1.region-a.geo-1"));
+
+ assertEquals(converted.getRam(), flavorToConvert.getRam());
+
+ assertNotNull(converted.getProcessors());
+ assertFalse(converted.getProcessors().isEmpty());
+ assertEquals(converted.getProcessors().iterator().next().getCores(), (double) flavorToConvert.getVcpus());
+
+ assertNotNull(converted.getVolumes());
+ assertFalse(converted.getVolumes().isEmpty());
+ assertEquals(converted.getVolumes().iterator().next().getSize(), Float.valueOf(flavorToConvert.getDisk()));
+
+ }
+
+ @Test(expectedExceptions = IllegalStateException.class)
+ public void testConversionWhereLocationNotFound() {
+
+ UUID id = UUID.randomUUID();
+
+ FlavorInZone flavorInZoneToConvert = new FlavorInZone(Flavor.builder().id(id.toString())
+ .name("Test Flavor " + id).ram(262144).disk(10000).vcpus(16).build(), "South");
+ new FlavorInZoneToHardware(locationIndex).apply(flavorInZoneToConvert);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageInZoneToImageTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageInZoneToImageTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageInZoneToImageTest.java
new file mode 100644
index 0000000..dfc15f4
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageInZoneToImageTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.jclouds.compute.domain.OperatingSystem;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
+import org.jclouds.openstack.nova.v2_0.domain.Image;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ImageInZone;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Function;
+import com.google.common.base.Functions;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests the function that transforms nova-specific images to generic images.
+ *
+ * @author Matt Stephenson, Adrian Cole
+ */
+@Test(testName = "ImageInZoneToHardwareTest")
+public class ImageInZoneToImageTest {
+
+ Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
+ "openstack-nova").build();
+ Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
+ LocationScope.ZONE).parent(provider).build();
+ Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
+ .<String, Location> of("az-1.region-a.geo-1", zone));
+
+ @Test
+ public void testConversionWhereLocationFound() {
+ UUID id = UUID.randomUUID();
+ Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).status(Image.Status.DELETED).build();
+ OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
+ "My Test OS", true);
+ ImageInZoneToImage converter = new ImageInZoneToImage(NovaComputeServiceContextModule.toPortableImageStatus,
+ constant(operatingSystem), locationIndex);
+
+ ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "az-1.region-a.geo-1");
+
+ org.jclouds.compute.domain.Image convertedImage = converter.apply(novaImageInZoneToConvert);
+
+ assertEquals(convertedImage.getId(), novaImageInZoneToConvert.slashEncode());
+ assertEquals(convertedImage.getProviderId(), novaImageToConvert.getId());
+ assertEquals(convertedImage.getLocation(), locationIndex.get().get("az-1.region-a.geo-1"));
+
+ assertEquals(convertedImage.getName(), novaImageToConvert.getName());
+ assertEquals(convertedImage.getStatus(), org.jclouds.compute.domain.Image.Status.DELETED);
+ assertEquals(convertedImage.getOperatingSystem(), operatingSystem);
+ }
+
+ @Test(expectedExceptions = IllegalStateException.class)
+ public void testConversionWhereLocationNotFound() {
+ UUID id = UUID.randomUUID();
+ Image novaImageToConvert = Image.builder().id(id.toString()).name("Test Image " + id).build();
+ OperatingSystem operatingSystem = new OperatingSystem(OsFamily.UBUNTU, "My Test OS", "My Test Version", "x86",
+ "My Test OS", true);
+ ImageInZoneToImage converter = new ImageInZoneToImage(NovaComputeServiceContextModule.toPortableImageStatus,
+ constant(operatingSystem), locationIndex);
+
+ ImageInZone novaImageInZoneToConvert = new ImageInZone(novaImageToConvert, "South");
+
+ converter.apply(novaImageInZoneToConvert);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Function<Image, OperatingSystem> constant(OperatingSystem operatingSystem) {
+ return Function.class.cast(Functions.constant(operatingSystem));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystemTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystemTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystemTest.java
new file mode 100644
index 0000000..2fdc0a4
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ImageToOperatingSystemTest.java
@@ -0,0 +1,192 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jclouds.compute.domain.OperatingSystem;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.openstack.nova.v2_0.domain.Image;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+
+/**
+ * Tests for the function for transforming a nova specific Image into a generic
+ * OperatingSystem object.
+ *
+ * @author Matt Stephenson
+ */
+public class ImageToOperatingSystemTest {
+
+ @Test(dataProvider = "getOsFamilyValues")
+ public void testOsFamilyValues(OsFamily family) {
+
+ Image imageToConvert = Image.builder().id("id-" + family.name()).name(family.name()).build();
+
+ ImageToOperatingSystem converter = new ImageToOperatingSystem(
+ new HashMap<OsFamily, Map<String, String>>());
+
+ OperatingSystem convertedOs = converter.apply(imageToConvert);
+
+ assertEquals(convertedOs.getName(), imageToConvert.getName());
+ assertEquals(convertedOs.getFamily(), family);
+ assertEquals(convertedOs.getDescription(), imageToConvert.getName());
+ assertEquals(convertedOs.getVersion(), null);
+ assertEquals(convertedOs.getArch(), null);
+ assertTrue(convertedOs.is64Bit());
+ }
+
+ @DataProvider
+ public Object[][] getOsFamilyValues() {
+ return Iterables.toArray(
+ Iterables.transform(Arrays.asList(OsFamily.values()), new Function<OsFamily, Object[]>() {
+ @Override
+ public Object[] apply(OsFamily osFamily) {
+ return new Object[] { osFamily };
+ }
+ }), Object[].class);
+ }
+
+ @Test
+ public void testWindowsServer2008R2x64() {
+ String name = "Windows Server 2008 R2 x64";
+
+ Image imageToConvert = Image.builder().id("id-" + name).name(name).build();
+
+ Map<OsFamily, Map<String, String>> osFamilyMap = Maps.newHashMap();
+ osFamilyMap.put(OsFamily.WINDOWS, ImmutableMap.of("Server 2008 R2", "Server-2008-R2"));
+
+ ImageToOperatingSystem converter = new ImageToOperatingSystem(osFamilyMap);
+
+ OperatingSystem convertedOs = converter.apply(imageToConvert);
+
+ assertEquals(convertedOs.getName(), imageToConvert.getName());
+ assertEquals(convertedOs.getFamily(), OsFamily.WINDOWS);
+ assertEquals(convertedOs.getDescription(), imageToConvert.getName());
+ assertEquals(convertedOs.getVersion(), "Server-2008-R2");
+ assertEquals(convertedOs.getArch(), null);
+ assertTrue(convertedOs.is64Bit());
+ }
+
+ @Test
+ public void testWindows98x86() {
+ String name = "Windows 98 x86";
+
+ Image imageToConvert = Image.builder().id("id-" + name).name(name).build();
+
+ Map<OsFamily, Map<String, String>> osFamilyMap = Maps.newHashMap();
+ osFamilyMap.put(OsFamily.WINDOWS, ImmutableMap.of("98", "98"));
+
+ ImageToOperatingSystem converter = new ImageToOperatingSystem(osFamilyMap);
+
+ OperatingSystem convertedOs = converter.apply(imageToConvert);
+
+ assertEquals(convertedOs.getName(), imageToConvert.getName());
+ assertEquals(convertedOs.getFamily(), OsFamily.WINDOWS);
+ assertEquals(convertedOs.getDescription(), imageToConvert.getName());
+ assertEquals(convertedOs.getVersion(), "98");
+ assertEquals(convertedOs.getArch(), null);
+ assertFalse(convertedOs.is64Bit());
+ }
+
+ @Test
+ public void testRHEL() {
+ String name = "Red Hat EL";
+
+ Image imageToConvert = Image.builder().id("id-" + name).name(name).build();
+
+ ImageToOperatingSystem converter = new ImageToOperatingSystem(
+ new HashMap<OsFamily, Map<String, String>>());
+
+ OperatingSystem convertedOs = converter.apply(imageToConvert);
+
+ assertEquals(convertedOs.getName(), imageToConvert.getName());
+ assertEquals(convertedOs.getFamily(), OsFamily.RHEL);
+ assertEquals(convertedOs.getDescription(), imageToConvert.getName());
+ assertEquals(convertedOs.getVersion(), null);
+ assertEquals(convertedOs.getArch(), null);
+ assertTrue(convertedOs.is64Bit());
+ }
+
+ @Test
+ public void testOEL() {
+ String name = "Oracle EL";
+
+ Image imageToConvert = Image.builder().id("id-" + name).name(name).build();
+
+ ImageToOperatingSystem converter = new ImageToOperatingSystem(
+ new HashMap<OsFamily, Map<String, String>>());
+
+ OperatingSystem convertedOs = converter.apply(imageToConvert);
+
+ assertEquals(convertedOs.getName(), imageToConvert.getName());
+ assertEquals(convertedOs.getFamily(), OsFamily.OEL);
+ assertEquals(convertedOs.getDescription(), imageToConvert.getName());
+ assertEquals(convertedOs.getVersion(), null);
+ assertEquals(convertedOs.getArch(), null);
+ assertTrue(convertedOs.is64Bit());
+ }
+
+
+ ImageToOperatingSystem converterForUbuntu = new ImageToOperatingSystem(ImmutableMap.<OsFamily, Map<String, String>> of(
+ OsFamily.UBUNTU, ImmutableMap.of("lucid", "10.04", "maverick", "10.10", "natty", "11.04", "oneiric",
+ "11.10")));
+ @Test
+ public void testTryStackOneric() {
+
+ String name = "oneiric-server-cloudimg-amd64";
+
+ Image imageToConvert = Image.builder().id("id-" + name).name(name).build();
+
+ OperatingSystem convertedOs = converterForUbuntu.apply(imageToConvert);
+
+ assertEquals(convertedOs.getName(), imageToConvert.getName());
+ assertEquals(convertedOs.getFamily(), OsFamily.UBUNTU);
+ assertEquals(convertedOs.getDescription(), imageToConvert.getName());
+ assertEquals(convertedOs.getVersion(), "11.10");
+ assertEquals(convertedOs.getArch(), null);
+ assertTrue(convertedOs.is64Bit());
+ }
+
+ @Test
+ public void testTryStackNatty() {
+
+ String name = "natty-server-cloudimg-amd64";
+
+ Image imageToConvert = Image.builder().id("id-" + name).name(name).build();
+
+ OperatingSystem convertedOs = converterForUbuntu.apply(imageToConvert);
+
+ assertEquals(convertedOs.getName(), imageToConvert.getName());
+ assertEquals(convertedOs.getFamily(), OsFamily.UBUNTU);
+ assertEquals(convertedOs.getDescription(), imageToConvert.getName());
+ assertEquals(convertedOs.getVersion(), "11.04");
+ assertEquals(convertedOs.getArch(), null);
+ assertTrue(convertedOs.is64Bit());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInZoneToSecurityGroupTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInZoneToSecurityGroupTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInZoneToSecurityGroupTest.java
new file mode 100644
index 0000000..c884987
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupInZoneToSecurityGroupTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static com.google.common.collect.Iterables.transform;
+import static org.jclouds.openstack.nova.v2_0.compute.functions.NovaSecurityGroupToSecurityGroupTest.securityGroupWithCidr;
+import static org.jclouds.openstack.nova.v2_0.compute.functions.NovaSecurityGroupToSecurityGroupTest.securityGroupWithGroup;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+
+import org.jclouds.compute.domain.SecurityGroup;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Andrew Bayer
+ */
+@Test(groups = "unit", testName = "NovaSecurityGroupInZoneToSecurityGroupTest")
+public class NovaSecurityGroupInZoneToSecurityGroupTest {
+
+ Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova")
+ .description("openstack-nova").build();
+ Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
+ .scope(LocationScope.ZONE).parent(provider).build();
+ Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
+ .<String, Location>of("az-1.region-a.geo-1", zone));
+
+
+ @Test
+ public void testApplyWithGroup() {
+ NovaSecurityGroupInZoneToSecurityGroup parser = createGroupParser();
+
+ SecurityGroupInZone origGroup = new SecurityGroupInZone(securityGroupWithGroup(), zone.getId());
+
+ SecurityGroup newGroup = parser.apply(origGroup);
+
+ assertEquals(newGroup.getId(), origGroup.getZone() + "/" + origGroup.getSecurityGroup().getId());
+ assertEquals(newGroup.getProviderId(), origGroup.getSecurityGroup().getId());
+ assertEquals(newGroup.getName(), origGroup.getSecurityGroup().getName());
+ assertEquals(newGroup.getOwnerId(), origGroup.getSecurityGroup().getTenantId());
+ assertEquals(newGroup.getIpPermissions(), ImmutableSet.copyOf(transform(origGroup.getSecurityGroup().getRules(),
+ NovaSecurityGroupToSecurityGroupTest.ruleConverter)));
+ assertEquals(newGroup.getLocation().getId(), origGroup.getZone());
+ }
+
+ @Test
+ public void testApplyWithCidr() {
+
+ NovaSecurityGroupInZoneToSecurityGroup parser = createGroupParser();
+
+ SecurityGroupInZone origGroup = new SecurityGroupInZone(securityGroupWithCidr(), zone.getId());
+
+ SecurityGroup newGroup = parser.apply(origGroup);
+
+ assertEquals(newGroup.getId(), origGroup.getZone() + "/" + origGroup.getSecurityGroup().getId());
+ assertEquals(newGroup.getProviderId(), origGroup.getSecurityGroup().getId());
+ assertEquals(newGroup.getName(), origGroup.getSecurityGroup().getName());
+ assertEquals(newGroup.getOwnerId(), origGroup.getSecurityGroup().getTenantId());
+ assertEquals(newGroup.getIpPermissions(), ImmutableSet.copyOf(transform(origGroup.getSecurityGroup().getRules(),
+ NovaSecurityGroupToSecurityGroupTest.ruleConverter)));
+ assertEquals(newGroup.getLocation().getId(), origGroup.getZone());
+ }
+
+ private NovaSecurityGroupInZoneToSecurityGroup createGroupParser() {
+ NovaSecurityGroupToSecurityGroup baseParser = new NovaSecurityGroupToSecurityGroup(NovaSecurityGroupToSecurityGroupTest.ruleConverter);
+
+ NovaSecurityGroupInZoneToSecurityGroup parser = new NovaSecurityGroupInZoneToSecurityGroup(baseParser, locationIndex);
+
+ return parser;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroupTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroupTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroupTest.java
new file mode 100644
index 0000000..6754087
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/NovaSecurityGroupToSecurityGroupTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static com.google.common.collect.Iterables.transform;
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jclouds.compute.domain.SecurityGroup;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.net.domain.IpProtocol;
+import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule;
+import org.jclouds.openstack.nova.v2_0.domain.TenantIdAndName;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Andrew Bayer
+ */
+@Test(groups = "unit", testName = "NovaSecurityGroupToSecurityGroupTest")
+public class NovaSecurityGroupToSecurityGroupTest {
+
+ private static final Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova")
+ .description("openstack-nova").build();
+ private static final Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
+ .scope(LocationScope.ZONE).parent(provider).build();
+ private static final Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
+ .<String, Location>of("az-1.region-a.geo-1", zone));
+
+
+ private static final Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysTrue();
+
+ private static final Map<ZoneAndName, SecurityGroupInZone> groupMap = ImmutableMap.of(
+ ZoneAndName.fromZoneAndName("az-1.region-a.geo-1", "some-group"), new SecurityGroupInZone(securityGroupWithGroup(), "az-1.region-a.geo-1"),
+ ZoneAndName.fromZoneAndName("az-1.region-a.geo-1", "some-other-group"), new SecurityGroupInZone(securityGroupWithCidr(), "az-1.region-a.geo-1"));
+
+ // weird compilation error means have to declare extra generics for call to build() - see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365818
+ private static final Supplier <LoadingCache<ZoneAndName, SecurityGroupInZone>> groupCache = Suppliers.<LoadingCache<ZoneAndName,SecurityGroupInZone>> ofInstance(
+ CacheBuilder.newBuilder().<ZoneAndName, SecurityGroupInZone>build(CacheLoader.from(Functions.forMap(groupMap))));
+
+ public static final SecurityGroupRuleToIpPermission ruleConverter = new SecurityGroupRuleToIpPermission(returnSecurityGroupExistsInZone, locationIndex,
+ groupCache.get());
+
+ public static org.jclouds.openstack.nova.v2_0.domain.SecurityGroup securityGroupWithGroup() {
+ TenantIdAndName group = TenantIdAndName.builder().tenantId("tenant").name("some-other-group").build();
+
+ SecurityGroupRule ruleToConvert = SecurityGroupRule.builder()
+ .id("some-id")
+ .ipProtocol(IpProtocol.TCP)
+ .fromPort(10)
+ .toPort(20)
+ .group(group)
+ .parentGroupId("some-other-id")
+ .build();
+
+ org.jclouds.openstack.nova.v2_0.domain.SecurityGroup origGroup = org.jclouds.openstack.nova.v2_0.domain.SecurityGroup.builder()
+ .tenantId("tenant")
+ .id("some-id")
+ .name("some-group")
+ .description("some-description")
+ .rules(ruleToConvert)
+ .build();
+
+ return origGroup;
+ }
+
+ public static org.jclouds.openstack.nova.v2_0.domain.SecurityGroup securityGroupWithCidr() {
+ SecurityGroupRule ruleToConvert = SecurityGroupRule.builder()
+ .id("some-id")
+ .ipProtocol(IpProtocol.TCP)
+ .fromPort(10)
+ .toPort(20)
+ .ipRange("0.0.0.0/0")
+ .parentGroupId("some-other-id")
+ .build();
+
+ org.jclouds.openstack.nova.v2_0.domain.SecurityGroup origGroup = org.jclouds.openstack.nova.v2_0.domain.SecurityGroup.builder()
+ .tenantId("tenant")
+ .id("some-id")
+ .name("some-other-group")
+ .description("some-description")
+ .rules(ruleToConvert)
+ .build();
+
+ return origGroup;
+ }
+
+ @Test
+ public void testApplyWithGroup() {
+ NovaSecurityGroupToSecurityGroup parser = createGroupParser();
+
+ org.jclouds.openstack.nova.v2_0.domain.SecurityGroup origGroup = securityGroupWithGroup();
+
+ SecurityGroup newGroup = parser.apply(origGroup);
+
+ assertEquals(newGroup.getId(), origGroup.getId());
+ assertEquals(newGroup.getProviderId(), origGroup.getId());
+ assertEquals(newGroup.getName(), origGroup.getName());
+ assertEquals(newGroup.getOwnerId(), origGroup.getTenantId());
+ assertEquals(newGroup.getIpPermissions(), ImmutableSet.copyOf(transform(origGroup.getRules(), ruleConverter)));
+ }
+
+ @Test
+ public void testApplyWithCidr() {
+
+ NovaSecurityGroupToSecurityGroup parser = createGroupParser();
+
+ org.jclouds.openstack.nova.v2_0.domain.SecurityGroup origGroup = securityGroupWithCidr();
+
+ SecurityGroup group = parser.apply(origGroup);
+
+ assertEquals(group.getId(), origGroup.getId());
+ assertEquals(group.getProviderId(), origGroup.getId());
+ assertEquals(group.getName(), origGroup.getName());
+ assertEquals(group.getOwnerId(), origGroup.getTenantId());
+ assertEquals(group.getIpPermissions(), ImmutableSet.copyOf(transform(origGroup.getRules(), ruleConverter)));
+ }
+
+ private NovaSecurityGroupToSecurityGroup createGroupParser() {
+ NovaSecurityGroupToSecurityGroup parser = new NovaSecurityGroupToSecurityGroup(ruleConverter);
+
+ return parser;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByZoneIdTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByZoneIdTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByZoneIdTest.java
new file mode 100644
index 0000000..1f520dc
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/OrphanedGroupsByZoneIdTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicates;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Guice;
+
+/**
+ *
+ *
+ * @author Adrian Cole
+ */
+@Test(testName = "OrphanedGroupsByZoneIdTest")
+public class OrphanedGroupsByZoneIdTest {
+
+ Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova").description(
+ "openstack-nova").build();
+ Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1").scope(
+ LocationScope.ZONE).parent(provider).build();
+ Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
+ .<String, Location> of("az-1.region-a.geo-1", zone));
+
+ GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
+
+ @Test
+ public void testWhenComputeServiceSaysAllNodesAreDeadBothGroupsAreReturned() {
+
+ ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
+ ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
+ .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
+
+ Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
+
+ assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysTrue()).apply(set), ImmutableMultimap
+ .<String, String> builder().putAll("az-1.region-a.geo-1", "sample", "test").build());
+ }
+
+ @Test
+ public void testWhenComputeServiceSaysAllNodesAreDeadNoGroupsAreReturned() {
+
+ ServerInZone withoutHost = new ServerInZone(new ServerInZoneToNodeMetadataTest().expectedServer(), "az-1.region-a.geo-1");
+ ServerInZone withHost = new ServerInZone(new ParseServerTest().expected(), "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(ImmutableSet.<Image> of()), Suppliers
+ .<Set<? extends Hardware>> ofInstance(ImmutableSet.<Hardware> of()), namingConvention);
+
+ Set<? extends NodeMetadata> set = ImmutableSet.of(converter.apply(withHost), converter.apply(withoutHost));
+
+ assertEquals(new OrphanedGroupsByZoneId(Predicates.<ZoneAndName> alwaysFalse()).apply(set), ImmutableMultimap
+ .<String, String> of());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java
new file mode 100644
index 0000000..59c59d0
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/SecurityGroupRuleToIpPermissionTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.net.domain.IpPermission;
+import org.jclouds.net.domain.IpProtocol;
+import org.jclouds.openstack.nova.v2_0.domain.SecurityGroupRule;
+import org.jclouds.openstack.nova.v2_0.domain.TenantIdAndName;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+
+/**
+ * Tests for the function for transforming a nova specific SecurityGroupRule into a generic
+ * IpPermission object.
+ *
+ * @author Andrew Bayer
+ */
+public class SecurityGroupRuleToIpPermissionTest {
+
+ @Test
+ public void testApplyWithGroup() {
+
+ TenantIdAndName group = TenantIdAndName.builder().tenantId("tenant").name("some-group").build();
+
+ SecurityGroupRule ruleToConvert = SecurityGroupRule.builder()
+ .id("some-id")
+ .ipProtocol(IpProtocol.TCP)
+ .fromPort(10)
+ .toPort(20)
+ .group(group)
+ .parentGroupId("some-other-id")
+ .build();
+
+ IpPermission convertedPerm = NovaSecurityGroupToSecurityGroupTest.ruleConverter.apply(ruleToConvert);
+
+ assertEquals(convertedPerm.getIpProtocol(), ruleToConvert.getIpProtocol());
+ assertEquals(convertedPerm.getFromPort(), ruleToConvert.getFromPort());
+ assertEquals(convertedPerm.getToPort(), ruleToConvert.getToPort());
+ assertTrue(convertedPerm.getGroupIds().contains("az-1.region-a.geo-1/some-id"));
+ assertTrue(convertedPerm.getCidrBlocks().size() == 0);
+ }
+
+ @Test
+ public void testApplyWithCidr() {
+ SecurityGroupRule ruleToConvert = SecurityGroupRule.builder()
+ .id("some-id")
+ .ipProtocol(IpProtocol.TCP)
+ .fromPort(10)
+ .toPort(20)
+ .ipRange("0.0.0.0/0")
+ .parentGroupId("some-other-id")
+ .build();
+
+ IpPermission convertedPerm = NovaSecurityGroupToSecurityGroupTest.ruleConverter.apply(ruleToConvert);
+
+ assertEquals(convertedPerm.getIpProtocol(), ruleToConvert.getIpProtocol());
+ assertEquals(convertedPerm.getFromPort(), ruleToConvert.getFromPort());
+ assertEquals(convertedPerm.getToPort(), ruleToConvert.getToPort());
+ assertEquals(convertedPerm.getCidrBlocks(), ImmutableSet.of("0.0.0.0/0"));
+ assertTrue(convertedPerm.getTenantIdGroupNamePairs().size() == 0);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java
new file mode 100644
index 0000000..7ef9fa7
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java
@@ -0,0 +1,311 @@
+/*
+ * 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.openstack.nova.v2_0.compute.functions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Set;
+
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.HardwareBuilder;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.ImageBuilder;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.OperatingSystem;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
+import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest;
+import org.jclouds.openstack.v2_0.domain.Link;
+import org.jclouds.openstack.v2_0.domain.Resource;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Guice;
+
+/**
+ * Tests for the function for transforming a nova specific Server into a generic
+ * NodeMetadata object.
+ *
+ * @author Matt Stephenson, Adam Lowe, Adrian Cole
+ */
+@Test(testName = "ServerInZoneToNodeMetadataTest")
+public class ServerInZoneToNodeMetadataTest {
+
+ Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova")
+ .description("openstack-nova").build();
+ Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
+ .scope(LocationScope.ZONE).parent(provider).build();
+ Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
+ .<String, Location> of("az-1.region-a.geo-1", zone));
+
+ GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
+
+ @Test
+ public void testWhenNoHardwareOrImageMatchServerScopedIdsImageIdIsStillSet() {
+
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/FOOOOOOOO").providerId("FOOOOOOOO")
+ .location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/FOOOOOOOO")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("FOOOOOOOO").description("foobuntu").location(zone).status(Image.Status.AVAILABLE).build();
+
+ checkHardwareAndImageStatus(null, existingHardware, "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54",
+ null, existingImage);
+ }
+
+ @Test
+ public void testWhenNoHardwareAndImageMatchServerScopedIdsHardwareOperatingSystemAndImageIdAreSet() {
+
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ checkHardwareAndImageStatus(existingHardware, existingHardware, existingImage.getId(),
+ existingImage.getOperatingSystem(), existingImage);
+ }
+
+ @Test
+ public void testNullAccessIPs() {
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected().toBuilder()
+ .accessIPv4(null)
+ .accessIPv6(null)
+ .build();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131"));
+ }
+
+ @Test
+ public void testDuplicateAccessIPs() {
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected().toBuilder()
+ .accessIPv4("67.23.10.132")
+ .accessIPv6("::babe:67.23.10.132")
+ .build();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131"));
+ }
+
+ @Test
+ public void testAlternateAccessIPs() {
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected().toBuilder()
+ .accessIPv4("76.32.1.231")
+ .accessIPv6("::babe:76.32.1.231")
+ .build();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131", "76.32.1.231"));
+ }
+
+ // TODO: clean up this syntax
+ private void checkHardwareAndImageStatus(Hardware expectedHardware, Hardware existingHardware,
+ String expectedImageId, OperatingSystem expectedOs, Image existingImage) {
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
+ assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
+
+ assertEquals(convertedNodeMetadata.getLocation().getScope(), LocationScope.HOST);
+ assertEquals(convertedNodeMetadata.getLocation().getId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
+
+ assertEquals(convertedNodeMetadata.getLocation().getParent(), locationIndex.get().get("az-1.region-a.geo-1"));
+
+ assertEquals(serverToConvert.getName(), convertedNodeMetadata.getName());
+ assertEquals(convertedNodeMetadata.getGroup(), "sample");
+
+ assertEquals(convertedNodeMetadata.getImageId(), expectedImageId);
+ assertEquals(convertedNodeMetadata.getOperatingSystem(), expectedOs);
+
+ assertEquals(convertedNodeMetadata.getHardware(), expectedHardware);
+
+ assertEquals(NovaComputeServiceContextModule.toPortableNodeStatus.get(serverToConvert.getStatus()),
+ convertedNodeMetadata.getStatus());
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131"));
+
+ assertNotNull(convertedNodeMetadata.getUserMetadata());
+ assertEquals(convertedNodeMetadata.getUserMetadata(),
+ ImmutableMap.<String, String> of("Server Label", "Web Head 1", "Image Version", "2.1"));
+
+ URI expectedURI = URI.create("http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f6f006e54");
+ assertEquals(convertedNodeMetadata.getUri(), expectedURI);
+ }
+
+ @Test
+ public void testNewServerWithoutHostIdSetsZoneAsLocation() {
+
+ Set<Image> images = ImmutableSet.<Image> of();
+ Set<Hardware> hardwares = ImmutableSet.<Hardware> of();
+
+ Server serverToConvert = expectedServer();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
+ assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
+
+ assertEquals(convertedNodeMetadata.getLocation(), zone);
+
+ URI expectedURI = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752");
+ assertEquals(convertedNodeMetadata.getUri(), expectedURI);
+ }
+
+ public Server expectedServer() {
+ return Server
+ .builder()
+ .id("71752")
+ .uuid("47491020-6a78-4f63-9475-23195ac4515c")
+ .tenantId("37936628937291")
+ .userId("54297837463082")
+ .name("test-e92")
+ .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-03-19T06:21:13Z"))
+ .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-03-19T06:21:13Z"))
+ .status(Server.Status.BUILD)
+ .image(
+ Resource
+ .builder()
+ .id("1241")
+ .links(
+ Link.create(
+ Link.Relation.BOOKMARK,
+ URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/images/1241")))
+ .build())
+ .flavor(
+ Resource
+ .builder()
+ .id("100")
+ .links(
+ Link.create(
+ Link.Relation.BOOKMARK,
+ URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/100")))
+ .build())
+ .links(
+ Link.create(Link.Relation.SELF, URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752")),
+ Link.create(Link.Relation.BOOKMARK, URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/servers/71752"))).build();
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java
new file mode 100644
index 0000000..9bca8e1
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.openstack.nova.v2_0.compute.loaders;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+
+import java.net.UnknownHostException;
+
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.TypeLiteral;
+
+/**
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "CreateUniqueKeyPairTest")
+public class CreateUniqueKeyPairTest {
+
+ @Test
+ public void testApply() throws UnknownHostException {
+ final NovaApi api = createMock(NovaApi.class);
+ KeyPairApi keyApi = createMock(KeyPairApi.class);
+
+ KeyPair pair = createMock(KeyPair.class);
+
+ Optional optKeyApi = Optional.of(keyApi);
+
+ expect(api.getKeyPairExtensionForZone("zone")).andReturn(optKeyApi).atLeastOnce();
+
+ expect(keyApi.create("group-1")).andReturn(pair);
+
+ replay(api, keyApi);
+
+ CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() {
+
+ @Override
+ protected void configure() {
+ bind(new TypeLiteral<Supplier<String>>() {
+ }).toInstance(Suppliers.ofInstance("1"));
+ bind(NovaApi.class).toInstance(api);
+ }
+
+ }).getInstance(CreateUniqueKeyPair.class);
+
+ assertEquals(parser.load(ZoneAndName.fromZoneAndName("zone", "group")), pair);
+
+ verify(api, keyApi);
+ }
+
+ @Test
+ public void testApplyWithIllegalStateException() throws UnknownHostException {
+ final NovaApi api = createMock(NovaApi.class);
+ KeyPairApi keyApi = createMock(KeyPairApi.class);
+ @SuppressWarnings("unchecked")
+ final Supplier<String> uniqueIdSupplier = createMock(Supplier.class);
+
+ KeyPair pair = createMock(KeyPair.class);
+
+ expect(api.getKeyPairExtensionForZone("zone")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();
+
+ expect(uniqueIdSupplier.get()).andReturn("1");
+ expect(keyApi.create("group-1")).andThrow(new IllegalStateException());
+ expect(uniqueIdSupplier.get()).andReturn("2");
+ expect(keyApi.create("group-2")).andReturn(pair);
+
+ replay(api, keyApi, uniqueIdSupplier);
+
+ CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() {
+
+ @Override
+ protected void configure() {
+ bind(new TypeLiteral<Supplier<String>>() {
+ }).toInstance(uniqueIdSupplier);
+ bind(NovaApi.class).toInstance(api);
+ }
+
+ }).getInstance(CreateUniqueKeyPair.class);
+
+ assertEquals(parser.load(ZoneAndName.fromZoneAndName("zone", "group")), pair);
+
+ verify(api, keyApi, uniqueIdSupplier);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java
new file mode 100644
index 0000000..62f45fd
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.openstack.nova.v2_0.compute.loaders;
+
+import static org.easymock.EasyMock.createMock;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Function;
+import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Adrian Cole
+ */
+@Test(groups = "unit", singleThreaded = true, testName = "FindSecurityGroupOrCreateTest")
+public class FindSecurityGroupOrCreateTest {
+
+ @Test
+ public void testWhenNotFoundCreatesANewSecurityGroup() throws Exception {
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysFalse();
+
+ SecurityGroupInZone securityGroupInZone = createMock(SecurityGroupInZone.class);
+
+ ZoneSecurityGroupNameAndPorts input = new ZoneSecurityGroupNameAndPorts("zone", "groupName", ImmutableSet
+ .<Integer> of(22, 8080));
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = Functions.forMap(ImmutableMap
+ .<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> of(input, securityGroupInZone));
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ assertEquals(parser.load(input), securityGroupInZone);
+
+ }
+
+ @Test
+ public void testWhenFoundReturnsSecurityGroupFromAtomicReferenceValueUpdatedDuringPredicateCheck() throws Exception {
+ final SecurityGroupInZone securityGroupInZone = createMock(SecurityGroupInZone.class);
+
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = new Predicate<AtomicReference<ZoneAndName>>() {
+
+ @Override
+ public boolean apply(AtomicReference<ZoneAndName> input) {
+ input.set(securityGroupInZone);
+ return true;
+ }
+
+ };
+
+ ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
+
+ @Override
+ public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
+ fail();
+ return null;
+ }
+
+ };
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ assertEquals(parser.load(input), securityGroupInZone);
+
+ }
+
+
+ @Test(expectedExceptions = IllegalStateException.class)
+ public void testWhenFoundPredicateMustUpdateAtomicReference() throws Exception {
+
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysTrue();
+
+ ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
+
+ @Override
+ public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
+ fail();
+ return null;
+ }
+
+ };
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ parser.load(input);
+
+ }
+
+
+
+ @Test(expectedExceptions = IllegalStateException.class)
+ public void testWhenNotFoundInputMustBeZoneSecurityGroupNameAndPorts() throws Exception {
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysFalse();
+
+ ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
+
+ @Override
+ public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
+ fail();
+ return null;
+ }
+
+ };
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ parser.load(input);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java
new file mode 100644
index 0000000..771d63f
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.openstack.nova.v2_0.compute.loaders;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+
+
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
+import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", singleThreaded = true, testName = "LoadFloatingIpsForInstanceTest")
+public class LoadFloatingIpsForInstanceTest {
+
+ @Test
+ public void testReturnsPublicIpOnMatch() throws Exception {
+ NovaApi api = createMock(NovaApi.class);
+ FloatingIPApi ipApi = createMock(FloatingIPApi.class);
+ FloatingIP testIp = FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build();
+
+ expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
+ expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(testIp)))
+ .atLeastOnce();
+
+ replay(api);
+ replay(ipApi);
+
+ LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
+
+ assertEquals(ImmutableSet.copyOf(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah"))), ImmutableSet.of(testIp));
+
+ verify(api);
+ verify(ipApi);
+ }
+
+ @Test
+ public void testReturnsNullWhenNotFound() throws Exception {
+ NovaApi api = createMock(NovaApi.class);
+ FloatingIPApi ipApi = createMock(FloatingIPApi.class);
+
+ expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
+
+ expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of()))
+ .atLeastOnce();
+
+ replay(api);
+ replay(ipApi);
+
+ LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
+
+ assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
+
+ verify(api);
+ verify(ipApi);
+
+ }
+
+ @Test
+ public void testReturnsNullWhenNotAssigned() throws Exception {
+ NovaApi api = createMock(NovaApi.class);
+ FloatingIPApi ipApi = createMock(FloatingIPApi.class);
+
+ expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
+
+ expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(FloatingIP.builder().id("1").ip("1.1.1.1").build())))
+ .atLeastOnce();
+
+ replay(api);
+ replay(ipApi);
+
+ LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
+
+ assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
+
+ verify(api);
+ verify(ipApi);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/19c8cdaf/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptionsTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptionsTest.java b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptionsTest.java
new file mode 100644
index 0000000..106da5b
--- /dev/null
+++ b/dependencies/jclouds/apis/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptionsTest.java
@@ -0,0 +1,263 @@
+/*
+ * 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.openstack.nova.v2_0.compute.options;
+
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.authorizePublicKey;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.autoAssignFloatingIp;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.blockOnPort;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.generateKeyPair;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.inboundPorts;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.installPrivateKey;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.securityGroupNames;
+import static org.testng.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests possible uses of NovaTemplateOptions and NovaTemplateOptions.Builder.*
+ *
+ * @author Adrian Cole
+ */
+@Test(testName = "NovaTemplateOptionsTest")
+public class NovaTemplateOptionsTest {
+
+ public void testAs() {
+ TemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.as(NovaTemplateOptions.class), options);
+ }
+
+ @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "all security groups must be non-empty")
+ public void testsecurityGroupNamesIterableBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames(ImmutableSet.of("group1", ""));
+ }
+
+ @Test
+ public void testsecurityGroupNamesIterable() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames(ImmutableSet.of("group1", "group2"));
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+
+ }
+
+ @Test
+ public void testsecurityGroupNamesIterableStatic() {
+ NovaTemplateOptions options = securityGroupNames(ImmutableSet.of("group1", "group2"));
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+ }
+
+ @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "all security groups must be non-empty")
+ public void testsecurityGroupNamesVarArgsBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames("mygroup", "");
+ }
+
+ @Test
+ public void testsecurityGroupNamesVarArgs() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames("group1", "group2");
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+
+ }
+
+ @Test
+ public void testDefaultGroupsVarArgsEmpty() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getSecurityGroupNames(), Optional.absent());
+ }
+
+ @Test
+ public void testsecurityGroupNamesVarArgsStatic() {
+ NovaTemplateOptions options = securityGroupNames("group1", "group2");
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+ }
+
+ @Test
+ public void testautoAssignFloatingIpDefault() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assert !options.shouldAutoAssignFloatingIp();
+ }
+
+ @Test
+ public void testautoAssignFloatingIp() {
+ NovaTemplateOptions options = new NovaTemplateOptions().autoAssignFloatingIp(true);
+ assert options.shouldAutoAssignFloatingIp();
+ }
+
+ @Test
+ public void testautoAssignFloatingIpStatic() {
+ NovaTemplateOptions options = autoAssignFloatingIp(true);
+ assert options.shouldAutoAssignFloatingIp();
+ }
+
+ @Test
+ public void testGenerateKeyPairDefault() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assert !options.shouldGenerateKeyPair();
+ }
+
+ @Test
+ public void testGenerateKeyPair() {
+ NovaTemplateOptions options = new NovaTemplateOptions().generateKeyPair(true);
+ assert options.shouldGenerateKeyPair();
+ }
+
+ @Test
+ public void testGenerateKeyPairStatic() {
+ NovaTemplateOptions options = generateKeyPair(true);
+ assert options.shouldGenerateKeyPair();
+ }
+
+ // superclass tests
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testinstallPrivateKeyBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.installPrivateKey("whompy");
+ }
+
+ @Test
+ public void testinstallPrivateKey() throws IOException {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
+ assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
+ }
+
+ @Test
+ public void testNullinstallPrivateKey() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getPrivateKey(), null);
+ }
+
+ @Test
+ public void testinstallPrivateKeyStatic() throws IOException {
+ NovaTemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
+ assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
+ }
+
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testinstallPrivateKeyNPE() {
+ installPrivateKey(null);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testauthorizePublicKeyBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.authorizePublicKey("whompy");
+ }
+
+ @Test
+ public void testauthorizePublicKey() throws IOException {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.authorizePublicKey("ssh-rsa");
+ assertEquals(options.getPublicKey(), "ssh-rsa");
+ }
+
+ @Test
+ public void testNullauthorizePublicKey() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getPublicKey(), null);
+ }
+
+ @Test
+ public void testauthorizePublicKeyStatic() throws IOException {
+ NovaTemplateOptions options = authorizePublicKey("ssh-rsa");
+ assertEquals(options.getPublicKey(), "ssh-rsa");
+ }
+
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testauthorizePublicKeyNPE() {
+ authorizePublicKey(null);
+ }
+
+ @Test
+ public void testUserData() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.userData("test".getBytes());
+ assertEquals(new String(options.getUserData()), "test");
+ }
+
+ @Test
+ public void testDiskConfig() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.diskConfig(Server.DISK_CONFIG_AUTO);
+ assertEquals(options.getDiskConfig(), Server.DISK_CONFIG_AUTO);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testblockOnPortBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.blockOnPort(-1, -1);
+ }
+
+ @Test
+ public void testblockOnPort() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.blockOnPort(22, 30);
+ assertEquals(options.getPort(), 22);
+ assertEquals(options.getSeconds(), 30);
+
+ }
+
+ @Test
+ public void testNullblockOnPort() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getPort(), -1);
+ assertEquals(options.getSeconds(), -1);
+ }
+
+ @Test
+ public void testblockOnPortStatic() {
+ NovaTemplateOptions options = blockOnPort(22, 30);
+ assertEquals(options.getPort(), 22);
+ assertEquals(options.getSeconds(), 30);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testinboundPortsBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.inboundPorts(-1, -1);
+ }
+
+ @Test
+ public void testinboundPorts() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.inboundPorts(22, 30);
+ assertEquals(options.getInboundPorts()[0], 22);
+ assertEquals(options.getInboundPorts()[1], 30);
+
+ }
+
+ @Test
+ public void testDefaultOpen22() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getInboundPorts()[0], 22);
+ }
+
+ @Test
+ public void testinboundPortsStatic() {
+ NovaTemplateOptions options = inboundPorts(22, 30);
+ assertEquals(options.getInboundPorts()[0], 22);
+ assertEquals(options.getInboundPorts()[1], 30);
+ }
+}