mirror of https://github.com/apache/jclouds.git
Completed TaskClient and tidied up OrgClient.
Note two types of API call here, one using traditional REST semantics and the other taking ReferenceTypes and extracting URIs from them.
This commit is contained in:
parent
73a2593f8b
commit
d29bd2eec8
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
* 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.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author grkvlt@apache.org
|
||||||
|
*/
|
||||||
|
public interface URISupplier {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns the {@link URI} for a particular {@link ReferenceType} or {@link ResourceType} object.
|
||||||
|
*
|
||||||
|
* @see ResourceType#getHref()
|
||||||
|
* @see ReferenceType#getHref()
|
||||||
|
*/
|
||||||
|
public URI getURI();
|
||||||
|
}
|
|
@ -23,6 +23,7 @@ import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
|
|
||||||
|
import org.jclouds.rest.annotations.EndpointParam;
|
||||||
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;
|
||||||
|
@ -30,8 +31,10 @@ 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.Org;
|
import org.jclouds.vcloud.director.v1_5.domain.Org;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
|
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
||||||
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
|
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
|
||||||
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xxOrNull;
|
import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -43,7 +46,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
public interface OrgAsyncClient {
|
public interface OrgAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see OrgClient#getOrgList
|
* @see OrgClient#getOrgList()
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/org")
|
@Path("/org")
|
||||||
|
@ -52,32 +55,61 @@ public interface OrgAsyncClient {
|
||||||
ListenableFuture<OrgList> getOrgList();
|
ListenableFuture<OrgList> getOrgList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see OrgClient#getOrg
|
* @see OrgClient#getOrg(String)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/org/{id}")
|
@Path("/org/{id}")
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<Org> getOrg(@PathParam("id") String orgId);
|
ListenableFuture<Org> getOrg(@PathParam("id") String orgId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see OrgClient#getMetadata
|
* @see OrgClient#getOrg(ReferenceType)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Consumes
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
|
ListenableFuture<Org> getOrg(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see OrgClient#getMetadata(String)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/org/{id}/metadata")
|
@Path("/org/{id}/metadata")
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<Metadata> getMetadata(@PathParam("id") String orgId);
|
ListenableFuture<Metadata> getMetadata(@PathParam("id") String orgId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see OrgClient#getMetadataEntry
|
* @see OrgClient#getMetadata(ReferenceType)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("/metadata")
|
||||||
|
@Consumes
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
|
ListenableFuture<Metadata> getMetadata(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see OrgClient#getMetadataEntry(String, String)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/org/{id}/metadata/{key}")
|
@Path("/org/{id}/metadata/{key}")
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<MetadataEntry> getMetadataEntry(@PathParam("id") String orgId, @PathParam("key") String key);
|
ListenableFuture<MetadataEntry> getMetadataEntry(@PathParam("id") String orgId, @PathParam("key") String key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see OrgClient#getMetadataEntry(ReferenceType, String)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("/metadata/{key}")
|
||||||
|
@Consumes
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
|
ListenableFuture<MetadataEntry> getMetadataEntry(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> orgRef, @PathParam("key") String key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ 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.Org;
|
import org.jclouds.vcloud.director.v1_5.domain.Org;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
|
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides synchronous access to Org.
|
* Provides synchronous access to Org.
|
||||||
* <p/>
|
* <p/>
|
||||||
*
|
*
|
||||||
* @see OrgAsyncClient
|
* @see OrgAsyncClient
|
||||||
* @see <a href= "http://support.theenterprisecloud.com/kb/default.asp?id=984&Lang=1&SID=" />
|
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 180, timeUnit = TimeUnit.SECONDS)
|
||||||
|
@ -51,6 +51,8 @@ public interface OrgClient {
|
||||||
*/
|
*/
|
||||||
Org getOrg(String orgId);
|
Org getOrg(String orgId);
|
||||||
|
|
||||||
|
Org getOrg(ReferenceType<?> orgRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an list of the organization's metadata
|
* Retrieves an list of the organization's metadata
|
||||||
*
|
*
|
||||||
|
@ -58,10 +60,14 @@ public interface OrgClient {
|
||||||
*/
|
*/
|
||||||
Metadata getMetadata(String orgId);
|
Metadata getMetadata(String orgId);
|
||||||
|
|
||||||
|
Metadata getMetadata(ReferenceType<?> orgRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a metadata
|
* Retrieves a metadata
|
||||||
*
|
*
|
||||||
* @return the metadata or null if not found
|
* @return the metadata or null if not found
|
||||||
*/
|
*/
|
||||||
MetadataEntry getMetadataEntry(String orgId, String key);
|
MetadataEntry getMetadataEntry(String orgId, String key);
|
||||||
|
|
||||||
|
MetadataEntry getMetadataEntry(ReferenceType<?> orgRef, String key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.director.v1_5.features;
|
package org.jclouds.vcloud.director.v1_5.features;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
|
@ -30,10 +28,12 @@ import org.jclouds.rest.annotations.EndpointParam;
|
||||||
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.vcloud.director.v1_5.domain.ReferenceType;
|
||||||
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.TasksList;
|
import org.jclouds.vcloud.director.v1_5.domain.TasksList;
|
||||||
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
|
import org.jclouds.vcloud.director.v1_5.filters.AddVCloudAuthorizationToRequest;
|
||||||
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xxOrNull;
|
import org.jclouds.vcloud.director.v1_5.functions.ReferenceToEndpoint;
|
||||||
|
import org.jclouds.vcloud.director.v1_5.functions.ThrowVCloudErrorOn4xx;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
@ -45,23 +45,43 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
public interface TaskAsyncClient {
|
public interface TaskAsyncClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TaskClient#getTaskList(URI)
|
* @see TaskClient#getTaskList(String)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Path("/tasksList/{id}")
|
@Path("/tasksList/{id}")
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<TasksList> getTaskList(@PathParam("id") String orgId);
|
ListenableFuture<TasksList> getTaskList(@PathParam("id") String orgId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TaskClient#getTask(URI)
|
* @see TaskClient#getTask(String id)
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("/task/{id}")
|
||||||
|
@Consumes
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
|
ListenableFuture<Task> getTask(@PathParam("id") String taskId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see TaskClient#getTask(ReferenceType<?>)
|
||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
ListenableFuture<Task> getTask(@EndpointParam URI taskHref);
|
ListenableFuture<Task> getTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> taskRef);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see TaskClient#cancelTask(URI)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/task/{id}/action/cancel")
|
||||||
|
@Consumes
|
||||||
|
@JAXBResponseParser
|
||||||
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
|
ListenableFuture<Void> cancelTask(@PathParam("id") String taskId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see TaskClient#cancelTask(URI)
|
* @see TaskClient#cancelTask(URI)
|
||||||
|
@ -70,6 +90,6 @@ public interface TaskAsyncClient {
|
||||||
@Path("/action/cancel")
|
@Path("/action/cancel")
|
||||||
@Consumes
|
@Consumes
|
||||||
@JAXBResponseParser
|
@JAXBResponseParser
|
||||||
@ExceptionParser(ThrowVCloudErrorOn4xxOrNull.class)
|
@ExceptionParser(ThrowVCloudErrorOn4xx.class)
|
||||||
void cancelTask(@EndpointParam URI taskHref);
|
ListenableFuture<Void> cancelTask(@EndpointParam(parser = ReferenceToEndpoint.class) ReferenceType<?> taskRef);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.vcloud.director.v1_5.features;
|
package org.jclouds.vcloud.director.v1_5.features;
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
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.ReferenceType;
|
||||||
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.TasksList;
|
import org.jclouds.vcloud.director.v1_5.domain.TasksList;
|
||||||
|
|
||||||
|
@ -47,10 +47,14 @@ public interface TaskClient {
|
||||||
*
|
*
|
||||||
* @return the task or null if not found
|
* @return the task or null if not found
|
||||||
*/
|
*/
|
||||||
Task getTask(URI taskHref);
|
Task getTask(String taskId);
|
||||||
|
|
||||||
|
Task getTask(ReferenceType<?> taskRef);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels a task.
|
* Cancels a task.
|
||||||
*/
|
*/
|
||||||
void cancelTask(URI taskHref);
|
void cancelTask(String taskId);
|
||||||
|
|
||||||
|
void cancelTask(ReferenceType<?> taskRef);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
* 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.net.URI;
|
||||||
|
|
||||||
|
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author grkvlt@apache.org
|
||||||
|
*/
|
||||||
|
public class ReferenceToEndpoint implements Function<Object, URI> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URI apply(Object input) {
|
||||||
|
Preconditions.checkNotNull(input);
|
||||||
|
Preconditions.checkArgument(input instanceof ReferenceType<?>);
|
||||||
|
ReferenceType<?> reference = (ReferenceType<?>) input;
|
||||||
|
return reference.getURI();
|
||||||
|
};
|
||||||
|
}
|
|
@ -37,16 +37,15 @@ import com.google.common.collect.Iterables;
|
||||||
* @author grkvlt@apache.org
|
* @author grkvlt@apache.org
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class ThrowVCloudErrorOn4xxOrNull implements Function<Exception, Object> {
|
public class ThrowVCloudErrorOn4xx implements Function<Exception, Object> {
|
||||||
@Inject
|
@Inject
|
||||||
private ThrowVCloudErrorOn4xxOrNull() { }
|
private ThrowVCloudErrorOn4xx() { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object apply(Exception from) {
|
public Object apply(Exception from) {
|
||||||
Iterable<HttpResponseException> throwables = Iterables.filter(Throwables.getCausalChain(from), HttpResponseException.class);
|
Iterable<HttpResponseException> throwables = Iterables.filter(Throwables.getCausalChain(from), HttpResponseException.class);
|
||||||
if (Iterables.size(throwables) == 1) {
|
HttpResponseException exception = Iterables.getFirst(throwables, null);
|
||||||
HttpResponseException exception = Iterables.getOnlyElement(throwables);
|
if (exception != null && exception.getResponse().getStatusCode() >= 400 && exception.getResponse().getStatusCode() < 500) {
|
||||||
if (exception.getResponse().getStatusCode() >= 400 && exception.getResponse().getStatusCode() < 500) {
|
|
||||||
try {
|
try {
|
||||||
Error error = JAXB.unmarshal(InputSuppliers.of(exception.getContent()).getInput(), Error.class);
|
Error error = JAXB.unmarshal(InputSuppliers.of(exception.getContent()).getInput(), Error.class);
|
||||||
throw new VCloudDirectorException(error);
|
throw new VCloudDirectorException(error);
|
||||||
|
@ -54,8 +53,6 @@ public class ThrowVCloudErrorOn4xxOrNull implements Function<Exception, Object>
|
||||||
Throwables.propagate(e);
|
Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throw Throwables.propagate(from);
|
||||||
}
|
}
|
||||||
return null; // TODO is this correct?
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -35,6 +35,8 @@ import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
|
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorRestClientExpectTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows us to test a client via its side effects.
|
* Allows us to test a client via its side effects.
|
||||||
*
|
*
|
||||||
|
@ -42,12 +44,12 @@ import org.testng.annotations.Test;
|
||||||
*/
|
*/
|
||||||
@Test(groups = "unit", singleThreaded = true, testName = "OrgClientExpectTest")
|
@Test(groups = "unit", singleThreaded = true, testName = "OrgClientExpectTest")
|
||||||
public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
|
public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWhenResponseIs2xxLoginReturnsValidOrgList() {
|
public void testWhenResponseIs2xxLoginReturnsValidOrgList() {
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
getStandardRequest("GET", "/org"),
|
getStandardRequest("GET", "/org"),
|
||||||
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORGLIST_XML+";version=1.5"));
|
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
|
||||||
|
|
||||||
OrgList expected = OrgList.builder()
|
OrgList expected = OrgList.builder()
|
||||||
.org(Reference.builder()
|
.org(Reference.builder()
|
||||||
|
@ -61,12 +63,15 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWhenResponseIs2xxLoginReturnsValidOrg() {
|
public void testWhenResponseIs2xxLoginReturnsValidOrgFromListByReference() {
|
||||||
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
|
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"),
|
getStandardRequest("GET", "/org"),
|
||||||
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG_XML+";version=1.5"));
|
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
|
||||||
|
Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs());
|
||||||
|
|
||||||
|
client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
getStandardRequest("GET", org.getHref()),
|
||||||
|
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
|
||||||
|
|
||||||
Org expected = Org
|
Org expected = Org
|
||||||
.builder()
|
.builder()
|
||||||
|
@ -74,7 +79,130 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.description("")
|
.description("")
|
||||||
.fullName("JClouds")
|
.fullName("JClouds")
|
||||||
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
|
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
|
||||||
.type(VCloudDirectorMediaType.ORG_XML)
|
.type("application/vnd.vmware.vcloud.org+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.vdc+xml")
|
||||||
|
.name("Cluster01-JClouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.tasksList+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.catalog+xml")
|
||||||
|
.name("Public")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.controlAccess+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
|
||||||
|
.name("ilsolation01-Jclouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
|
||||||
|
.name("internet01-Jclouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.metadata+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(client.getOrgClient().getOrg(org), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWhenResponseIs2xxLoginReturnsValidOrgFromListById() {
|
||||||
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
getStandardRequest("GET", "/org"),
|
||||||
|
getStandardPayloadResponse("/org/orglist.xml", VCloudDirectorMediaType.ORG_LIST));
|
||||||
|
Reference org = Iterables.getOnlyElement(client.getOrgClient().getOrgList().getOrgs());
|
||||||
|
client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
getStandardRequest("GET", "/org/" + org.getUuid()),
|
||||||
|
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
|
||||||
|
|
||||||
|
Org expected = Org
|
||||||
|
.builder()
|
||||||
|
.name("JClouds")
|
||||||
|
.description("")
|
||||||
|
.fullName("JClouds")
|
||||||
|
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
|
||||||
|
.type("application/vnd.vmware.vcloud.org+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.vdc+xml")
|
||||||
|
.name("Cluster01-JClouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/vdc/d16d333b-e3c0-4176-845d-a5ee6392df07"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.tasksList+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.catalog+xml")
|
||||||
|
.name("Public")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.controlAccess+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/catalog/9e08c2f6-077a-42ce-bece-d5332e2ebb5c/controlAccess/"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
|
||||||
|
.name("ilsolation01-Jclouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/f3ba8256-6f48-4512-aad6-600e85b4dc38"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.orgNetwork+xml")
|
||||||
|
.name("internet01-Jclouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/network/55a677cf-ab3f-48ae-b880-fab90421980c"))
|
||||||
|
.build())
|
||||||
|
.link(Link.builder()
|
||||||
|
.rel("down")
|
||||||
|
.type("application/vnd.vmware.vcloud.metadata+xml")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"))
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(org.getUuid(), "6f312e42-cd2b-488d-a2bb-97519cd57ed0");
|
||||||
|
assertEquals(client.getOrgClient().getOrg(org.getUuid()), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWhenResponseIs2xxLoginReturnsValidOrg() {
|
||||||
|
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
|
||||||
|
|
||||||
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
|
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"),
|
||||||
|
getStandardPayloadResponse("/org/org.xml", VCloudDirectorMediaType.ORG));
|
||||||
|
|
||||||
|
Org expected = Org
|
||||||
|
.builder()
|
||||||
|
.name("JClouds")
|
||||||
|
.description("")
|
||||||
|
.fullName("JClouds")
|
||||||
|
.id("urn:vcloud:org:6f312e42-cd2b-488d-a2bb-97519cd57ed0")
|
||||||
|
.type("application/vnd.vmware.vcloud.org+xml")
|
||||||
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
.link(Link.builder()
|
.link(Link.builder()
|
||||||
.rel("down")
|
.rel("down")
|
||||||
|
@ -127,7 +255,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
getStandardRequest("GET", "/org/NOTAUUID"),
|
getStandardRequest("GET", "/org/NOTAUUID"),
|
||||||
getStandardPayloadResponse(400, "/org/error400.xml", VCloudDirectorMediaType.ERROR_XML));
|
getStandardPayloadResponse(400, "/org/error400.xml", VCloudDirectorMediaType.ERROR));
|
||||||
|
|
||||||
Error expected = Error.builder()
|
Error expected = Error.builder()
|
||||||
.message("validation error on field 'id': String value has invalid format or length")
|
.message("validation error on field 'id': String value has invalid format or length")
|
||||||
|
@ -152,10 +280,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"),
|
getStandardRequest("GET", "/org/9e08c2f6-077a-42ce-bece-d5332e2ebb5c"),
|
||||||
getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR_XML));
|
getStandardPayloadResponse(403, "/org/error403-catalog.xml", VCloudDirectorMediaType.ERROR));
|
||||||
|
|
||||||
Error expected = Error.builder()
|
Error expected = Error.builder()
|
||||||
.message("No access to entity "com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c".")
|
.message("No access to entity \"com.vmware.vcloud.entity.org:9e08c2f6-077a-42ce-bece-d5332e2ebb5c\".")
|
||||||
.majorErrorCode(403)
|
.majorErrorCode(403)
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
||||||
.build();
|
.build();
|
||||||
|
@ -177,10 +305,10 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
|
getStandardRequest("GET", "/org/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"),
|
||||||
getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR_XML));
|
getStandardPayloadResponse(403, "/org/error403-fake.xml", VCloudDirectorMediaType.ERROR));
|
||||||
|
|
||||||
Error expected = Error.builder()
|
Error expected = Error.builder()
|
||||||
.message("No access to entity "com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee".")
|
.message("No access to entity \"com.vmware.vcloud.entity.org:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee\".")
|
||||||
.majorErrorCode(403)
|
.majorErrorCode(403)
|
||||||
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
.minorErrorCode("ACCESS_TO_RESOURCE_IS_FORBIDDEN")
|
||||||
.build();
|
.build();
|
||||||
|
@ -202,7 +330,7 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"),
|
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata"),
|
||||||
getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA_XML+";version=1.5"));
|
getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA));
|
||||||
|
|
||||||
Metadata expected = Metadata.builder()
|
Metadata expected = Metadata.builder()
|
||||||
.type("application/vnd.vmware.vcloud.metadata+xml")
|
.type("application/vnd.vmware.vcloud.metadata+xml")
|
||||||
|
@ -223,8 +351,8 @@ public class OrgClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
|
URI orgRef = URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0");
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse,
|
||||||
getStandardRequest("GET", "i/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"),
|
getStandardRequest("GET", "/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0/metadata/KEY"),
|
||||||
getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATAENTRY_XML+";version=1.5"));
|
getStandardPayloadResponse("/org/metadata.xml", VCloudDirectorMediaType.METADATA_ENTRY));
|
||||||
|
|
||||||
MetadataEntry expected = MetadataEntry.builder()
|
MetadataEntry expected = MetadataEntry.builder()
|
||||||
.key("KEY")
|
.key("KEY")
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTaskListForValidOrg() {
|
public void testTaskListForValidOrg() {
|
||||||
HttpRequest orgListRequest = HttpRequest.builder()
|
HttpRequest taskRequest = HttpRequest.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint(URI.create(endpoint + "/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
.endpoint(URI.create(endpoint + "/tasksList/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
|
@ -55,12 +55,12 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse orgListResponse = HttpResponse.builder()
|
HttpResponse taskResponse = HttpResponse.builder()
|
||||||
.statusCode(200)
|
.statusCode(200)
|
||||||
.payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKSLIST_XML + ";version=1.5"))
|
.payload(payloadFromResourceWithContentType("/task/taskslist.xml", VCloudDirectorMediaType.TASKS_LIST.getMediaType() + ";version=1.5"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse);
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
|
||||||
|
|
||||||
String orgId = getUuidFromReference.apply(Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build());
|
String orgId = getUuidFromReference.apply(Reference.builder().href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0")).build());
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTaskListForInvalidOrgId() {
|
public void testTaskListForInvalidOrgId() {
|
||||||
HttpRequest orgListRequest = HttpRequest.builder()
|
HttpRequest taskRequest = HttpRequest.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint(URI.create(endpoint + "/tasksList/NOTAUUID"))
|
.endpoint(URI.create(endpoint + "/tasksList/NOTAUUID"))
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
|
@ -133,12 +133,12 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse orgListResponse = HttpResponse.builder()
|
HttpResponse taskResponse = HttpResponse.builder()
|
||||||
.statusCode(400)
|
.statusCode(400)
|
||||||
.payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR_XML + ";version=1.5"))
|
.payload(payloadFromResourceWithContentType("/task/error400.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse);
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
|
||||||
|
|
||||||
String orgId = "NOTAUUID";
|
String orgId = "NOTAUUID";
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTaskListForNotFoundOrgId() {
|
public void testTaskListForNotFoundOrgId() {
|
||||||
HttpRequest orgListRequest = HttpRequest.builder()
|
HttpRequest taskRequest = HttpRequest.builder()
|
||||||
.method("GET")
|
.method("GET")
|
||||||
.endpoint(URI.create(endpoint + "/tasksList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
|
.endpoint(URI.create(endpoint + "/tasksList/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"))
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
|
@ -168,12 +168,12 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
HttpResponse orgListResponse = HttpResponse.builder()
|
HttpResponse taskResponse = HttpResponse.builder()
|
||||||
.statusCode(403)
|
.statusCode(403)
|
||||||
.payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR_XML + ";version=1.5"))
|
.payload(payloadFromResourceWithContentType("/task/error403.xml", VCloudDirectorMediaType.ERROR.getMediaType() + ";version=1.5"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, orgListRequest, orgListResponse);
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
|
||||||
|
|
||||||
String orgId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
String orgId = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
|
||||||
|
|
||||||
|
@ -192,4 +192,158 @@ public class TaskClientExpectTest extends BaseVCloudDirectorRestClientExpectTest
|
||||||
fail("Should have thrown a VCloudDirectorException");
|
fail("Should have thrown a VCloudDirectorException");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTaskForTaskId() {
|
||||||
|
HttpRequest taskRequest = HttpRequest.builder()
|
||||||
|
.method("GET")
|
||||||
|
.endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
|
||||||
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "*/*")
|
||||||
|
.put("x-vcloud-authorization", token)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse taskResponse = HttpResponse.builder()
|
||||||
|
.statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
|
||||||
|
|
||||||
|
String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b";
|
||||||
|
|
||||||
|
Task expected = Task.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.task+xml")
|
||||||
|
.name("task")
|
||||||
|
.id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
|
||||||
|
.status("success")
|
||||||
|
.operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)")
|
||||||
|
.operationName("catalogCreateCatalog")
|
||||||
|
.startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00"))
|
||||||
|
.endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00"))
|
||||||
|
.expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00"))
|
||||||
|
.owner(Reference.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.catalog+xml")
|
||||||
|
.name("QunyingTestCatalog")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
|
||||||
|
.build())
|
||||||
|
.user(Reference.builder()
|
||||||
|
.type("application/vnd.vmware.admin.user+xml")
|
||||||
|
.name("JClouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.build())
|
||||||
|
.org(Reference.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.org+xml")
|
||||||
|
.name("JClouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(client.getTaskClient().getTask(taskId), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTaskForTaskRef() {
|
||||||
|
HttpRequest taskRequest = HttpRequest.builder()
|
||||||
|
.method("GET")
|
||||||
|
.endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
|
||||||
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "*/*")
|
||||||
|
.put("x-vcloud-authorization", token)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse taskResponse = HttpResponse.builder()
|
||||||
|
.statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/task/task.xml", VCloudDirectorMediaType.TASK.getMediaType() + ";version=1.5"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
|
||||||
|
|
||||||
|
Reference taskRef = Reference.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.task+xml")
|
||||||
|
.name("task")
|
||||||
|
.href(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Task expected = Task.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.task+xml")
|
||||||
|
.name("task")
|
||||||
|
.id("urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
|
||||||
|
.status("success")
|
||||||
|
.operation("Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)")
|
||||||
|
.operationName("catalogCreateCatalog")
|
||||||
|
.startTime(dateService.iso8601DateParse("2012-02-07T00:16:28.450-05:00"))
|
||||||
|
.endTime(dateService.iso8601DateParse("2012-02-07T00:16:28.867-05:00"))
|
||||||
|
.expiryTime(dateService.iso8601DateParse("2012-05-07T00:16:28.450-04:00"))
|
||||||
|
.owner(Reference.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.catalog+xml")
|
||||||
|
.name("QunyingTestCatalog")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"))
|
||||||
|
.build())
|
||||||
|
.user(Reference.builder()
|
||||||
|
.type("application/vnd.vmware.admin.user+xml")
|
||||||
|
.name("JClouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.build())
|
||||||
|
.org(Reference.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.org+xml")
|
||||||
|
.name("JClouds")
|
||||||
|
.href(URI.create("https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"))
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(client.getTaskClient().getTask(taskRef), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCancelTaskByTaskId() {
|
||||||
|
HttpRequest taskRequest = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel"))
|
||||||
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "*/*")
|
||||||
|
.put("x-vcloud-authorization", token)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse taskResponse = HttpResponse.builder()
|
||||||
|
.statusCode(200)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
|
||||||
|
|
||||||
|
String taskId = "5fcd2af3-d0ec-45ce-9451-8c585a2c766b";
|
||||||
|
|
||||||
|
client.getTaskClient().cancelTask(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCancelTaskByTaskRef() {
|
||||||
|
HttpRequest taskRequest = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b/action/cancel"))
|
||||||
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
|
.put("Accept", "*/*")
|
||||||
|
.put("x-vcloud-authorization", token)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpResponse taskResponse = HttpResponse.builder()
|
||||||
|
.statusCode(200)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
VCloudDirectorClient client = requestsSendResponses(loginRequest, sessionResponse, taskRequest, taskResponse);
|
||||||
|
|
||||||
|
Reference taskRef = Reference.builder()
|
||||||
|
.type("application/vnd.vmware.vcloud.task+xml")
|
||||||
|
.name("task")
|
||||||
|
.href(URI.create(endpoint + "/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
client.getTaskClient().cancelTask(taskRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.jclouds.rest.BaseRestClientExpectTest;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
import org.jclouds.vcloud.director.v1_5.domain.ReferenceType;
|
||||||
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.BeforeTest;
|
import org.testng.annotations.BeforeTest;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -50,7 +51,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
|
||||||
|
|
||||||
protected DateService dateService;
|
protected DateService dateService;
|
||||||
|
|
||||||
@BeforeTest
|
@BeforeClass
|
||||||
protected void setUpInjector() {
|
protected void setUpInjector() {
|
||||||
dateService = Guice.createInjector().getInstance(DateService.class);
|
dateService = Guice.createInjector().getInstance(DateService.class);
|
||||||
assert dateService != null;
|
assert dateService != null;
|
||||||
|
@ -79,7 +80,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
|
||||||
.put("x-vcloud-authorization", token)
|
.put("x-vcloud-authorization", token)
|
||||||
.put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token))
|
.put("Set-Cookie", String.format("vcloud-token=%s; Secure; Path=/", token))
|
||||||
.build())
|
.build())
|
||||||
.payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML + ";version=1.5"))
|
.payload(payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType() + ";version=1.5"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public BaseVCloudDirectorRestClientExpectTest() {
|
public BaseVCloudDirectorRestClientExpectTest() {
|
||||||
|
@ -96,24 +97,24 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
|
||||||
return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY);
|
return getStandardRequest(method, uri, VCloudDirectorMediaType.ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpRequest getStandardRequest(String method, URI uri, String mediaType) {
|
protected HttpRequest getStandardRequest(String method, URI uri, VCloudDirectorMediaType mediaType) {
|
||||||
return HttpRequest.builder()
|
return HttpRequest.builder()
|
||||||
.method(method)
|
.method(method)
|
||||||
.endpoint(uri)
|
.endpoint(uri)
|
||||||
.headers(ImmutableMultimap.<String, String> builder()
|
.headers(ImmutableMultimap.<String, String> builder()
|
||||||
.put("Accept", mediaType)
|
.put("Accept", mediaType.getMediaType())
|
||||||
.put("x-vcloud-authorization", token)
|
.put("x-vcloud-authorization", token)
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpResponse getStandardPayloadResponse(String relativeFilePath, String mediaType) {
|
protected HttpResponse getStandardPayloadResponse(String relativeFilePath, VCloudDirectorMediaType mediaType) {
|
||||||
return getStandardPayloadResponse(200, relativeFilePath, mediaType);
|
return getStandardPayloadResponse(200, relativeFilePath, mediaType);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, String mediaType) {
|
protected HttpResponse getStandardPayloadResponse(int statusCode, String relativeFilePath, VCloudDirectorMediaType mediaType) {
|
||||||
return HttpResponse.builder()
|
return HttpResponse.builder()
|
||||||
.statusCode(statusCode)
|
.statusCode(statusCode)
|
||||||
.payload(payloadFromResourceWithContentType(relativeFilePath, mediaType+";version=1.5")).build();
|
.payload(payloadFromResourceWithContentType(relativeFilePath, mediaType.getMediaType()+";version=1.5")).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionCli
|
||||||
ImmutableMultimap.<String, String> builder().put("x-vcloud-authorization", token).put("Set-Cookie",
|
ImmutableMultimap.<String, String> builder().put("x-vcloud-authorization", token).put("Set-Cookie",
|
||||||
String.format("vcloud-token=%s; Secure; Path=/", token)).build())
|
String.format("vcloud-token=%s; Secure; Path=/", token)).build())
|
||||||
.payload(
|
.payload(
|
||||||
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML
|
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType()
|
||||||
+ ";version=1.5")).build()
|
+ ";version=1.5")).build()
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -97,7 +97,7 @@ public class SessionClientExpectTest extends BaseRestClientExpectTest<SessionCli
|
||||||
|
|
||||||
HttpResponse.builder().statusCode(200)
|
HttpResponse.builder().statusCode(200)
|
||||||
.payload(
|
.payload(
|
||||||
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION_XML
|
payloadFromResourceWithContentType("/session.xml", VCloudDirectorMediaType.SESSION.getMediaType()
|
||||||
+ ";version=1.5")).build()
|
+ ";version=1.5")).build()
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Task xmlns="http://www.vmware.com/vcloud/v1.5" status="success" startTime="2012-02-07T00:16:28.450-05:00" operationName="catalogCreateCatalog" operation="Created Catalog QunyingTestCatalog(7212e451-76e1-4631-b2de-ba1dfd8080e4)" expiryTime="2012-05-07T00:16:28.450-04:00" endTime="2012-02-07T00:16:28.867-05:00" name="task" id="urn:vcloud:task:5fcd2af3-d0ec-45ce-9451-8c585a2c766b" type="application/vnd.vmware.vcloud.task+xml" href="https://vcloudbeta.bluelock.com/api/task/5fcd2af3-d0ec-45ce-9451-8c585a2c766b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://vcloudbeta.bluelock.com/api/v1.5/schema/master.xsd">
|
||||||
|
<Owner type="application/vnd.vmware.vcloud.catalog+xml" name="QunyingTestCatalog" href="https://vcloudbeta.bluelock.com/api/catalog/7212e451-76e1-4631-b2de-ba1dfd8080e4"/>
|
||||||
|
<User type="application/vnd.vmware.admin.user+xml" name="qunying.huang@enstratus.com" href="https://vcloudbeta.bluelock.com/api/admin/user/967d317c-4273-4a95-b8a4-bf63b78e9c69"/>
|
||||||
|
<Organization type="application/vnd.vmware.vcloud.org+xml" name="JClouds" href="https://vcloudbeta.bluelock.com/api/org/6f312e42-cd2b-488d-a2bb-97519cd57ed0"/>
|
||||||
|
</Task>
|
Loading…
Reference in New Issue