You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2013/09/10 14:25:52 UTC
git commit: Cleanup tests
Updated Branches:
refs/heads/master 5733d694f -> 22f9233e3
Cleanup tests
* Use TestNG assertions
* Formatted code in compute tests
* Removed unnecessary local variables in tests to avoid using them by
mistake between independent tests.
Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/commit/22f9233e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/tree/22f9233e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/diff/22f9233e
Branch: refs/heads/master
Commit: 22f9233e38083f8c362059c3299df2ea6f129d0d
Parents: 5733d69
Author: Ignasi Barrera <na...@apache.org>
Authored: Mon Sep 9 16:20:46 2013 +0200
Committer: Ignasi Barrera <na...@apache.org>
Committed: Tue Sep 10 14:25:05 2013 +0200
----------------------------------------------------------------------
.../compute/ChefComputeServiceLiveTest.java | 15 +--
...puteServiceIntegratedChefClientLiveTest.java | 129 +++++++++----------
.../chef/internal/BaseChefApiLiveTest.java | 24 ++--
3 files changed, 78 insertions(+), 90 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/22f9233e/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java
----------------------------------------------------------------------
diff --git a/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java
index 0c8fcc5..67a716a 100644
--- a/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java
+++ b/compute/src/test/java/org/jclouds/chef/compute/ChefComputeServiceLiveTest.java
@@ -20,10 +20,11 @@ import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.getLast;
import static org.jclouds.chef.predicates.CookbookVersionPredicates.containsRecipe;
-import static org.jclouds.chef.predicates.CookbookVersionPredicates.containsRecipes;
import static org.jclouds.compute.options.TemplateOptions.Builder.runScript;
import static org.jclouds.reflect.Reflection2.typeToken;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
import java.io.IOException;
import java.io.InputStream;
@@ -69,14 +70,8 @@ public class ChefComputeServiceLiveTest extends BaseComputeServiceIntegratedChef
view.getChefService().updateBootstrapConfigForGroup(group, bootstrap);
assertEquals(view.getChefService().getRunListForGroup(group), runList);
} else {
- assert false : String.format("recipe %s not in %s", recipe, cookbookVersions);
+ fail(String.format("recipe %s not in %s", recipe, cookbookVersions));
}
-
- // TODO move this to a unit test
- assert any(cookbookVersions, containsRecipe("apache2::mod_proxy"));
- assert any(cookbookVersions, containsRecipes("apache2", "apache2::mod_proxy", "apache2::mod_proxy_http"));
- assert !any(cookbookVersions, containsRecipe("apache2::bar"));
- assert !any(cookbookVersions, containsRecipe("foo::bar"));
}
@Test(dependsOnMethods = "testCanUpdateRunList")
@@ -94,9 +89,9 @@ public class ChefComputeServiceLiveTest extends BaseComputeServiceIntegratedChef
URI uri = URI.create("http://" + getLast(node.getPublicAddresses()));
InputStream content = computeContext.utils().http().get(uri);
String string = Strings2.toStringAndClose(content);
- assert string.indexOf("It works!") >= 0 : string;
+ assertTrue(string.indexOf("It works!") >= 0,
+ String.format("The default Apache page was not found: %s", string));
}
-
}
@AfterClass(groups = { "integration", "live" })
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/22f9233e/compute/src/test/java/org/jclouds/chef/compute/internal/BaseComputeServiceIntegratedChefClientLiveTest.java
----------------------------------------------------------------------
diff --git a/compute/src/test/java/org/jclouds/chef/compute/internal/BaseComputeServiceIntegratedChefClientLiveTest.java b/compute/src/test/java/org/jclouds/chef/compute/internal/BaseComputeServiceIntegratedChefClientLiveTest.java
index 4eca736..4c87592 100644
--- a/compute/src/test/java/org/jclouds/chef/compute/internal/BaseComputeServiceIntegratedChefClientLiveTest.java
+++ b/compute/src/test/java/org/jclouds/chef/compute/internal/BaseComputeServiceIntegratedChefClientLiveTest.java
@@ -16,6 +16,8 @@
*/
package org.jclouds.chef.compute.internal;
+import static com.google.common.base.Throwables.propagate;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
@@ -43,82 +45,71 @@ import com.google.inject.Module;
/**
* @author Adrian Cole
*/
-public abstract class BaseComputeServiceIntegratedChefClientLiveTest
- extends
- BaseViewLiveTest<ChefContext> {
+public abstract class BaseComputeServiceIntegratedChefClientLiveTest extends BaseViewLiveTest<ChefContext> {
- protected TemplateBuilderSpec template;
- protected LoginCredentials loginCredentials = LoginCredentials.builder()
- .user("root").build();
+ protected TemplateBuilderSpec template;
+ protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build();
- // isolate tests from eachother, as default credentialStore is static
- protected Module credentialStoreModule = new CredentialStoreModule(
- new CopyInputStreamInputSupplierMap(
- new ConcurrentHashMap<String, InputSupplier<InputStream>>()));
+ // isolate tests from each other, as default credentialStore is static
+ protected Module credentialStoreModule = new CredentialStoreModule(new CopyInputStreamInputSupplierMap(
+ new ConcurrentHashMap<String, InputSupplier<InputStream>>()));
- private String computeProvider;
+ private String computeProvider;
- protected Properties setupComputeProperties() {
- Properties overrides = new Properties();
- overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
- overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
- computeProvider = setIfTestSystemPropertyPresent(overrides, provider
- + ".compute.provider");
- setIfTestSystemPropertyPresent(overrides, provider
- + ".compute.identity");
- setIfTestSystemPropertyPresent(overrides, provider
- + ".compute.credential");
- setIfTestSystemPropertyPresent(overrides, provider
- + ".compute.endpoint");
- setIfTestSystemPropertyPresent(overrides, provider
- + ".compute.api-version");
- setIfTestSystemPropertyPresent(overrides, provider
- + ".compute.build-version");
- String spec = setIfTestSystemPropertyPresent(overrides, provider
- + ".compute.template");
- if (spec != null) {
- template = TemplateBuilderSpec.parse(spec);
- if (template.getLoginUser() != null) {
- Iterable<String> userPass = Splitter.on(':').split(
- template.getLoginUser());
- Builder loginCredentialsBuilder = LoginCredentials.builder();
- loginCredentialsBuilder.user(Iterables.get(userPass, 0));
- if (Iterables.size(userPass) == 2)
- loginCredentialsBuilder
- .password(Iterables.get(userPass, 1));
- if (template.getAuthenticateSudo() != null)
- loginCredentialsBuilder.authenticateSudo(template
- .getAuthenticateSudo());
- loginCredentials = loginCredentialsBuilder.build();
- }
- }
- return overrides;
- }
+ protected Properties setupComputeProperties() {
+ Properties overrides = new Properties();
+ overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
+ overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
+ computeProvider = setIfTestSystemPropertyPresent(overrides, provider + ".compute.provider");
+ setIfTestSystemPropertyPresent(overrides, provider + ".compute.identity");
+ setIfTestSystemPropertyPresent(overrides, provider + ".compute.credential");
+ setIfTestSystemPropertyPresent(overrides, provider + ".compute.endpoint");
+ setIfTestSystemPropertyPresent(overrides, provider + ".compute.api-version");
+ setIfTestSystemPropertyPresent(overrides, provider + ".compute.build-version");
+ String spec = setIfTestSystemPropertyPresent(overrides, provider + ".compute.template");
+ if (spec != null) {
+ template = TemplateBuilderSpec.parse(spec);
+ if (template.getLoginUser() != null) {
+ Iterable<String> userPass = Splitter.on(':').split(template.getLoginUser());
+ Builder loginCredentialsBuilder = LoginCredentials.builder();
+ loginCredentialsBuilder.user(Iterables.get(userPass, 0));
+ if (Iterables.size(userPass) == 2)
+ loginCredentialsBuilder.password(Iterables.get(userPass, 1));
+ if (template.getAuthenticateSudo() != null)
+ loginCredentialsBuilder.authenticateSudo(template.getAuthenticateSudo());
+ loginCredentials = loginCredentialsBuilder.build();
+ }
+ }
+ return overrides;
+ }
- @Override
- protected Iterable<Module> setupModules() {
- return ImmutableSet.<Module> of(getLoggingModule(),
- credentialStoreModule, getSshModule());
- }
+ @Override
+ protected Iterable<Module> setupModules() {
+ return ImmutableSet.<Module> of(getLoggingModule(), credentialStoreModule, getSshModule());
+ }
- protected Module getSshModule() {
- return new SshjSshClientModule();
- }
+ protected Module getSshModule() {
+ return new SshjSshClientModule();
+ }
- protected volatile ComputeServiceContext computeContext;
+ protected volatile ComputeServiceContext computeContext;
- @Override
- protected void initializeContext() {
- super.initializeContext();
- computeContext = ContextBuilder.newBuilder(computeProvider)
- .modules(setupModules()).overrides(setupComputeProperties())
- .buildView(ComputeServiceContext.class);
- }
+ @Override
+ protected void initializeContext() {
+ super.initializeContext();
+ computeContext = ContextBuilder.newBuilder(computeProvider).modules(setupModules())
+ .overrides(setupComputeProperties()).buildView(ComputeServiceContext.class);
+ }
- @AfterClass(groups = {"integration", "live"})
- @Override
- protected void tearDownContext() {
- Closeables.closeQuietly(computeContext);
- super.tearDownContext();
- }
+ @AfterClass(groups = { "integration", "live" })
+ @Override
+ protected void tearDownContext() {
+ try {
+ Closeables.close(computeContext, true);
+ } catch (IOException e) {
+ throw propagate(e);
+ } finally {
+ super.tearDownContext();
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-jclouds-chef/blob/22f9233e/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java b/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java
index 0130821..0cd9562 100644
--- a/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java
+++ b/core/src/test/java/org/jclouds/chef/internal/BaseChefApiLiveTest.java
@@ -46,6 +46,7 @@ import org.jclouds.chef.domain.Metadata;
import org.jclouds.chef.domain.Node;
import org.jclouds.chef.domain.Resource;
import org.jclouds.chef.domain.Role;
+import org.jclouds.chef.domain.Sandbox;
import org.jclouds.chef.domain.SearchResult;
import org.jclouds.chef.domain.UploadSandbox;
import org.jclouds.chef.options.CreateClientOptions;
@@ -76,10 +77,9 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
// It may take a bit until the search index is populated
protected int maxWaitForIndexInMs = 60000;
-
- private Node node;
- private Role role;
- protected DatabagItem databagItem;
+
+ // The id of the data bag item used in search tests
+ private String databagitemId;
public void testCreateNewCookbook() throws Exception {
// Define the file you want in the cookbook
@@ -103,7 +103,8 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
if (status.needsUpload()) {
api.uploadContent(status.getUrl(), content);
}
- api.commitSandbox(site.getSandboxId(), true);
+ Sandbox sandbox = api.commitSandbox(site.getSandboxId(), true);
+ assertTrue(sandbox.isCompleted(), "Sandbox should be completed after uploading");
} catch (RuntimeException e) {
api.commitSandbox(site.getSandboxId(), false);
fail("Could not upload content");
@@ -210,7 +211,7 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
public void testCreateNode() throws Exception {
api.deleteNode(PREFIX);
api.createNode(Node.builder().name(PREFIX).runListElement("role[" + PREFIX + "]").environment("_default").build());
- node = api.getNode(PREFIX);
+ Node node = api.getNode(PREFIX);
// TODO check recipes
assertNotNull(node, "Created node should not be null");
Set<String> nodes = api.listNodes();
@@ -235,7 +236,7 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
public void testCreateRole() throws Exception {
api.deleteRole(PREFIX);
api.createRole(Role.builder().name(PREFIX).runListElement("recipe[java]").build());
- role = api.getRole(PREFIX);
+ Role role = api.getRole(PREFIX);
assertNotNull(role, "Created role should not be null");
assertEquals(role.getName(), PREFIX);
assertEquals(role.getRunList(), Collections.singleton("recipe[java]"));
@@ -272,7 +273,8 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
Properties config = new Properties();
config.setProperty("foo", "bar");
api.deleteDatabagItem(PREFIX, PREFIX);
- databagItem = api.createDatabagItem(PREFIX, new DatabagItem("config", json.toJson(config)));
+ DatabagItem databagItem = api.createDatabagItem(PREFIX, new DatabagItem("config", json.toJson(config)));
+ databagitemId = databagItem.getId();
assertNotNull(databagItem, "Created data bag item should not be null");
assertEquals(databagItem.getId(), "config");
@@ -401,7 +403,7 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
assertNotNull(results);
if (results.size() > 0) {
assertEquals(results.size(), 1);
- assertEquals(results.iterator().next().getId(), databagItem.getId());
+ assertEquals(results.iterator().next().getId(), databagitemId);
return true;
} else {
// The index may still not be populated
@@ -410,7 +412,7 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
}
}, maxWaitForIndexInMs, 5000L, MILLISECONDS);
- SearchOptions options = SearchOptions.Builder.query("id:" + databagItem.getId());
+ SearchOptions options = SearchOptions.Builder.query("id:" + databagitemId);
assertTrue(waitForIndex.apply(options));
}
@@ -475,7 +477,7 @@ public abstract class BaseChefApiLiveTest<A extends ChefApi> extends BaseChefLiv
public void testListEnvironmentNodes() {
api.deleteNode(ENV_NODE);
api.createNode(Node.builder().name(ENV_NODE).runListElement("role[" + PREFIX + "]").environment(PREFIX).build());
- node = api.getNode(ENV_NODE);
+ Node node = api.getNode(ENV_NODE);
assertNotNull(node, "Created node should not be null");
Set<String> nodeList = api.listEnvironmentNodes(PREFIX);
assertTrue(!nodeList.isEmpty());