Merge branch 'master' of github.com:jclouds/jclouds

This commit is contained in:
andreaturli 2011-10-15 01:00:42 +01:00
commit 362d79d879
12 changed files with 468 additions and 227 deletions

View File

@ -133,7 +133,7 @@ public class AMIClientLiveTest {
} }
public void testDescribeImagesCC() { public void testDescribeImagesCC() {
Set<? extends Image> twoResults = client.describeImagesInRegion(Region.US_EAST_1, filters( Set<? extends Image> ccResults = client.describeImagesInRegion(Region.US_EAST_1, filters(
ImmutableMultimap.<String, String> builder()// ImmutableMultimap.<String, String> builder()//
.put("virtualization-type", "hvm")// .put("virtualization-type", "hvm")//
.put("architecture", "x86_64")// .put("architecture", "x86_64")//
@ -143,8 +143,8 @@ public class AMIClientLiveTest {
.put("image-type", "machine")// .put("image-type", "machine")//
.put("root-device-type", "ebs")// .put("root-device-type", "ebs")//
.build()).ownedBy("137112412989", "099720109477")); .build()).ownedBy("137112412989", "099720109477"));
assertNotNull(twoResults); assertNotNull(ccResults);
assertEquals(twoResults.size(), 35); assert (ccResults.size() >= 34) : ccResults;
} }
@Test(enabled = false) @Test(enabled = false)

View File

@ -54,27 +54,35 @@ public class BillingToken implements Comparable<BillingToken> {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object obj) {
if (this == o) return true; if (this == obj)
if (o == null || getClass() != o.getClass()) return false; return true;
if (obj == null)
BillingToken that = (BillingToken) o; return false;
if (getClass() != obj.getClass())
if (id != that.id) return false; return false;
if (Double.compare(that.price, price) != 0) return false; BillingToken other = (BillingToken) obj;
if (!name.equals(that.name)) return false; if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (Double.doubleToLongBits(price) != Double.doubleToLongBits(other.price))
return false;
return true; return true;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result; final int prime = 31;
int result = 1;
result = prime * result + (int) (id ^ (id >>> 32));
result = prime * result + ((name == null) ? 0 : name.hashCode());
long temp; long temp;
result = (int) (id ^ (id >>> 32)); temp = Double.doubleToLongBits(price);
result = 31 * result + name.hashCode(); result = prime * result + (int) (temp ^ (temp >>> 32));
temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L;
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result; return result;
} }
@ -85,10 +93,6 @@ public class BillingToken implements Comparable<BillingToken> {
@Override @Override
public String toString() { public String toString() {
return "BillingToken{" + return "BillingToken{" + "id=" + id + ", name='" + name + '\'' + ", price=" + price + '}';
"id=" + id +
", name='" + name + '\'' +
", price=" + price +
'}';
} }
} }

View File

@ -36,29 +36,25 @@ import org.jclouds.http.options.BaseHttpRequestOptions;
public class GetImageListOptions extends BaseHttpRequestOptions { public class GetImageListOptions extends BaseHttpRequestOptions {
public GetImageListOptions setType(ServerImageType imageType) { public GetImageListOptions setType(ServerImageType imageType) {
checkState(!queryParameters.containsKey(IMAGE_TYPE_KEY), checkState(!queryParameters.containsKey(IMAGE_TYPE_KEY), "Can't have duplicate image type restrictions");
"Can't have duplicate image type restrictions");
queryParameters.put(IMAGE_TYPE_KEY, imageType.toString()); queryParameters.put(IMAGE_TYPE_KEY, imageType.toString());
return this; return this;
} }
public GetImageListOptions setState(ServerImageState imageState) { public GetImageListOptions setState(ServerImageState imageState) {
checkState(!queryParameters.containsKey(IMAGE_STATE_KEY), checkState(!queryParameters.containsKey(IMAGE_STATE_KEY), "Can't have duplicate image state restrictions");
"Can't have duplicate image state restrictions");
queryParameters.put(IMAGE_STATE_KEY, imageState.toString()); queryParameters.put(IMAGE_STATE_KEY, imageState.toString());
return this; return this;
} }
public GetImageListOptions onlyPublic() { public GetImageListOptions onlyPublic() {
checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), "Can't have duplicate image visibility restrictions");
"Can't have duplicate image visibility restrictions");
queryParameters.put(IS_PUBLIC_KEY, "true"); queryParameters.put(IS_PUBLIC_KEY, "true");
return this; return this;
} }
public GetImageListOptions onlyPrivate() { public GetImageListOptions onlyPrivate() {
checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), "Can't have duplicate image visibility restrictions");
"Can't have duplicate image visibility restrictions");
queryParameters.put(IS_PUBLIC_KEY, "false"); queryParameters.put(IS_PUBLIC_KEY, "false");
return this; return this;
} }
@ -70,26 +66,28 @@ public class GetImageListOptions extends BaseHttpRequestOptions {
} }
public GetImageListOptions maxItemsNumber(Integer maxNumber) { public GetImageListOptions maxItemsNumber(Integer maxNumber) {
checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items");
"Can't have duplicate parameter of max returned items");
queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString()); queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString());
return this; return this;
} }
public static class Builder { public static class Builder {
public GetImageListOptions inDatacenter(String datacenterId) { public static GetImageListOptions maxItems(int maxNumber) {
GetImageListOptions getImageListOptions = new GetImageListOptions(); return new GetImageListOptions().maxItemsNumber(maxNumber);
return getImageListOptions.inDatacenter(checkNotNull(datacenterId));
} }
public GetImageListOptions publicWebServers() { public static GetImageListOptions inDatacenter(String datacenterId) {
return new GetImageListOptions().inDatacenter(checkNotNull(datacenterId, "datacenterId"));
}
public static GetImageListOptions publicWebServers() {
return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType( return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType(
ServerImageType.WEB_APPLICATION_SERVER).onlyPublic(); ServerImageType.WEB_APPLICATION_SERVER).onlyPublic();
} }
public GetImageListOptions publicDatabaseServers() { public static GetImageListOptions publicDatabaseServers() {
return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType( return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType(ServerImageType.DATABASE_SERVER)
ServerImageType.DATABASE_SERVER).onlyPublic(); .onlyPublic();
} }
} }

View File

@ -18,14 +18,20 @@
*/ */
package org.jclouds.gogrid.options; package org.jclouds.gogrid.options;
import org.jclouds.gogrid.domain.JobState; import static com.google.common.base.Preconditions.checkState;
import org.jclouds.gogrid.domain.ObjectType; import static org.jclouds.gogrid.reference.GoGridQueryParams.END_DATE_KEY;
import org.jclouds.http.options.BaseHttpRequestOptions; import static org.jclouds.gogrid.reference.GoGridQueryParams.JOB_OBJECT_TYPE_KEY;
import static org.jclouds.gogrid.reference.GoGridQueryParams.JOB_STATE_KEY;
import static org.jclouds.gogrid.reference.GoGridQueryParams.MAX_NUMBER_KEY;
import static org.jclouds.gogrid.reference.GoGridQueryParams.OBJECT_KEY;
import static org.jclouds.gogrid.reference.GoGridQueryParams.OWNER_KEY;
import static org.jclouds.gogrid.reference.GoGridQueryParams.START_DATE_KEY;
import java.util.Date; import java.util.Date;
import static com.google.common.base.Preconditions.checkState; import org.jclouds.gogrid.domain.JobState;
import static org.jclouds.gogrid.reference.GoGridQueryParams.*; import org.jclouds.gogrid.domain.ObjectType;
import org.jclouds.http.options.BaseHttpRequestOptions;
/** /**
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
@ -76,13 +82,19 @@ public class GetJobListOptions extends BaseHttpRequestOptions {
return this; return this;
} }
public GetJobListOptions latestJobForObjectByName(String serverName) {
return maxItemsNumber(1).onlyForObjectName(serverName);
}
/* /*
* This method is intended for testing * This method is intended for testing
*/ */
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o)
if (o == null || getClass() != o.getClass()) return false; return true;
if (o == null || getClass() != o.getClass())
return false;
GetJobListOptions options = (GetJobListOptions) o; GetJobListOptions options = (GetJobListOptions) o;
@ -90,14 +102,17 @@ public class GetJobListOptions extends BaseHttpRequestOptions {
} }
public static class Builder { public static class Builder {
public GetJobListOptions create() {
return new GetJobListOptions(); public static GetJobListOptions maxItems(int maxNumber) {
return new GetJobListOptions().maxItemsNumber(maxNumber);
} }
public GetJobListOptions latestJobForObjectByName(String serverName) { public static GetJobListOptions startDate(Date startDate){
return new GetJobListOptions(). return new GetJobListOptions().withStartDate(startDate);
maxItemsNumber(1). }
onlyForObjectName(serverName);
public static GetJobListOptions latestJobForObjectByName(String serverName) {
return new GetJobListOptions().latestJobForObjectByName(serverName);
} }
} }

View File

@ -18,20 +18,21 @@
*/ */
package org.jclouds.gogrid.predicates; package org.jclouds.gogrid.predicates;
import com.google.common.base.Predicate; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Iterables; import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName;
import com.google.inject.Inject;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.JobState;
import org.jclouds.gogrid.domain.LoadBalancer;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.jclouds.gogrid.services.GridJobClient;
import org.jclouds.logging.Logger;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Singleton; import javax.inject.Singleton;
import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.JobState;
import org.jclouds.gogrid.domain.LoadBalancer;
import org.jclouds.gogrid.services.GridJobClient;
import org.jclouds.logging.Logger;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
/** /**
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
@ -53,9 +54,7 @@ public class LoadBalancerLatestJobCompleted implements Predicate<LoadBalancer> {
public boolean apply(LoadBalancer loadBalancer) { public boolean apply(LoadBalancer loadBalancer) {
checkNotNull(loadBalancer, "Load balancer must be a valid instance"); checkNotNull(loadBalancer, "Load balancer must be a valid instance");
checkNotNull(loadBalancer.getName(), "Load balancer must be a valid name"); checkNotNull(loadBalancer.getName(), "Load balancer must be a valid name");
GetJobListOptions jobOptions = new GetJobListOptions.Builder(). Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(latestJobForObjectByName(loadBalancer.getName())));
latestJobForObjectByName(loadBalancer.getName());
Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions));
return JobState.SUCCEEDED.equals(latestJob.getCurrentState()); return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
} }
} }

View File

@ -18,25 +18,26 @@
*/ */
package org.jclouds.gogrid.predicates; package org.jclouds.gogrid.predicates;
import com.google.common.base.Predicate; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.Iterables; import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName;
import com.google.inject.Inject;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.JobState;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.jclouds.gogrid.services.GridJobClient;
import org.jclouds.logging.Logger;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Singleton; import javax.inject.Singleton;
import static com.google.common.base.Preconditions.checkNotNull; import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.JobState;
import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.services.GridJobClient;
import org.jclouds.logging.Logger;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.inject.Inject;
/** /**
* Checks if the latest job for the server is in "Succeeded" state. * Checks if the latest job for the server is in "Succeeded" state. To achieve meaningful results,
* To achieve meaningful results, this must be run in a sequential * this must be run in a sequential environment when a server has only one job related to it at a
* environment when a server has only one job related to it at a time. * time.
* *
* The passed server instance must not be null and must have a name. * The passed server instance must not be null and must have a name.
* *
@ -59,9 +60,7 @@ public class ServerLatestJobCompleted implements Predicate<Server> {
public boolean apply(Server server) { public boolean apply(Server server) {
checkNotNull(server, "Server must be a valid instance"); checkNotNull(server, "Server must be a valid instance");
checkNotNull(server.getName(), "Server must be a valid name"); checkNotNull(server.getName(), "Server must be a valid name");
GetJobListOptions jobOptions = new GetJobListOptions.Builder(). Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(latestJobForObjectByName(server.getName())));
latestJobForObjectByName(server.getName());
Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions));
return JobState.SUCCEEDED.equals(latestJob.getCurrentState()); return JobState.SUCCEEDED.equals(latestJob.getCurrentState());
} }
} }

View File

@ -45,6 +45,7 @@ public interface GridJobClient {
* *
* @return jobs found by request * @return jobs found by request
*/ */
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
Set<Job> getJobList(GetJobListOptions... options); Set<Job> getJobList(GetJobListOptions... options);
/** /**

View File

@ -21,12 +21,12 @@ package org.jclouds.gogrid.predicates;
import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.replay;
import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName;
import static org.testng.Assert.assertTrue; import static org.testng.Assert.assertTrue;
import org.jclouds.gogrid.domain.Job; import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.domain.JobState; import org.jclouds.gogrid.domain.JobState;
import org.jclouds.gogrid.domain.Server; import org.jclouds.gogrid.domain.Server;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.jclouds.gogrid.services.GridJobClient; import org.jclouds.gogrid.services.GridJobClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableSet;
/** /**
* @author Oleksiy Yarmula * @author Oleksiy Yarmula
*/ */
//NOTE:without testName, this will not call @Before* and fail w/NPE during surefire // NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "ServerLatestJobCompletedTest") @Test(groups = "unit", testName = "ServerLatestJobCompletedTest")
public class ServerLatestJobCompletedTest { public class ServerLatestJobCompletedTest {
@ -45,15 +45,11 @@ public class ServerLatestJobCompletedTest {
Server server = createMock(Server.class); Server server = createMock(Server.class);
expect(server.getName()).andStubReturn(serverName); expect(server.getName()).andStubReturn(serverName);
GetJobListOptions jobOptions = new GetJobListOptions.Builder().
latestJobForObjectByName(serverName);
Job job = createMock(Job.class); Job job = createMock(Job.class);
expect(job.getCurrentState()).andReturn(JobState.SUCCEEDED); expect(job.getCurrentState()).andReturn(JobState.SUCCEEDED);
GridJobClient client = createMock(GridJobClient.class); GridJobClient client = createMock(GridJobClient.class);
expect(client.getJobList(jobOptions)). expect(client.getJobList(latestJobForObjectByName(serverName))).andReturn(ImmutableSet.<Job> of(job));
andReturn(ImmutableSet.<Job>of(job));
replay(job); replay(job);
replay(client); replay(client);

View File

@ -0,0 +1,90 @@
/**
* 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.gogrid.services;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Properties;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.gogrid.GoGridAsyncClient;
import org.jclouds.gogrid.GoGridClient;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
/**
* Tests behavior of {@code GoGridClient}
*
* @author Adrian Cole
*/
@Test(groups = "live")
public class BaseGoGridClientLiveTest {
protected RestContext<GoGridClient, GoGridAsyncClient> restContext;
protected String provider = "gogrid";
protected String identity;
protected String credential;
protected String endpoint;
protected String apiversion;
protected ComputeServiceContext context;
protected String prefix = System.getProperty("user.name");
protected void setupCredentials() {
identity = checkNotNull(System.getProperty("test." + provider + ".identity"), "test." + provider + ".identity");
credential = checkNotNull(System.getProperty("test." + provider + ".credential"), "test." + provider
+ ".credential");
endpoint = System.getProperty("test." + provider + ".endpoint");
apiversion = System.getProperty("test." + provider + ".apiversion");
}
protected Properties setupProperties() {
Properties overrides = new Properties();
overrides.setProperty(provider + ".identity", identity);
overrides.setProperty(provider + ".credential", credential);
if (endpoint != null)
overrides.setProperty(provider + ".endpoint", endpoint);
if (apiversion != null)
overrides.setProperty(provider + ".apiversion", apiversion);
return overrides;
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties overrides = setupProperties();
context = new ComputeServiceContextFactory().createContext(provider, ImmutableSet.<Module> of(
new Log4JLoggingModule(), new SshjSshClientModule()), overrides);
restContext = context.getProviderSpecificContext();
}
@AfterGroups(groups = "live")
protected void tearDown() {
if (context != null)
context.close();
}
}

View File

@ -0,0 +1,72 @@
/**
* 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.gogrid.services;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import java.util.logging.Logger;
import org.jclouds.gogrid.domain.ServerImage;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "GridImageClientLiveTest")
public class GridImageClientLiveTest extends BaseGoGridClientLiveTest {
public void testListImages() throws Exception {
Set<ServerImage> response = restContext.getApi().getImageServices().getImageList();
assert null != response;
for (ServerImage image : response) {
assert image.getId() >= 0 : image;
checkImage(image);
ServerImage query = Iterables.getOnlyElement(restContext.getApi().getImageServices().getImagesById(
image.getId()));
assertEquals(query.getId(), image.getId());
checkImage(query);
}
}
private void checkImage(ServerImage image) {
assert image.getArchitecture() != null : image;
assert image.getBillingTokens() != null : image;
if (image.getCreatedTime() == null)
Logger.getAnonymousLogger().warning("image " + image.getId() + " is missing the createdon field");
assert image.getDescription() != null : image;
assert image.getFriendlyName() != null : image;
assert image.getId() >= 0 : image;
assert image.getLocation() != null : image;
assert image.getName() != null : image;
assert image.getOs() != null : image;
assert image.getOwner() != null : image;
assert image.getPrice() >= 0 : image;
assert image.getState() != null : image;
assert image.getType() != null : image;
if (image.getUpdatedTime() == null)
Logger.getAnonymousLogger().warning("image " + image.getId() + " is missing the updatedon field");
}
}

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.gogrid.services; package org.jclouds.gogrid.services;
import static org.jclouds.gogrid.options.GetJobListOptions.Builder.startDate;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Date; import java.util.Date;
@ -45,10 +47,9 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest<GridJobAsy
@Test @Test
public void testGetJobListWithOptions() throws NoSuchMethodException, IOException { public void testGetJobListWithOptions() throws NoSuchMethodException, IOException {
Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class); Method method = GridJobAsyncClient.class.getMethod("getJobList", GetJobListOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, HttpRequest httpRequest = processor
new GetJobListOptions.Builder().create().withStartDate(new Date(1267385381770L)).withEndDate( .createRequest(method, startDate(new Date(1267385381770L)).withEndDate(new Date(1267385382770L))
new Date(1267385382770L)).onlyForObjectType(ObjectType.VIRTUAL_SERVER).onlyForState( .onlyForObjectType(ObjectType.VIRTUAL_SERVER).onlyForState(JobState.PROCESSING));
JobState.PROCESSING));
assertRequestLineEquals(httpRequest, assertRequestLineEquals(httpRequest,
"GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&" "GET https://api.gogrid.com/api/grid/job/list?v=1.5&startdate=1267385381770&"

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.gogrid.services;
import static org.testng.Assert.assertEquals;
import java.util.Set;
import org.jclouds.gogrid.domain.Job;
import org.jclouds.gogrid.options.GetJobListOptions;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
@Test(groups = "unit", testName = "GridJobClientLiveTest")
public class GridJobClientLiveTest extends BaseGoGridClientLiveTest {
public void testListJobs() throws Exception {
Set<Job> response = restContext.getApi().getJobServices().getJobList(GetJobListOptions.Builder.maxItems(10));
assert null != response;
assert response.size() <= 10 : response;
for (Job job : response) {
assert job.getId() >= 0 : job;
checkJob(job);
Job query = Iterables.getOnlyElement(restContext.getApi().getJobServices().getJobsById(job.getId()));
assertEquals(query.getId(), job.getId());
checkJob(query);
}
}
private void checkJob(Job job) {
assert job.getAttempts() >= 0 : job;
assert job.getCommand() != null : job;
assert job.getCreatedOn() != null : job;
assert job.getCreatedOn() != null : job;
assert job.getDetails() != null : job;
assert job.getHistory() != null : job;
assert job.getId() >= 0 : job;
assert job.getLastUpdatedOn() != null : job;
assert job.getObjectType() != null : job;
assert job.getOwner() != null : job;
}
}