decrufted metadataapi

This commit is contained in:
Adrian Cole 2012-08-24 00:19:49 -07:00
parent 03326849e0
commit 7db0519d0b
30 changed files with 511 additions and 657 deletions

View File

@ -0,0 +1,49 @@
/**
* 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.vcloud.director.v1_5.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.xml.XMLParser;
/**
* Changes a Map to the crufty {@link Metadata type}
*/
@Singleton
public class BindMapAsMetadata extends BindToXMLPayload {
@Inject
public BindMapAsMetadata(final XMLParser xmlParser) {
super(xmlParser);
}
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
return super.bindToRequest(request, Metadata.toMetadata(Map.class.cast(checkNotNull(input, "input"))));
}
}

View File

@ -0,0 +1,66 @@
/**
* 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.vcloud.director.v1_5.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.binders.BindToXMLPayload;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.Resource;
import org.jclouds.xml.XMLParser;
/**
* Changes a String to the crufty {@link MetadataValue type}
*/
@Singleton
public class BindStringAsMetadataValue extends BindToXMLPayload {
@XmlRootElement(name = "MetadataValue")
public static class MetadataValue extends Resource {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_VALUE;
public MetadataValue() {
}
public MetadataValue(String value) {
super(Resource.builder());
this.value = value;
}
@XmlElement(name = "Value", required = true)
private String value;
}
@Inject
public BindStringAsMetadataValue(final XMLParser xmlParser) {
super(xmlParser);
}
@Override
public <R extends HttpRequest> R bindToRequest(final R request, final Object input) {
return super.bindToRequest(request, new MetadataValue(checkNotNull(input, "input").toString()));
}
}

View File

@ -1,4 +1,4 @@
/** /*
* Licensed to jclouds, Inc. (jclouds) under one or more * Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file * contributor license agreements. See the NOTICE file
* distributed with this work for additional information * distributed with this work for additional information
@ -16,21 +16,20 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.jclouds.carrenza.vcloud.director; @XmlSchema(namespace = VCLOUD_1_5_NS,
elementFormDefault = XmlNsForm.QUALIFIED,
import org.jclouds.vcloud.director.v1_5.HttpClientLiveTest; xmlns = {
import org.testng.annotations.Test; @XmlNs(prefix = "", namespaceURI = VCLOUD_1_5_NS)
/**
* {@inheritDoc}
*
* @author danikov
* @author grkvlt
*/
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "CarrenzaVCloudDirectorHttpClientLiveTest")
public class CarrenzaVCloudDirectorHttpClientLiveTest extends HttpClientLiveTest {
public CarrenzaVCloudDirectorHttpClientLiveTest() {
provider = "carrenza-vcloud-director";
} }
} )
@XmlAccessorType(XmlAccessType.FIELD)
package org.jclouds.vcloud.director.v1_5.binders;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants.VCLOUD_1_5_NS;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

View File

@ -49,6 +49,16 @@ import com.google.common.collect.Sets;
@XmlRootElement(name = "Metadata") @XmlRootElement(name = "Metadata")
public class Metadata extends Resource implements Map<String, String> { public class Metadata extends Resource implements Map<String, String> {
public static Metadata toMetadata(Map<String, String> input) {
if (input instanceof Metadata)
return Metadata.class.cast(input);
Builder<?> builder = builder();
for (Map.Entry<String, String> entry : input.entrySet()) {
builder.entry(MetadataEntry.builder().entry(entry.getKey(), entry.getValue()).build());
}
return builder.build();
}
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA; public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA;
public static Builder<?> builder() { public static Builder<?> builder() {

View File

@ -42,116 +42,3 @@ import com.google.common.collect.Sets;
* *
* @author grkvlt@apache.org * @author grkvlt@apache.org
*/ */
@XmlRootElement(name = "MetadataValue")
public class MetadataValue extends Resource {
public static final String MEDIA_TYPE = VCloudDirectorMediaType.METADATA_ENTRY;
public static Builder<?> builder() {
return new ConcreteBuilder();
}
@Override
public Builder<?> toBuilder() {
return builder().fromMetadataValue(this);
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
}
public static abstract class Builder<B extends Builder<B>> extends Resource.Builder<B> {
private String value;
/**
* @see MetadataValue#getValue
*/
public B value(String value) {
this.value = value;
return self();
}
@Override
public MetadataValue build() {
return new MetadataValue(this);
}
/**
* @see ResourceType#getHref()
*/
@Override
public B href(URI href) {
super.href(href);
return self();
}
/**
* @see ResourceType#getType()
*/
@Override
public B type(String type) {
super.type(type);
return self();
}
/**
* @see ResourceType#getLinks()
*/
@Override
public B links(Set<Link> links) {
super.links(Sets.newLinkedHashSet(checkNotNull(links, "links")));
return self();
}
/**
* @see ResourceType#getLinks()
*/
@Override
public B link(Link link) {
super.link(link);
return self();
}
public B fromMetadataValue(MetadataValue in) {
return fromResource(in).value(value);
}
}
protected MetadataValue() {
// For JAXB
}
protected MetadataValue(Builder<?> builder) {
super(builder);
this.value = checkNotNull(builder.value, "value");
}
@XmlElement(name = "Value", required = true)
private String value;
/**
* The value.
*/
public String getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
MetadataValue that = MetadataValue.class.cast(o);
return super.equals(that) && equal(this.value, that.value);
}
@Override
public int hashCode() {
return Objects.hashCode(super.hashCode(), value);
}
@Override
public ToStringHelper string() {
return super.string().add("value", value);
}
}

View File

@ -18,18 +18,18 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
/** /**
* Provides synchronous access to {@link Metadata}. * Provides synchronous access to {@link Metadata}.
* *
* @see MetadataAsyncApi * @see MetadataAsyncApi
* @author danikov * @author danikov, Adrian Cole
*/ */
public interface MetadataApi { public interface MetadataApi {
@ -47,7 +47,7 @@ public interface MetadataApi {
* *
* @return the metadata value, or null if not found * @return the metadata value, or null if not found
*/ */
MetadataValue getValue(String key); String get(String key);
} }
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
@ -56,27 +56,30 @@ public interface MetadataApi {
/** /**
* Merges the metadata for a media with the information provided. * Merges the metadata for a media with the information provided.
* *
* @return a task. This operation is asynchronous and the user should monitor the returned * @return a task. This operation is asynchronous and the user should
* task status in order to check when it is completed. * monitor the returned task status in order to check when it is
* completed.
*/ */
Task merge(Metadata metadata); Task putAll(Map<String, String> metadata);
/** /**
* Sets the metadata for the particular key for the media to the value provided. Note: this * Sets the metadata for the particular key for the media to the value
* will replace any existing metadata information * provided. Note: this will replace any existing metadata information
* *
* @return a task. This operation is asynchronous and the user should monitor the returned * @return a task. This operation is asynchronous and the user should
* task status in order to check when it is completed. * monitor the returned task status in order to check when it is
* completed.
*/ */
Task putEntry(String key, MetadataValue metadataValue); Task put(String key, String value);
/** /**
* Deletes a metadata entry. * Deletes a metadata entry.
* *
* @return a task. This operation is asynchronous and the user should monitor the returned * @return a task. This operation is asynchronous and the user should
* task status in order to check when it is completed. * monitor the returned task status in order to check when it is
* completed.
*/ */
Task removeEntry(String key); Task remove(String key);
} }
} }

View File

@ -18,7 +18,7 @@
*/ */
package org.jclouds.vcloud.director.v1_5.features; package org.jclouds.vcloud.director.v1_5.features;
import java.net.URI; import java.util.Map;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
@ -33,29 +33,29 @@ import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
import org.jclouds.rest.annotations.JAXBResponseParser; import org.jclouds.rest.annotations.JAXBResponseParser;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.binders.BindToXMLPayload; import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.binders.BindMapAsMetadata;
import org.jclouds.vcloud.director.v1_5.binders.BindStringAsMetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest; import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationAndCookieToRequest;
import org.jclouds.vcloud.director.v1_5.functions.RegexValueParser;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
/** /**
* @see MetadataApi * @see MetadataApi
* @author danikov * @author Adrian Cole, danikov
*/ */
// TODO: take out the endpoint params and supply them in the Delegate calls.
public interface MetadataAsyncApi { public interface MetadataAsyncApi {
@RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class) @RequestFilters(AddVCloudAuthorizationAndCookieToRequest.class)
public static interface Readable extends MetadataAsyncApi { public static interface Readable extends MetadataAsyncApi {
/** /**
* @see MetadataApi.Readable#get(URI) * @see MetadataApi.Readable#get()
*/ */
@GET @GET
@Path("/metadata") @Path("/metadata")
@ -65,14 +65,14 @@ public interface MetadataAsyncApi {
ListenableFuture<Metadata> get(); ListenableFuture<Metadata> get();
/** /**
* @see MetadataApi.Readable#getValue(String) * @see MetadataApi.Readable#get(String)
*/ */
@GET @GET
@Path("/metadata/{key}") @Path("/metadata/{key}")
@Consumes @Consumes
@JAXBResponseParser @ResponseParser(RegexValueParser.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<MetadataValue> getValue(@PathParam("key") String key); ListenableFuture<String> get(@PathParam("key") String key);
} }
@ -80,35 +80,34 @@ public interface MetadataAsyncApi {
public static interface Writeable extends Readable { public static interface Writeable extends Readable {
/** /**
* @see MetadataApi.Writable#merge(Metadata) * @see MetadataApi.Writable#putAll
*/ */
@POST @POST
@Path("/metadata") @Path("/metadata")
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA) @Produces(VCloudDirectorMediaType.METADATA)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> merge(@BinderParam(BindToXMLPayload.class) Metadata metadata); ListenableFuture<Task> putAll(@BinderParam(BindMapAsMetadata.class) Map<String, String> metadata);
/** /**
* @see MetadataApi.Writeable#putEntry(String, MetadataEntry) * @see MetadataApi.Writeable#put
*/ */
@PUT @PUT
@Path("/metadata/{key}") @Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@Produces(VCloudDirectorMediaType.METADATA_VALUE) @Produces(VCloudDirectorMediaType.METADATA_VALUE)
@JAXBResponseParser @JAXBResponseParser
// TODO: this is rediculous. get rid of the MetadataValue type, as it is only a string! ListenableFuture<Task> put(@PathParam("key") String key,
ListenableFuture<Task> putEntry(@PathParam("key") String key, @BinderParam(BindStringAsMetadataValue.class) String metadataValue);
@BinderParam(BindToXMLPayload.class) MetadataValue metadataValue);
/** /**
* @see MetadataApi.Writable#removeEntry(String) * @see MetadataApi.Writable#remove
*/ */
@DELETE @DELETE
@Path("/metadata/{key}") @Path("/metadata/{key}")
@Consumes(VCloudDirectorMediaType.TASK) @Consumes(VCloudDirectorMediaType.TASK)
@JAXBResponseParser @JAXBResponseParser
ListenableFuture<Task> removeEntry(@PathParam("key") String key); ListenableFuture<Task> remove(@PathParam("key") String key);
} }
} }

View File

@ -0,0 +1,58 @@
/**
* 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.vcloud.director.v1_5.functions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.inject.Inject;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ReturnStringIf2xx;
import com.google.common.base.Function;
import com.google.inject.Singleton;
/**
*
* @author Adrian Cole
*/
@Singleton
public class RegexValueParser implements Function<HttpResponse, String> {
Pattern pattern = Pattern.compile("<Value>([^<]+)</Value>");
private final ReturnStringIf2xx returnStringIf200;
@Inject
RegexValueParser(ReturnStringIf2xx returnStringIf200) {
this.returnStringIf200 = returnStringIf200;
}
@Override
public String apply(HttpResponse response) {
String content = returnStringIf200.apply(response);
if (content != null) {
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
return matcher.group(1);
}
}
return null;
}
}

View File

@ -1,107 +0,0 @@
/*
* 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.vcloud.director.v1_5;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpResponse;
import org.jclouds.rest.HttpClient;
import org.jclouds.util.Strings2;
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Tests live behavior of operations that use {@link HttpClient}.
*
* @author danikov
*/
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "HttpClientLiveTest")
public class HttpClientLiveTest extends BaseVCloudDirectorApiLiveTest {
private JAXBParser parser = new JAXBParser("true");
private SessionWithToken sessionWithToken;
@Override
protected void setupRequiredApis() {
}
@Test(description = "POST /login")
public void testPostLogin() throws IOException {
testLoginWithMethod("POST");
}
@Test(description = "GET /login")
public void testGetLogin() throws IOException {
testLoginWithMethod("GET");
}
private void testLoginWithMethod(final String method) throws IOException {
String user = identity.substring(0, identity.lastIndexOf('@'));
String org = identity.substring(identity.lastIndexOf('@') + 1);
String password = credential;
String authHeader = "Basic " + CryptoStreams.base64(String.format("%s@%s:%s", checkNotNull(user), checkNotNull(org), checkNotNull(password)).getBytes("UTF-8"));
HttpResponse response = context.getUtils().getHttpClient().invoke(HttpRequest.builder()
.method(method)
.endpoint(endpoint + "/login")
.addHeader("Authorization", authHeader)
.addHeader("Accept", "*/*").build());
sessionWithToken = SessionWithToken.builder().session(session).token(response.getFirstHeaderOrNull("x-vcloud-authorization")).build();
assertEquals(sessionWithToken.getSession().getUser(), user);
assertEquals(sessionWithToken.getSession().get(), org);
assertTrue(sessionWithToken.getSession().getLinks().size() > 0);
assertNotNull(sessionWithToken.getToken());
OrgList orgList = parser.fromXML(Strings2.toString(response.getPayload()), OrgList.class);
assertTrue(orgList.size() > 0, "must have orgs");
context.getApi().getOrgApi().get(Iterables.getLast(orgList).getHref());
}
@Test(description = "GET /schema/{schemaFileName}", dependsOnMethods = { "testPostLogin", "testGetLogin" })
public void testGetSchema() throws IOException {
String schemafileName = "master.xsd";
HttpResponse response = context.getUtils().getHttpClient().invoke(HttpRequest.builder()
.method("GET")
.endpoint(endpoint + "/v1.5/schema/" + schemafileName)
.addHeader("x-vcloud-authorization", sessionWithToken.getToken())
.addHeader("Accept", "*/*").build());
String schema = Strings2.toString(response.getPayload());
// TODO: asserting something about the schema
}
}

View File

@ -0,0 +1,57 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
*(Link.builder().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(Link.builder().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.director.v1_5.binders;
import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/**
* Tests behavior of {@code BindMapAsMetadata}.
*
*/
@Test(groups = "unit", testName = "BindMapAsMetadataTest")
public class BindMapAsMetadataTest {
XMLParser xml = new JAXBParser("true");
@Test
public void testBindMap() {
BindMapAsMetadata binder = new BindMapAsMetadata(xml);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
request = binder.bindToRequest(request, ImmutableMap.of("foo", "bar"));
assertEquals(request.getPayload().getRawContent(),
XMLParser.DEFAULT_XML_HEADER + "\n"+
"<Metadata xmlns=\"http://www.vmware.com/vcloud/v1.5\">" + "\n"+
" <MetadataEntry>" + "\n" +
" <Key>foo</Key>" + "\n" +
" <Value>bar</Value>" + "\n" +
" </MetadataEntry>" + "\n" +
"</Metadata>" + "\n");
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
}
}

View File

@ -0,0 +1,52 @@
/*
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
*(Link.builder().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(Link.builder().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.director.v1_5.binders;
import static org.testng.Assert.assertEquals;
import javax.ws.rs.core.MediaType;
import org.jclouds.http.HttpRequest;
import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code BindStringAsMetadataValue}.
*
*/
@Test(groups = "unit", testName = "BindStringAsMetadataValueTest")
public class BindStringAsMetadataValueTest {
XMLParser xml = new JAXBParser("true");
@Test
public void testBindMap() {
BindStringAsMetadataValue binder = new BindStringAsMetadataValue(xml);
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
request = binder.bindToRequest(request, "foo");
assertEquals(request.getPayload().getRawContent(),
XMLParser.DEFAULT_XML_HEADER + "\n"+
"<MetadataValue xmlns=\"http://www.vmware.com/vcloud/v1.5\">" + "\n"+
" <Value>foo</Value>" + "\n" +
"</MetadataValue>" + "\n");
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.APPLICATION_XML);
}
}

View File

@ -141,7 +141,7 @@ public class Checks {
} }
// Check parent type // Check parent type
checkResourceType(entity); checkResource(entity);
} }
/** /**
@ -173,20 +173,20 @@ public class Checks {
/** /**
* Assumes the validTypes to be vcloud-specific types. * Assumes the validTypes to be vcloud-specific types.
* *
* @see #checkResourceType(ResourceType, Collection) * @see #checkResource(Resource, Collection)
*/ */
public static void checkResourceType(Resource resource) { public static void checkResource(Resource resource) {
checkResourceType(resource, VCloudDirectorMediaType.ALL); checkResource(resource, VCloudDirectorMediaType.ALL);
} }
/** /**
* @see #checkResourceType(ResourceType, Collection) * @see #checkResource(Resource, Collection)
*/ */
public static void checkResourceType(Resource resource, String type) { public static void checkResource(Resource resource, String type) {
checkResourceType(resource, ImmutableSet.of(type)); checkResource(resource, ImmutableSet.of(type));
} }
public static void checkResourceType(Resource resource, Collection<String> validTypes) { public static void checkResource(Resource resource, Collection<String> validTypes) {
// Check optional fields // Check optional fields
URI href = resource.getHref(); URI href = resource.getHref();
if (href != null) checkHref(href); if (href != null) checkHref(href);
@ -294,7 +294,7 @@ public class Checks {
} }
// Check parent type // Check parent type
checkResourceType(metadata); checkResource(metadata);
} }
public static void checkMetadataEntry(MetadataEntry metadataEntry) { public static void checkMetadataEntry(MetadataEntry metadataEntry) {
@ -303,15 +303,7 @@ public class Checks {
assertNotNull(metadataEntry.getValue(), String.format(NOT_NULL_OBJ_FIELD_FMT, "Value", "MetadataEntry")); assertNotNull(metadataEntry.getValue(), String.format(NOT_NULL_OBJ_FIELD_FMT, "Value", "MetadataEntry"));
// Check parent type // Check parent type
checkResourceType(metadataEntry); checkResource(metadataEntry);
}
public static void checkMetadataValue(MetadataValue metadataValue) {
// Check required elements and attributes
assertNotNull(metadataValue.getValue(), String.format(NOT_NULL_OBJ_FIELD_FMT, "Value", "MetadataValue"));
// Check parent type
checkResourceType(metadataValue);
} }
public static void checkProgress(Integer progress) { public static void checkProgress(Integer progress) {
@ -339,7 +331,7 @@ public class Checks {
public static void checkAdminOrg(AdminOrg org) { public static void checkAdminOrg(AdminOrg org) {
// required // required
assertNotNull(org.getSettings(), String.format(NOT_NULL_OBJ_FIELD_FMT, "settings", "AdminOrg")); assertNotNull(org.getSettings(), String.format(NOT_NULL_OBJ_FIELD_FMT, "settings", "AdminOrg"));
checkResourceType(org, VCloudDirectorMediaType.ADMIN_ORG); checkResource(org, VCloudDirectorMediaType.ADMIN_ORG);
// optional // optional
for (Reference user : org.getUsers()) { for (Reference user : org.getUsers()) {
@ -387,7 +379,7 @@ public class Checks {
} }
// Check parent type // Check parent type
checkResourceType(owner); checkResource(owner);
} }
public static void checkCatalogItem(CatalogItem catalogItem) { public static void checkCatalogItem(CatalogItem catalogItem) {
@ -573,29 +565,13 @@ public class Checks {
String.format(OBJ_FIELD_ATTRB_REQ, api, "MetadataEntry", entry.getValue(), "value")); String.format(OBJ_FIELD_ATTRB_REQ, api, "MetadataEntry", entry.getValue(), "value"));
// Check parent type // Check parent type
checkResourceType(entry); checkResource(entry);
} }
// Check parent type // Check parent type
checkResourceType(metadata); checkResource(metadata);
} }
public static void checkMetadataValueFor(String api, MetadataValue metadataValue) {
checkMetadataValueFor(api, metadataValue, "value");
}
public static void checkMetadataValueFor(String api, MetadataValue metadataValue, String expectedValue) {
// Check required fields
String value = metadataValue.getValue();
assertNotNull(value,
String.format(OBJ_FIELD_ATTRB_REQ, api, "MetadataEntry",
metadataValue.toString(), "value"));
assertEquals(value, expectedValue,
String.format(OBJ_FIELD_EQ, api, "metadataEntry.value", expectedValue, value));
// Check parent type
checkResourceType(metadataValue);
}
public static void checkMetadataKeyAbsentFor(String api, Metadata metadata, String key) { public static void checkMetadataKeyAbsentFor(String api, Metadata metadata, String key) {
Map<String,String> metadataMap = metadataToMap(metadata); Map<String,String> metadataMap = metadataToMap(metadata);
@ -628,7 +604,7 @@ public class Checks {
} }
// Check parent type // Check parent type
checkResourceType(question); checkResource(question);
} }
public static void checkVmQuestionAnswerChoice(VmQuestionAnswerChoice choice) { public static void checkVmQuestionAnswerChoice(VmQuestionAnswerChoice choice) {
@ -848,7 +824,7 @@ public class Checks {
} }
// parent type // parent type
checkResourceType(settings); checkResource(settings);
} }
public static void checkEmailSettings(OrgEmailSettings settings) { public static void checkEmailSettings(OrgEmailSettings settings) {
@ -864,7 +840,7 @@ public class Checks {
// NOTE alertEmailsTo cannot be checked // NOTE alertEmailsTo cannot be checked
// parent type // parent type
checkResourceType(settings); checkResource(settings);
} }
public static void checkEmailAddress(String email) { public static void checkEmailAddress(String email) {
@ -889,7 +865,7 @@ public class Checks {
} }
// parent type // parent type
checkResourceType(settings); checkResource(settings);
} }
public static void checkLdapSettings(OrgLdapSettings settings) { public static void checkLdapSettings(OrgLdapSettings settings) {
@ -905,7 +881,7 @@ public class Checks {
} }
// parent type // parent type
checkResourceType(settings); checkResource(settings);
} }
public static void checkCustomOrgLdapSettings(CustomOrgLdapSettings settings) { public static void checkCustomOrgLdapSettings(CustomOrgLdapSettings settings) {
@ -980,7 +956,7 @@ public class Checks {
String.format(OBJ_FIELD_GTE_0, "OrgPasswordPolicySettings", "accountLockoutIntervalMinutes", settings.getAccountLockoutIntervalMinutes())); String.format(OBJ_FIELD_GTE_0, "OrgPasswordPolicySettings", "accountLockoutIntervalMinutes", settings.getAccountLockoutIntervalMinutes()));
// parent type // parent type
checkResourceType(settings); checkResource(settings);
} }
public static void checkVAppLeaseSettings(OrgLeaseSettings settings) { public static void checkVAppLeaseSettings(OrgLeaseSettings settings) {
@ -996,7 +972,7 @@ public class Checks {
} }
// parent type // parent type
checkResourceType(settings); checkResource(settings);
} }
public static void checkVAppTemplateLeaseSettings(OrgVAppTemplateLeaseSettings settings) { public static void checkVAppTemplateLeaseSettings(OrgVAppTemplateLeaseSettings settings) {
@ -1008,7 +984,7 @@ public class Checks {
} }
// parent type // parent type
checkResourceType(settings); checkResource(settings);
} }
public static void checkUser(User user) { public static void checkUser(User user) {
@ -1087,7 +1063,7 @@ public class Checks {
} }
// Check parent type // Check parent type
checkResourceType(sections); checkResource(sections);
} }
public static void checkGuestCustomizationSection(GuestCustomizationSection section) { public static void checkGuestCustomizationSection(GuestCustomizationSection section) {
@ -1220,7 +1196,7 @@ public class Checks {
assertNotNull(val.getNetworkName(), String.format(NOT_NULL_OBJ_FIELD_FMT, "NetworkName", "VAppNetworkConfiguration")); assertNotNull(val.getNetworkName(), String.format(NOT_NULL_OBJ_FIELD_FMT, "NetworkName", "VAppNetworkConfiguration"));
checkNetworkConfiguration(val.getConfiguration()); checkNetworkConfiguration(val.getConfiguration());
checkResourceType(val); checkResource(val);
} }
public static void checkNetworkConnectionSection(NetworkConnectionSection val) { public static void checkNetworkConnectionSection(NetworkConnectionSection val) {
@ -1517,6 +1493,6 @@ public class Checks {
} }
// parent type // parent type
checkResourceType(container); checkResource(container);
} }
} }

View File

@ -37,12 +37,12 @@ import org.jclouds.vcloud.director.v1_5.domain.CatalogItem;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi; import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorApi;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HttpHeaders; import com.google.common.net.HttpHeaders;
@ -182,7 +182,7 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
@Test @Test
public void testGetCatalogMetadataEntryHref() { public void testGetCatalogMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse);
assertEquals(api.getCatalogApi().getMetadataApi(catalogHref).getValue("KEY"), metadataValue()); assertEquals(api.getCatalogApi().getMetadataApi(catalogHref).get("KEY"), "VALUE");
} }
static String item = "a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df"; static String item = "a36fdac9-b8c2-43e2-9a4c-2ffaf3ee13df";
@ -328,9 +328,7 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
@Test @Test
public void testMergeCatalogItemMetadataHref() { public void testMergeCatalogItemMetadataHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, mergeItemMetadata, mergeItemMetadataResponse); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, mergeItemMetadata, mergeItemMetadataResponse);
// TODO: horrendous way of representing Map<String,String> assertEquals(api.getCatalogApi().getItemMetadataApi(itemHref).putAll(ImmutableMap.of("KEY", "VALUE")), mergeMetadataTask());
Metadata metadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "VALUE").build()).build();
assertEquals(api.getCatalogApi().getItemMetadataApi(itemHref).merge(metadata), mergeMetadataTask());
} }
HttpRequest getItemMetadataValue = HttpRequest.builder() HttpRequest getItemMetadataValue = HttpRequest.builder()
@ -348,7 +346,7 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
@Test @Test
public void testGetCatalogItemMetadataEntryHref() { public void testGetCatalogItemMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItemMetadataValue, getItemMetadataValueResponse); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getItemMetadataValue, getItemMetadataValueResponse);
assertEquals(api.getCatalogApi().getMetadataApi(itemHref).getValue("KEY"), itemMetadataValue()); assertEquals(api.getCatalogApi().getMetadataApi(itemHref).get("KEY"), "VALUE");
} }
HttpRequest putItemMetadata = HttpRequest.builder() HttpRequest putItemMetadata = HttpRequest.builder()
@ -368,7 +366,7 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
@Test @Test
public void testSetCatalogItemMetadataEntryHref() { public void testSetCatalogItemMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, putItemMetadata, putItemMetadataResponse); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, putItemMetadata, putItemMetadataResponse);
assertEquals(api.getCatalogApi().getItemMetadataApi(itemHref).putEntry("KEY", MetadataValue.builder().value("KITTENS").build()), setMetadataValueTask()); assertEquals(api.getCatalogApi().getItemMetadataApi(itemHref).put("KEY", "KITTENS"), setMetadataValueTask());
} }
HttpRequest removeItemMetadataEntry = HttpRequest.builder() HttpRequest removeItemMetadataEntry = HttpRequest.builder()
@ -386,7 +384,7 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
@Test @Test
public void testRemoveCatalogItemMetadataEntryHref() { public void testRemoveCatalogItemMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, removeItemMetadataEntry, removeItemMetadataEntryResponse); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, removeItemMetadataEntry, removeItemMetadataEntryResponse);
assertEquals(api.getCatalogApi().getItemMetadataApi(itemHref).removeEntry("KEY"), removeEntryTask()); assertEquals(api.getCatalogApi().getItemMetadataApi(itemHref).remove("KEY"), removeTask());
} }
public static final Catalog catalog() { public static final Catalog catalog() {
@ -487,30 +485,6 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
.build(); .build();
} }
public static MetadataValue metadataValue() {
return MetadataValue.builder()
.href(URI.create(endpoint + "/catalog/" + catalog + "/metadata/KEY"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create(endpoint + "/catalog/" + catalog + "/metadata"))
.build())
.value("VALUE")
.build();
}
public static MetadataValue itemMetadataValue() {
return MetadataValue.builder()
.href(URI.create(endpoint + "/catalogItem/" + item + "/metadata/KEY"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create(endpoint + "/catalogItem/" + item + "/metadata"))
.build())
.value("VALUE")
.build();
}
public static CatalogItem catalogItem() { public static CatalogItem catalogItem() {
return CatalogItem.builder() return CatalogItem.builder()
.name("ubuntu10") .name("ubuntu10")
@ -607,7 +581,7 @@ public class CatalogApiExpectTest extends VCloudDirectorApiExpectTest {
.build(); .build();
} }
public static Task removeEntryTask() { public static Task removeTask() {
return Task.builder() return Task.builder()
.name("task") .name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")

View File

@ -24,7 +24,6 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.C
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkCatalogItem; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkCatalogItem;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkTask; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkTask;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals; import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.relEquals;
import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals; import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEquals;
@ -41,8 +40,6 @@ import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Media;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.Vdc; import org.jclouds.vcloud.director.v1_5.domain.Vdc;
@ -51,8 +48,7 @@ import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorApiLiveTest;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/** /**
* Tests live behavior of {@link CatalogApi}. * Tests live behavior of {@link CatalogApi}.
@ -184,25 +180,15 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /catalog/{id}/metadata/{key}") @Test(description = "GET /catalog/{id}/metadata/{key}")
public void testGetCatalogMetadataValue() { public void testGetCatalogMetadataValue() {
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build()) Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi(catalogUrn)
.build(); .putAll(ImmutableMap.of("KEY", "MARMALADE"));
Task mergeCatalogMetadata = adminCatalogApi.getMetadataApi(catalogUrn).merge(newMetadata);
assertTaskSucceedsLong(mergeCatalogMetadata); assertTaskSucceedsLong(mergeCatalogMetadata);
Metadata catalogMetadata = catalogApi.getMetadataApi(catalogUrn).get(); Metadata catalogMetadata = catalogApi.getMetadataApi(catalogUrn).get();
MetadataEntry existingMetadataEntry = Iterables.find(catalogMetadata.getMetadataEntries(),
new Predicate<MetadataEntry>() { String metadataValue = catalogApi.getMetadataApi(catalogUrn).get("KEY");
@Override assertEquals(metadataValue, catalogMetadata.get("KEY"), String.format(CORRECT_VALUE_OBJECT_FMT, "Value",
public boolean apply(MetadataEntry input) { "MetadataValue", catalogMetadata.get("KEY"), metadataValue));
return input.getKey().equals("KEY");
}
});
MetadataValue metadataValue = catalogApi.getMetadataApi(catalogUrn)
.getValue("KEY");
assertEquals(metadataValue.getValue(), existingMetadataEntry.getValue(), String.format(CORRECT_VALUE_OBJECT_FMT,
"Value", "MetadataValue", existingMetadataEntry.getValue(), metadataValue.getValue()));
checkMetadataValue(metadataValue);
} }
@Test(description = "GET /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem") @Test(description = "GET /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
@ -213,12 +199,10 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem") @Test(description = "POST /catalogItem/{id}/metadata", dependsOnMethods = "testAddCatalogItem")
public void testMergeCatalogItemMetadata() { public void testMergeCatalogItemMetadata() {
Metadata newMetadata = Metadata.builder().entry(MetadataEntry.builder().entry("KEY", "MARMALADE").build())
.entry(MetadataEntry.builder().entry("VEGIMITE", "VALUE").build()).build();
Metadata before = catalogApi.getItemMetadataApi(catalogItem.getId()).get(); Metadata before = catalogApi.getItemMetadataApi(catalogItem.getId()).get();
Task mergeCatalogItemMetadata = catalogApi.getItemMetadataApi(catalogItem.getId()).merge(newMetadata); Task mergeCatalogItemMetadata = catalogApi.getItemMetadataApi(catalogItem.getId()).putAll(
ImmutableMap.of("KEY", "MARMALADE", "VEGIMITE", "VALUE"));
checkTask(mergeCatalogItemMetadata); checkTask(mergeCatalogItemMetadata);
assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata), assertTrue(retryTaskSuccess.apply(mergeCatalogItemMetadata),
String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata")); String.format(TASK_COMPLETE_TIMELY, "mergeCatalogItemMetadata"));
@ -227,47 +211,40 @@ public class CatalogApiLiveTest extends BaseVCloudDirectorApiLiveTest {
assertTrue(mergedCatalogItemMetadata.getMetadataEntries().size() > before.getMetadataEntries().size(), assertTrue(mergedCatalogItemMetadata.getMetadataEntries().size() > before.getMetadataEntries().size(),
"Should have added at least one other MetadataEntry to the CatalogItem"); "Should have added at least one other MetadataEntry to the CatalogItem");
MetadataValue keyMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("KEY"); String keyMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).get("KEY");
assertEquals(keyMetadataValue.getValue(), "MARMALADE", assertEquals(keyMetadataValue, "MARMALADE", "The Value of the MetadataValue for KEY should have changed");
"The Value of the MetadataValue for KEY should have changed");
checkMetadataValue(keyMetadataValue);
MetadataValue newKeyMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("VEGIMITE"); String newKeyMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).get("VEGIMITE");
assertEquals(newKeyMetadataValue.getValue(), "VALUE", assertEquals(newKeyMetadataValue, "VALUE", "The Value of the MetadataValue for NEW_KEY should have been set");
"The Value of the MetadataValue for NEW_KEY should have been set");
checkMetadataValue(newKeyMetadataValue);
} }
@Test(description = "GET /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testSetCatalogItemMetadataValue") @Test(description = "GET /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testSetCatalogItemMetadataValue")
public void testGetCatalogItemMetadataValue() { public void testGetCatalogItemMetadataValue() {
MetadataValue metadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("KEY"); String metadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).get("KEY");
checkMetadataValue(metadataValue); assertNotNull(metadataValue);
} }
@Test(description = "PUT /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testMergeCatalogItemMetadata") @Test(description = "PUT /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testMergeCatalogItemMetadata")
public void testSetCatalogItemMetadataValue() { public void testSetCatalogItemMetadataValue() {
MetadataValue newMetadataValue = MetadataValue.builder().value("NEW").build();
Task setCatalogItemMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).putEntry("KEY", Task setCatalogItemMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).put("KEY", "NEW");
newMetadataValue);
checkTask(setCatalogItemMetadataValue); checkTask(setCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue), assertTrue(retryTaskSuccess.apply(setCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue")); String.format(TASK_COMPLETE_TIMELY, "setCatalogItemMetadataValue"));
MetadataValue editedMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("KEY"); String editedMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).get("KEY");
assertEquals(editedMetadataValue.getValue(), newMetadataValue.getValue(), String.format(CORRECT_VALUE_OBJECT_FMT, assertEquals(editedMetadataValue, "NEW",
"Value", "MetadataValue", newMetadataValue.getValue(), editedMetadataValue.getValue())); String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", "NEW", editedMetadataValue));
checkMetadataValue(editedMetadataValue);
} }
@Test(description = "DELETE /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testGetCatalogItemMetadataValue") @Test(description = "DELETE /catalogItem/{id}/metadata/{key}", dependsOnMethods = "testGetCatalogItemMetadataValue")
public void testRemoveCatalogItemMetadataValue() { public void testRemoveCatalogItemMetadataValue() {
Task removeCatalogItemMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).removeEntry("KEY"); Task removeCatalogItemMetadataValue = catalogApi.getItemMetadataApi(catalogItem.getId()).remove("KEY");
checkTask(removeCatalogItemMetadataValue); checkTask(removeCatalogItemMetadataValue);
assertTrue(retryTaskSuccess.apply(removeCatalogItemMetadataValue), assertTrue(retryTaskSuccess.apply(removeCatalogItemMetadataValue),
String.format(TASK_COMPLETE_TIMELY, "removeCatalogItemMetadataValue")); String.format(TASK_COMPLETE_TIMELY, "removeCatalogItemMetadataValue"));
MetadataValue removed = catalogApi.getItemMetadataApi(catalogItem.getId()).getValue("KEY"); String removed = catalogApi.getItemMetadataApi(catalogItem.getId()).get("KEY");
assertNull(removed); assertNull(removed);
} }

View File

@ -33,7 +33,6 @@ import org.jclouds.vcloud.director.v1_5.domain.Media;
import org.jclouds.vcloud.director.v1_5.domain.Media.ImageType; import org.jclouds.vcloud.director.v1_5.domain.Media.ImageType;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
@ -259,7 +258,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
Metadata inputMetadata = metadata(); Metadata inputMetadata = metadata();
Task expectedTask = mergeMetadataTask(); Task expectedTask = mergeMetadataTask();
assertEquals(api.getMediaApi().getMetadataApi(mediaUri).merge(inputMetadata), expectedTask); assertEquals(api.getMediaApi().getMetadataApi(mediaUri).putAll(inputMetadata), expectedTask);
} }
public void testGetMetadataValue() { public void testGetMetadataValue() {
@ -274,10 +273,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/media/metadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE) .xmlFilePayload("/media/metadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)
.httpResponseBuilder().build()); .httpResponseBuilder().build());
MetadataValue expected = metadataValue(); assertEquals(api.getMediaApi().getMetadataApi(mediaUri).get("key"), "value");
assertEquals(api.getMediaApi().getMetadataApi(mediaUri).getValue("key"), expected);
} }
@Test @Test
@ -294,11 +290,9 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/media/setMetadataValueTask.xml", VCloudDirectorMediaType.TASK) .xmlFilePayload("/media/setMetadataValueTask.xml", VCloudDirectorMediaType.TASK)
.httpResponseBuilder().build()); .httpResponseBuilder().build());
MetadataValue inputMetadataValue = MetadataValue.builder().value("value").build();
Task expectedTask = setMetadataEntryTask(); Task expectedTask = setMetadataEntryTask();
assertEquals(api.getMediaApi().getMetadataApi(mediaUri).putEntry("key", inputMetadataValue), expectedTask); assertEquals(api.getMediaApi().getMetadataApi(mediaUri).put("key", "value"), expectedTask);
} }
@Test @Test
@ -314,9 +308,9 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/media/removeMetadataEntryTask.xml", VCloudDirectorMediaType.TASK) .xmlFilePayload("/media/removeMetadataEntryTask.xml", VCloudDirectorMediaType.TASK)
.httpResponseBuilder().build()); .httpResponseBuilder().build());
Task expectedTask = removeEntryTask(); Task expectedTask = removeTask();
assertEquals(api.getMediaApi().getMetadataApi(mediaUri).removeEntry("key"), expectedTask); assertEquals(api.getMediaApi().getMetadataApi(mediaUri).remove("key"), expectedTask);
} }
@Test @Test
@ -635,27 +629,6 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build(); .build();
} }
private static MetadataValue metadataValue() {
return MetadataValue.builder()
.type("application/vnd.vmware.vcloud.metadata.value+xml")
.href(URI.create("https://mycloud.greenhousedata.com/api/media/c93e5cdc-f29a-4749-8ed2-093df04cc75e/metadata/key"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://mycloud.greenhousedata.com/api/media/c93e5cdc-f29a-4749-8ed2-093df04cc75e/metadata"))
.build())
.link(Link.builder()
.rel("edit")
.type("application/vnd.vmware.vcloud.metadata.value+xml")
.href(URI.create("https://mycloud.greenhousedata.com/api/media/c93e5cdc-f29a-4749-8ed2-093df04cc75e/metadata/key"))
.build())
.link(Link.builder()
.rel("remove")
.href(URI.create("https://mycloud.greenhousedata.com/api/media/c93e5cdc-f29a-4749-8ed2-093df04cc75e/metadata/key"))
.build())
.value("value").build();
}
private Task mergeMetadataTask() { private Task mergeMetadataTask() {
return Task.builder() return Task.builder()
.status("running") .status("running")
@ -722,7 +695,7 @@ public class MediaApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.build(); .build();
} }
public static Task removeEntryTask() { public static Task removeTask() {
return Task.builder() return Task.builder()
.name("task") .name("task")
.id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c") .id("urn:vcloud:task:c6dca927-eab4-41fa-ad6a-3ac58602541c")

View File

@ -27,7 +27,6 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.G
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_DEL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_DEL; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_ATTRB_DEL;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_CLONE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_CLONE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_CONTAINS;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_LIST_SIZE_EQ; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_LIST_SIZE_EQ;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_LIST_SIZE_GE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_LIST_SIZE_GE;
@ -55,8 +54,6 @@ import org.jclouds.vcloud.director.v1_5.domain.File;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Media;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
@ -69,7 +66,7 @@ import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
@ -95,7 +92,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
private Media media, oldMedia; private Media media, oldMedia;
private Owner owner; private Owner owner;
private Metadata metadata; private Metadata metadata;
private MetadataValue metadataValue; private String metadataValue;
private String metadataEntryValue = "value"; private String metadataEntryValue = "value";
@Override @Override
@ -179,7 +176,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
owner = media.getOwner(); owner = media.getOwner();
assertNotNull(owner, String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "owner")); assertNotNull(owner, String.format(OBJ_FIELD_REQ_LIVE, MEDIA, "owner"));
Checks.checkResourceType(media.getOwner()); Checks.checkResource(media.getOwner());
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
} }
@ -193,7 +190,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
directOwner.toString())); directOwner.toString()));
// parent type // parent type
Checks.checkResourceType(directOwner); Checks.checkResource(directOwner);
// required // required
assertNotNull(directOwner.getUser(), String.format(OBJ_FIELD_REQ, "Owner", "user")); assertNotNull(directOwner.getUser(), String.format(OBJ_FIELD_REQ, "Owner", "user"));
@ -223,7 +220,7 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
assertTrue(media.clone(oldMedia), assertTrue(media.clone(oldMedia),
String.format(OBJ_FIELD_CLONE, MEDIA, "copied media", media.toString(), oldMedia.toString())); String.format(OBJ_FIELD_CLONE, MEDIA, "copied media", media.toString(), oldMedia.toString()));
mediaApi.getMetadataApi(media.getId()).putEntry("key", MetadataValue.builder().value("value").build()); mediaApi.getMetadataApi(media.getId()).put("key", "value");
media = vdcApi media = vdcApi
.cloneMedia(vdcUrn, CloneMediaParams.builder().source(Reference.builder().fromEntity(media).build()) .cloneMedia(vdcUrn, CloneMediaParams.builder().source(Reference.builder().fromEntity(media).build())
@ -286,83 +283,59 @@ public class MediaApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "POST /media/{id}/metadata", dependsOnMethods = { "testGetMedia" }) @Test(description = "POST /media/{id}/metadata", dependsOnMethods = { "testGetMedia" })
public void testMergeMetadata() { public void testMergeMetadata() {
// test new // test new
Set<MetadataEntry> inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "testValue").build()); Task mergeMetadata = mediaApi.getMetadataApi(media.getId()).putAll(ImmutableMap.of("testKey", "testValue"));
Metadata inputMetadata = Metadata.builder().entries(inputEntries).build();
Task mergeMetadata = mediaApi.getMetadataApi(media.getId()).merge(inputMetadata);
Checks.checkTask(mergeMetadata); Checks.checkTask(mergeMetadata);
assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)")); assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(new)"));
metadata = mediaApi.getMetadataApi(media.getId()).get(); metadata = mediaApi.getMetadataApi(media.getId()).get();
Checks.checkMetadataFor(MEDIA, metadata); Checks.checkMetadataFor(MEDIA, metadata);
checkMetadataContainsEntries(metadata, inputEntries); assertEquals(metadata.get("testKey"), "testValue");
media = mediaApi.get(media.getId()); media = mediaApi.get(media.getId());
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
// test edit // test edit
inputEntries = ImmutableSet.of(MetadataEntry.builder().entry("testKey", "new testValue").build()); mergeMetadata = mediaApi.getMetadataApi(media.getId()).put("testKey", "new testValue");
inputMetadata = Metadata.builder().entries(inputEntries).build();
mergeMetadata = mediaApi.getMetadataApi(media.getId()).merge(inputMetadata);
Checks.checkTask(mergeMetadata); Checks.checkTask(mergeMetadata);
assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(edit)")); assertTrue(retryTaskSuccess.apply(mergeMetadata), String.format(TASK_COMPLETE_TIMELY, "mergeMetadata(edit)"));
metadata = mediaApi.getMetadataApi(media.getId()).get(); metadata = mediaApi.getMetadataApi(media.getId()).get();
Checks.checkMetadataFor(MEDIA, metadata); Checks.checkMetadataFor(MEDIA, metadata);
checkMetadataContainsEntries(metadata, inputEntries); assertEquals(metadata.get("testKey"), "new testValue");
media = mediaApi.get(media.getId()); media = mediaApi.get(media.getId());
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);
} }
private void checkMetadataContainsEntries(Metadata metadata, Set<MetadataEntry> entries) {
for (MetadataEntry inputEntry : entries) {
boolean found = false;
for (MetadataEntry entry : metadata.getMetadataEntries()) {
if (equal(inputEntry.getKey(), entry.getKey())) {
found = true;
break;
}
}
if (!found) {
String.format(OBJ_FIELD_CONTAINS, MEDIA, "metadata", Iterables.toString(metadata.getMetadataEntries()),
Iterables.toString(entries));
}
}
}
@Test(description = "GET /media/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "GET /media/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
metadataValue = mediaApi.getMetadataApi(media.getId()).getValue("key"); metadataValue = mediaApi.getMetadataApi(media.getId()).get("key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); assertNotNull(metadataValue);
} }
@Test(description = "PUT /media/{id}/metadata/{key}", dependsOnMethods = { "testMergeMetadata" }) @Test(description = "PUT /media/{id}/metadata/{key}", dependsOnMethods = { "testMergeMetadata" })
public void testSetMetadataValue() { public void testSetMetadataValue() {
metadataEntryValue = "value"; metadataEntryValue = "value";
MetadataValue newValue = MetadataValue.builder().value(metadataEntryValue).build();
Task setMetadataEntry = mediaApi.getMetadataApi(media.getId()).putEntry("key", newValue); Task setMetadataEntry = mediaApi.getMetadataApi(media.getId()).put("key", metadataEntryValue);
Checks.checkTask(setMetadataEntry); Checks.checkTask(setMetadataEntry);
assertTrue(retryTaskSuccess.apply(setMetadataEntry), String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry")); assertTrue(retryTaskSuccess.apply(setMetadataEntry), String.format(TASK_COMPLETE_TIMELY, "setMetadataEntry"));
metadataValue = mediaApi.getMetadataApi(media.getId()).getValue("key"); metadataValue = mediaApi.getMetadataApi(media.getId()).get("key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); assertNotNull(metadataValue);
} }
@Test(description = "DELETE /media/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata", @Test(description = "DELETE /media/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata",
"testGetMetadataValue" }) "testGetMetadataValue" })
public void testRemoveMetadata() { public void testRemoveMetadata() {
Task removeEntry = mediaApi.getMetadataApi(media.getId()).removeEntry("testKey"); Task remove = mediaApi.getMetadataApi(media.getId()).remove("testKey");
Checks.checkTask(removeEntry); Checks.checkTask(remove);
assertTrue(retryTaskSuccess.apply(removeEntry), String.format(TASK_COMPLETE_TIMELY, "removeEntry")); assertTrue(retryTaskSuccess.apply(remove), String.format(TASK_COMPLETE_TIMELY, "remove"));
metadataValue = mediaApi.getMetadataApi(media.getId()).getValue("testKey"); metadataValue = mediaApi.getMetadataApi(media.getId()).get("testKey");
assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA, "Metadata", assertNull(metadataValue, String.format(OBJ_FIELD_ATTRB_DEL, MEDIA, "Metadata",
metadataValue != null ? metadataValue.toString() : "", "MetadataEntry", metadataValue != null ? metadataValue.toString() : "", "MetadataEntry",
metadataValue != null ? metadataValue.toString() : "")); metadataValue != null ? metadataValue.toString() : ""));
metadataValue = mediaApi.getMetadataApi(media.getId()).getValue("key"); metadataValue = mediaApi.getMetadataApi(media.getId()).get("key");
Checks.checkMetadataValueFor(MEDIA, metadataValue); assertNotNull(metadataValue);
media = mediaApi.get(media.getId()); media = mediaApi.get(media.getId());
Checks.checkMediaFor(MEDIA, media); Checks.checkMediaFor(MEDIA, media);

View File

@ -38,7 +38,6 @@ import org.jclouds.vcloud.director.v1_5.domain.Error;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.network.DhcpService; import org.jclouds.vcloud.director.v1_5.domain.network.DhcpService;
import org.jclouds.vcloud.director.v1_5.domain.network.IpAddresses; import org.jclouds.vcloud.director.v1_5.domain.network.IpAddresses;
import org.jclouds.vcloud.director.v1_5.domain.network.IpRange; import org.jclouds.vcloud.director.v1_5.domain.network.IpRange;
@ -216,22 +215,9 @@ public class NetworkApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test @Test
public void testGetNetworkMetadataEntryHref() { public void testGetNetworkMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse);
assertEquals(api.getNetworkApi().getMetadataApi(networkHref).getValue("KEY"), metadataValue()); assertEquals(api.getNetworkApi().getMetadataApi(networkHref).get("KEY"), "value");
} }
private MetadataValue metadataValue() {
return MetadataValue.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata/key"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c/metadata"))
.build())
.value("value")
.build();
}
public static OrgNetwork network() { public static OrgNetwork network() {
return OrgNetwork.builder() return OrgNetwork.builder()
.name("ilsolation01-Jclouds") .name("ilsolation01-Jclouds")

View File

@ -24,7 +24,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkResourceType; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkResource;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
@ -33,7 +33,6 @@ import static org.testng.Assert.assertTrue;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.network.Network; import org.jclouds.vcloud.director.v1_5.domain.network.Network;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgNetwork; import org.jclouds.vcloud.director.v1_5.domain.org.OrgNetwork;
@ -71,7 +70,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void cleanUp() { public void cleanUp() {
if (metadataSet) { if (metadataSet) {
try { try {
Task remove = adminContext.getApi().getNetworkApi().getMetadataApi(networkUrn).removeEntry("key"); Task remove = adminContext.getApi().getNetworkApi().getMetadataApi(networkUrn).remove("key");
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata"); logger.warn(e, "Error when deleting metadata");
@ -95,8 +94,8 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
} }
private void setupMetadata() { private void setupMetadata() {
adminContext.getApi().getNetworkApi().getMetadataApi(networkUrn) //TODO: block until complete
.putEntry("key", MetadataValue.builder().value("value").build()); adminContext.getApi().getNetworkApi().getMetadataApi(networkUrn).put("key", "value");
metadataSet = true; metadataSet = true;
} }
@ -112,7 +111,7 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
String.format(OBJ_FIELD_REQ_LIVE, NETWORK, "metadata.entries")); String.format(OBJ_FIELD_REQ_LIVE, NETWORK, "metadata.entries"));
// parent type // parent type
checkResourceType(metadata); checkResource(metadata);
for (MetadataEntry entry : metadata.getMetadataEntries()) { for (MetadataEntry entry : metadata.getMetadataEntries()) {
// required elements and attributes // required elements and attributes
@ -122,21 +121,14 @@ public class NetworkApiLiveTest extends BaseVCloudDirectorApiLiveTest {
String.format(OBJ_FIELD_ATTRB_REQ, networkApi, "MetadataEntry", entry.getValue(), "value")); String.format(OBJ_FIELD_ATTRB_REQ, networkApi, "MetadataEntry", entry.getValue(), "value"));
// parent type // parent type
checkResourceType(entry); checkResource(entry);
} }
} }
@Test(description = "GET /network/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" }) @Test(description = "GET /network/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetMetadataValue() { public void testGetMetadataValue() {
MetadataValue metadataValue = networkApi.getMetadataApi(networkUrn).getValue("key"); String metadataValue = networkApi.getMetadataApi(networkUrn).get("key");
// Check parent type assertEquals(metadataValue, "value", String.format(OBJ_FIELD_EQ, NETWORK, "metadataEntry.value", "value", metadataValue));
checkResourceType(metadataValue);
// Check required elements and attributes
String value = metadataValue.getValue();
assertNotNull(value,
String.format(OBJ_FIELD_ATTRB_REQ, NETWORK, "MetadataEntry", metadataValue.toString(), "value"));
assertEquals(value, "value", String.format(OBJ_FIELD_EQ, NETWORK, "metadataEntry.value", "value", value));
} }
} }

View File

@ -33,7 +33,6 @@ import org.jclouds.http.HttpResponse;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.org.Org; import org.jclouds.vcloud.director.v1_5.domain.org.Org;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList; import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
@ -179,7 +178,7 @@ public class OrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
@Test @Test
public void testGetOrgMetadataEntryHref() { public void testGetOrgMetadataEntryHref() {
VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse); VCloudDirectorApi api = requestsSendResponses(loginRequest, sessionResponse, getMetadataValue, getMetadataValueResponse);
assertEquals(api.getOrgApi().getMetadataApi(orgHref).getValue("KEY"), metadataValue()); assertEquals(api.getOrgApi().getMetadataApi(orgHref).get("KEY"), "VALUE");
} }
public static Org org() { public static Org org() {
@ -243,16 +242,4 @@ public class OrgApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.entry("KEY", "VALUE") .entry("KEY", "VALUE")
.build(); .build();
} }
public static MetadataValue metadataValue() {
return MetadataValue.builder()
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"))
.link(Link.builder()
.rel("up")
.type("application/vnd.vmware.vcloud.metadata+xml")
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
.build())
.value("VALUE")
.build();
}
} }

View File

@ -22,7 +22,6 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.C
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOrg; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOrg;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkReferenceType; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkReferenceType;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
@ -32,7 +31,6 @@ import static org.testng.Assert.assertNotNull;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType; import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog; import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList; import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
@ -67,7 +65,7 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void cleanUp() throws Exception { public void cleanUp() throws Exception {
if (adminMembersSet) { if (adminMembersSet) {
try { try {
Task remove = adminContext.getApi().getOrgApi().getMetadataApi(orgUrn).removeEntry("KEY"); Task remove = adminContext.getApi().getOrgApi().getMetadataApi(orgUrn).remove("KEY");
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry"); logger.warn(e, "Error when deleting metadata entry");
@ -126,8 +124,8 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
* the need for configuration * the need for configuration
*/ */
private void setupAdminMembers() { private void setupAdminMembers() {
adminContext.getApi().getOrgApi().getMetadataApi(orgUrn) //TODO: block until complete
.putEntry("KEY", MetadataValue.builder().value("VALUE").build()); adminContext.getApi().getOrgApi().getMetadataApi(orgUrn).put("KEY", "VALUE");
AdminCatalog newCatalog = AdminCatalog.builder().name("Test Catalog " + getTestDateTimeStamp()) AdminCatalog newCatalog = AdminCatalog.builder().name("Test Catalog " + getTestDateTimeStamp())
.description("created by testOrg()").build(); .description("created by testOrg()").build();
@ -156,16 +154,14 @@ public class OrgApiLiveTest extends BaseVCloudDirectorApiLiveTest {
@Test(description = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" }) @Test(description = "GET /org/{id}/metadata/{key}", dependsOnMethods = { "testGetOrgMetadata" })
public void testGetOrgMetadataValue() { public void testGetOrgMetadataValue() {
// Call the method being tested // Call the method being tested
MetadataValue value = orgApi.getMetadataApi(orgUrn).getValue("KEY"); String value = orgApi.getMetadataApi(orgUrn).get("KEY");
// NOTE The environment MUST have configured the metadata entry as '{ key="KEY", value="VALUE" // NOTE The environment MUST have configured the metadata entry as '{ key="KEY", value="VALUE"
// )' // )'
String expected = "VALUE"; String expected = "VALUE";
checkMetadataValue(value); assertEquals(value, expected, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value));
assertEquals(value.getValue(), expected,
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value.getValue()));
} }
} }

View File

@ -31,8 +31,6 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkLeaseSettingsS
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValueFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOwner; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOwner;
@ -59,8 +57,6 @@ import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest;
import org.jclouds.vcloud.director.v1_5.domain.AccessSetting; import org.jclouds.vcloud.director.v1_5.domain.AccessSetting;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList; import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
@ -117,7 +113,6 @@ import com.google.common.collect.Sets;
@Test(singleThreaded = true, testName = "VAppApiLiveTest") @Test(singleThreaded = true, testName = "VAppApiLiveTest")
public class VAppApiLiveTest extends AbstractVAppApiLiveTest { public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
private MetadataValue metadataValue;
private String key; private String key;
private boolean testUserCreated = false; private boolean testUserCreated = false;
private User user; private User user;
@ -751,22 +746,20 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
public void testSetMetadataValue() { public void testSetMetadataValue() {
key = name("key-"); key = name("key-");
String value = name("value-"); String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); vAppApi.getMetadataApi(vAppUrn).put(key, value);
vAppApi.getMetadataApi(vAppUrn).putEntry(key, metadataValue);
// Retrieve the value, and assert it was set correctly // Retrieve the value, and assert it was set correctly
MetadataValue newMetadataValue = vAppApi.getMetadataApi(vAppUrn).getValue(key); String newMetadataValue = vAppApi.getMetadataApi(vAppUrn).get(key);
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkMetadataValueFor(VAPP, newMetadataValue, value); assertEquals(newMetadataValue, value);
} }
@Test(groups = { "live", "user" }, description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" }) @Test(groups = { "live", "user" }, description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
public void testGetMetadata() { public void testGetMetadata() {
key = name("key-"); key = name("key-");
String value = name("value-"); String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); vAppApi.getMetadataApi(vAppUrn).put(key, value);
vAppApi.getMetadataApi(vAppUrn).putEntry(key, metadataValue);
// Call the method being tested // Call the method being tested
Metadata metadata = vAppApi.getMetadataApi(vAppUrn).get(); Metadata metadata = vAppApi.getMetadataApi(vAppUrn).get();
@ -783,23 +776,18 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-"); key = name("key-");
String value = name("value-"); String value = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); vAppApi.getMetadataApi(vAppUrn).put(key, value);
vAppApi.getMetadataApi(vAppUrn).putEntry(key, metadataValue);
// Call the method being tested // Call the method being tested
MetadataValue newValue = vAppApi.getMetadataApi(vAppUrn).getValue(key); String newValue = vAppApi.getMetadataApi(vAppUrn).get(key);
String expected = metadataValue.getValue(); assertEquals(newValue, value, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", value, newValue));
checkMetadataValue(newValue);
assertEquals(newValue.getValue(), expected,
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, newValue.getValue()));
} }
@Test(groups = { "live", "user" }, description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }) @Test(groups = { "live", "user" }, description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testRemoveMetadataEntry() { public void testRemoveMetadataEntry() {
// Delete the entry // Delete the entry
Task task = vAppApi.getMetadataApi(vAppUrn).removeEntry(key); Task task = vAppApi.getMetadataApi(vAppUrn).remove(key);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry has been removed // Confirm the entry has been removed
@ -817,8 +805,7 @@ public class VAppApiLiveTest extends AbstractVAppApiLiveTest {
// Store a value, to be removed // Store a value, to be removed
String key = name("key-"); String key = name("key-");
String value = name("value-"); String value = name("value-");
Metadata addedMetadata = Metadata.builder().entry(MetadataEntry.builder().key(key).value(value).build()).build(); Task task = vAppApi.getMetadataApi(vAppUrn).putAll(ImmutableMap.of(key, value));
Task task = vAppApi.getMetadataApi(vAppUrn).merge(addedMetadata);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry contains everything that was there, and everything that was being added // Confirm the entry contains everything that was there, and everything that was being added

View File

@ -78,7 +78,7 @@ public class VAppNetworksLiveTest extends AbstractVAppApiLiveTest {
protected void tidyUp() { protected void tidyUp() {
if (key != null) { if (key != null) {
try { try {
Task remove = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).removeEntry(key); Task remove = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).remove(key);
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry '%s'", key); logger.warn(e, "Error when deleting metadata entry '%s'", key);

View File

@ -42,7 +42,6 @@ import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.Link; import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
@ -251,7 +250,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
assertEquals(metadata, exampleMetadata()); assertEquals(metadata, exampleMetadata());
Task task = api.getMetadataApi(uri).merge(exampleMetadata()); Task task = api.getMetadataApi(uri).putAll(exampleMetadata());
assertNotNull(task); assertNotNull(task);
} }
@ -276,7 +275,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("POST", templateId + "/metadata").xmlFilePayload("/vapptemplate/metadata.xml", METADATA).acceptMedia(TASK).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("POST", templateId + "/metadata").xmlFilePayload("/vapptemplate/metadata.xml", METADATA).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.getMetadataApi(uri).merge(exampleMetadata()); api.getMetadataApi(uri).putAll(exampleMetadata());
} }
public void testVappTemplateMetadataValue() { public void testVappTemplateMetadataValue() {
@ -293,14 +292,14 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
).getVAppTemplateApi(); ).getVAppTemplateApi();
assertNotNull(api); assertNotNull(api);
MetadataValue metadata = api.getMetadataApi(uri).getValue("12345"); String metadata = api.getMetadataApi(uri).get("12345");
assertEquals(metadata, exampleMetadataValue()); assertEquals(metadata, "some value");
Task task = api.getMetadataApi(uri).putEntry("12345", exampleMetadataValue()); Task task = api.getMetadataApi(uri).put("12345", "some value");
assertNotNull(task); assertNotNull(task);
task = api.getMetadataApi(uri).removeEntry("12345"); task = api.getMetadataApi(uri).remove("12345");
assertNotNull(task); assertNotNull(task);
} }
@ -312,7 +311,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata/12345").acceptMedia(METADATA_ENTRY).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("GET", templateId + "/metadata/12345").acceptMedia(METADATA_ENTRY).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi();
assertNull(api.getMetadataApi(uri).getValue("12345")); assertNull(api.getMetadataApi(uri).get("12345"));
} }
@Test(expectedExceptions = VCloudDirectorException.class) @Test(expectedExceptions = VCloudDirectorException.class)
@ -324,7 +323,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/metadata/12345").xmlFilePayload("/vapptemplate/metadataValue.xml", METADATA_ENTRY).acceptMedia(TASK).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("PUT", templateId + "/metadata/12345").xmlFilePayload("/vapptemplate/metadataValue.xml", METADATA_ENTRY).acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error400.xml", ERROR).httpResponseBuilder().statusCode(400).build()).getVAppTemplateApi();
api.getMetadataApi(uri).putEntry("12345", exampleMetadataValue()); api.getMetadataApi(uri).put("12345", "some value");
} }
@Test(expectedExceptions = ResourceNotFoundException.class) @Test(expectedExceptions = ResourceNotFoundException.class)
@ -336,7 +335,7 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
new VcloudHttpRequestPrimer().apiCommand("DELETE", templateId + "/metadata/12345").acceptMedia(TASK).httpRequestBuilder().build(), new VcloudHttpRequestPrimer().apiCommand("DELETE", templateId + "/metadata/12345").acceptMedia(TASK).httpRequestBuilder().build(),
new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi(); new VcloudHttpResponsePrimer().xmlFilePayload("/vapptemplate/error403.xml", ERROR).httpResponseBuilder().statusCode(403).build()).getVAppTemplateApi();
api.getMetadataApi(uri).removeEntry("12345"); api.getMetadataApi(uri).remove("12345");
} }
@Test(expectedExceptions = VCloudDirectorException.class) @Test(expectedExceptions = VCloudDirectorException.class)
@ -437,8 +436,4 @@ public class VAppTemplateApiExpectTest extends VCloudDirectorAdminApiExpectTest
.entry(MetadataEntry.builder().key("key").value("value").build()).build(); .entry(MetadataEntry.builder().key("key").value("value").build()).build();
} }
private MetadataValue exampleMetadataValue() {
return MetadataValue.builder().value("some value").build();
}
} }

View File

@ -23,7 +23,6 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkLeaseSettingsS
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfEnvelope; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfEnvelope;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfNetworkSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOvfNetworkSection;
@ -48,7 +47,6 @@ import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Link.Rel; import org.jclouds.vcloud.director.v1_5.domain.Link.Rel;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry; import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList; import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
@ -84,7 +82,7 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
protected void tidyUp() { protected void tidyUp() {
if (key != null) { if (key != null) {
try { try {
Task remove = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).removeEntry(key); Task remove = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).remove(key);
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error when deleting metadata entry '%s'", key); logger.warn(e, "Error when deleting metadata entry '%s'", key);
@ -157,10 +155,9 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
Metadata metadata = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get(); Metadata metadata = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get();
MetadataEntry entry = Iterables.get(metadata.getMetadataEntries(), 0); MetadataEntry entry = Iterables.get(metadata.getMetadataEntries(), 0);
MetadataValue val = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).getValue(entry.getKey()); String val = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get(entry.getKey());
checkMetadataValue(val); assertEquals(val, entry.getValue());
assertEquals(val.getValue(), entry.getValue());
} }
@Test(description = "GET /vAppTemplate/{id}/networkConfigSection") @Test(description = "GET /vAppTemplate/{id}/networkConfigSection")
@ -205,10 +202,8 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
key = name("key-"); key = name("key-");
val = name("value-"); val = name("value-");
MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).build();
Metadata metadata = Metadata.builder().fromMetadata(oldMetadata).entry(metadataEntry).build();
final Task task = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).merge(metadata); final Task task = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).putAll(ImmutableMap.of(key, val));
assertTaskSucceeds(task); assertTaskSucceeds(task);
Metadata newMetadata = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get(); Metadata newMetadata = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get();
@ -220,18 +215,17 @@ public class VAppTemplateApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "PUT /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testEditMetadata" }) @Test(description = "PUT /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testEditMetadata" })
public void testEditMetadataValue() { public void testEditMetadataValue() {
val = "new" + val; val = "new" + val;
MetadataValue metadataValue = MetadataValue.builder().value(val).build();
final Task task = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).putEntry(key, metadataValue); final Task task = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).put(key, val);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
MetadataValue newMetadataValue = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).getValue(key); String newMetadataValue = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get(key);
assertEquals(newMetadataValue.getValue(), metadataValue.getValue()); assertEquals(newMetadataValue, val);
} }
@Test(description = "DELETE /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" }) @Test(description = "DELETE /vAppTemplate/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" })
public void testRemoveVAppTemplateMetadataValue() { public void testRemoveVAppTemplateMetadataValue() {
final Task deletionTask = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).removeEntry(key); final Task deletionTask = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).remove(key);
assertTaskSucceeds(deletionTask); assertTaskSucceeds(deletionTask);
Metadata newMetadata = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get(); Metadata newMetadata = vAppTemplateApi.getMetadataApi(vAppTemplateUrn).get();

View File

@ -35,7 +35,6 @@ import org.jclouds.vcloud.director.v1_5.domain.Link;
import org.jclouds.vcloud.director.v1_5.domain.Media; import org.jclouds.vcloud.director.v1_5.domain.Media;
import org.jclouds.vcloud.director.v1_5.domain.Media.ImageType; import org.jclouds.vcloud.director.v1_5.domain.Media.ImageType;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Owner; import org.jclouds.vcloud.director.v1_5.domain.Owner;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.User; import org.jclouds.vcloud.director.v1_5.domain.User;
@ -371,9 +370,7 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
.xmlFilePayload("/vdc/metadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE) .xmlFilePayload("/vdc/metadataValue.xml", VCloudDirectorMediaType.METADATA_VALUE)
.httpResponseBuilder().build()); .httpResponseBuilder().build());
MetadataValue expected = metadataValue(); assertEquals(api.getVdcApi().getMetadataApi(vdcUri).get("key"), "");
assertEquals(api.getVdcApi().getMetadataApi(vdcUri).getValue("key"), expected);
} }
public static Vdc getVdc() { public static Vdc getVdc() {
@ -582,9 +579,4 @@ public class VdcApiExpectTest extends VCloudDirectorAdminApiExpectTest {
return null; return null;
} }
private MetadataValue metadataValue() {
// TODO Auto-generated method stub
return null;
}
} }

View File

@ -24,8 +24,8 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.O
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.URN_REQ_LIVE;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail; import static org.testng.Assert.fail;
import java.util.Map; import java.util.Map;
@ -33,8 +33,6 @@ import java.util.Set;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity; import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
@ -123,7 +121,7 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
if (metadataSet) { if (metadataSet) {
try { try {
Task remove = adminContext.getApi().getVdcApi().getMetadataApi(vdcUrn).removeEntry("key"); Task remove = adminContext.getApi().getVdcApi().getMetadataApi(vdcUrn).remove("key");
taskDoneEventually(remove); taskDoneEventually(remove);
} catch (Exception e) { } catch (Exception e) {
logger.warn(e, "Error deleting metadata entry"); logger.warn(e, "Error deleting metadata entry");
@ -323,13 +321,9 @@ public class VdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
String key = Iterables.getFirst(metadataMap.keySet(), "MadeUpKey!"); String key = Iterables.getFirst(metadataMap.keySet(), "MadeUpKey!");
String value = metadataMap.get(key); String value = metadataMap.get(key);
MetadataValue metadataValue = vdcApi.getMetadataApi(vdcUrn).getValue(key); String metadataValue = vdcApi.getMetadataApi(vdcUrn).get(key);
Checks.checkMetadataValueFor(VDC, metadataValue, value); assertEquals(metadataValue, value);
} }
private void setupMetadata() {
adminContext.getApi().getVdcApi().getMetadataApi(vdcUrn).putEntry("key", MetadataValue.builder().value("value").build());
metadataSet = true;
}
} }

View File

@ -28,8 +28,6 @@ import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkGuestCustomiza
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValueFor;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOperatingSystemSection; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkOperatingSystemSection;
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkProductSectionList; import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkProductSectionList;
@ -59,8 +57,6 @@ import org.jclouds.dmtf.ovf.ProductSection;
import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest; import org.jclouds.vcloud.director.v1_5.AbstractVAppApiLiveTest;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList; import org.jclouds.vcloud.director.v1_5.domain.ProductSectionList;
import org.jclouds.vcloud.director.v1_5.domain.RasdItemsList; import org.jclouds.vcloud.director.v1_5.domain.RasdItemsList;
import org.jclouds.vcloud.director.v1_5.domain.Reference; import org.jclouds.vcloud.director.v1_5.domain.Reference;
@ -104,7 +100,7 @@ import com.google.common.collect.Sets;
@Test(groups = { "live", "user" }, singleThreaded = true, testName = "VmApiLiveTest") @Test(groups = { "live", "user" }, singleThreaded = true, testName = "VmApiLiveTest")
public class VmApiLiveTest extends AbstractVAppApiLiveTest { public class VmApiLiveTest extends AbstractVAppApiLiveTest {
private MetadataValue metadataValue; private String metadataValue;
private String key; private String key;
private boolean testUserCreated = false; private boolean testUserCreated = false;
@ -872,15 +868,16 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "PUT /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetVm" }) @Test(description = "PUT /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetVm" })
public void testSetMetadataValue() { public void testSetMetadataValue() {
key = name("key-"); key = name("key-");
String value = name("value-"); metadataValue = name("value-");
metadataValue = MetadataValue.builder().value(value).build(); //TODO: block!!
vmApi.getMetadataApi(vmUrn).putEntry(key, metadataValue); vmApi.getMetadataApi(vmUrn).put(key, metadataValue);
// Retrieve the value, and assert it was set correctly // Retrieve the value, and assert it was set correctly
MetadataValue newMetadataValue = vmApi.getMetadataApi(vmUrn).getValue(key); String newMetadataValue = vmApi.getMetadataApi(vmUrn).get(key);
// Check the retrieved object is well formed // Check the retrieved object is well formed
checkMetadataValueFor(VM, newMetadataValue, value); assertEquals(newMetadataValue, metadataValue,
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", metadataValue, newMetadataValue));
} }
@Test(description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
@ -898,24 +895,22 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
@Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" }) @Test(description = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
public void testGetOrgMetadataValue() { public void testGetOrgMetadataValue() {
key = name("key-"); key = name("key-");
String value = name("value-"); metadataValue = name("value-");
metadataValue = MetadataValue.builder().value(value).build();
vmApi.getMetadataApi(vmUrn).putEntry(key, metadataValue); //TODO: block!!
vmApi.getMetadataApi(vmUrn).put(key, metadataValue);
// Call the method being tested // Call the method being tested
MetadataValue metadataValue = vmApi.getMetadataApi(vmUrn).getValue(key); String newMetadataValue = vmApi.getMetadataApi(vmUrn).get(key);
String expected = metadataValue.getValue(); assertEquals(newMetadataValue, metadataValue,
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", metadataValue, newMetadataValue));
checkMetadataValue(metadataValue);
assertEquals(metadataValue.getValue(), expected,
String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, metadataValue.getValue()));
} }
@Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" }) @Test(description = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
public void testRemoveMetadataEntry() { public void testRemoveMetadataEntry() {
// Delete the entry // Delete the entry
Task task = vmApi.getMetadataApi(vmUrn).removeEntry(key); Task task = vmApi.getMetadataApi(vmUrn).remove(key);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry has been removed // Confirm the entry has been removed
@ -933,8 +928,7 @@ public class VmApiLiveTest extends AbstractVAppApiLiveTest {
// Store a value, to be removed // Store a value, to be removed
String key = name("key-"); String key = name("key-");
String value = name("value-"); String value = name("value-");
Metadata addedMetadata = Metadata.builder().entry(MetadataEntry.builder().key(key).value(value).build()).build(); Task task = vmApi.getMetadataApi(vmUrn).putAll(ImmutableMap.of(key, value));
Task task = vmApi.getMetadataApi(vmUrn).merge(addedMetadata);
retryTaskSuccess.apply(task); retryTaskSuccess.apply(task);
// Confirm the entry contains everything that was there, and everything that was being added // Confirm the entry contains everything that was there, and everything that was being added

View File

@ -21,14 +21,12 @@ package org.jclouds.vcloud.director.v1_5.features.admin;
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE; import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_REQ_LIVE;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.fail; import static org.testng.Assert.assertNull;
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException; import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
import org.jclouds.vcloud.director.v1_5.domain.AdminVdc; import org.jclouds.vcloud.director.v1_5.domain.AdminVdc;
import org.jclouds.vcloud.director.v1_5.domain.Checks; import org.jclouds.vcloud.director.v1_5.domain.Checks;
import org.jclouds.vcloud.director.v1_5.domain.Metadata; import org.jclouds.vcloud.director.v1_5.domain.Metadata;
import org.jclouds.vcloud.director.v1_5.domain.MetadataEntry;
import org.jclouds.vcloud.director.v1_5.domain.MetadataValue;
import org.jclouds.vcloud.director.v1_5.domain.Task; import org.jclouds.vcloud.director.v1_5.domain.Task;
import org.jclouds.vcloud.director.v1_5.features.MetadataApi; import org.jclouds.vcloud.director.v1_5.features.MetadataApi;
import org.jclouds.vcloud.director.v1_5.features.VdcApi; import org.jclouds.vcloud.director.v1_5.features.VdcApi;
@ -37,6 +35,8 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
/** /**
* Tests behavior of {@link VdcApi} * Tests behavior of {@link VdcApi}
* *
@ -67,7 +67,7 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void cleanUp() throws Exception { public void cleanUp() throws Exception {
if (metadataKey != null) { if (metadataKey != null) {
try { try {
Task task = metadataApi.removeEntry(metadataKey); Task task = metadataApi.remove(metadataKey);
taskDoneEventually(task); taskDoneEventually(task);
} catch (VCloudDirectorException e) { } catch (VCloudDirectorException e) {
logger.warn(e, "Error deleting metadata-value (perhaps it doesn't exist?); continuing..."); logger.warn(e, "Error deleting metadata-value (perhaps it doesn't exist?); continuing...");
@ -171,36 +171,33 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testSetMetadata() throws Exception { public void testSetMetadata() throws Exception {
metadataKey = name("key-"); metadataKey = name("key-");
metadataValue = name("value-"); metadataValue = name("value-");
Metadata metadata = Metadata.builder().entry(MetadataEntry.builder().entry(metadataKey, metadataValue).build())
.build();
Task task = metadataApi.merge(metadata); Task task = metadataApi.putAll(ImmutableMap.of(metadataKey, metadataValue));
assertTaskSucceeds(task); assertTaskSucceeds(task);
MetadataValue modified = metadataApi.getValue(metadataKey); String modified = metadataApi.get(metadataKey);
Checks.checkMetadataValueFor("AdminVdc", modified, metadataValue); assertEquals(modified, metadataValue);
Checks.checkMetadata(metadata);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "GET /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadata" }, enabled = false) @Test(description = "GET /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadata" }, enabled = false)
public void testGetMetadataValue() throws Exception { public void testGetMetadataValue() throws Exception {
MetadataValue retrievedMetadataValue = metadataApi.getValue(metadataKey); String retrievedMetadataValue = metadataApi.get(metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue); assertEquals(retrievedMetadataValue, metadataValue);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@Test(description = "PUT /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" }, enabled = false) @Test(description = "PUT /admin/vdc/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadataValue" }, enabled = false)
public void testSetMetadataValue() throws Exception { public void testSetMetadataValue() throws Exception {
metadataValue = name("value-"); metadataValue = name("value-");
MetadataValue newV = MetadataValue.builder().value(metadataValue).build();
Task task = metadataApi.putEntry(metadataKey, newV); Task task = metadataApi.put(metadataKey, metadataValue);
assertTaskSucceeds(task); assertTaskSucceeds(task);
MetadataValue retrievedMetadataValue = metadataApi.getValue(metadataKey); String retrievedMetadataValue = metadataApi.get(metadataKey);
Checks.checkMetadataValueFor("AdminVdc", retrievedMetadataValue, metadataValue); assertEquals(retrievedMetadataValue, metadataValue);
} }
// TODO insufficient permissions to test // TODO insufficient permissions to test
@ -208,14 +205,9 @@ public class AdminVdcApiLiveTest extends BaseVCloudDirectorApiLiveTest {
public void testRemoveMetadataValue() throws Exception { public void testRemoveMetadataValue() throws Exception {
// TODO Remove dependency on other tests; make cleanUp remove a list of metadata entries? // TODO Remove dependency on other tests; make cleanUp remove a list of metadata entries?
Task task = metadataApi.removeEntry(metadataKey); Task task = metadataApi.remove(metadataKey);
assertTaskSucceeds(task); assertTaskSucceeds(task);
try { assertNull(metadataApi.get(metadataKey));
metadataApi.getValue(metadataKey);
fail("Retrieval of metadata value " + metadataKey + " should have fail after deletion");
} catch (VCloudDirectorException e) {
// success; should not be accessible
}
} }
} }

View File

@ -234,7 +234,7 @@ public abstract class BaseVCloudDirectorExpectTest<T> extends BaseRestApiExpectT
@Deprecated @Deprecated
protected class VcloudHttpResponsePrimer { protected class VcloudHttpResponsePrimer {
private HttpResponse.Builder<?> builder = HttpResponse.builder(); private HttpResponse.Builder<?> builder = HttpResponse.builder().statusCode(200);
public VcloudHttpResponsePrimer() { public VcloudHttpResponsePrimer() {
} }

View File

@ -1,4 +1,3 @@
<MetadataValue <MetadataValue xmlns="http://www.vmware.com/vcloud/v1.5">
xmlns="http://www.vmware.com/vcloud/v1.5">
<Value>some value</Value> <Value>some value</Value>
</MetadataValue> </MetadataValue>