From 89c47ed6dd712ab4ac4394d1f2a7d4087d88a4fb Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 29 Sep 2011 10:10:30 -0700 Subject: [PATCH 1/2] fixed location for openhosting to FL, not VA --- .../jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java | 2 +- .../jclouds/openhosting/OpenHostingEast1ProviderMetadata.java | 2 +- .../compute/OpenHostingEast1TemplateBuilderLiveTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java index 0edec57b05..01c05710fd 100644 --- a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java +++ b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1PropertiesBuilder.java @@ -35,7 +35,7 @@ public class OpenHostingEast1PropertiesBuilder extends ElasticStackPropertiesBui @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); - properties.setProperty(PROPERTY_ISO3166_CODES, "US-VA"); + properties.setProperty(PROPERTY_ISO3166_CODES, "US-FL"); properties.setProperty(PROPERTY_ENDPOINT, "https://api.east1.openhosting.com"); properties.setProperty(PROPERTY_API_VERSION, "2.0"); return properties; diff --git a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java index ef5341a027..aae3250faf 100644 --- a/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java +++ b/providers/openhosting-east1/src/main/java/org/jclouds/openhosting/OpenHostingEast1ProviderMetadata.java @@ -102,7 +102,7 @@ public class OpenHostingEast1ProviderMetadata extends BaseProviderMetadata { */ @Override public Set getIso3166Codes() { - return ImmutableSet.of("US-VA"); + return ImmutableSet.of("US-FL"); } } diff --git a/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java b/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java index d7d034413a..f01de9ec3a 100644 --- a/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java +++ b/providers/openhosting-east1/src/test/java/org/jclouds/openhosting/compute/OpenHostingEast1TemplateBuilderLiveTest.java @@ -78,6 +78,6 @@ public class OpenHostingEast1TemplateBuilderLiveTest extends BaseTemplateBuilder @Override protected Set getIso3166Codes() { - return ImmutableSet. of("US-VA"); + return ImmutableSet. of("US-FL"); } } From 4c042e65c5a0267c9485723f692725814918090d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Thu, 29 Sep 2011 10:11:00 -0700 Subject: [PATCH 2/2] added option to specify domainName as an option when using softlayer --- .../SoftLayerComputeServiceContextModule.java | 14 +- .../options/SoftLayerTemplateOptions.java | 231 ++++++++++++++++++ .../SoftLayerComputeServiceAdapter.java | 55 +++-- ...oftLayerComputeServiceAdapterLiveTest.java | 10 +- .../SoftLayerTemplateBuilderLiveTest.java | 24 +- .../options/SoftLayerTemplateOptionsTest.java | 74 ++++++ 6 files changed, 372 insertions(+), 36 deletions(-) create mode 100644 sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java create mode 100644 sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java index 9a88418fd1..0bc9dfd027 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/config/SoftLayerComputeServiceContextModule.java @@ -18,15 +18,14 @@ */ package org.jclouds.softlayer.compute.config; -import com.google.common.base.Function; -import com.google.common.base.Supplier; -import com.google.inject.Injector; -import com.google.inject.TypeLiteral; +import java.util.Set; + import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; import org.jclouds.location.suppliers.OnlyLocationOrFirstZone; import org.jclouds.softlayer.SoftLayerAsyncClient; @@ -35,12 +34,16 @@ import org.jclouds.softlayer.compute.functions.DatacenterToLocation; import org.jclouds.softlayer.compute.functions.ProductItemToImage; import org.jclouds.softlayer.compute.functions.ProductItemsToHardware; import org.jclouds.softlayer.compute.functions.VirtualGuestToNodeMetadata; +import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; import org.jclouds.softlayer.domain.Datacenter; import org.jclouds.softlayer.domain.ProductItem; import org.jclouds.softlayer.domain.VirtualGuest; -import java.util.Set; +import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.inject.Injector; +import com.google.inject.TypeLiteral; /** * @@ -68,6 +71,7 @@ public class SoftLayerComputeServiceContextModule extends .to(DatacenterToLocation.class); bind(new TypeLiteral>() {}) .to(OnlyLocationOrFirstZone.class); + bind(TemplateOptions.class).to(SoftLayerTemplateOptions.class); } protected TemplateBuilder provideTemplate(Injector injector, TemplateBuilder template) { diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java new file mode 100644 index 0000000000..8d11e23513 --- /dev/null +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptions.java @@ -0,0 +1,231 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.compute.options; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.io.Payload; +import org.jclouds.softlayer.features.VirtualGuestClient; + +import com.google.common.net.InternetDomainName; + +/** + * Contains options supported by the + * {@link ComputeService#createNodesInGroup(String, int, TemplateOptions)} and + * {@link ComputeService#runNodesWithTag(String, int, TemplateOptions)} operations on the + * gogrid provider. + * + *

Usage

The recommended way to instantiate a {@link SoftLayerTemplateOptions} object is to + * statically import {@code SoftLayerTemplateOptions.*} and invoke a static creation method followed + * by an instance mutator (if needed): + *

+ * + *

+ * import static org.jclouds.compute.options.SoftLayerTemplateOptions.Builder.*;
+ * ComputeService client = // get connection
+ * templateBuilder.options(inboundPorts(22, 80, 8080, 443));
+ * Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build());
+ * 
+ * + * @author Adrian Cole + */ +public class SoftLayerTemplateOptions extends TemplateOptions implements Cloneable { + + protected String domainName = "jclouds.org"; + + @Override + public SoftLayerTemplateOptions clone() { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + copyTo(options); + return options; + } + + @Override + public void copyTo(TemplateOptions to) { + super.copyTo(to); + if (to instanceof SoftLayerTemplateOptions) { + SoftLayerTemplateOptions eTo = SoftLayerTemplateOptions.class.cast(to); + eTo.domainName(domainName); + } + } + + /** + * will replace the default domain used when ordering virtual guests. Note this needs to contain + * a public suffix! + * + * @see VirtualGuestClient#orderVirtualGuest + * @see InternetDomainName#hasPublicSuffix + */ + public TemplateOptions domainName(String domainName) { + checkNotNull(domainName, "domainName was null"); + checkArgument(InternetDomainName.from(domainName).hasPublicSuffix(), "domainName %s has no public suffix", + domainName); + this.domainName = domainName; + return this; + } + + public String getDomainName() { + return domainName; + } + + public static final SoftLayerTemplateOptions NONE = new SoftLayerTemplateOptions(); + + public static class Builder { + + /** + * @see #domainName + */ + public static SoftLayerTemplateOptions domainName(String domainName) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.domainName(domainName)); + } + + // methods that only facilitate returning the correct object type + + /** + * @see TemplateOptions#inboundPorts(int...) + */ + public static SoftLayerTemplateOptions inboundPorts(int... ports) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.inboundPorts(ports)); + } + + /** + * @see TemplateOptions#blockOnPort(int, int) + */ + public static SoftLayerTemplateOptions blockOnPort(int port, int seconds) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.blockOnPort(port, seconds)); + } + + /** + * @see TemplateOptions#runScript(Payload) + */ + public static SoftLayerTemplateOptions runScript(Payload script) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.runScript(script)); + } + + /** + * @see TemplateOptions#installPrivateKey(Payload) + */ + @Deprecated + public static SoftLayerTemplateOptions installPrivateKey(Payload rsaKey) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.installPrivateKey(rsaKey)); + } + + /** + * @see TemplateOptions#authorizePublicKey(Payload) + */ + @Deprecated + public static SoftLayerTemplateOptions authorizePublicKey(Payload rsaKey) { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.authorizePublicKey(rsaKey)); + } + + /** + * @see TemplateOptions#withMetadata() + */ + public static SoftLayerTemplateOptions withMetadata() { + SoftLayerTemplateOptions options = new SoftLayerTemplateOptions(); + return SoftLayerTemplateOptions.class.cast(options.withMetadata()); + } + } + + // methods that only facilitate returning the correct object type + + /** + * @see TemplateOptions#blockOnPort(int, int) + */ + @Override + public SoftLayerTemplateOptions blockOnPort(int port, int seconds) { + return SoftLayerTemplateOptions.class.cast(super.blockOnPort(port, seconds)); + } + + /** + * @see TemplateOptions#inboundPorts(int...) + */ + @Override + public SoftLayerTemplateOptions inboundPorts(int... ports) { + return SoftLayerTemplateOptions.class.cast(super.inboundPorts(ports)); + } + + /** + * @see TemplateOptions#authorizePublicKey(String) + */ + @Override + public SoftLayerTemplateOptions authorizePublicKey(String publicKey) { + return SoftLayerTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); + } + + /** + * @see TemplateOptions#authorizePublicKey(Payload) + */ + @Override + @Deprecated + public SoftLayerTemplateOptions authorizePublicKey(Payload publicKey) { + return SoftLayerTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); + } + + /** + * @see TemplateOptions#installPrivateKey(String) + */ + @Override + public SoftLayerTemplateOptions installPrivateKey(String privateKey) { + return SoftLayerTemplateOptions.class.cast(super.installPrivateKey(privateKey)); + } + + /** + * @see TemplateOptions#installPrivateKey(Payload) + */ + @Override + @Deprecated + public SoftLayerTemplateOptions installPrivateKey(Payload privateKey) { + return SoftLayerTemplateOptions.class.cast(super.installPrivateKey(privateKey)); + } + + /** + * @see TemplateOptions#runScript(Payload) + */ + @Override + public SoftLayerTemplateOptions runScript(Payload script) { + return SoftLayerTemplateOptions.class.cast(super.runScript(script)); + } + + /** + * @see TemplateOptions#runScript(byte[]) + */ + @Override + @Deprecated + public SoftLayerTemplateOptions runScript(byte[] script) { + return SoftLayerTemplateOptions.class.cast(super.runScript(script)); + } + + /** + * @see TemplateOptions#withMetadata() + */ + @Override + public SoftLayerTemplateOptions withMetadata() { + return SoftLayerTemplateOptions.class.cast(super.withMetadata()); + } +} diff --git a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java index 398f4befb3..ed9f19b017 100644 --- a/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java +++ b/sandbox-providers/softlayer/src/main/java/org/jclouds/softlayer/compute/strategy/SoftLayerComputeServiceAdapter.java @@ -18,32 +18,46 @@ */ package org.jclouds.softlayer.compute.strategy; -import com.google.common.base.Predicates; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode; +import static org.jclouds.softlayer.predicates.ProductItemPredicates.matches; +import static org.jclouds.softlayer.predicates.ProductItemPredicates.units; +import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named; + +import java.util.Map; +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Template; import org.jclouds.domain.Credentials; import org.jclouds.softlayer.SoftLayerClient; import org.jclouds.softlayer.compute.functions.ProductItems; -import org.jclouds.softlayer.domain.*; +import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; +import org.jclouds.softlayer.domain.BillingItemVirtualGuest; +import org.jclouds.softlayer.domain.Datacenter; +import org.jclouds.softlayer.domain.OperatingSystem; +import org.jclouds.softlayer.domain.Password; +import org.jclouds.softlayer.domain.ProductItem; +import org.jclouds.softlayer.domain.ProductItemPrice; +import org.jclouds.softlayer.domain.ProductOrder; +import org.jclouds.softlayer.domain.ProductPackage; +import org.jclouds.softlayer.domain.VirtualGuest; import org.jclouds.softlayer.features.AccountClient; import org.jclouds.softlayer.features.ProductPackageClient; import org.jclouds.softlayer.reference.SoftLayerConstants; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; -import java.util.Map; -import java.util.Set; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.*; -import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named; +import com.google.common.base.Predicates; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; /** * defines the connection between the {@link SoftLayerClient} implementation and the jclouds @@ -70,7 +84,12 @@ public class SoftLayerComputeServiceAdapter implements @Override public VirtualGuest createNodeWithGroupEncodedIntoNameThenStoreCredentials(String group, String name, Template template, Map credentialStore) { - + checkNotNull(template, "template was null"); + checkNotNull(template.getOptions(), "template options was null"); + checkArgument(template.getOptions().getClass().isAssignableFrom(SoftLayerTemplateOptions.class), + "options class %s should have been assignable from SoftLayerTemplateOptions", template.getOptions() + .getClass()); + Iterable existing = findVirtualGuests(name,group); if(!Iterables.isEmpty(existing)) { throw new IllegalStateException( @@ -78,7 +97,7 @@ public class SoftLayerComputeServiceAdapter implements } VirtualGuest newGuest = VirtualGuest.builder() - .domain(group) + .domain(template.getOptions().as(SoftLayerTemplateOptions.class).getDomainName()) .hostname(name) .build(); diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java index 1687a52ba5..ccc6f0fca6 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java @@ -30,6 +30,7 @@ import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.Template; import org.jclouds.domain.Credentials; import org.jclouds.net.IPSocket; +import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; import org.jclouds.softlayer.domain.ProductItem; import org.jclouds.softlayer.domain.VirtualGuest; @@ -64,16 +65,19 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL @Test public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { - String group = "jclouds.org"; + String group = "foo"; String name = "foo-ef4"; Template template = computeContext.getComputeService().templateBuilder() .locationId("3") // the default (singapore) doesn't work. .build(); - + + // test passing custom options + template.getOptions().as(SoftLayerTemplateOptions.class).domainName("me.org"); + Map credentialStore = Maps.newLinkedHashMap(); guest = adapter.createNodeWithGroupEncodedIntoNameThenStoreCredentials(group, name, template, credentialStore); assertEquals(guest.getHostname(), name); - assertEquals(guest.getDomain(), group); + assertEquals(guest.getDomain(), template.getOptions().as(SoftLayerTemplateOptions.class).getDomainName()); // check other things, like cpu correct, mem correct, image/os is correct // (as possible) assert credentialStore.containsKey("node#" + guest.getId()) : "credentials to log into guest not found " + guest; diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java index 6a1cc0245a..bd15c03323 100644 --- a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerTemplateBuilderLiveTest.java @@ -18,20 +18,22 @@ */ package org.jclouds.softlayer.compute; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableSet; -import org.jclouds.compute.BaseTemplateBuilderLiveTest; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.OsFamilyVersion64Bit; -import org.jclouds.compute.domain.Template; -import org.testng.annotations.Test; +import static org.jclouds.compute.util.ComputeServiceUtils.getCores; +import static org.testng.Assert.assertEquals; import java.io.IOException; import java.util.Set; -import static org.jclouds.compute.util.ComputeServiceUtils.getCores; -import static org.testng.Assert.assertEquals; +import org.jclouds.compute.BaseTemplateBuilderLiveTest; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.OsFamilyVersion64Bit; +import org.jclouds.compute.domain.Template; +import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableSet; /** * @@ -80,6 +82,8 @@ public class SoftLayerTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTes assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true); assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), OsFamily.UBUNTU); assertEquals(getCores(defaultTemplate.getHardware()), 2.0d); + // test that we bound the correct templateoptions in guice + assertEquals(defaultTemplate.getOptions().getClass(), SoftLayerTemplateOptions.class); } @Override diff --git a/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java new file mode 100644 index 0000000000..5988d3f232 --- /dev/null +++ b/sandbox-providers/softlayer/src/test/java/org/jclouds/softlayer/compute/options/SoftLayerTemplateOptionsTest.java @@ -0,0 +1,74 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.softlayer.compute.options; + +import static org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions.Builder.domainName; +import static org.testng.Assert.assertEquals; + +import org.jclouds.compute.options.TemplateOptions; +import org.testng.annotations.Test; + +/** + * Tests possible uses of {@code SoftLayerTemplateOptions} and {@code + * SoftLayerTemplateOptions.Builder.*}. + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire +@Test(groups = "unit", testName = "SoftLayerTemplateOptionsTest") +public class SoftLayerTemplateOptionsTest { + @Test + public void testAs() { + TemplateOptions options = new SoftLayerTemplateOptions(); + assertEquals(options.as(SoftLayerTemplateOptions.class), options); + } + + @Test + public void testDefaultDomainName() { + TemplateOptions options = new SoftLayerTemplateOptions(); + assertEquals(options.as(SoftLayerTemplateOptions.class).getDomainName(), "jclouds.org"); + } + + @Test + public void testDomainName() { + TemplateOptions options = new SoftLayerTemplateOptions().domainName("me.com"); + assertEquals(options.as(SoftLayerTemplateOptions.class).getDomainName(), "me.com"); + } + + @Test + public void testDomainNameStatic() { + TemplateOptions options = domainName("me.com"); + assertEquals(options.as(SoftLayerTemplateOptions.class).getDomainName(), "me.com"); + } + + @Test + public void testDomainNameNullHasDecentMessage() { + try { + new SoftLayerTemplateOptions().domainName(null); + assert false : "should NPE"; + } catch (NullPointerException e) { + assertEquals(e.getMessage(), "domainName was null"); + } + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testDomainNameIsInvalidThrowsIllegalArgument() { + new SoftLayerTemplateOptions().domainName("foo"); + } +}