Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add /BlogPost/featured and integration tests

  • Loading branch information...
commit 3baaf7160ba203e7ffde615f3c2ec2ebbe9f681b 1 parent 768d0e4
@dasevilla dasevilla authored
View
49 src/main/java/com/ning/api/client/access/BlogPosts.java
@@ -38,11 +38,11 @@ public Counter counter(ReadableDateTime createdAfter) {
public Creator<BlogPost> creator(BlogPost blogPost) {
return new BlogPostCreator(connection, config, endpointForPOST(), blogPost);
}
-
+
public final Deleter<BlogPost> deleter(Key<BlogPost> id) {
return new DefaultDeleter<BlogPost>(connection, config, endpointForDELETE(), id);
}
-
+
public Lister listerForRecent(BlogPostField firstField, BlogPostField... otherFields) {
return listerForRecent(new Fields<BlogPostField>(BlogPostField.class, firstField, otherFields));
}
@@ -52,15 +52,24 @@ public Lister listerForRecent(Fields<BlogPostField> fields) {
null, null, null);
}
+ public Lister listerForFeatured(BlogPostField firstField, BlogPostField... otherFields) {
+ return listerForFeatured(new Fields<BlogPostField>(BlogPostField.class, firstField, otherFields));
+ }
+
+ public Lister listerForFeatured(Fields<BlogPostField> fields) {
+ return new Lister(connection, config, endpointForFeatured(), fields,
+ null, null, null);
+ }
+
public Updater<BlogPost> updater(BlogPost blogPost) {
return new BlogPostUpdater(connection, config, endpointForPUT(), blogPost);
}
-
+
/*
///////////////////////////////////////////////////////////////////////
// Request builder classes (Creator, Updater, Finder, UserLister, ActivityCounter)
///////////////////////////////////////////////////////////////////////
- */
+ */
/**
* Intermediate accessor used for building and executing "count" requests.
@@ -79,7 +88,7 @@ protected Counter(Counter base, String author, Boolean isPrivate, Boolean isAppr
this(base.connection, base.config, base.endpoint, base.createdAfter,
author, isPrivate, isApproved);
}
-
+
public Counter author(String author) {
return new Counter(this, author, isPrivate, isApproved);
}
@@ -91,7 +100,7 @@ public Counter approved() {
public Counter unapproved() {
return new Counter(this, author, isPrivate, Boolean.FALSE);
}
-
+
public Counter onlyPrivate() {
return new Counter(this, author, Boolean.TRUE, isApproved);
}
@@ -104,7 +113,7 @@ public Counter onlyPublic() {
public static class BlogPostCreator extends DefaultCreator<BlogPost>
{
protected BlogPost blogPost;
-
+
public BlogPostCreator(NingConnection connection, NingClientConfig config, String endpoint,
BlogPost blogPost)
{
@@ -130,7 +139,7 @@ public BlogPostCreator draft() {
blogPost.setPublishStatus(PublishStatus.draft);
blogPost.setPublishTime(null);
return this;
- }
+ }
/**
* Method for indicating that the BlogPost being created will be published
@@ -141,7 +150,7 @@ public BlogPostCreator published() {
blogPost.setPublishStatus(PublishStatus.publish);
blogPost.setPublishTime(null);
return this;
- }
+ }
/**
* Method for indicating that the BlogPost being created will be published
@@ -152,8 +161,8 @@ public BlogPostCreator published(ReadableDateTime publishTime) {
blogPost.setPublishStatus(PublishStatus.queued);
blogPost.setPublishTime(publishTime);
return this;
- }
-
+ }
+
@Override
protected NingHttpPost addCreateParameters(NingHttpPost create)
{
@@ -175,7 +184,7 @@ protected NingHttpPost addCreateParameters(NingHttpPost create)
return create;
}
}
-
+
/**
* Accessor used for fetching sequences of items
*/
@@ -196,12 +205,12 @@ public Lister approved() {
return new Lister(connection, config, endpoint, fields,
author, isPrivate, Boolean.TRUE);
}
-
+
public Lister unapproved() {
return new Lister(connection, config, endpoint, fields,
author, isPrivate, Boolean.FALSE);
}
-
+
public Lister onlyPrivate() {
return new Lister(connection, config, endpoint, fields,
author, Boolean.TRUE, isApproved);
@@ -217,7 +226,7 @@ public Lister onlyPublic() {
return new PagedListImpl<BlogPost,BlogPostField>(connection, config, endpoint,
BlogPost.class, fields, author, isPrivate, isApproved);
}
- }
+ }
public static class BlogPostUpdater extends DefaultUpdater<BlogPost>
{
@@ -248,7 +257,7 @@ public BlogPostUpdater draft() {
blogPost.setPublishStatus(PublishStatus.draft);
blogPost.setPublishTime(null);
return this;
- }
+ }
/**
* Method for indicating that the BlogPost being created will be published
@@ -259,7 +268,7 @@ public BlogPostUpdater published() {
blogPost.setPublishStatus(PublishStatus.publish);
blogPost.setPublishTime(null);
return this;
- }
+ }
/**
* Method for indicating that the BlogPost being created will be published
@@ -270,14 +279,14 @@ public BlogPostUpdater published(ReadableDateTime publishTime) {
blogPost.setPublishStatus(PublishStatus.queued);
blogPost.setPublishTime(publishTime);
return this;
- }
+ }
public BlogPostUpdater approved(Boolean approvedOrNot) {
this.blogPost = blogPost.clone();
blogPost.setApproved(approvedOrNot);
return this;
}
-
+
@Override
protected NingHttpPut addUpdateParameters(NingHttpPut put)
{
@@ -286,7 +295,7 @@ protected NingHttpPut addUpdateParameters(NingHttpPut put)
throw new IllegalArgumentException("Missing mandatory field 'id'");
}
put = put.addFormParameter("id", id.toString());
-
+
if (blogPost.getDescription() != null) {
put = put.addFormParameter("description", blogPost.getDescription());
}
View
1  src/main/java/com/ning/api/client/item/BlogPostField.java
@@ -27,6 +27,7 @@
// And then the rest
updatedDate(ReadableDateTime.class),
+ featuredDate(ReadableDateTime.class),
url(URI.class),
visibility(Visibility.class),
commentCount(Integer.class),
View
370 src/test/java/com/ning/api/client/tests/BlogPostsIT.java
@@ -14,173 +14,205 @@
@Test(groups = { "BlogPost" })
public class BlogPostsIT extends BaseIT {
- @Parameters( { "xapi-host", "http-port", "https-port", "subdomain",
- "consumer-key", "consumer-secret", "user-email", "user-password" })
- public BlogPostsIT(String xapiHost, int defaultHttpPort,
- int DefaultHttpsPort, String subdomain, String consumerKey,
- String consumerSecret, String userEmail, String userPassword) {
- super(xapiHost, defaultHttpPort, DefaultHttpsPort, subdomain,
- consumerKey, consumerSecret, userEmail, userPassword);
- }
-
- @Test
- public void BlogPosts() {
- conn.blogPosts();
- }
-
- @Test(groups = { "creators" })
- public void creator() {
- BlogPosts posts = conn.blogPosts();
- DateTime now = new DateTime();
- String nowStr = now.toString();
-
- String title = "Java client Blog post";
- String desc = "Test post, sent via Java client at " + nowStr;
- BlogPost post = new BlogPost(title, desc);
- post.setPublishTime(now);
- posts.creator(post).create();
- }
-
- @Test(dependsOnMethods = { "creator" }, groups = { "updaters" })
- public void updater() {
- BlogPosts posts = conn.blogPosts();
-
- BlogPost blogPost = fetchRecentBlogPost();
- blogPost.setTitle("Java client was here");
- posts.updater(blogPost).update();
- }
-
- @Test(dependsOnMethods = { "updater" }, groups = { "deleters" })
- public void deleter() {
- BlogPosts posts = conn.blogPosts();
- BlogPost blogPost = fetchRecentBlogPost();
- posts.deleter(blogPost.id()).delete();
- }
-
- @Test(groups = { "counters" })
- public void counter() {
- BlogPosts posts = conn.blogPosts();
- DateTime now = new DateTime();
- posts.counter(now.minusDays(5)).count();
- }
-
- @Test(groups = { "counters" })
- public void counterApproved() {
- BlogPosts posts = conn.blogPosts();
- DateTime now = new DateTime();
- posts.counter(now.minusDays(5)).approved().count();
- }
-
- @Test(groups = { "counters" })
- public void counterUnpproved() {
- BlogPosts posts = conn.blogPosts();
- DateTime now = new DateTime();
- posts.counter(now.minusDays(5)).unapproved().count();
- }
-
- @Test(groups = { "counters" })
- public void counterPublic() {
- BlogPosts posts = conn.blogPosts();
- DateTime now = new DateTime();
- posts.counter(now.minusDays(5)).onlyPublic().count();
- }
-
- @Test(groups = { "admin", "counters" })
- public void counterPrivate() {
- BlogPosts posts = conn.blogPosts();
- DateTime now = new DateTime();
- posts.counter(now.minusDays(5)).onlyPrivate().count();
- }
-
- @Test(groups = { "counters" })
- public void counterForAuthor() {
- String currentAuthor = getCurrentUserAuthorString();
- BlogPosts posts = conn.blogPosts();
- DateTime now = new DateTime();
- posts.counter(now.minusDays(5)).author(currentAuthor).count();
- }
-
- @Test(groups = { "listers" })
- public void listerForRecent() {
- BlogPosts posts = conn.blogPosts();
- Lister blogLister = posts.listerForRecent(BlogPostField.title);
- iterateBlogPosts(blogLister);
- }
-
- @Test(groups = { "listers" })
- public void listerForRecentApproved() {
- BlogPosts posts = conn.blogPosts();
- Lister blogLister = posts.listerForRecent(BlogPostField.title);
- blogLister = blogLister.approved();
- iterateBlogPosts(blogLister);
- }
-
- @Test(groups = { "listers" })
- public void listerForRecentUnapproved() {
- BlogPosts posts = conn.blogPosts();
- Lister blogLister = posts.listerForRecent(BlogPostField.title);
- blogLister = blogLister.unapproved();
- iterateBlogPosts(blogLister);
- }
-
- @Test(groups = { "admin", "listers" })
- public void listerForRecentPrivate() {
- BlogPosts posts = conn.blogPosts();
- Lister blogLister = posts.listerForRecent(BlogPostField.title);
- blogLister = blogLister.onlyPrivate();
- iterateBlogPosts(blogLister);
- }
-
- @Test(groups = { "listers" })
- public void listerForRecentPublic() {
- BlogPosts posts = conn.blogPosts();
- Lister blogLister = posts.listerForRecent(BlogPostField.title);
- blogLister = blogLister.onlyPublic();
- iterateBlogPosts(blogLister);
- }
-
- @Test(groups = { "listers" })
- public void listerForRecentAuthor() {
- String currentAuthor = getCurrentUserAuthorString();
- BlogPosts posts = conn.blogPosts();
- Lister blogLister = posts.listerForRecent(BlogPostField.title);
- blogLister = blogLister.author(currentAuthor);
- iterateBlogPosts(blogLister);
- }
-
- /**
- * Fetch the most recent BlogPost
- *
- * @return The most recent BlogPost
- */
- private BlogPost fetchRecentBlogPost() {
- String currentAuthor = getCurrentUserAuthorString();
- BlogPosts posts = conn.blogPosts();
- Lister blogLister = posts.listerForRecent(BlogPostField.title);
- blogLister = blogLister.author(currentAuthor);
- Iterator<BlogPost> blogIterator = blogLister.iterator();
- assert blogIterator.hasNext() : "Current member has no blog posts to test with";
- BlogPost blogPost = blogIterator.next();
-
- return blogPost;
- }
-
- /**
- * Iterate over the given Lister five times
- *
- * @param lister
- * Lister to iterate over
- */
- private void iterateBlogPosts(Lister lister) {
- int count = 0;
- Iterator<BlogPost> blogIterator = lister.iterator();
- while (blogIterator.hasNext()) {
- blogIterator.next();
- if (count > 5) {
- break;
- } else {
- count += 1;
- }
- }
- }
+ @Parameters( { "xapi-host", "http-port", "https-port", "subdomain",
+ "consumer-key", "consumer-secret", "user-email", "user-password" })
+ public BlogPostsIT(String xapiHost, int defaultHttpPort,
+ int DefaultHttpsPort, String subdomain, String consumerKey,
+ String consumerSecret, String userEmail, String userPassword) {
+ super(xapiHost, defaultHttpPort, DefaultHttpsPort, subdomain,
+ consumerKey, consumerSecret, userEmail, userPassword);
+ }
+
+ @Test
+ public void BlogPosts() {
+ conn.blogPosts();
+ }
+
+ @Test(groups = { "creators" })
+ public void creator() {
+ BlogPosts posts = conn.blogPosts();
+ DateTime now = new DateTime();
+ String nowStr = now.toString();
+
+ String title = "Java client Blog post";
+ String desc = "Test post, sent via Java client at " + nowStr;
+ BlogPost post = new BlogPost(title, desc);
+ post.setPublishTime(now);
+ posts.creator(post).create();
+ }
+
+ @Test(dependsOnMethods = { "creator" }, groups = { "updaters" })
+ public void updater() {
+ BlogPosts posts = conn.blogPosts();
+
+ BlogPost blogPost = fetchRecentBlogPost();
+ blogPost.setTitle("Java client was here");
+ posts.updater(blogPost).update();
+ }
+
+ @Test(dependsOnMethods = { "updater" }, groups = { "deleters" })
+ public void deleter() {
+ BlogPosts posts = conn.blogPosts();
+ BlogPost blogPost = fetchRecentBlogPost();
+ posts.deleter(blogPost.id()).delete();
+ }
+
+ @Test(groups = { "counters" })
+ public void counter() {
+ BlogPosts posts = conn.blogPosts();
+ DateTime now = new DateTime();
+ posts.counter(now.minusDays(5)).count();
+ }
+
+ @Test(groups = { "counters" })
+ public void counterApproved() {
+ BlogPosts posts = conn.blogPosts();
+ DateTime now = new DateTime();
+ posts.counter(now.minusDays(5)).approved().count();
+ }
+
+ @Test(groups = { "counters" })
+ public void counterUnpproved() {
+ BlogPosts posts = conn.blogPosts();
+ DateTime now = new DateTime();
+ posts.counter(now.minusDays(5)).unapproved().count();
+ }
+
+ @Test(groups = { "counters" })
+ public void counterPublic() {
+ BlogPosts posts = conn.blogPosts();
+ DateTime now = new DateTime();
+ posts.counter(now.minusDays(5)).onlyPublic().count();
+ }
+
+ @Test(groups = { "admin", "counters" })
+ public void counterPrivate() {
+ BlogPosts posts = conn.blogPosts();
+ DateTime now = new DateTime();
+ posts.counter(now.minusDays(5)).onlyPrivate().count();
+ }
+
+ @Test(groups = { "counters" })
+ public void counterForAuthor() {
+ String currentAuthor = getCurrentUserAuthorString();
+ BlogPosts posts = conn.blogPosts();
+ DateTime now = new DateTime();
+ posts.counter(now.minusDays(5)).author(currentAuthor).count();
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForRecent() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForRecent(BlogPostField.title);
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForRecentApproved() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForRecent(BlogPostField.title);
+ blogLister = blogLister.approved();
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForRecentUnapproved() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForRecent(BlogPostField.title);
+ blogLister = blogLister.unapproved();
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "admin", "listers" })
+ public void listerForRecentPrivate() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForRecent(BlogPostField.title);
+ blogLister = blogLister.onlyPrivate();
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForRecentPublic() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForRecent(BlogPostField.title);
+ blogLister = blogLister.onlyPublic();
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForRecentAuthor() {
+ String currentAuthor = getCurrentUserAuthorString();
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForRecent(BlogPostField.title);
+ blogLister = blogLister.author(currentAuthor);
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForFeatured() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForFeatured(BlogPostField.featuredDate);
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForFeaturedApproved() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForFeatured(BlogPostField.featuredDate);
+ blogLister = blogLister.approved();
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForFeaturedUnapproved() {
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForFeatured(BlogPostField.featuredDate);
+ blogLister = blogLister.unapproved();
+ iterateBlogPosts(blogLister);
+ }
+
+ @Test(groups = { "listers" })
+ public void listerForFeaturedAuthor() {
+ String currentAuthor = getCurrentUserAuthorString();
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForFeatured(BlogPostField.featuredDate);
+ blogLister = blogLister.author(currentAuthor);
+ iterateBlogPosts(blogLister);
+ }
+
+ /**
+ * Fetch the most recent BlogPost
+ *
+ * @return The most recent BlogPost
+ */
+ private BlogPost fetchRecentBlogPost() {
+ String currentAuthor = getCurrentUserAuthorString();
+ BlogPosts posts = conn.blogPosts();
+ Lister blogLister = posts.listerForRecent(BlogPostField.title);
+ blogLister = blogLister.author(currentAuthor);
+ Iterator<BlogPost> blogIterator = blogLister.iterator();
+ assert blogIterator.hasNext() : "Current member has no blog posts to test with";
+ BlogPost blogPost = blogIterator.next();
+
+ return blogPost;
+ }
+
+ /**
+ * Iterate over the given Lister five times
+ *
+ * @param lister
+ * Lister to iterate over
+ */
+ private void iterateBlogPosts(Lister lister) {
+ int count = 0;
+ Iterator<BlogPost> blogIterator = lister.iterator();
+ while (blogIterator.hasNext()) {
+ blogIterator.next();
+ if (count > 5) {
+ break;
+ } else {
+ count += 1;
+ }
+ }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.