mirror of https://github.com/apache/jclouds.git
issue 384: fixed tests
This commit is contained in:
parent
3aaaa22660
commit
762f8d29bb
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
U * 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
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
* 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.virtualbox.domain;
|
||||
|
||||
import static org.jclouds.scriptbuilder.domain.Statements.interpret;
|
||||
import static org.jclouds.virtualbox.domain.Statements.exportIpAddressFromVmNamed;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.scriptbuilder.ScriptBuilder;
|
||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||
import org.jclouds.scriptbuilder.domain.ShellToken;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.google.common.io.Resources;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class GetIPAddressFromGuestAdditionsTest {
|
||||
|
||||
ScriptBuilder getIpAddressBuilder = new ScriptBuilder()
|
||||
.addStatement(exportIpAddressFromVmNamed("{args}"))
|
||||
.addStatement(interpret("echo {varl}FOUND_IP_ADDRESS{varr}{lf}"));
|
||||
|
||||
public void testUNIX() throws IOException {
|
||||
assertEquals(getIpAddressBuilder.render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||
.getResource("test_get_ip_address." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)));
|
||||
}
|
||||
|
||||
// TODO
|
||||
/*
|
||||
public void testWINDOWS() throws IOException {
|
||||
assertEquals(getIpAddressBuilder.render(OsFamily.WINDOWS), CharStreams.toString(Resources.newReaderSupplier(Resources
|
||||
.getResource("test_get_ip_address." + ShellToken.SH.to(OsFamily.WINDOWS)), Charsets.UTF_8)));
|
||||
}
|
||||
*/
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* 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.virtualbox.domain;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Andrea Turli
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class GetIPAddressFromMACTest {
|
||||
|
||||
private static final String macAddressWith00 = "0800271A9806";
|
||||
private static final String unixMacAddressWith00 = "08:00:27:1a:98:06";
|
||||
private static final String bsdMacAddressWith00 = "8:0:27:1a:98:6";
|
||||
private static final String macAddressWith0c = "0811271A9806";
|
||||
private static final String unixMacAddressWith0c = "08:11:27:1a:98:06";
|
||||
private static final String bsdMacAddressWith0c = "8:11:27:1a:98:6";
|
||||
|
||||
public void testGetIPAdressFromMacAddressUnix() {
|
||||
GetIPAddressFromMAC statement = new GetIPAddressFromMAC(macAddressWith00);
|
||||
assertEquals(statement.render(OsFamily.UNIX), "MAC="
|
||||
+ unixMacAddressWith00
|
||||
+ " && [[ `uname -s` = \"Darwin\" ]] && MAC=" + bsdMacAddressWith00
|
||||
+ "\n arp -an | grep $MAC\n");
|
||||
|
||||
statement = new GetIPAddressFromMAC(macAddressWith0c);
|
||||
assertEquals(statement.render(OsFamily.UNIX), "MAC="
|
||||
+ unixMacAddressWith0c
|
||||
+ " && [[ `uname -s` = \"Darwin\" ]] && MAC=" + bsdMacAddressWith0c
|
||||
+ "\n arp -an | grep $MAC\n");
|
||||
}
|
||||
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
package org.jclouds.virtualbox.domain;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
@ -63,11 +64,12 @@ public class VmSpecTest {
|
|||
}
|
||||
|
||||
private VmSpec.Builder defaultVm() {
|
||||
return VmSpec.builder()
|
||||
return VmSpec.builder()
|
||||
.id("MyVmId")
|
||||
.name("My VM")
|
||||
.osTypeId("Ubuntu")
|
||||
.memoryMB(1024)
|
||||
.cleanUpMode(CleanupMode.Full)
|
||||
.natNetworkAdapter(
|
||||
0,
|
||||
NatAdapter.builder().tcpRedirectRule("localhost", 2222, "", 22).build())
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.jclouds.virtualbox.domain.StorageController;
|
|||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.jclouds.virtualbox.util.PropertyUtils;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.ISession;
|
||||
import org.virtualbox_4_1.StorageBus;
|
||||
|
@ -92,8 +93,10 @@ public class CloneAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends Ba
|
|||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin")
|
||||
.attachISO(1, 1, workingDir + "/VBoxGuestAdditions_4.1.2.iso").build();
|
||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId(osTypeId)
|
||||
.controller(ideController)
|
||||
.forceOverwrite(true).build();
|
||||
.memoryMB(512)
|
||||
.cleanUpMode(CleanupMode.Full)
|
||||
.controller(ideController)
|
||||
.forceOverwrite(true).build();
|
||||
return new CreateAndInstallVm(manager, guestId, localHostContext, hostId, socketTester,
|
||||
"127.0.0.1", 8080, HEADLESS).apply(vmSpecification);
|
||||
} catch (IllegalStateException e) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
|||
@Test
|
||||
public void testCreateNewMachine() throws Exception {
|
||||
String vmName = "jclouds-test-create-1-node";
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).controller(ideController).cleanUpMode(mode)
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).controller(ideController).cleanUpMode(mode)
|
||||
.osTypeId("Debian").forceOverwrite(true).build();
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(launchSpecification);
|
||||
IMachine debianNode = new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
|
@ -70,7 +70,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsLiveTest extends B
|
|||
@Test
|
||||
public void testCreateNewMachineWithBadOsType() throws Exception {
|
||||
String vmName = "jclouds-test-create-2-node";
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).controller(ideController).cleanUpMode(mode)
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).memoryMB(512).controller(ideController).cleanUpMode(mode)
|
||||
.osTypeId("SomeWeirdUnknownOs").forceOverwrite(true).build();
|
||||
new UnregisterMachineIfExistsAndDeleteItsMedia(manager).apply(launchSpecification);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import static org.easymock.classextension.EasyMock.verify;
|
|||
import org.easymock.EasyMock;
|
||||
import org.jclouds.virtualbox.domain.VmSpec;
|
||||
import org.testng.annotations.Test;
|
||||
import org.virtualbox_4_1.CleanupMode;
|
||||
import org.virtualbox_4_1.IMachine;
|
||||
import org.virtualbox_4_1.IVirtualBox;
|
||||
import org.virtualbox_4_1.VBoxException;
|
||||
|
@ -49,7 +50,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
IVirtualBox vBox = createMock(IVirtualBox.class);
|
||||
String vmName = "jclouds-image-my-ubuntu-image";
|
||||
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).build();
|
||||
VmSpec launchSpecification = VmSpec.builder().id(vmName).name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(CleanupMode.Full).build();
|
||||
|
||||
IMachine createdMachine = createMock(IMachine.class);
|
||||
|
||||
|
@ -90,7 +91,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
replay(manager, vBox);
|
||||
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).build();
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).cleanUpMode(CleanupMode.Full).build();
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
}
|
||||
|
||||
|
@ -111,7 +112,7 @@ public class CreateAndRegisterMachineFromIsoIfNotAlreadyExistsTest {
|
|||
|
||||
replay(manager, vBox);
|
||||
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").memoryMB(1024).build();
|
||||
VmSpec launchSpecification = VmSpec.builder().id("").name(vmName).osTypeId("").cleanUpMode(CleanupMode.Full).memoryMB(1024).build();
|
||||
new CreateAndRegisterMachineFromIsoIfNotAlreadyExists(manager).apply(launchSpecification);
|
||||
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class UnregisterMachineIfExistsAndDeleteItsMediaTest {
|
|||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).memoryMB(512).osTypeId(osTypeId)
|
||||
.controller(ideController)
|
||||
.forceOverwrite(true)
|
||||
.cleanUpMode(CleanupMode.DetachAllReturnHardDisksOnly)
|
||||
.cleanUpMode(CleanupMode.Full)
|
||||
.natNetworkAdapter(0, NatAdapter.builder().tcpRedirectRule("127.0.0.1", 2222, "", 22).build()).build();
|
||||
|
||||
expect(manager.getVBox()).andReturn(vBox).anyTimes();
|
||||
|
|
|
@ -71,6 +71,7 @@ public class SshAvailableLiveTest extends BaseVirtualBoxClientLiveTest {
|
|||
.attachISO(0, 0, workingDir + "/ubuntu-11.04-server-i386.iso")
|
||||
.attachHardDisk(0, 1, workingDir + "/testadmin.vdi", "testadmin").build();
|
||||
VmSpec vmSpecification = VmSpec.builder().id(vmId).name(vmName).osTypeId("")
|
||||
.memoryMB(512)
|
||||
.controller(ideController)
|
||||
.forceOverwrite(true).build();
|
||||
|
||||
|
|
Loading…
Reference in New Issue