|
| 1 | +package net.bican.wordpress.test; |
| 2 | + |
| 3 | +import static org.junit.Assert.*; |
| 4 | + |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +import net.bican.wordpress.FilterPost; |
| 10 | +import net.bican.wordpress.Post; |
| 11 | +import net.bican.wordpress.exceptions.InsufficientRightsException; |
| 12 | +import net.bican.wordpress.exceptions.InvalidArgumentsException; |
| 13 | +import net.bican.wordpress.exceptions.ObjectNotFoundException; |
| 14 | +import redstone.xmlrpc.XmlRpcFault; |
| 15 | + |
| 16 | +@SuppressWarnings({"static-method", "javadoc", "nls"}) |
| 17 | +public class PostFilterTest extends AbstractWordpressTest { |
| 18 | + @Test |
| 19 | + public void testPostPagination() throws InsufficientRightsException, InvalidArgumentsException, |
| 20 | + ObjectNotFoundException, XmlRpcFault { |
| 21 | + Post post1 = create1Post(); |
| 22 | + Post post2 = create1Post(); |
| 23 | + Post post3 = create1Post(); |
| 24 | + Post post4 = create1Post(); |
| 25 | + Post post5 = create1Post(); |
| 26 | + FilterPost filter = new FilterPost(); |
| 27 | + filter.setNumber(Integer.valueOf(2)); |
| 28 | + int pos = 0; |
| 29 | + int paginationSize = 2; |
| 30 | + while (true) { |
| 31 | + filter.setOffset(Integer.valueOf(pos)); |
| 32 | + List<Post> result = WP.getPosts(filter); |
| 33 | + assertTrue(result.size() <= paginationSize); |
| 34 | + if (result.size() == 0) { |
| 35 | + break; |
| 36 | + } |
| 37 | + pos = pos + paginationSize; |
| 38 | + } |
| 39 | + WP.deletePost(post1.getPost_id()); |
| 40 | + WP.deletePost(post2.getPost_id()); |
| 41 | + WP.deletePost(post3.getPost_id()); |
| 42 | + WP.deletePost(post4.getPost_id()); |
| 43 | + WP.deletePost(post5.getPost_id()); |
| 44 | + } |
| 45 | + |
| 46 | + private Post create1Post() throws InsufficientRightsException, InvalidArgumentsException, |
| 47 | + ObjectNotFoundException, XmlRpcFault { |
| 48 | + Post post = new Post(); |
| 49 | + post.setPost_name("test post name"); |
| 50 | + post.setPost_content("test content"); |
| 51 | + post.setPost_title("test post title"); |
| 52 | + post.setPost_excerpt("test post excerpt"); |
| 53 | + Integer p = WP.newPost(post); |
| 54 | + return WP.getPost(p); |
| 55 | + } |
| 56 | +} |
0 commit comments