PageRenderTime 38ms CodeModel.GetById 27ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/VAppTemplateHandlerTest.java

https://github.com/vkris/jclouds
Java | 151 lines | 114 code | 13 blank | 24 comment | 0 complexity | 6dae6b76e320c87f8c34e58de2164597 MD5 | raw file
  1/**
  2 * Licensed to jclouds, Inc. (jclouds) under one or more
  3 * contributor license agreements.  See the NOTICE file
  4 * distributed with this work for additional information
  5 * regarding copyright ownership.  jclouds licenses this file
  6 * to you under the Apache License, Version 2.0 (the
  7 * "License"); you may not use this file except in compliance
  8 * with the License.  You may obtain a copy of the License at
  9 *
 10 *   http://www.apache.org/licenses/LICENSE-2.0
 11 *
 12 * Unless required by applicable law or agreed to in writing,
 13 * software distributed under the License is distributed on an
 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15 * KIND, either express or implied.  See the License for the
 16 * specific language governing permissions and limitations
 17 * under the License.
 18 */
 19package org.jclouds.vcloud.xml;
 20
 21import static org.testng.Assert.assertEquals;
 22
 23import java.io.InputStream;
 24import java.net.URI;
 25
 26import org.jclouds.date.DateService;
 27import org.jclouds.http.functions.ParseSax;
 28import org.jclouds.http.functions.ParseSax.Factory;
 29import org.jclouds.http.functions.config.SaxParserModule;
 30import org.jclouds.ovf.Network;
 31import org.jclouds.vcloud.VCloudMediaType;
 32import org.jclouds.vcloud.domain.GuestCustomizationSection;
 33import org.jclouds.vcloud.domain.Status;
 34import org.jclouds.vcloud.domain.TaskStatus;
 35import org.jclouds.vcloud.domain.VAppTemplate;
 36import org.jclouds.vcloud.domain.Vm;
 37import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
 38import org.jclouds.vcloud.domain.internal.TaskImpl;
 39import org.jclouds.vcloud.domain.ovf.VCloudNetworkSection;
 40import org.testng.annotations.Test;
 41
 42import com.google.common.collect.ImmutableList;
 43import com.google.common.collect.ImmutableSet;
 44import com.google.common.collect.Iterables;
 45import com.google.inject.Guice;
 46import com.google.inject.Injector;
 47
 48/**
 49 * Tests behavior of {@code VAppTemplateHandler}
 50 * 
 51 * @author Adrian Cole
 52 */
 53@Test(groups = "unit")
 54public class VAppTemplateHandlerTest {
 55
 56   public void testUbuntuTemplate() {
 57      InputStream is = getClass().getResourceAsStream("/vAppTemplate.xml");
 58      Injector injector = Guice.createInjector(new SaxParserModule());
 59      Factory factory = injector.getInstance(ParseSax.Factory.class);
 60      VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(is);
 61      assertEquals(result.getName(), "Ubuntu Template");
 62      assertEquals(result.getHref(), URI
 63               .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921"));
 64      assertEquals(result.getType(), "application/vnd.vmware.vcloud.vAppTemplate+xml");
 65      assertEquals(result.getStatus(), Status.OFF);
 66      assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudMediaType.VDC_XML, URI
 67               .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1014839439")));
 68      assertEquals(result.getDescription(), null);
 69      assertEquals(result.getTasks(), ImmutableList.of());
 70      assertEquals(result.getVAppScopedLocalId(), null);
 71      assert result.isOvfDescriptorUploaded();
 72      Vm vm = Iterables.getOnlyElement(result.getChildren());
 73      assertEquals(vm.getName(), "Ubuntu1004");
 74      assertEquals(vm.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vm-172837194"));
 75      // NOTE this is vAppTemplate not VM!
 76      assertEquals(vm.getType(), "application/vnd.vmware.vcloud.vAppTemplate+xml");
 77      assertEquals(vm.getStatus(), null);
 78      assertEquals(vm.getParent(), new ReferenceTypeImpl(null, VCloudMediaType.VAPPTEMPLATE_XML, URI
 79               .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921")));
 80      assertEquals(vm.getDescription(), null);
 81      assertEquals(vm.getTasks(), ImmutableList.of());
 82      assertEquals(vm.getVAppScopedLocalId(), "02_ubuntu_template");
 83
 84      GuestCustomizationSection guestC = vm.getGuestCustomizationSection();
 85
 86      assertEquals(guestC.getType(), VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML);
 87      assertEquals(
 88               guestC.getHref(),
 89               URI
 90                        .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vm-172837194/guestCustomizationSection/"));
 91      assertEquals(guestC.getInfo(), "Specifies Guest OS Customization Settings");
 92      assertEquals(guestC.isEnabled(), new Boolean(true));
 93      assertEquals(guestC.shouldChangeSid(), new Boolean(false));
 94      assertEquals(guestC.getVirtualMachineId(), "172837194");
 95      assertEquals(guestC.isJoinDomainEnabled(), new Boolean(false));
 96      assertEquals(guestC.useOrgSettings(), new Boolean(false));
 97      assertEquals(guestC.getDomainName(), null);
 98      assertEquals(guestC.getDomainUserName(), null);
 99      assertEquals(guestC.getDomainUserPassword(), null);
100      assertEquals(guestC.isAdminPasswordEnabled(), new Boolean(true));
101      assertEquals(guestC.isAdminPasswordAuto(), new Boolean(true));
102      assertEquals(guestC.getAdminPassword(), "%3eD%gmF");
103      assertEquals(guestC.isResetPasswordRequired(), new Boolean(false));
104      assertEquals(
105               guestC.getCustomizationScript(),
106               "#!/bin/bash if [ \"$1\" = \"postcustomization\" ]; then echo \"post customization\" touch /root/.postcustomization sleep 30 #regenerate keys /bin/rm /etc/ssh/ssh_host_* /usr/sbin/dpkg-reconfigure openssh-server echo \"completed\" fi");
107      assertEquals(guestC.getComputerName(), "Ubuntu1004");
108      assertEquals(guestC.getEdit(), null);
109
110      VCloudNetworkSection network = result.getNetworkSection();
111      assertEquals(
112               network.getHref(),
113               URI
114                        .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-1201908921/networkSection/"));
115      assertEquals(network.getType(), VCloudMediaType.NETWORKSECTION_XML);
116      assertEquals(network.getInfo(), "The list of logical networks");
117      assertEquals(network.getNetworks(), ImmutableSet.of(new Network("vAppNet-vApp Internal", null)));
118
119   }
120
121   public void testCopyingTemplate() {
122      InputStream is = getClass().getResourceAsStream("/vAppTemplate-copying.xml");
123      Injector injector = Guice.createInjector(new SaxParserModule());
124      Factory factory = injector.getInstance(ParseSax.Factory.class);
125      DateService dateService = injector.getInstance(DateService.class);
126
127      VAppTemplate result = factory.create(injector.getInstance(VAppTemplateHandler.class)).parse(is);
128      assertEquals(result.getName(), "Ubuntu10.04_v2");
129      assertEquals(result.getHref(), URI
130               .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-699683881"));
131      assertEquals(result.getType(), "application/vnd.vmware.vcloud.vAppTemplate+xml");
132      assertEquals(result.getStatus(), Status.UNRESOLVED);
133      assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudMediaType.VDC_XML, URI
134               .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/105186609")));
135      assertEquals(result.getDescription(), null);
136      assertEquals(result.getTasks(), ImmutableList.of(new TaskImpl(URI
137               .create("https://vcenterprise.bluelock.com/api/v1.0/task/q62gxhi32xgd9yrqvr"),
138               "Copying Virtual Application Template Ubuntu10.04_v2(699683881)", TaskStatus.RUNNING, dateService
139                        .iso8601DateParse("2010-09-17T23:20:46.039-04:00"), dateService
140                        .iso8601DateParse("9999-12-31T23:59:59.999-05:00"), dateService
141                        .iso8601DateParse("2010-12-16T23:20:46.039-05:00"), new ReferenceTypeImpl("Ubuntu10.04_v2",
142                        "application/vnd.vmware.vcloud.vAppTemplate+xml",
143                        URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/vappTemplate-699683881")),
144               null)));
145      assertEquals(result.getVAppScopedLocalId(), null);
146      assert result.isOvfDescriptorUploaded();
147      assertEquals(result.getChildren(), ImmutableList.of());
148      assertEquals(result.getNetworkSection(), null);
149
150   }
151}