PageRenderTime 352ms CodeModel.GetById 71ms app.highlight 49ms RepoModel.GetById 1ms app.codeStats 0ms

/providers/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/xml/VDCHandlerTest.java

https://github.com/adiantum/jclouds
Java | 194 lines | 158 code | 13 blank | 23 comment | 0 complexity | 2c5ab16b78e95312a3f8fc3d1807a380 MD5 | raw file
  1/**
  2 *
  3 * Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
  4 *
  5 * ====================================================================
  6 * Licensed under the Apache License, Version 2.0 (the "License");
  7 * you may not use this file except in compliance with the License.
  8 * 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, software
 13 * distributed under the License is distributed on an "AS IS" BASIS,
 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 * ====================================================================
 18 */
 19
 20package org.jclouds.savvis.vpdc.xml;
 21
 22import static org.testng.Assert.assertEquals;
 23
 24import java.io.InputStream;
 25import java.net.URI;
 26
 27import org.jclouds.http.functions.ParseSax;
 28import org.jclouds.http.functions.ParseSax.Factory;
 29import org.jclouds.http.functions.config.SaxParserModule;
 30import org.jclouds.savvis.vpdc.domain.Resource;
 31import org.jclouds.savvis.vpdc.domain.ResourceImpl;
 32import org.jclouds.savvis.vpdc.domain.VDC;
 33import org.jclouds.savvis.vpdc.domain.VDC.Status;
 34import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
 35import org.testng.annotations.Test;
 36
 37import com.google.common.collect.ImmutableSet;
 38import com.google.inject.Guice;
 39import com.google.inject.Injector;
 40
 41/**
 42 * Tests behavior of {@code VDCHandler}
 43 * 
 44 * @author Adrian Cole
 45 */
 46@Test(groups = "unit")
 47public class VDCHandlerTest {
 48
 49   public void test() {
 50      InputStream is = getClass().getResourceAsStream("/vdc.xml");
 51      Injector injector = Guice.createInjector(new SaxParserModule());
 52      Factory factory = injector.getInstance(ParseSax.Factory.class);
 53      VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
 54      assertEquals(result.getName(), "demo_vpdcname");
 55      assertEquals(result.getDescription(),
 56               "ServiceProfileName = Balanced; ServiceLocation = North America; Email = jim@company.com;");
 57      assertEquals(result.getStatus(), Status.DEPLOYED);
 58      assertEquals(
 59               result.getResourceEntities(),
 60               ImmutableSet
 61                        .<Resource> of(
 62                                 new ResourceImpl(
 63                                          "1001",
 64                                          "DemoHost-1",
 65                                          VCloudMediaType.VAPP_XML,
 66                                          URI
 67                                                   .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1001")),
 68                                 new ResourceImpl(
 69                                          "1002",
 70                                          "DemoHost-2",
 71                                          VCloudMediaType.VAPP_XML,
 72                                          URI
 73                                                   .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1002")),
 74                                 new ResourceImpl(
 75                                          "1003",
 76                                          "DemoHost-3",
 77                                          VCloudMediaType.VAPP_XML,
 78                                          URI
 79                                                   .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vApp/1003")),
 80                                 new ResourceImpl(
 81                                          "1234",
 82                                          "CustomerTemplateName",
 83                                          VCloudMediaType.VAPPTEMPLATE_XML,
 84                                          URI
 85                                                   .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/vAppTemplate/1234")),
 86                                 new ResourceImpl(
 87                                          "FirewallService",
 88                                          "firewall",
 89                                          "api.symphonyvpdc.savvis.net+xml",
 90                                          URI
 91                                                   .create("https://api.sandbox.symphonyvpdc.savvis.net/rest/api/v0.8/org/100000.0/vdc/2736/FirewallService"))));
 92      assertEquals(result.getAvailableNetworks(), ImmutableSet.of());
 93   }
 94
 95   public void test1net() {
 96      InputStream is = getClass().getResourceAsStream("/vdc-1net.xml");
 97      Injector injector = Guice.createInjector(new SaxParserModule());
 98      Factory factory = injector.getInstance(ParseSax.Factory.class);
 99      VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
100      assertEquals(result.getName(), "demo6");
101      assertEquals(result.getDescription(),
102               "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;");
103      assertEquals(result.getStatus(), Status.DEPLOYED);
104      assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1",
105               VCloudMediaType.VAPP_XML, URI
106                        .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1001")),
107               new ResourceImpl("1002", "Host2", VCloudMediaType.VAPP_XML, URI
108                        .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1002")),
109               new ResourceImpl("1003", "Host3", VCloudMediaType.VAPP_XML, URI
110                        .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1003")),
111               new ResourceImpl("1004", "Host4", VCloudMediaType.VAPP_XML, URI
112                        .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/vApp/1004"))));
113      assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
114               "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
115               URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1619/network/VM-Tier01"))
116               .build()));
117
118   }
119
120   public void testFailed() {
121      InputStream is = getClass().getResourceAsStream("/vdc-failed.xml");
122      Injector injector = Guice.createInjector(new SaxParserModule());
123      Factory factory = injector.getInstance(ParseSax.Factory.class);
124      VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
125      assertEquals(result.getName(), "Demo7");
126      assertEquals(result.getDescription(),
127               "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = red@chair.com;");
128      assertEquals(result.getStatus(), Status.FAILED);
129      assertEquals(result.getResourceEntities(), ImmutableSet.of(new ResourceImpl("1001", "Host1",
130               VCloudMediaType.VAPP_XML, URI
131                        .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/vApp/1001"))));
132      assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
133               "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
134               URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/1641/network/VM-Tier01"))
135               .build()));
136
137   }
138
139   public void testSaved() {
140      InputStream is = getClass().getResourceAsStream("/vdc-saved.xml");
141      Injector injector = Guice.createInjector(new SaxParserModule());
142      Factory factory = injector.getInstance(ParseSax.Factory.class);
143      VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
144      assertEquals(result.getName(), "CloudBurst1");
145      assertEquals(result.getDescription(),
146               "ServiceProfileName = Essential; ServiceLocation = US_WEST; Email = me@my.com;");
147      assertEquals(result.getStatus(), Status.SAVED);
148      assertEquals(
149               result.getResourceEntities(),
150               ImmutableSet
151                        .of(
152                                 ResourceImpl
153                                          .builder()
154                                          .name("templateHost")
155                                          .type("application/vnd.vmware.vcloud.vApp+xml")
156                                          .id("1001")
157                                          .href(
158                                                   URI
159                                                            .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1001"))
160                                          .build(),
161                                 ResourceImpl
162                                          .builder()
163                                          .name("host-c501")
164                                          .type("application/vnd.vmware.vcloud.vApp+xml")
165                                          .id("1037")
166                                          .href(
167                                                   URI
168                                                            .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1037"))
169                                          .build(),
170                                 ResourceImpl
171                                          .builder()
172                                          .name("host-c501")
173                                          .type("application/vnd.vmware.vcloud.vApp+xml")
174                                          .id("1038")
175                                          .href(
176                                                   URI
177                                                            .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1038"))
178                                          .build(),
179                                 ResourceImpl
180                                          .builder()
181                                          .name("host-c601")
182                                          .type("application/vnd.vmware.vcloud.vApp+xml")
183                                          .id("1039")
184                                          .href(
185                                                   URI
186                                                            .create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/vApp/1039"))
187                                          .build()));
188      assertEquals(result.getAvailableNetworks(), ImmutableSet.of(ResourceImpl.builder().id("VM-Tier01").name(
189               "VM Tier01").type(VCloudMediaType.NETWORK_XML).href(
190               URI.create("https://api.symphonyVPDC.savvis.net/rest/api/v0.8/org/606677.0/vdc/2555/network/VM-Tier01"))
191               .build()));
192
193   }
194}