Issue 112: completed get vDC and also added a separate parser for Terremark

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2242 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-09 19:06:50 +00:00
parent 7602f1b7b8
commit eb101f6263
16 changed files with 700 additions and 12 deletions

View File

@ -23,8 +23,11 @@
*/ */
package org.jclouds.vcloud; package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import static org.jclouds.vcloud.VCloudMediaType.*;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -32,8 +35,10 @@ import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VDCHandler;
/** /**
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
@ -53,8 +58,9 @@ public interface VCloudClient {
@GET @GET
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@XMLResponseParser(VDCHandler.class)
@Consumes(VDC_XML) @Consumes(VDC_XML)
String getDefaultVDC(); VDC getDefaultVDC();
// //
// @GET // @GET

View File

@ -0,0 +1,44 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.domain;
import java.util.Map;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.VDC
@ImplementedBy(VDCImpl.class)
public interface VDC extends Link {
Map<String, Link> getAvailableNetworks();
Map<String, Link> getResourceEntities();
}

View File

@ -0,0 +1,93 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.VDC;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class VDCImpl extends LinkImpl implements VDC {
private final Map<String, Link> availableNetworks;
private final Map<String, Link> resourceEntities;
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public VDCImpl(String name, String type, URI location, Map<String, Link> resourceEntities,
Map<String, Link> availableNetworks) {
super(name, type, location);
this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks");
this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities");
}
public Map<String, Link> getAvailableNetworks() {
return availableNetworks;
}
public Map<String, Link> getResourceEntities() {
return resourceEntities;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode());
result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VDCImpl other = (VDCImpl) obj;
if (availableNetworks == null) {
if (other.availableNetworks != null)
return false;
} else if (!availableNetworks.equals(other.availableNetworks))
return false;
if (resourceEntities == null) {
if (other.resourceEntities != null)
return false;
} else if (!resourceEntities.equals(other.resourceEntities))
return false;
return true;
}
}

View File

@ -37,7 +37,7 @@ import javax.inject.Qualifier;
* *
*/ */
@Retention(value = RetentionPolicy.RUNTIME) @Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) @Target(value = {ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier @Qualifier
public @interface VDC { public @interface VDC {

View File

@ -0,0 +1,52 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.terremark.domain;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVDCImpl;
import org.jclouds.vcloud.terremark.endpoints.InternetServices;
import org.jclouds.vcloud.terremark.endpoints.PublicIPs;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@org.jclouds.vcloud.endpoints.VDC
@ImplementedBy(TerremarkVDCImpl.class)
public interface TerremarkVDC extends VDC {
@Catalog
Link getCatalog();
@PublicIPs
Link getPublicIps();
@InternetServices
Link getInternetServices();
// TODO getDescription() // what is the type?
}

View File

@ -0,0 +1,108 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.terremark.domain.internal;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
import java.util.Map;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
/**
* Locations of resources in Terremark vDC
*
* @author Adrian Cole
*
*/
public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC {
private final Link catalog;
private final Link publicIps;
private final Link internetServices;
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public TerremarkVDCImpl(String name, String type, URI location,
Map<String, Link> availableNetworks, Map<String, Link> resourceEntities, Link catalog,
Link publicIps, Link internetServices) {
super(name, type, location, availableNetworks, resourceEntities);
this.catalog = checkNotNull(catalog, "catalog");
this.publicIps = checkNotNull(publicIps, "publicIps");
this.internetServices = checkNotNull(internetServices, "internetServices");
}
public Link getCatalog() {
return catalog;
}
public Link getPublicIps() {
return publicIps;
}
public Link getInternetServices() {
return internetServices;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode());
result = prime * result + ((internetServices == null) ? 0 : internetServices.hashCode());
result = prime * result + ((publicIps == null) ? 0 : publicIps.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
TerremarkVDCImpl other = (TerremarkVDCImpl) obj;
if (catalog == null) {
if (other.catalog != null)
return false;
} else if (!catalog.equals(other.catalog))
return false;
if (internetServices == null) {
if (other.internetServices != null)
return false;
} else if (!internetServices.equals(other.internetServices))
return false;
if (publicIps == null) {
if (other.publicIps != null)
return false;
} else if (!publicIps.equals(other.publicIps))
return false;
return true;
}
}

View File

@ -0,0 +1,44 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.terremark.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to Terremark Internet Services.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface InternetServices {
}

View File

@ -0,0 +1,44 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.terremark.endpoints;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Related to Terremark Public IPs.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface PublicIPs {
}

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.terremark.xml;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.util.Utils;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVDCImpl;
import org.jclouds.vcloud.xml.VDCHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class TerremarkVDCHandler extends VDCHandler {
private Link catalog;
private Link publicIps;
private Link internetServices;
public TerremarkVDC getResult() {
VDC vDC = super.getResult();
return new TerremarkVDCImpl(vDC.getName(), vDC.getType(), vDC.getLocation(), vDC
.getResourceEntities(), vDC.getAvailableNetworks(), catalog, publicIps,
internetServices);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
super.startElement(uri, localName, qName, attributes);
if (qName.equals("Link")) {
String name = attributes.getValue(attributes.getIndex("name"));
if (name.equals("Internet Services")) {
internetServices = Utils.newLink(attributes);
} else if (name.equals("Public IPs")) {
publicIps = Utils.newLink(attributes);
} else {
String type = attributes.getValue(attributes.getIndex("type"));
if (type.equals(VCloudMediaType.CATALOG_XML)) {
catalog = Utils.newLink(attributes);
}
}
}
}
}

View File

@ -0,0 +1,68 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.xml;
import static org.jclouds.rest.util.Utils.putLink;
import java.net.URI;
import java.util.Map;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.Maps;
/**
* @author Adrian Cole
*/
public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
private Link vDC;
private Map<String, Link> resourceEntities = Maps.newHashMap();
private Map<String, Link> availableNetworks = Maps.newHashMap();
public VDC getResult() {
return new VDCImpl(vDC.getName(), vDC.getType(), vDC.getLocation(), resourceEntities,
availableNetworks);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("Vdc")) {
vDC = new LinkImpl(attributes.getValue(attributes.getIndex("name")), attributes
.getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes
.getIndex("href"))));
} else if (qName.equals("Network")) {
putLink(availableNetworks, attributes);
} else if (qName.equals("ResourceEntity")) {
putLink(resourceEntities, attributes);
}
}
}

View File

@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -58,9 +59,13 @@ public class VCloudClientLiveTest {
@Test @Test
public void testDefaultVDC() throws Exception { public void testDefaultVDC() throws Exception {
String response = connection.getDefaultVDC(); VDC response = connection.getDefaultVDC();
assertNotNull(response); assertNotNull(response);
System.err.println(response); assertNotNull(response.getName());
assertNotNull(response.getLocation());
assertEquals(response.getType(), "application/vnd.vmware.vcloud.vdc+xml");
assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks());
} }
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })

View File

@ -32,7 +32,6 @@ import java.net.URI;
import javax.inject.Provider; import javax.inject.Provider;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory; import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest; import org.jclouds.rest.RestClientTest;
@ -42,6 +41,7 @@ import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VDCHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -79,8 +79,8 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
assertEntityEquals(httpMethod, null); assertEntityEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ReturnStringIf200.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, null); assertSaxResponseParserClassEquals(method, VDCHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(httpMethod);

View File

@ -0,0 +1,80 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.terremark.xml;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
* Tests behavior of {@code TerremarkVDCHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.TerremarkVDCHandlerTest")
public class TerremarkVDCHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
super.setUpInjector();
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/vdc.xml");
TerremarkVDC result = (TerremarkVDC) factory.create(
injector.getInstance(TerremarkVDCHandler.class)).parse(is);
assertEquals(result.getName(), "Miami Environment 1");
assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vdc+xml");
assertEquals(result.getResourceEntities(), ImmutableMap.<String, Link> of());
assertEquals(result.getAvailableNetworks(), ImmutableMap.of("10.114.34.128/26", new LinkImpl(
"10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml",
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
assertEquals(result.getCatalog(), new LinkImpl("Miami Environment 1", CATALOG_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")));
assertEquals(result.getPublicIps(), new LinkImpl("Public IPs", "application/xml", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps")));
assertEquals(
result.getInternetServices(),
new LinkImpl(
"Internet Services",
"application/xml",
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices")));
}
}

View File

@ -0,0 +1,67 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.vcloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
* Tests behavior of {@code VDCHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VDCHandlerTest")
public class VDCHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
super.setUpInjector();
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/vdc.xml");
VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
assertEquals(result.getName(), "Miami Environment 1");
assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vdc+xml");
assertEquals(result.getResourceEntities(), ImmutableMap.<String, Link> of());
assertEquals(result.getAvailableNetworks(), ImmutableMap.of("10.114.34.128/26", new LinkImpl(
"10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml",
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708"))));
}
}

View File

@ -0,0 +1,10 @@
<Vdc href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog" type="application/vnd.vmware.vcloud.catalog+xml" name="Miami Environment 1"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps" type="application/xml" name="Public IPs"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices" type="application/xml" name="Internet Services"/>
<Description/>
<ResourceEntities/>
<AvailableNetworks>
<Network href="https://services.vcloudexpress.terremark.com/api/v0.8/network/1708" type="application/vnd.vmware.vcloud.network+xml" name="10.114.34.128/26"/>
</AvailableNetworks>
</Vdc>

View File

@ -1,8 +1,4 @@
<Vdc href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Vdc href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog" type="application/vnd.vmware.vcloud.catalog+xml" name="Miami Environment 1"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps" type="application/xml" name="Public IPs"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/internetServices" type="application/xml" name="Internet Services"/>
<Description/>
<ResourceEntities/> <ResourceEntities/>
<AvailableNetworks> <AvailableNetworks>
<Network href="https://services.vcloudexpress.terremark.com/api/v0.8/network/1708" type="application/vnd.vmware.vcloud.network+xml" name="10.114.34.128/26"/> <Network href="https://services.vcloudexpress.terremark.com/api/v0.8/network/1708" type="application/vnd.vmware.vcloud.network+xml" name="10.114.34.128/26"/>