Repository: jclouds-labs Updated Branches: refs/heads/unittests [created] d6cdd0be9
Added unit tests for compute functions Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/d6cdd0be Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/d6cdd0be Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/d6cdd0be Branch: refs/heads/unittests Commit: d6cdd0be9a7b9f9d034af02bcf3ec0a9876b3f02 Parents: 4cb6b9e Author: Ignasi Barrera <[email protected]> Authored: Fri May 16 15:33:04 2014 +0200 Committer: Ignasi Barrera <[email protected]> Committed: Fri May 16 15:33:04 2014 +0200 ---------------------------------------------------------------------- .../functions/DropletStatusToStatusTest.java | 40 +++++ .../functions/DropletToNodeMetadataTest.java | 178 +++++++++++++++++++ .../compute/functions/ImageToImageTest.java | 52 ++++++ .../compute/functions/RegionToLocationTest.java | 55 ++++++ .../compute/functions/SizeToHardwareTest.java | 48 +++++ ...eOptionsToStatementWithoutPublicKeyTest.java | 75 ++++++++ .../DigitalOceanTemplateOptionsTest.java | 48 +++++ 7 files changed, 496 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/d6cdd0be/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java ---------------------------------------------------------------------- diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java new file mode 100644 index 0000000..2a1c3b7 --- /dev/null +++ b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java @@ -0,0 +1,40 @@ +/* + * 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.digitalocean.compute.functions; + +import static org.jclouds.compute.domain.NodeMetadata.Status.UNRECOGNIZED; +import static org.testng.Assert.assertNotEquals; + +import org.jclouds.digitalocean.domain.Droplet.Status; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link DropletStatusToStatus} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "DropletStatusToStatusTest") +public class DropletStatusToStatusTest { + + public void testAllStatesHaveMapping() { + DropletStatusToStatus function = new DropletStatusToStatus(); + for (Status status : Status.values()) { + assertNotEquals(function.apply(status), UNRECOGNIZED); + } + + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/d6cdd0be/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java ---------------------------------------------------------------------- diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java new file mode 100644 index 0000000..caca5db --- /dev/null +++ b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java @@ -0,0 +1,178 @@ +/* + * 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.digitalocean.compute.functions; + +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.jclouds.compute.domain.Image.Status.AVAILABLE; +import static org.jclouds.compute.domain.NodeMetadata.Status.RUNNING; +import static org.jclouds.digitalocean.domain.Droplet.Status.ACTIVE; +import static org.testng.Assert.assertEquals; + +import java.text.ParseException; +import java.util.Date; +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.NodeMetadataBuilder; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume.Type; +import org.jclouds.compute.domain.VolumeBuilder; +import org.jclouds.compute.functions.GroupNamingConvention; +import org.jclouds.digitalocean.DigitalOceanApiMetadata; +import org.jclouds.digitalocean.domain.Droplet; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.domain.LoginCredentials; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.name.Names; + +/** + * Unit tests for the {@link DropletToNodeMetadata} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "DropletToNodeMetadataTest") +public class DropletToNodeMetadataTest { + + private Set<Hardware> hardwares; + + private Set<Image> images; + + private Set<Location> locations; + + private LoginCredentials credentials; + + private DropletToNodeMetadata function; + + @BeforeMethod + public void setup() { + images = ImmutableSet.of(new ImageBuilder() + .ids("1") + .name("mock image") + .status(AVAILABLE) + .operatingSystem( + OperatingSystem.builder().name("Ubuntu 14.04 x86_64").description("Ubuntu").family(OsFamily.UBUNTU) + .version("10.04").arch("x86_64").is64Bit(true).build()).build()); + + hardwares = ImmutableSet.of(new HardwareBuilder().ids("1").name("mock hardware") + .processor(new Processor(1.0, 1.0)).ram(2048) + .volume(new VolumeBuilder().size(20f).type(Type.LOCAL).build()).build()); + + locations = ImmutableSet.of(new LocationBuilder() + .id("1") + .description("1/mock location") + .scope(LocationScope.REGION) + .parent( + new LocationBuilder().id("0").description("mock parent location").scope(LocationScope.PROVIDER) + .build()).build()); + + credentials = LoginCredentials.builder().user("foo").password("bar").build(); + + function = createNodeParser(hardwares, images, locations, ImmutableMap.of("node#1", (Credentials) credentials)); + } + + public void testConvertDroplet() throws ParseException { + Droplet droplet = new Droplet(1, "mock-droplet", 1, 1, 1, false, ImmutableList.of(), ImmutableList.of(), + "84.45.69.3", "192.168.2.5", false, ACTIVE, new Date()); + + NodeMetadata expected = new NodeMetadataBuilder().ids("1").hardware(getOnlyElement(hardwares)).imageId("1") + .status(RUNNING).location(getOnlyElement(locations)).name("mock-droplet").hostname("mock-droplet") + .group("mock").credentials(credentials).publicAddresses(ImmutableSet.of("84.45.69.3")) + .privateAddresses(ImmutableSet.of("192.168.2.5")).providerId("1").backendStatus(ACTIVE.name()) + .operatingSystem(getOnlyElement(images).getOperatingSystem()).build(); + + NodeMetadata actual = function.apply(droplet); + + assertEquals(actual, expected); + // NodeMetadata equals method does not use all fields in equals. It assumes that same ids in same locations + // determine the equivalence + assertEquals(actual.getStatus(), expected.getStatus()); + assertEquals(actual.getBackendStatus(), expected.getBackendStatus()); + assertEquals(actual.getLoginPort(), expected.getLoginPort()); + assertEquals(actual.getPublicAddresses(), expected.getPublicAddresses()); + assertEquals(actual.getPrivateAddresses(), expected.getPrivateAddresses()); + assertEquals(actual.getCredentials(), expected.getCredentials()); + assertEquals(actual.getGroup(), expected.getGroup()); + assertEquals(actual.getImageId(), expected.getImageId()); + assertEquals(actual.getHardware(), expected.getHardware()); + assertEquals(actual.getOperatingSystem(), expected.getOperatingSystem()); + assertEquals(actual.getHostname(), expected.getHostname()); + } + + private DropletToNodeMetadata createNodeParser(final Set<Hardware> hardware, final Set<Image> images, + final Set<Location> locations, Map<String, Credentials> credentialStore) { + Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() { + @Override + public Set<? extends Location> get() { + return locations; + } + }; + + Supplier<Map<String, ? extends Hardware>> hardwareSupplier = new Supplier<Map<String, ? extends Hardware>>() { + @Override + public Map<String, ? extends Hardware> get() { + return Maps.uniqueIndex(hardware, new Function<Hardware, String>() { + @Override + public String apply(Hardware input) { + return input.getId(); + } + }); + } + }; + + Supplier<Map<String, ? extends Image>> imageSupplier = new Supplier<Map<String, ? extends Image>>() { + @Override + public Map<String, ? extends Image> get() { + return Maps.uniqueIndex(images, new Function<Image, String>() { + @Override + public String apply(Image input) { + return input.getId(); + } + }); + } + }; + + GroupNamingConvention.Factory namingConvention = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + Names.bindProperties(binder(), new DigitalOceanApiMetadata().getDefaultProperties()); + } + }).getInstance(GroupNamingConvention.Factory.class); + + return new DropletToNodeMetadata(imageSupplier, hardwareSupplier, locationSupplier, new DropletStatusToStatus(), + namingConvention, credentialStore); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/d6cdd0be/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java ---------------------------------------------------------------------- diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java new file mode 100644 index 0000000..10e9f87 --- /dev/null +++ b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java @@ -0,0 +1,52 @@ +/* + * 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.digitalocean.compute.functions; + +import static org.jclouds.compute.domain.Image.Status.AVAILABLE; +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.domain.ImageBuilder; +import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.digitalocean.domain.Image; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +/** + * Unit tests for the {@link ImageToImage} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "ImageToImageTest") +public class ImageToImageTest { + + public void testConvertImage() { + Image image = new Image(1, "Ubuntu 14.04 x64", "Ubuntu 14.04 x64", true, "ubuntu-1404"); + org.jclouds.compute.domain.Image expected = new ImageBuilder() + .ids("1") + .name("Ubuntu 14.04 x64") + .status(AVAILABLE) + .operatingSystem( + OperatingSystem.builder().name("Ubuntu 14.04 x64").description("Ubuntu 14.04 x64") + .family(OsFamily.UBUNTU).version("14.04").arch("x64").is64Bit(true).build()) + .userMetadata(ImmutableMap.of("publicImage", "true")).build(); + + ImageToImage function = new ImageToImage(); + assertEquals(function.apply(image), expected); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/d6cdd0be/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java ---------------------------------------------------------------------- diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java new file mode 100644 index 0000000..713fc8b --- /dev/null +++ b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java @@ -0,0 +1,55 @@ +/* + * 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.digitalocean.compute.functions; + +import static com.google.common.collect.Iterables.getOnlyElement; +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.digitalocean.DigitalOceanProviderMetadata; +import org.jclouds.digitalocean.domain.Region; +import org.jclouds.domain.Location; +import org.jclouds.domain.LocationBuilder; +import org.jclouds.domain.LocationScope; +import org.jclouds.location.suppliers.all.JustProvider; +import org.testng.annotations.Test; + +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableSet; + +/** + * Unit tests for the {@link RegionToLocation} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "RegionToLocationTest") +public class RegionToLocationTest { + + public void testConvertRegion() { + DigitalOceanProviderMetadata metadata = new DigitalOceanProviderMetadata(); + JustProvider locationsSupplier = new JustProvider(metadata.getId(), Suppliers.<URI> ofInstance(URI + .create(metadata.getEndpoint())), ImmutableSet.<String> of()); + RegionToLocation function = new RegionToLocation(locationsSupplier); + + Region region = new Region(1, "Region 1", "reg1"); + Location expected = new LocationBuilder().id("reg1").description("1/Region 1") + .parent(getOnlyElement(locationsSupplier.get())).scope(LocationScope.REGION).build(); + + assertEquals(function.apply(region), expected); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/d6cdd0be/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java ---------------------------------------------------------------------- diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java new file mode 100644 index 0000000..eabfe52 --- /dev/null +++ b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.digitalocean.compute.functions; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.HardwareBuilder; +import org.jclouds.compute.domain.Processor; +import org.jclouds.compute.domain.Volume.Type; +import org.jclouds.compute.domain.VolumeBuilder; +import org.jclouds.digitalocean.domain.Size; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +/** + * Unit tests for the {@link SizeToHardware} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "SizeToHardwareTest") +public class SizeToHardwareTest { + + public void testConvertSize() { + Size size = new Size(1, "Medium", "2GB", 2048, 1, 20, "0.05", "10"); + Hardware expected = new HardwareBuilder().ids("1").name("Medium").processor(new Processor(1.0, 1.0)).ram(2048) + .volume(new VolumeBuilder().size(20f).type(Type.LOCAL).build()) + .userMetadata(ImmutableMap.of("costPerHour", "0.05", "costPerMonth", "10")).build(); + + SizeToHardware function = new SizeToHardware(); + assertEquals(function.apply(size), expected); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/d6cdd0be/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java ---------------------------------------------------------------------- diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java new file mode 100644 index 0000000..9732fda --- /dev/null +++ b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java @@ -0,0 +1,75 @@ +/* + * 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.digitalocean.compute.functions; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.Map; + +import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.scriptbuilder.domain.OsFamily; +import org.jclouds.scriptbuilder.domain.Statement; +import org.jclouds.scriptbuilder.domain.StatementList; +import org.jclouds.scriptbuilder.statements.ssh.InstallRSAPrivateKey; +import org.jclouds.ssh.SshKeys; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link TemplateOptionsToStatementWithoutPublicKey} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "TemplateOptionsToStatementWithoutPublicKeyTest") +public class TemplateOptionsToStatementWithoutPublicKeyTest { + + public void testPublicKeyDoesNotGenerateStatement() { + Map<String, String> keys = SshKeys.generate(); + TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")); + + TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey(); + assertNull(function.apply(options)); + } + + public void testPublicAndRunScriptKeyDoesNotGenerateStatement() { + Map<String, String> keys = SshKeys.generate(); + TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")).runScript("uptime"); + + TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey(); + Statement statement = function.apply(options); + + assertFalse(statement instanceof StatementList); + assertEquals(statement.render(OsFamily.UNIX), "uptime\n"); + } + + public void testPublicAndPrivateKeyAndRunScriptDoesNotGenerateStatement() { + Map<String, String> keys = SshKeys.generate(); + TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")) + .installPrivateKey(keys.get("private")).runScript("uptime"); + + TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey(); + Statement statement = function.apply(options); + + assertTrue(statement instanceof StatementList); + StatementList statements = (StatementList) statement; + assertEquals(statements.size(), 2); + assertEquals(statements.get(0).render(OsFamily.UNIX), "uptime\n"); + assertTrue(statements.get(1) instanceof InstallRSAPrivateKey); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/d6cdd0be/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java ---------------------------------------------------------------------- diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java new file mode 100644 index 0000000..3673083 --- /dev/null +++ b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.digitalocean.compute.options; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.options.TemplateOptions; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Unit tests for the {@link DigitalOceanTemplateOptions} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "DigitalOceanTemplateOptionsTest") +public class DigitalOceanTemplateOptionsTest { + + public void testSShKeyIds() { + TemplateOptions options = new DigitalOceanTemplateOptions().sshKeyIds(ImmutableSet.of(1, 2, 3)); + assertEquals(options.as(DigitalOceanTemplateOptions.class).getSshKeyIds(), ImmutableSet.of(1, 2, 3)); + } + + public void testPrivateNetworking() { + TemplateOptions options = new DigitalOceanTemplateOptions().privateNetworking(true); + assertEquals(options.as(DigitalOceanTemplateOptions.class).getPrivateNetworking(), Boolean.TRUE); + } + + public void testBackupsEnabled() { + TemplateOptions options = new DigitalOceanTemplateOptions().backupsEnabled(true); + assertEquals(options.as(DigitalOceanTemplateOptions.class).getBackupsEnabled(), Boolean.TRUE); + } +}
