test tidies

This commit is contained in:
Adrian Cole 2012-03-06 18:00:44 -08:00
parent d069b0b745
commit 7704b6b8f0
2 changed files with 37 additions and 49 deletions

View File

@ -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}
@ -73,17 +72,35 @@ public class BaseVirtualBoxClientLiveTest extends BaseVersionedServiceLiveTest {
}
protected ComputeServiceContext context;
@Inject
protected Supplier<VirtualBoxManager> manager;
@Inject
void eagerlyStartManager(Supplier<VirtualBoxManager> 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<IsoSpec, URI> preconfigurationUri;
protected String hostVersion;
protected String operatingSystemIso;
protected String guestAdditionsIso;
@Inject
@Named(VirtualBoxConstants.VIRTUALBOX_WORKINGDIR)
protected String workingDir;
protected String isosDir;
@Inject
protected Supplier<NodeMetadata> 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.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule(), hostModule), overrides);
Function<String, String> 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<Supplier<NodeMetadata>>() {
}));
// this will eagerly startup Jetty, note the impl will shut itself down
preconfigurationUri = context.utils().injector()
.getInstance(Key.get(new TypeLiteral<LoadingCache<IsoSpec, URI>>() {
}, Preconfiguration.class));
// this will eagerly startup Jetty, note the impl will shut itself down
manager = context.utils().injector().getInstance(Key.get(new TypeLiteral<Supplier<VirtualBoxManager>>() {
}));
// 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);

View File

@ -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<IMachine> 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<IMachine> profiles = adapter.listHardwareProfiles();
assertEquals(1, Iterables.size(profiles));
//TODO: check state;
}
@Test
public void testListImages() {
Iterable<Image> iMageIterable = adapter.listImages();
for (Image image : iMageIterable) {
System.out.println(image);
}
// check state;
assertEquals(1, Iterables.size(iMageIterable));
//TODO: check state;
}
@Override