From 921ca628f7a2b5e5469dfdc4fdd31edc1d197e0a Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Fri, 14 Oct 2011 15:50:38 -0700 Subject: [PATCH] Issue 722: added specific tests to help troubleshoot GoGrid api issues --- .../aws/ec2/services/AMIClientLiveTest.java | 6 +- .../jclouds/gogrid/domain/BillingToken.java | 118 ++++++++-------- .../gogrid/options/GetImageListOptions.java | 32 ++--- .../gogrid/options/GetJobListOptions.java | 133 ++++++++++-------- .../LoadBalancerLatestJobCompleted.java | 51 ++++--- .../predicates/ServerLatestJobCompleted.java | 61 ++++---- .../gogrid/services/GridJobClient.java | 1 + .../ServerLatestJobCompletedTest.java | 38 +++-- .../services/BaseGoGridClientLiveTest.java | 90 ++++++++++++ .../services/GridImageClientLiveTest.java | 72 ++++++++++ .../services/GridJobAsyncClientTest.java | 27 ++-- .../services/GridJobClientLiveTest.java | 66 +++++++++ 12 files changed, 468 insertions(+), 227 deletions(-) create mode 100644 providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java create mode 100644 providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageClientLiveTest.java create mode 100644 providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobClientLiveTest.java diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java index 34f71b2afb..c62cff6c80 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/AMIClientLiveTest.java @@ -133,7 +133,7 @@ public class AMIClientLiveTest { } public void testDescribeImagesCC() { - Set twoResults = client.describeImagesInRegion(Region.US_EAST_1, filters( + Set ccResults = client.describeImagesInRegion(Region.US_EAST_1, filters( ImmutableMultimap. builder()// .put("virtualization-type", "hvm")// .put("architecture", "x86_64")// @@ -143,8 +143,8 @@ public class AMIClientLiveTest { .put("image-type", "machine")// .put("root-device-type", "ebs")// .build()).ownedBy("137112412989", "099720109477")); - assertNotNull(twoResults); - assertEquals(twoResults.size(), 35); + assertNotNull(ccResults); + assert (ccResults.size() >= 34) : ccResults; } @Test(enabled = false) diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java index 5954f51745..58aff2efed 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java @@ -25,70 +25,74 @@ import com.google.common.primitives.Longs; */ public class BillingToken implements Comparable { - private long id; - private String name; - private double price; + private long id; + private String name; + private double price; - /** - * A no-args constructor is required for deserialization - */ - public BillingToken() { - } + /** + * A no-args constructor is required for deserialization + */ + public BillingToken() { + } - public BillingToken(long id, String name, double price) { - this.id = id; - this.name = name; - this.price = price; - } + public BillingToken(long id, String name, double price) { + this.id = id; + this.name = name; + this.price = price; + } - public long getId() { - return id; - } + public long getId() { + return id; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public double getPrice() { - return price; - } + public double getPrice() { + return price; + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BillingToken other = (BillingToken) obj; + 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; + } - BillingToken that = (BillingToken) o; + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + long temp; + temp = Double.doubleToLongBits(price); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } - if (id != that.id) return false; - if (Double.compare(that.price, price) != 0) return false; - if (!name.equals(that.name)) return false; + @Override + public int compareTo(BillingToken o) { + return Longs.compare(id, o.getId()); + } - return true; - } - - @Override - public int hashCode() { - int result; - long temp; - result = (int) (id ^ (id >>> 32)); - result = 31 * result + name.hashCode(); - temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L; - result = 31 * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public int compareTo(BillingToken o) { - return Longs.compare(id, o.getId()); - } - - @Override - public String toString() { - return "BillingToken{" + - "id=" + id + - ", name='" + name + '\'' + - ", price=" + price + - '}'; - } + @Override + public String toString() { + return "BillingToken{" + "id=" + id + ", name='" + name + '\'' + ", price=" + price + '}'; + } } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetImageListOptions.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetImageListOptions.java index b70631aba3..0770896e9b 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetImageListOptions.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetImageListOptions.java @@ -36,29 +36,25 @@ import org.jclouds.http.options.BaseHttpRequestOptions; public class GetImageListOptions extends BaseHttpRequestOptions { public GetImageListOptions setType(ServerImageType imageType) { - checkState(!queryParameters.containsKey(IMAGE_TYPE_KEY), - "Can't have duplicate image type restrictions"); + checkState(!queryParameters.containsKey(IMAGE_TYPE_KEY), "Can't have duplicate image type restrictions"); queryParameters.put(IMAGE_TYPE_KEY, imageType.toString()); return this; } public GetImageListOptions setState(ServerImageState imageState) { - checkState(!queryParameters.containsKey(IMAGE_STATE_KEY), - "Can't have duplicate image state restrictions"); + checkState(!queryParameters.containsKey(IMAGE_STATE_KEY), "Can't have duplicate image state restrictions"); queryParameters.put(IMAGE_STATE_KEY, imageState.toString()); return this; } public GetImageListOptions onlyPublic() { - checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), - "Can't have duplicate image visibility restrictions"); + checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), "Can't have duplicate image visibility restrictions"); queryParameters.put(IS_PUBLIC_KEY, "true"); return this; } public GetImageListOptions onlyPrivate() { - checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), - "Can't have duplicate image visibility restrictions"); + checkState(!queryParameters.containsKey(IS_PUBLIC_KEY), "Can't have duplicate image visibility restrictions"); queryParameters.put(IS_PUBLIC_KEY, "false"); return this; } @@ -70,26 +66,28 @@ public class GetImageListOptions extends BaseHttpRequestOptions { } public GetImageListOptions maxItemsNumber(Integer maxNumber) { - checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), - "Can't have duplicate parameter of max returned items"); + checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items"); queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString()); return this; } public static class Builder { - public GetImageListOptions inDatacenter(String datacenterId) { - GetImageListOptions getImageListOptions = new GetImageListOptions(); - return getImageListOptions.inDatacenter(checkNotNull(datacenterId)); + public static GetImageListOptions maxItems(int maxNumber) { + return new GetImageListOptions().maxItemsNumber(maxNumber); } - 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( ServerImageType.WEB_APPLICATION_SERVER).onlyPublic(); } - public GetImageListOptions publicDatabaseServers() { - return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType( - ServerImageType.DATABASE_SERVER).onlyPublic(); + public static GetImageListOptions publicDatabaseServers() { + return new GetImageListOptions().setState(ServerImageState.AVAILABLE).setType(ServerImageType.DATABASE_SERVER) + .onlyPublic(); } } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetJobListOptions.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetJobListOptions.java index f3bd6ea2b8..246cf7ebcb 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetJobListOptions.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/options/GetJobListOptions.java @@ -18,87 +18,102 @@ */ package org.jclouds.gogrid.options; -import org.jclouds.gogrid.domain.JobState; -import org.jclouds.gogrid.domain.ObjectType; -import org.jclouds.http.options.BaseHttpRequestOptions; +import static com.google.common.base.Preconditions.checkState; +import static org.jclouds.gogrid.reference.GoGridQueryParams.END_DATE_KEY; +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 static com.google.common.base.Preconditions.checkState; -import static org.jclouds.gogrid.reference.GoGridQueryParams.*; +import org.jclouds.gogrid.domain.JobState; +import org.jclouds.gogrid.domain.ObjectType; +import org.jclouds.http.options.BaseHttpRequestOptions; /** * @author Oleksiy Yarmula */ public class GetJobListOptions extends BaseHttpRequestOptions { - public static final GetJobListOptions NONE = new GetJobListOptions(); + public static final GetJobListOptions NONE = new GetJobListOptions(); - public GetJobListOptions maxItemsNumber(Integer maxNumber) { - checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items"); - queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString()); - return this; - } + public GetJobListOptions maxItemsNumber(Integer maxNumber) { + checkState(!queryParameters.containsKey(MAX_NUMBER_KEY), "Can't have duplicate parameter of max returned items"); + queryParameters.put(MAX_NUMBER_KEY, maxNumber.toString()); + return this; + } - public GetJobListOptions withStartDate(Date startDate) { - checkState(!queryParameters.containsKey(START_DATE_KEY), "Can't have duplicate start date for filtering"); - queryParameters.put(START_DATE_KEY, String.valueOf(startDate.getTime())); - return this; - } + public GetJobListOptions withStartDate(Date startDate) { + checkState(!queryParameters.containsKey(START_DATE_KEY), "Can't have duplicate start date for filtering"); + queryParameters.put(START_DATE_KEY, String.valueOf(startDate.getTime())); + return this; + } - public GetJobListOptions withEndDate(Date endDate) { - checkState(!queryParameters.containsKey(END_DATE_KEY), "Can't have duplicate end date for filtering"); - queryParameters.put(END_DATE_KEY, String.valueOf(endDate.getTime())); - return this; - } + public GetJobListOptions withEndDate(Date endDate) { + checkState(!queryParameters.containsKey(END_DATE_KEY), "Can't have duplicate end date for filtering"); + queryParameters.put(END_DATE_KEY, String.valueOf(endDate.getTime())); + return this; + } - public GetJobListOptions withOwner(String owner) { - checkState(!queryParameters.containsKey(OWNER_KEY), "Can't have duplicate owner name for filtering"); - queryParameters.put(OWNER_KEY, owner); - return this; - } + public GetJobListOptions withOwner(String owner) { + checkState(!queryParameters.containsKey(OWNER_KEY), "Can't have duplicate owner name for filtering"); + queryParameters.put(OWNER_KEY, owner); + return this; + } - public GetJobListOptions onlyForState(JobState jobState) { - checkState(!queryParameters.containsKey(JOB_STATE_KEY), "Can't have duplicate job state for filtering"); - queryParameters.put(JOB_STATE_KEY, jobState.toString()); - return this; - } + public GetJobListOptions onlyForState(JobState jobState) { + checkState(!queryParameters.containsKey(JOB_STATE_KEY), "Can't have duplicate job state for filtering"); + queryParameters.put(JOB_STATE_KEY, jobState.toString()); + return this; + } - public GetJobListOptions onlyForObjectType(ObjectType objectType) { - checkState(!queryParameters.containsKey(JOB_OBJECT_TYPE_KEY), "Can't have duplicate object type for filtering"); - queryParameters.put(JOB_OBJECT_TYPE_KEY, objectType.toString()); - return this; - } + public GetJobListOptions onlyForObjectType(ObjectType objectType) { + checkState(!queryParameters.containsKey(JOB_OBJECT_TYPE_KEY), "Can't have duplicate object type for filtering"); + queryParameters.put(JOB_OBJECT_TYPE_KEY, objectType.toString()); + return this; + } - public GetJobListOptions onlyForObjectName(String objectName) { - checkState(!queryParameters.containsKey(OBJECT_KEY), "Can't have duplicate object name for filtering"); - queryParameters.put(OBJECT_KEY, objectName); - return this; - } + public GetJobListOptions onlyForObjectName(String objectName) { + checkState(!queryParameters.containsKey(OBJECT_KEY), "Can't have duplicate object name for filtering"); + queryParameters.put(OBJECT_KEY, objectName); + return this; + } - /* + public GetJobListOptions latestJobForObjectByName(String serverName) { + return maxItemsNumber(1).onlyForObjectName(serverName); + } + + /* * This method is intended for testing */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; - GetJobListOptions options = (GetJobListOptions) o; + GetJobListOptions options = (GetJobListOptions) o; - return buildQueryParameters().equals(options.buildQueryParameters()); - } + return buildQueryParameters().equals(options.buildQueryParameters()); + } - public static class Builder { - public GetJobListOptions create() { - return new GetJobListOptions(); - } + public static class Builder { - public GetJobListOptions latestJobForObjectByName(String serverName) { - return new GetJobListOptions(). - maxItemsNumber(1). - onlyForObjectName(serverName); - } - } + public static GetJobListOptions maxItems(int maxNumber) { + return new GetJobListOptions().maxItemsNumber(maxNumber); + } + + public static GetJobListOptions startDate(Date startDate){ + return new GetJobListOptions().withStartDate(startDate); + } + + public static GetJobListOptions latestJobForObjectByName(String serverName) { + return new GetJobListOptions().latestJobForObjectByName(serverName); + } + } } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/LoadBalancerLatestJobCompleted.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/LoadBalancerLatestJobCompleted.java index eac4fb241c..1baa3338f0 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/LoadBalancerLatestJobCompleted.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/LoadBalancerLatestJobCompleted.java @@ -18,20 +18,21 @@ */ package org.jclouds.gogrid.predicates; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -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 static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName; import javax.annotation.Resource; 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 @@ -39,23 +40,21 @@ import static com.google.common.base.Preconditions.checkNotNull; @Singleton public class LoadBalancerLatestJobCompleted implements Predicate { - protected GridJobClient jobClient; + protected GridJobClient jobClient; - @Resource - protected Logger logger = Logger.NULL; + @Resource + protected Logger logger = Logger.NULL; - @Inject - public LoadBalancerLatestJobCompleted(GridJobClient jobClient) { - this.jobClient = jobClient; - } + @Inject + public LoadBalancerLatestJobCompleted(GridJobClient jobClient) { + this.jobClient = jobClient; + } - @Override - public boolean apply(LoadBalancer loadBalancer) { - checkNotNull(loadBalancer, "Load balancer must be a valid instance"); - checkNotNull(loadBalancer.getName(), "Load balancer must be a valid name"); - GetJobListOptions jobOptions = new GetJobListOptions.Builder(). - latestJobForObjectByName(loadBalancer.getName()); - Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions)); - return JobState.SUCCEEDED.equals(latestJob.getCurrentState()); - } + @Override + public boolean apply(LoadBalancer loadBalancer) { + checkNotNull(loadBalancer, "Load balancer must be a valid instance"); + checkNotNull(loadBalancer.getName(), "Load balancer must be a valid name"); + Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(latestJobForObjectByName(loadBalancer.getName()))); + return JobState.SUCCEEDED.equals(latestJob.getCurrentState()); + } } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/ServerLatestJobCompleted.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/ServerLatestJobCompleted.java index 22eac087e9..1e5f68a217 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/ServerLatestJobCompleted.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/predicates/ServerLatestJobCompleted.java @@ -18,50 +18,49 @@ */ package org.jclouds.gogrid.predicates; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -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 static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName; import javax.annotation.Resource; 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. - * To achieve meaningful results, this must be run in a sequential - * environment when a server has only one job related to it at a time. - * + * Checks if the latest job for the server is in "Succeeded" state. To achieve meaningful results, + * this must be run in a sequential environment when a server has only one job related to it at a + * time. + * * The passed server instance must not be null and must have a name. - * + * * @author Oleksiy Yarmula */ @Singleton public class ServerLatestJobCompleted implements Predicate { - protected GridJobClient jobClient; + protected GridJobClient jobClient; - @Resource - protected Logger logger = Logger.NULL; + @Resource + protected Logger logger = Logger.NULL; - @Inject - public ServerLatestJobCompleted(GridJobClient jobClient) { - this.jobClient = jobClient; - } + @Inject + public ServerLatestJobCompleted(GridJobClient jobClient) { + this.jobClient = jobClient; + } - @Override - public boolean apply(Server server) { - checkNotNull(server, "Server must be a valid instance"); - checkNotNull(server.getName(), "Server must be a valid name"); - GetJobListOptions jobOptions = new GetJobListOptions.Builder(). - latestJobForObjectByName(server.getName()); - Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(jobOptions)); - return JobState.SUCCEEDED.equals(latestJob.getCurrentState()); - } + @Override + public boolean apply(Server server) { + checkNotNull(server, "Server must be a valid instance"); + checkNotNull(server.getName(), "Server must be a valid name"); + Job latestJob = Iterables.getOnlyElement(jobClient.getJobList(latestJobForObjectByName(server.getName()))); + return JobState.SUCCEEDED.equals(latestJob.getCurrentState()); + } } diff --git a/providers/gogrid/src/main/java/org/jclouds/gogrid/services/GridJobClient.java b/providers/gogrid/src/main/java/org/jclouds/gogrid/services/GridJobClient.java index fffa71fe13..90d0c18fa9 100644 --- a/providers/gogrid/src/main/java/org/jclouds/gogrid/services/GridJobClient.java +++ b/providers/gogrid/src/main/java/org/jclouds/gogrid/services/GridJobClient.java @@ -45,6 +45,7 @@ public interface GridJobClient { * * @return jobs found by request */ + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) Set getJobList(GetJobListOptions... options); /** diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/predicates/ServerLatestJobCompletedTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/predicates/ServerLatestJobCompletedTest.java index e2d6716432..ede106e93c 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/predicates/ServerLatestJobCompletedTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/predicates/ServerLatestJobCompletedTest.java @@ -21,12 +21,12 @@ package org.jclouds.gogrid.predicates; import static org.easymock.EasyMock.expect; import static org.easymock.classextension.EasyMock.createMock; import static org.easymock.classextension.EasyMock.replay; +import static org.jclouds.gogrid.options.GetJobListOptions.Builder.latestJobForObjectByName; import static org.testng.Assert.assertTrue; 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.testng.annotations.Test; @@ -35,33 +35,29 @@ import com.google.common.collect.ImmutableSet; /** * @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") public class ServerLatestJobCompletedTest { - @Test - public void testPredicate() { - final String serverName = "SERVER_NAME"; - Server server = createMock(Server.class); - expect(server.getName()).andStubReturn(serverName); + @Test + public void testPredicate() { + final String serverName = "SERVER_NAME"; + Server server = createMock(Server.class); + expect(server.getName()).andStubReturn(serverName); - GetJobListOptions jobOptions = new GetJobListOptions.Builder(). - latestJobForObjectByName(serverName); + Job job = createMock(Job.class); + expect(job.getCurrentState()).andReturn(JobState.SUCCEEDED); - Job job = createMock(Job.class); - expect(job.getCurrentState()).andReturn(JobState.SUCCEEDED); + GridJobClient client = createMock(GridJobClient.class); + expect(client.getJobList(latestJobForObjectByName(serverName))).andReturn(ImmutableSet. of(job)); - GridJobClient client = createMock(GridJobClient.class); - expect(client.getJobList(jobOptions)). - andReturn(ImmutableSet.of(job)); + replay(job); + replay(client); + replay(server); - replay(job); - replay(client); - replay(server); + ServerLatestJobCompleted predicate = new ServerLatestJobCompleted(client); + assertTrue(predicate.apply(server), "The result of the predicate should've been 'true'"); - ServerLatestJobCompleted predicate = new ServerLatestJobCompleted(client); - assertTrue(predicate.apply(server), "The result of the predicate should've been 'true'"); - - } + } } diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java new file mode 100644 index 0000000000..3a7c7c9684 --- /dev/null +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/BaseGoGridClientLiveTest.java @@ -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 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. of( + new Log4JLoggingModule(), new SshjSshClientModule()), overrides); + restContext = context.getProviderSpecificContext(); + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (context != null) + context.close(); + } + +} diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageClientLiveTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageClientLiveTest.java new file mode 100644 index 0000000000..9620b49710 --- /dev/null +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridImageClientLiveTest.java @@ -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 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"); + } +} diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java index bd048ff3d1..24dd638b8b 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/services/GridJobAsyncClientTest.java @@ -18,6 +18,8 @@ */ package org.jclouds.gogrid.services; +import static org.jclouds.gogrid.options.GetJobListOptions.Builder.startDate; + import java.io.IOException; import java.lang.reflect.Method; import java.util.Date; @@ -45,14 +47,13 @@ public class GridJobAsyncClientTest extends BaseGoGridAsyncClientTest 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; + } +}