From 24d3bd5d04d2e958c3e2854512c5758403f9e133 Mon Sep 17 00:00:00 2001 From: Jason King Date: Thu, 15 Dec 2011 23:10:05 +0000 Subject: [PATCH] Issue 695: Implemented createVirtualMachineFromTemplate --- ...ndCreateVirtualMachineKeyToXmlPayload.java | 167 ++++++++++++++++++ .../domain/network/LinuxCustomization.java | 2 +- .../domain/network/NetworkSettings.java | 2 +- ...Request.java => CreateVirtualMachine.java} | 65 ++++--- .../features/VirtualMachineAsyncClient.java | 12 ++ .../features/VirtualMachineClient.java | 13 +- ...eateVirtualMachineKeyToXmlPayloadTest.java | 119 +++++++++++++ .../VirtualMachineClientLiveTest.java | 52 +++++- 8 files changed, 405 insertions(+), 27 deletions(-) create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayload.java rename sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/{CreateOsTemplateVirtualMachineRequest.java => CreateVirtualMachine.java} (74%) create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayloadTest.java diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayload.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayload.java new file mode 100644 index 0000000000..bcfb04ab89 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayload.java @@ -0,0 +1,167 @@ +/** + * 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.tmrk.enterprisecloud.binders; + +import com.jamesmurty.utils.XMLBuilder; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.Binder; +import org.jclouds.rest.binders.BindToStringPayload; +import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource; +import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest; +import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization; +import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting; +import org.jclouds.tmrk.enterprisecloud.domain.network.WindowsCustomization; +import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import java.util.Properties; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * For use with {@see VirtualMachineClient#createVirtualMachineFromTemplate} + * @author Jason King + */ +@Singleton +public class BindCreateVirtualMachineKeyToXmlPayload implements Binder { + + private final BindToStringPayload stringBinder; + + @Inject + BindCreateVirtualMachineKeyToXmlPayload(BindToStringPayload stringBinder) { + this.stringBinder = stringBinder; + } + + @Override + public R bindToRequest(R request, Object key) { + checkArgument(checkNotNull(key, "key") instanceof CreateVirtualMachine, "this binder is only valid for CreateOsTemplateVirtualMachineRequest instances!"); + checkNotNull(request, "request"); + CreateVirtualMachine vmData = CreateVirtualMachine.class.cast(key); + + String payload = createXMLPayload(vmData); + return stringBinder.bindToRequest(request, payload); + } + + private String createXMLPayload(CreateVirtualMachine vmData) { + try { + Properties outputProperties = new Properties(); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + + final String name = vmData.getName(); + final String processorCount = Integer.toString(vmData.getProcessorCount()); + final String memoryUnit = vmData.getMemory().getUnit(); + final int memoryValue = ((Double)(vmData.getMemory().getValue())).intValue(); + final Set tags = vmData.getTags(); + final String description = vmData.getDescription(); + final LayoutRequest layout = vmData.getLayout(); + final String poweredOn = Boolean.toString(vmData.isPoweredOn()); + final AnonymousResource template = vmData.getTemplate(); + + XMLBuilder builder = XMLBuilder.create("CreateVirtualMachine").a("name",name) + .e("ProcessorCount").t(processorCount).up() + .e("Memory").e("Unit").t(memoryUnit).up() + .e("Value").t(Integer.toString(memoryValue)).up().up(); + builder = layout(builder,layout); + builder.e("Description").t(description).up(); + builder = tags(builder,tags); + builder = linuxCustomization(builder, vmData); + builder = windowsCustomization(builder, vmData); + builder.e("PoweredOn").t(poweredOn).up() + .e("Template").a("href",template.getHref().toString()) + .a("type", template.getType()).up(); + + return builder.asString(outputProperties); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } catch (TransformerException t) { + throw new RuntimeException(t); + } + } + + private XMLBuilder layout(XMLBuilder in, LayoutRequest layout) { + in = in.e("Layout"); + if(layout.getGroup()!=null) { + in = in.e("Group").a("href",layout.getGroup().getHref().toString()) + .a("type",layout.getGroup().getType()).up(); + } else if (layout.getRow()!=null) { + checkNotNull(layout.getNewGroup(),"newGroup"); + in = in.e("Row").a("href",layout.getRow().getHref().toString()) + .a("type", layout.getRow().getType()).up() + .e("NewGroup").t(layout.getNewGroup()).up(); + } else { + checkNotNull(layout.getNewRow(),"newRow"); + checkNotNull(layout.getNewGroup(), "newGroup"); + in = in.e("NewRow").t(layout.getNewRow()).up() + .e("NewGroup").t(layout.getNewGroup()).up(); + } + return in.up(); + } + + private XMLBuilder tags(XMLBuilder in, Set tags ) { + checkNotNull(tags,"tags"); + in = in.e("Tags"); + for(String tag: tags) { + in = in.e("Tag").t(tag).up(); + } + return in.up(); + } + + private XMLBuilder linuxCustomization(XMLBuilder in, CreateVirtualMachine vmData) { + LinuxCustomization linuxCustomization = vmData.getLinuxCustomization(); + if(linuxCustomization==null) return in; + if(vmData.getWindowsCustomization()!=null) throw new IllegalStateException("Cannot have linux and windows customizations"); + + in = in.e("LinuxCustomization") + .e("NetworkSettings") + .e("NetworkAdapterSettings"); + for(NetworkAdapterSetting setting:linuxCustomization.getNetworkSettings().getNetworkAdapterSettings().getNetworkAdapterSettings()) { + in = networkAdapterSetting(in,setting); + } + + //TODO DNS Settings + String href = linuxCustomization.getSshKey().getHref().toString(); + String type = linuxCustomization.getSshKey().getType(); + return in.up().up().e("SshKey").a("href",href).a("type",type).up().up(); + } + + private XMLBuilder networkAdapterSetting(XMLBuilder builder, NetworkAdapterSetting setting) { + String href = setting.getNetwork().getHref().toString(); + String name = setting.getNetwork().getName(); + String type = setting.getNetwork().getType(); + builder.e("NetworkAdapter") + .e("Network").a("href",href).a("name",name).a("type",type).up() + .e("IpAddress").t(setting.getIpAddress()).up(); + return builder; + } + + private XMLBuilder windowsCustomization(XMLBuilder builder, CreateVirtualMachine vmData) { + WindowsCustomization windowsCustomization = vmData.getWindowsCustomization(); + if(windowsCustomization==null) return builder; + if(vmData.getLinuxCustomization()!=null) throw new IllegalStateException("Cannot have linux and windows customizations"); + + //TODO: Not implemented yet + throw new UnsupportedOperationException("windowsCustomization has not been implemented yet"); + //return builder; + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/LinuxCustomization.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/LinuxCustomization.java index 0d4761201d..74ff4f82b2 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/LinuxCustomization.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/LinuxCustomization.java @@ -40,7 +40,7 @@ public class LinuxCustomization { public static class Builder { - private NetworkSettings networkSettings; + private NetworkSettings networkSettings = NetworkSettings.builder().build(); private AnonymousResource sshKey; /** diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkSettings.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkSettings.java index 58bceae348..a1c943c447 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkSettings.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/NetworkSettings.java @@ -39,7 +39,7 @@ public class NetworkSettings { public static class Builder { - private NetworkAdapterSettings networkAdapterSettings; + private NetworkAdapterSettings networkAdapterSettings = NetworkAdapterSettings.builder().build(); private DnsSettings dnsSettings; /** diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/CreateOsTemplateVirtualMachineRequest.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/CreateVirtualMachine.java similarity index 74% rename from sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/CreateOsTemplateVirtualMachineRequest.java rename to sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/CreateVirtualMachine.java index 6371874b3e..6d4d65a1d5 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/CreateOsTemplateVirtualMachineRequest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/CreateVirtualMachine.java @@ -19,6 +19,7 @@ package org.jclouds.tmrk.enterprisecloud.domain.vm; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource; import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest; import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization; @@ -29,12 +30,14 @@ import javax.xml.bind.annotation.XmlRootElement; import java.util.Set; /** - * + * * @author Jason King - * */ @XmlRootElement(name = "CreateVirtualMachineRequest") -public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineRequest { +public class CreateVirtualMachine extends CreateVirtualMachineRequest { + // Note that this class collapses both + // CreateOsTemplateVirtualMachineRequestType and CreateVirtualMachineType + // into the same class as the separate classes are not needed. @SuppressWarnings("unchecked") public static Builder builder() { @@ -49,14 +52,15 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR return new Builder().fromCreateOsTemplateVirtualMachineRequest(this); } - public static class Builder extends CreateVirtualMachineRequest.Builder { + public static class Builder extends CreateVirtualMachineRequest.Builder { private LinuxCustomization linuxCustomization; private WindowsCustomization windowsCustomization; private boolean poweredOn; + private AnonymousResource template; /** - * @see org.jclouds.tmrk.enterprisecloud.domain.vm.CreateOsTemplateVirtualMachineRequest#getLinuxCustomization + * @see CreateVirtualMachine#getLinuxCustomization */ public Builder linuxCustomization(LinuxCustomization linuxCustomization) { this.linuxCustomization = linuxCustomization; @@ -64,7 +68,7 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR } /** - * @see org.jclouds.tmrk.enterprisecloud.domain.vm.CreateOsTemplateVirtualMachineRequest#getWindowsCustomization + * @see CreateVirtualMachine#getWindowsCustomization */ public Builder windowsCustomization(WindowsCustomization windowsCustomization) { this.windowsCustomization = windowsCustomization; @@ -73,13 +77,21 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR /** - * @see org.jclouds.tmrk.enterprisecloud.domain.vm.CreateOsTemplateVirtualMachineRequest#isPoweredOn + * @see CreateVirtualMachine#isPoweredOn */ public Builder poweredOn(boolean poweredOn) { this.poweredOn = poweredOn; return this; } + /** + * @see CreateVirtualMachine#getTemplate + */ + public Builder template(AnonymousResource template) { + this.template = template; + return this; + } + /** * @see CreateVirtualMachineRequest#getName() */ @@ -127,17 +139,18 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR } @Override - public CreateOsTemplateVirtualMachineRequest build() { - return new CreateOsTemplateVirtualMachineRequest(name, processorCount,memory, + public CreateVirtualMachine build() { + return new CreateVirtualMachine(name, processorCount,memory, description,layout,tags, - linuxCustomization,windowsCustomization,poweredOn); + linuxCustomization,windowsCustomization,poweredOn, template); } - public Builder fromCreateOsTemplateVirtualMachineRequest(CreateOsTemplateVirtualMachineRequest in) { + public Builder fromCreateOsTemplateVirtualMachineRequest(CreateVirtualMachine in) { return fromCreateVirtualMachineRequest(in) .linuxCustomization(in.getLinuxCustomization()) .windowsCustomization(in.getWindowsCustomization()) - .poweredOn(in.isPoweredOn()); + .poweredOn(in.isPoweredOn()) + .template(in.getTemplate()); } } @@ -149,18 +162,23 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR @XmlElement(name = "PoweredOn", required = false) private boolean poweredOn; - - - private CreateOsTemplateVirtualMachineRequest(String name, int processorCount, ResourceCapacity memory, - @Nullable String description,@Nullable LayoutRequest layout,@Nullable Set tags, - @Nullable LinuxCustomization linuxCustomization, @Nullable WindowsCustomization windowsCustomization, boolean poweredOn) { + + @XmlElement(name = "Template", required = false) + private AnonymousResource template; + + + private CreateVirtualMachine(String name, int processorCount, ResourceCapacity memory, + @Nullable String description, @Nullable LayoutRequest layout, @Nullable Set tags, + @Nullable LinuxCustomization linuxCustomization, @Nullable WindowsCustomization windowsCustomization, + boolean poweredOn, @Nullable AnonymousResource template) { super(name,processorCount,memory,description,layout,tags); this.linuxCustomization = linuxCustomization; this.windowsCustomization = windowsCustomization; this.poweredOn = poweredOn; + this.template = template; } - protected CreateOsTemplateVirtualMachineRequest() { + protected CreateVirtualMachine() { //For JAXB } @@ -176,16 +194,22 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR return poweredOn; } + public AnonymousResource getTemplate() { + return template; + } + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - CreateOsTemplateVirtualMachineRequest that = (CreateOsTemplateVirtualMachineRequest) o; + CreateVirtualMachine that = (CreateVirtualMachine) o; if (poweredOn != that.poweredOn) return false; if (linuxCustomization != null ? !linuxCustomization.equals(that.linuxCustomization) : that.linuxCustomization != null) return false; + if (template != null ? !template.equals(that.template) : that.template != null) + return false; if (windowsCustomization != null ? !windowsCustomization.equals(that.windowsCustomization) : that.windowsCustomization != null) return false; @@ -197,11 +221,12 @@ public class CreateOsTemplateVirtualMachineRequest extends CreateVirtualMachineR int result = linuxCustomization != null ? linuxCustomization.hashCode() : 0; result = 31 * result + (windowsCustomization != null ? windowsCustomization.hashCode() : 0); result = 31 * result + (poweredOn ? 1 : 0); + result = 31 * result + (template != null ? template.hashCode() : 0); return result; } @Override public String string() { - return super.string()+", linuxCustomization="+linuxCustomization+", windowsCustomization="+windowsCustomization+", poweredOn="+poweredOn; + return super.string()+", linuxCustomization="+linuxCustomization+", windowsCustomization="+windowsCustomization+", poweredOn="+poweredOn+", template="+template; } } \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java index 75b3b36d65..971235d854 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineAsyncClient.java @@ -22,15 +22,18 @@ import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.*; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; +import org.jclouds.tmrk.enterprisecloud.binders.BindCreateVirtualMachineKeyToXmlPayload; import org.jclouds.tmrk.enterprisecloud.domain.Task; import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration; import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses; +import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine; import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine; import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions; import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines; import org.jclouds.tmrk.enterprisecloud.functions.ReturnEmptyVirtualMachinesOnNotFoundOr404; import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; import java.net.URI; /** @@ -92,6 +95,15 @@ public interface VirtualMachineAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getHardwareConfiguration(@EndpointParam URI uri); + /** + * @see VirtualMachineClient#createVirtualMachineFromTemplate + */ + @POST + @Consumes("application/vnd.tmrk.cloud.virtualMachine") + @Produces(MediaType.APPLICATION_XML) + @JAXBResponseParser + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture createVirtualMachineFromTemplate(@EndpointParam URI uri, @BinderParam(BindCreateVirtualMachineKeyToXmlPayload.class)CreateVirtualMachine request); /** * @see VirtualMachineClient#powerOn */ diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java index ff9935efaa..67fe2b3e84 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/VirtualMachineClient.java @@ -22,9 +22,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.tmrk.enterprisecloud.domain.Task; import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration; import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses; -import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine; -import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineConfigurationOptions; -import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines; +import org.jclouds.tmrk.enterprisecloud.domain.vm.*; import java.net.URI; import java.util.concurrent.TimeUnit; @@ -81,6 +79,15 @@ public interface VirtualMachineClient { */ HardwareConfiguration getHardwareConfiguration(URI uri); + /** + * The Create Virtual Machines from Template call creates a new virtual machine from a template in the compute pool. + * If successful, the call returns information regarding the virtual machine that was created. + * @param uri the uri to create a virtual machine based upon the compute pool + * e.g. /cloudapi/ecloud/virtualMachines/computePools/{compute pool identifier}/action/createVirtualMachine + * @return the created virtual machine + */ + VirtualMachine createVirtualMachineFromTemplate(URI uri,CreateVirtualMachine request); + /** * The Action Virtual Machines Power On call powers on a specified virtual machine. * If successful, the call returns the task that powered on the virtual machine. diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayloadTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayloadTest.java new file mode 100644 index 0000000000..796f1360a6 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateVirtualMachineKeyToXmlPayloadTest.java @@ -0,0 +1,119 @@ +/** + * 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.tmrk.enterprisecloud.binders; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.http.HttpRequest; +import org.jclouds.tmrk.enterprisecloud.domain.NamedResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.AnonymousResource; +import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity; +import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest; +import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization; +import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting; +import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSettings; +import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkSettings; +import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.net.URI; + +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@code BindCreateVirtualMachineKeyToXmlPayload} + * @author Jason King + */ +@Test(groups = "unit", testName = "BindCreateVirtualMachineKeyToXmlPayloadTest") +public class BindCreateVirtualMachineKeyToXmlPayloadTest { + Injector injector = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + } + }); + + public void testPayloadXmlContent() throws IOException { + String expected = + "" + + "2" + + "MB1024" + + "" + + "This is my first VM" + + "Web" + + "" + + "" + + "" + + "" + + "" + + "10.146.204.68" + + "" + + "" + + "" + + "" + + "" + + "false" + + "