use of org.b3log.latke.repository.Transaction in project solo by b3log.
the class ArticleRepositoryImplTestCase method getMostViewCountArticles.
/**
* Get Most View Count Articles
*
* @throws Exception exception
*/
@Test(dependsOnMethods = { "add", "previousAndNext", "getMostCommentArticles" })
public void getMostViewCountArticles() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
final JSONObject article = new JSONObject();
article.put(Article.ARTICLE_TITLE, "article title4");
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, 3);
article.put(Article.ARTICLE_VIEW_COUNT, 3);
article.put(Article.ARTICLE_CONTENT, "article content");
article.put(Article.ARTICLE_PERMALINK, "article permalink4");
article.put(Article.ARTICLE_HAD_BEEN_PUBLISHED, false);
// Unpublished
article.put(Article.ARTICLE_IS_PUBLISHED, false);
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();
List<JSONObject> mostViewCountArticles = articleRepository.getMostViewCountArticles(2);
Assert.assertNotNull(mostViewCountArticles);
Assert.assertEquals(mostViewCountArticles.size(), 2);
Assert.assertEquals(mostViewCountArticles.get(0).getInt(Article.ARTICLE_VIEW_COUNT), 2);
Assert.assertEquals(mostViewCountArticles.get(1).getInt(Article.ARTICLE_VIEW_COUNT), 1);
mostViewCountArticles = articleRepository.getMostViewCountArticles(1);
Assert.assertNotNull(mostViewCountArticles);
Assert.assertEquals(mostViewCountArticles.size(), 1);
Assert.assertEquals(mostViewCountArticles.get(0).getInt(Article.ARTICLE_VIEW_COUNT), 2);
}
use of org.b3log.latke.repository.Transaction in project solo by b3log.
the class CommentRepositoryImplTestCase method add.
/**
* Adds successfully.
*
* @throws Exception exception
*/
@Test
public void add() throws Exception {
final CommentRepository commentRepository = getCommentRepository();
final JSONObject comment = new JSONObject();
comment.put(Comment.COMMENT_CONTENT, "comment1 content");
comment.put(Comment.COMMENT_DATE, new Date());
comment.put(Comment.COMMENT_EMAIL, "test@gmail.com");
comment.put(Comment.COMMENT_NAME, "comment1 name");
comment.put(Comment.COMMENT_ON_ID, "comment1 on id");
comment.put(Comment.COMMENT_ON_TYPE, "comment1 on type");
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_ID, "");
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, "");
comment.put(Comment.COMMENT_SHARP_URL, "comment1 sharp url");
comment.put(Comment.COMMENT_URL, "comment1 url");
comment.put(Comment.COMMENT_THUMBNAIL_URL, "comment1 thumbnail url");
final Transaction transaction = commentRepository.beginTransaction();
commentRepository.add(comment);
transaction.commit();
final List<JSONObject> comments = commentRepository.getComments("comment1 on id", 1, Integer.MAX_VALUE);
Assert.assertNotNull(comments);
Assert.assertEquals(comments.size(), 1);
Assert.assertEquals(commentRepository.getComments("not found", 1, Integer.MAX_VALUE).size(), 0);
Assert.assertEquals(commentRepository.getRecentComments(3).size(), 1);
}
use of org.b3log.latke.repository.Transaction in project solo by b3log.
the class LinkRepositoryImplTestCase method test.
/**
* Tests.
*
* @throws Exception exception
*/
@Test
public void test() throws Exception {
final LinkRepository linkRepository = getLinkRepository();
final int link1Order = 1, link2Order = 2, link3Order = 3;
JSONObject link1 = new JSONObject();
link1.put(Link.LINK_TITLE, "link title");
link1.put(Link.LINK_DESCRIPTION, "link description");
link1.put(Link.LINK_ADDRESS, "link address");
link1.put(Link.LINK_ORDER, link1Order);
Transaction transaction = linkRepository.beginTransaction();
linkRepository.add(link1);
transaction.commit();
Assert.assertNull(linkRepository.getByAddress("test"));
Assert.assertNotNull(linkRepository.getByAddress("link address"));
Assert.assertNull(linkRepository.getByOrder(0));
Assert.assertNotNull(linkRepository.getByOrder(link1Order));
final JSONObject link2 = new JSONObject();
link2.put(Link.LINK_TITLE, "link title");
link2.put(Link.LINK_DESCRIPTION, "link description");
link2.put(Link.LINK_ADDRESS, "link address");
link2.put(Link.LINK_ORDER, link2Order);
transaction = linkRepository.beginTransaction();
final String link2Id = linkRepository.add(link2);
transaction.commit();
Assert.assertEquals(linkRepository.getMaxOrder(), link2Order);
JSONObject link3 = new JSONObject();
link3.put(Link.LINK_TITLE, "link title");
link3.put(Link.LINK_DESCRIPTION, "link description");
link3.put(Link.LINK_ADDRESS, "link address");
link3.put(Link.LINK_ORDER, link3Order);
transaction = linkRepository.beginTransaction();
linkRepository.add(link3);
transaction.commit();
final int total = 3;
Assert.assertEquals(linkRepository.count(), total);
link1 = linkRepository.getUpper(link2Id);
Assert.assertNotNull(link1);
Assert.assertEquals(link1.getInt(Link.LINK_ORDER), link1Order);
link3 = linkRepository.getUnder(link2Id);
Assert.assertNotNull(link3);
Assert.assertEquals(link3.getInt(Link.LINK_ORDER), link3Order);
}
use of org.b3log.latke.repository.Transaction in project solo by b3log.
the class OptionRepositoryImplTestCase method test.
/**
* Tests.
*
* @throws Exception exception
*/
@Test
public void test() throws Exception {
final OptionRepository optionRepository = getOptionRepository();
final JSONObject option = new JSONObject();
option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST);
option.put(Option.OPTION_VALUE, 0L);
Transaction transaction = optionRepository.beginTransaction();
optionRepository.add(option);
transaction.commit();
Assert.assertEquals(optionRepository.count(), 1);
Assert.assertNotNull(optionRepository.get(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME));
}
use of org.b3log.latke.repository.Transaction in project solo by b3log.
the class PageRepositoryImplTestCase method getMaxOrder.
/**
* Get Max Order.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "add")
public void getMaxOrder() throws Exception {
final PageRepository pageRepository = getPageRepository();
final JSONObject page = new JSONObject();
page.put(Page.PAGE_COMMENT_COUNT, 0);
page.put(Page.PAGE_CONTENT, "page2 content");
page.put(Page.PAGE_ORDER, 1);
page.put(Page.PAGE_PERMALINK, "page2 permalink");
page.put(Page.PAGE_TITLE, "page2 title");
page.put(Page.PAGE_COMMENTABLE, true);
page.put(Page.PAGE_TYPE, "page");
page.put(Page.PAGE_OPEN_TARGET, "_self");
page.put(Page.PAGE_EDITOR_TYPE, "");
final Transaction transaction = pageRepository.beginTransaction();
pageRepository.add(page);
transaction.commit();
final int maxOrder = pageRepository.getMaxOrder();
Assert.assertEquals(maxOrder, 1);
}
Aggregations