PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/regularfry/jclouds
Java | 137 lines | 104 code | 10 blank | 23 comment | 1 complexity | f8000e40aa2732b2c96362df65960cb8 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.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
 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.vcloud.domain.Catalog;
 31import org.jclouds.vcloud.domain.ReferenceType;
 32import org.jclouds.vcloud.domain.Task;
 33import org.jclouds.vcloud.domain.internal.CatalogImpl;
 34import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
 35import org.testng.annotations.Test;
 36
 37import com.google.common.collect.ImmutableList;
 38import com.google.common.collect.ImmutableMap;
 39import com.google.inject.Guice;
 40import com.google.inject.Injector;
 41
 42/**
 43 * Tests behavior of {@code CatalogHandler}
 44 * 
 45 * @author Adrian Cole
 46 */
 47@Test(groups = "unit")
 48public class CatalogHandlerTest {
 49
 50   private Injector injector;
 51
 52   private Factory factory;
 53
 54   public void testVCloud1_0() {
 55      InputStream is = getClass().getResourceAsStream("/catalog-blank.xml");
 56      injector = Guice.createInjector(new SaxParserModule());
 57      factory = injector.getInstance(ParseSax.Factory.class);
 58      Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(is);
 59      assertEquals(result, new CatalogImpl("Jclouds-private", "application/vnd.vmware.vcloud.catalog+xml", URI
 60               .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/921222081"), new ReferenceTypeImpl(null,
 61               "application/vnd.vmware.vcloud.org+xml", URI
 62                        .create("https://vcenterprise.bluelock.com/api/v1.0/org/9566014")), null, ImmutableMap
 63               .<String, ReferenceType> of(), ImmutableList.<Task> of(), false, false));
 64   }
 65
 66   public void testTerremark() {
 67      InputStream is = getClass().getResourceAsStream("/catalog.xml");
 68      injector = Guice.createInjector(new SaxParserModule());
 69      factory = injector.getInstance(ParseSax.Factory.class);
 70      Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(is);
 71      assertEquals(result.getName(), "Miami Environment 1");
 72      assert result.getDescription() == null;
 73
 74      assertEquals(result.getHref(), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"));
 75      assertEquals(result.get("CentOS 5.3 (32-bit)"), new ReferenceTypeImpl("CentOS 5.3 (32-bit)", CATALOGITEM_XML, URI
 76               .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/5")));
 77      assertEquals(result.get("CentOS 5.3 (64-bit)"), new ReferenceTypeImpl("CentOS 5.3 (64-bit)", CATALOGITEM_XML, URI
 78               .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/6")));
 79      assertEquals(result.get("RHEL 5.3 (32-bit)"), new ReferenceTypeImpl("RHEL 5.3 (32-bit)", CATALOGITEM_XML, URI
 80               .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/7")));
 81      assertEquals(result.get("RHEL 5.3 (64-bit)"), new ReferenceTypeImpl("RHEL 5.3 (64-bit)", CATALOGITEM_XML, URI
 82               .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/8")));
 83      assertEquals(result.get("Ubuntu JeOS 9.04 (32-bit)"), new ReferenceTypeImpl("Ubuntu JeOS 9.04 (32-bit)",
 84               CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/11")));
 85      assertEquals(result.get("Ubuntu JeOS 9.04 (64-bit)"), new ReferenceTypeImpl("Ubuntu JeOS 9.04 (64-bit)",
 86               CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/12")));
 87      assertEquals(result.get("Ubuntu Server 9.04 (32-bit)"), new ReferenceTypeImpl("Ubuntu Server 9.04 (32-bit)",
 88               CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/9")));
 89      assertEquals(result.get("Ubuntu Server 9.04 (64-bit)"), new ReferenceTypeImpl("Ubuntu Server 9.04 (64-bit)",
 90               CATALOGITEM_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/10")));
 91      assertEquals(result.get("Windows 2003 Enterprise R2 (32-bit)"), new ReferenceTypeImpl(
 92               "Windows 2003 Enterprise R2 (32-bit)", CATALOGITEM_XML, URI
 93                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/1")));
 94      assertEquals(result.get("Windows 2003 Enterprise R2 (64-bit)"), new ReferenceTypeImpl(
 95               "Windows 2003 Enterprise R2 (64-bit)", CATALOGITEM_XML, URI
 96                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/2")));
 97      assertEquals(result.get("Windows 2003 Standard R2 (32-bit)"), new ReferenceTypeImpl(
 98               "Windows 2003 Standard R2 (32-bit)", CATALOGITEM_XML, URI
 99                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/3")));
100      assertEquals(result.get("Windows 2003 Standard R2 (64-bit)"), new ReferenceTypeImpl(
101               "Windows 2003 Standard R2 (64-bit)", CATALOGITEM_XML, URI
102                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/4")));
103      assertEquals(result.get("Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)"), new ReferenceTypeImpl(
104               "Windows 2003 Standard R2 w.SQL 2008 Web (64-bit)", CATALOGITEM_XML, URI
105                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/23")));
106      assertEquals(result.get("Windows Server 2008 Enterprise (32-bit)"), new ReferenceTypeImpl(
107               "Windows Server 2008 Enterprise (32-bit)", CATALOGITEM_XML, URI
108                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/13")));
109      assertEquals(result.get("Windows Server 2008 Enterprise (64-bit)"), new ReferenceTypeImpl(
110               "Windows Server 2008 Enterprise (64-bit)", CATALOGITEM_XML, URI
111                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/15")));
112      assertEquals(result.get("Windows Server 2008 Enterprise R2 (64-bit)"), new ReferenceTypeImpl(
113               "Windows Server 2008 Enterprise R2 (64-bit)", CATALOGITEM_XML, URI
114                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/16")));
115      assertEquals(result.get("Windows Server 2008 Standard (32-bit)"), new ReferenceTypeImpl(
116               "Windows Server 2008 Standard (32-bit)", CATALOGITEM_XML, URI
117                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/17")));
118      assertEquals(result.get("Windows Server 2008 Standard (64-bit)"), new ReferenceTypeImpl(
119               "Windows Server 2008 Standard (64-bit)", CATALOGITEM_XML, URI
120                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/18")));
121      assertEquals(result.get("Windows Server 2008 Standard R2 (64-bit)"), new ReferenceTypeImpl(
122               "Windows Server 2008 Standard R2 (64-bit)", CATALOGITEM_XML, URI
123                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/19")));
124      assertEquals(result.get("Windows Server 2008 Standard w.SQL 2008 Web (64-bit)"), new ReferenceTypeImpl(
125               "Windows Server 2008 Standard w.SQL 2008 Web (64-bit)", CATALOGITEM_XML, URI
126                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/14")));
127      assertEquals(result.get("Windows Web Server 2008 (32-bit)"), new ReferenceTypeImpl(
128               "Windows Web Server 2008 (32-bit)", CATALOGITEM_XML, URI
129                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/20")));
130      assertEquals(result.get("Windows Web Server 2008 (64-bit)"), new ReferenceTypeImpl(
131               "Windows Web Server 2008 (64-bit)", CATALOGITEM_XML, URI
132                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/21")));
133      assertEquals(result.get("Windows Web Server 2008 R2 (64-bit)"), new ReferenceTypeImpl(
134               "Windows Web Server 2008 R2 (64-bit)", CATALOGITEM_XML, URI
135                        .create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22")));
136   }
137}