*
* @throws Exception exception
*/
@Test(dependsOnMethods = {"add"})
public void previousAndNext() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
final JSONObject article = new JSONObject();
article.put(Article.ARTICLE_TITLE, "article title2");
article.put(Article.ARTICLE_ABSTRACT, "article abstract");
article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2");
article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com");
article.put(Article.ARTICLE_COMMENT_COUNT, 1);
article.put(Article.ARTICLE_VIEW_COUNT, 1);
article.put(Article.ARTICLE_CONTENT, "article content");
article.put(Article.ARTICLE_PERMALINK, "article permalink2");
article.put(Article.ARTICLE_HAD_BEEN_PUBLISHED, true);
article.put(Article.ARTICLE_IS_PUBLISHED, true);
article.put(Article.ARTICLE_PUT_TOP, false);
article.put(Article.ARTICLE_CREATE_DATE, new Date());
article.put(Article.ARTICLE_UPDATE_DATE, new Date());
article.put(Article.ARTICLE_RANDOM_DOUBLE, Math.random());
article.put(Article.ARTICLE_SIGN_ID, "1");
article.put(Article.ARTICLE_COMMENTABLE, true);
article.put(Article.ARTICLE_VIEW_PWD, "");
article.put(Article.ARTICLE_EDITOR_TYPE, "");
final Transaction transaction = articleRepository.beginTransaction();
articleRepository.add(article);
transaction.commit();
Assert.assertEquals(articleRepository.count(), 2);
JSONObject previousArticle = articleRepository.getPreviousArticle(article.getString(Keys.OBJECT_ID));
Assert.assertNotNull(previousArticle);
Assert.assertEquals(previousArticle.getString(Article.ARTICLE_TITLE), "article title1");
Assert.assertEquals(previousArticle.getString(Article.ARTICLE_PERMALINK), "article permalink1");
Assert.assertNull(previousArticle.opt(Keys.OBJECT_ID));
previousArticle = articleRepository.getByPermalink(previousArticle.getString(Article.ARTICLE_PERMALINK));
final JSONObject nextArticle = articleRepository.getNextArticle(previousArticle.getString(Keys.OBJECT_ID));
Assert.assertNotNull(previousArticle);
Assert.assertEquals(nextArticle.getString(Article.ARTICLE_TITLE), "article title2");
}