From 7704b6b8f0849d8e5120a7d498a4b22997d663f9 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 6 Mar 2012 18:00:44 -0800 Subject: [PATCH] test tidies --- .../BaseVirtualBoxClientLiveTest.java | 52 +++++++++---------- ...rtualBoxComputeServiceAdapterLiveTest.java | 34 ++++-------- 2 files changed, 37 insertions(+), 49 deletions(-) diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java index 586b879798..b755570f50 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/BaseVirtualBoxClientLiveTest.java @@ -23,6 +23,9 @@ import java.io.File; import java.net.URI; import java.util.Properties; +import javax.inject.Inject; +import javax.inject.Named; + import org.jclouds.Constants; import org.jclouds.byon.Node; import org.jclouds.byon.config.CacheNodeStoreModule; @@ -31,9 +34,7 @@ import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; -import org.jclouds.config.ValueOfConfigurationKeyOrNull; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.virtualbox.config.VirtualBoxConstants; @@ -57,9 +58,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import com.google.inject.Key; import com.google.inject.Module; -import com.google.inject.TypeLiteral; /** * Tests behavior of {@code VirtualBoxClient} @@ -71,19 +70,37 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { public BaseVirtualBoxClientLiveTest() { provider = "virtualbox"; } - + protected ComputeServiceContext context; + + @Inject protected Supplier manager; + + @Inject + void eagerlyStartManager(Supplier manager){ + this.manager = manager; + manager.get(); + } + + @Inject protected MachineUtils machineUtils; + + // this will eagerly startup Jetty, note the impl will shut itself down + @Inject + @Preconfiguration protected LoadingCache preconfigurationUri; + protected String hostVersion; protected String operatingSystemIso; protected String guestAdditionsIso; + @Inject + @Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR) protected String workingDir; protected String isosDir; + @Inject protected Supplier host; - protected static final PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate = new PrioritizeCredentialsFromTemplate( - new DefaultCredentialsFromImageOrOverridingCredentials()); + @Inject + protected PrioritizeCredentialsFromTemplate prioritizeCredentialsFromTemplate; @Override protected void setupCredentials() { @@ -117,31 +134,14 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest { context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet. of(new SLF4JLoggingModule(), new SshjSshClientModule(), hostModule), overrides); - Function configProperties = context.utils().injector() - .getInstance(ValueOfConfigurationKeyOrNull.class); + context.utils().injector().injectMembers(this); + imageId = "ubuntu-11.04-server-i386"; - workingDir = configProperties.apply(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR); isosDir = workingDir + File.separator + "isos"; File isosDirFile = new File(isosDir); if (!isosDirFile.exists()) { isosDirFile.mkdirs(); } - host = context.utils().injector().getInstance(Key.get(new TypeLiteral>() { - })); - - // this will eagerly startup Jetty, note the impl will shut itself down - preconfigurationUri = context.utils().injector() - .getInstance(Key.get(new TypeLiteral>() { - }, Preconfiguration.class)); - // this will eagerly startup Jetty, note the impl will shut itself down - - manager = context.utils().injector().getInstance(Key.get(new TypeLiteral>() { - })); - // this will eagerly startup vbox - manager.get(); - - machineUtils = context.utils().injector().getInstance(MachineUtils.class); - hostVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0); operatingSystemIso = String.format("%s/%s.iso", isosDir, imageId); guestAdditionsIso = String.format("%s/VBoxGuestAdditions_%s.iso", isosDir, hostVersion); diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java index ee27ea0505..0be2cf2d46 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/compute/VirtualBoxComputeServiceAdapterLiveTest.java @@ -22,6 +22,8 @@ package org.jclouds.virtualbox.compute; import static org.jclouds.virtualbox.config.VirtualBoxConstants.VIRTUALBOX_NODE_PREFIX; import static org.testng.Assert.assertEquals; +import javax.inject.Inject; + import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.Image; @@ -37,34 +39,21 @@ import com.google.common.collect.Iterables; @Test(groups = "live", singleThreaded = true, testName = "VirtualBoxComputeServiceAdapterLiveTest") public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClientLiveTest { - + @Inject private VirtualBoxComputeServiceAdapter adapter; + private NodeAndInitialCredentials machine; - @Override - public void setupClient() { - super.setupClient(); - adapter = context.utils().injector().getInstance(VirtualBoxComputeServiceAdapter.class); - } - @Test - public void testCreateNodeWithGroupEncodedIntoNameThenStoreCredentials() { + public void testCreatedNodeHasExpectedNameAndWeCanConnectViaSsh() { String group = "foo"; String name = "foo-ef4"; String machineName = VIRTUALBOX_NODE_PREFIX + "myTestId-" + group + "-" + name; - // get the image from - Image image = Iterables.get(adapter.listImages(), 0); - System.out.println(context.getComputeService().templateBuilder()); - Template template = context.getComputeService().templateBuilder().fromImage(image).build(); + + Template template = context.getComputeService().templateBuilder().build(); machine = adapter.createNodeWithGroupEncodedIntoName(group, name, template); + assertEquals(machine.getNode().getName(), machineName); - // is there a place for group? - // check other things, like cpu correct, mem correct, image/os is correct - // (as possible) - // TODO: what's the IP address? - // assert - // InetAddresses.isInetAddress(machine.getPrimaryBackendIpAddress()) : - // machine; doConnectViaSsh(machine.getNode(), prioritizeCredentialsFromTemplate.apply(template, machine.getCredentials())); } @@ -87,15 +76,14 @@ public class VirtualBoxComputeServiceAdapterLiveTest extends BaseVirtualBoxClien public void testListHardwareProfiles() { Iterable profiles = adapter.listHardwareProfiles(); assertEquals(1, Iterables.size(profiles)); + //TODO: check state; } @Test public void testListImages() { Iterable iMageIterable = adapter.listImages(); - for (Image image : iMageIterable) { - System.out.println(image); - } - // check state; + assertEquals(1, Iterables.size(iMageIterable)); + //TODO: check state; } @Override