From 4d81a5aa28dd91b90108d20d9e98c2471f81735f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Mon, 16 May 2011 18:59:31 -0700 Subject: [PATCH] Issue 550: moved providers into a scoped package and made a base test class --- core/pom.xml | 2 +- .../jclouds/providers/BaseProviderTest.java | 75 +++++++++++++++++++ .../org/jclouds/providers/ProvidersTest.java | 2 +- .../ec2}/AWSEC2ProviderMetadata.java | 19 +++-- .../org.jclouds.providers.ProviderMetadata | 2 +- .../jclouds/providers/AWSEC2ProviderTest.java | 42 ++--------- ...erremarkVCloudExpressProviderMetadata.java | 73 ++++++++++++++++++ .../org.jclouds.providers.ProviderMetadata | 1 + .../TerremarkVCloudExpressProviderTest.java} | 29 ++----- 9 files changed, 177 insertions(+), 68 deletions(-) create mode 100644 core/src/test/java/org/jclouds/providers/BaseProviderTest.java rename providers/aws-ec2/src/main/java/org/jclouds/{providers => aws/ec2}/AWSEC2ProviderMetadata.java (77%) create mode 100644 providers/trmk-vcloudexpress/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressProviderMetadata.java create mode 100644 providers/trmk-vcloudexpress/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata rename providers/trmk-vcloudexpress/src/test/java/org/jclouds/{vcloud/terremark/ProvidersInPropertiesTest.java => providers/TerremarkVCloudExpressProviderTest.java} (56%) diff --git a/core/pom.xml b/core/pom.xml index 33a8bb5dbb..80361b4bef 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -138,7 +138,7 @@ --> META-INF/services/ - org/jclouds/providers/*Test*.class + org/jclouds/providers/ProvidersTest.class diff --git a/core/src/test/java/org/jclouds/providers/BaseProviderTest.java b/core/src/test/java/org/jclouds/providers/BaseProviderTest.java new file mode 100644 index 0000000000..a4cf4f3fa2 --- /dev/null +++ b/core/src/test/java/org/jclouds/providers/BaseProviderTest.java @@ -0,0 +1,75 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.providers; + +import static org.testng.Assert.assertEquals; + +import java.util.Set; + +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +/** + * + * @author Jeremy Whitlock + */ +@Test(groups = "unit") +public abstract class BaseProviderTest { + protected Set allTypes = ImmutableSet.of(ProviderMetadata.BLOBSTORE_TYPE, ProviderMetadata.COMPUTE_TYPE); + private final ProviderMetadata toTest; + private final String expectedType; + + public BaseProviderTest(ProviderMetadata toTest, String expectedType) { + this.toTest = toTest; + this.expectedType = expectedType; + } + + @Test + public void testWithId() { + ProviderMetadata providerMetadata = Providers.withId(toTest.getId()); + + assertEquals(toTest, providerMetadata); + } + + @Test + public void testOfType() { + assertEquals(Iterables.getOnlyElement(Providers.ofType(expectedType)), toTest); + + for (String type : Sets.difference(allTypes, ImmutableSet.of(expectedType))) + assertEquals(Iterables.size(Providers.ofType(type)), 0); + } + + @Test + public void testAll() { + Iterable providersMetadata = Providers.all(); + + for (ProviderMetadata providerMetadata : providersMetadata) { + assertEquals(toTest, providerMetadata); + } + } + + @Test + public void testInRestProperties() { + Iterable providers = org.jclouds.rest.Providers.getSupportedProviders(); + assert Iterables.contains(providers, toTest.getId()) : providers; + } +} \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/providers/ProvidersTest.java b/core/src/test/java/org/jclouds/providers/ProvidersTest.java index 4b45aaec4f..2cc1ab31ca 100644 --- a/core/src/test/java/org/jclouds/providers/ProvidersTest.java +++ b/core/src/test/java/org/jclouds/providers/ProvidersTest.java @@ -39,7 +39,7 @@ public class ProvidersTest { @Test public void testWithId() { ProviderMetadata providerMetadata; - + try { providerMetadata = Providers.withId("fake-id"); fail("Looking for a provider with an id that doesn't exist should " + diff --git a/providers/aws-ec2/src/main/java/org/jclouds/providers/AWSEC2ProviderMetadata.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java similarity index 77% rename from providers/aws-ec2/src/main/java/org/jclouds/providers/AWSEC2ProviderMetadata.java rename to providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java index 7352040d93..9301cdd8e4 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/providers/AWSEC2ProviderMetadata.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/AWSEC2ProviderMetadata.java @@ -16,10 +16,13 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.providers; +package org.jclouds.aws.ec2; import java.net.URI; +import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.providers.ProviderMetadata; + /** * Implementation of {@ link org.jclouds.types.ProviderMetadata} for Amazon's * Elastic Compute Cloud (EC2) provider. @@ -29,7 +32,7 @@ import java.net.URI; public class AWSEC2ProviderMetadata extends BaseProviderMetadata { /** - * {@ see org.jclouds.types.ProviderMetadata#getId()} + * {@inheritDoc} */ @Override public String getId() { @@ -37,7 +40,7 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata { } /** - * {@ see org.jclouds.types.ProviderMetadata#getType()} + * {@inheritDoc} */ @Override public String getType() { @@ -45,7 +48,7 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata { } /** - * {@ see org.jclouds.types.ProviderMetadata#getName()} + * {@inheritDoc} */ @Override public String getName() { @@ -53,19 +56,19 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata { } /** - * {@ see org.jclouds.types.ProviderMetadata#getHomepage()} + * {@inheritDoc} */ @Override public URI getHomepage() { - return URI.create("http://aws.amazon.com/"); + return URI.create("http://aws.amazon.com/ec2/"); } /** - * {@ see org.jclouds.types.ProviderMetadata#getConsole()} + * {@inheritDoc} */ @Override public URI getConsole() { - return URI.create("http://aws.amazon.com/console/"); + return URI.create("https://console.aws.amazon.com/ec2/home"); } } \ No newline at end of file diff --git a/providers/aws-ec2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/aws-ec2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata index 8ef1088acb..636b065928 100644 --- a/providers/aws-ec2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata +++ b/providers/aws-ec2/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -1 +1 @@ -org.jclouds.providers.AWSEC2ProviderMetadata +org.jclouds.aws.ec2.AWSEC2ProviderMetadata diff --git a/providers/aws-ec2/src/test/java/org/jclouds/providers/AWSEC2ProviderTest.java b/providers/aws-ec2/src/test/java/org/jclouds/providers/AWSEC2ProviderTest.java index e4a8dc8c85..7148ca46bb 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/providers/AWSEC2ProviderTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/providers/AWSEC2ProviderTest.java @@ -18,48 +18,18 @@ */ package org.jclouds.providers; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; - +import org.jclouds.aws.ec2.AWSEC2ProviderMetadata; import org.testng.annotations.Test; /** * The AWSEC2ProviderTest tests the org.jclouds.providers.AWSEC2Provider class. - * + * * @author Jeremy Whitlock */ -@Test( groups = "unit" ) -public class AWSEC2ProviderTest { +@Test(groups = "unit", testName = "AWSEC2ProviderTest") +public class AWSEC2ProviderTest extends BaseProviderTest { - private final ProviderMetadata awsEc2ProviderMetadata = new AWSEC2ProviderMetadata(); - - @Test - public void testWithId() { - ProviderMetadata providerMetadata = Providers.withId(awsEc2ProviderMetadata.getId()); - - assertEquals(awsEc2ProviderMetadata, providerMetadata); + public AWSEC2ProviderTest() { + super(new AWSEC2ProviderMetadata(), ProviderMetadata.COMPUTE_TYPE); } - - @Test - public void testOfType() { - Iterable providersMetadata = Providers.ofType(ProviderMetadata.COMPUTE_TYPE); - - for (ProviderMetadata providerMetadata : providersMetadata) { - assertEquals(awsEc2ProviderMetadata, providerMetadata); - } - - providersMetadata = Providers.ofType(ProviderMetadata.BLOBSTORE_TYPE); - - assertFalse(providersMetadata.iterator().hasNext()); - } - - @Test - public void testAll() { - Iterable providersMetadata = Providers.all(); - - for (ProviderMetadata providerMetadata : providersMetadata) { - assertEquals(awsEc2ProviderMetadata, providerMetadata); - } - } - } \ No newline at end of file diff --git a/providers/trmk-vcloudexpress/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressProviderMetadata.java b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressProviderMetadata.java new file mode 100644 index 0000000000..62d6d55fad --- /dev/null +++ b/providers/trmk-vcloudexpress/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudExpressProviderMetadata.java @@ -0,0 +1,73 @@ +/** + * + * Copyright (C) 2011 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed 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.vcloud.terremark; + +import java.net.URI; + +import org.jclouds.providers.BaseProviderMetadata; +import org.jclouds.providers.ProviderMetadata; + +/** + * Implementation of {@link org.jclouds.types.ProviderMetadata} for Terremark's vCloud Express. + * + * @author Adrian Cole + */ +public class TerremarkVCloudExpressProviderMetadata extends BaseProviderMetadata { + + /** + * {@inheritDoc} + */ + @Override + public String getId() { + return "trmk-vcloudexpress"; + } + + /** + * {@inheritDoc} + */ + @Override + public String getType() { + return ProviderMetadata.COMPUTE_TYPE; + } + + /** + * {@inheritDoc} + */ + @Override + public String getName() { + return "Terremark vCloud Express"; + } + + /** + * {@inheritDoc} + */ + @Override + public URI getHomepage() { + return URI.create("https://vcloudexpress.terremark.com/"); + } + + /** + * {@inheritDoc} + */ + @Override + public URI getConsole() { + return URI.create("https://my.vcloudexpress.terremark.com"); + } + +} \ No newline at end of file diff --git a/providers/trmk-vcloudexpress/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/providers/trmk-vcloudexpress/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000000..826eb45584 --- /dev/null +++ b/providers/trmk-vcloudexpress/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.vcloud.terremark.TerremarkVCloudExpressProviderMetadata diff --git a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/vcloud/terremark/ProvidersInPropertiesTest.java b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/providers/TerremarkVCloudExpressProviderTest.java similarity index 56% rename from providers/trmk-vcloudexpress/src/test/java/org/jclouds/vcloud/terremark/ProvidersInPropertiesTest.java rename to providers/trmk-vcloudexpress/src/test/java/org/jclouds/providers/TerremarkVCloudExpressProviderTest.java index 7208060ea7..708395bf4a 100644 --- a/providers/trmk-vcloudexpress/src/test/java/org/jclouds/vcloud/terremark/ProvidersInPropertiesTest.java +++ b/providers/trmk-vcloudexpress/src/test/java/org/jclouds/providers/TerremarkVCloudExpressProviderTest.java @@ -16,33 +16,20 @@ * limitations under the License. * ==================================================================== */ -package org.jclouds.vcloud.terremark; +package org.jclouds.providers; -import org.jclouds.compute.util.ComputeServiceUtils; -import org.jclouds.rest.Providers; +import org.jclouds.vcloud.terremark.TerremarkVCloudExpressProviderMetadata; import org.testng.annotations.Test; -import com.google.common.collect.Iterables; - /** + * The TerremarkVCloudExpressProviderTest tests the org.jclouds.providers.TerremarkVCloudExpressProvider class. * * @author Adrian Cole - * */ -@Test(groups = "unit") -public class ProvidersInPropertiesTest { - - @Test - public void testSupportedProviders() { - Iterable providers = Providers.getSupportedProviders(); - assert Iterables.contains(providers, "trmk-vcloudexpress") : providers; +@Test(groups = "unit", testName = "TerremarkVCloudExpressProviderTest") +public class TerremarkVCloudExpressProviderTest extends BaseProviderTest { + public TerremarkVCloudExpressProviderTest() { + super(new TerremarkVCloudExpressProviderMetadata(), ProviderMetadata.COMPUTE_TYPE); } - - @Test - public void testSupportedComputeServiceProviders() { - Iterable providers = ComputeServiceUtils.getSupportedProviders(); - assert Iterables.contains(providers, "trmk-vcloudexpress") : providers; - } - -} +} \ No newline at end of file