Search in sources :

Example 56 with Transaction

use of org.b3log.latke.repository.Transaction in project solo by b3log.

the class PageRepositoryImplTestCase method getUnderAndUpper.

/**
     * Get Under and Upper.
     * 
     * @throws Exception exception
     */
@Test(dependsOnMethods = { "add", "getMaxOrder" })
public void getUnderAndUpper() throws Exception {
    final PageRepository pageRepository = getPageRepository();
    final JSONObject page = new JSONObject();
    page.put(Page.PAGE_COMMENT_COUNT, 0);
    page.put(Page.PAGE_CONTENT, "page3 content");
    page.put(Page.PAGE_ORDER, 2);
    page.put(Page.PAGE_PERMALINK, "page3 permalink");
    page.put(Page.PAGE_TITLE, "page3 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 JSONObject page2 = pageRepository.getByPermalink("page2 permalink");
    Assert.assertNotNull(page2);
    final JSONObject page1 = pageRepository.getUpper(page2.getString(Keys.OBJECT_ID));
    Assert.assertNotNull(page1);
    final JSONObject page3 = pageRepository.getUnder(page2.getString(Keys.OBJECT_ID));
    Assert.assertNotNull(page3);
    final JSONObject notFound = pageRepository.getUpper(page1.getString(Keys.OBJECT_ID));
    Assert.assertNull(notFound);
    Assert.assertNull(pageRepository.getUpper("not found"));
    Assert.assertNull(pageRepository.getUnder("not found"));
}
Also used : JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) PageRepository(org.b3log.solo.repository.PageRepository) Test(org.testng.annotations.Test)

Example 57 with Transaction

use of org.b3log.latke.repository.Transaction in project solo by b3log.

the class TagRepositoryImplTestCase method add.

/**
     * Add.
     *
     * @throws Exception exception
     */
@Test
public void add() throws Exception {
    final TagRepository tagRepository = getTagRepository();
    final JSONObject tag = new JSONObject();
    tag.put(Tag.TAG_TITLE, "tag title1");
    tag.put(Tag.TAG_REFERENCE_COUNT, 1);
    tag.put(Tag.TAG_PUBLISHED_REFERENCE_COUNT, 0);
    final Transaction transaction = tagRepository.beginTransaction();
    tagRepository.add(tag);
    transaction.commit();
}
Also used : JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) TagRepository(org.b3log.solo.repository.TagRepository) Test(org.testng.annotations.Test)

Aggregations

Transaction (org.b3log.latke.repository.Transaction)57 JSONObject (org.json.JSONObject)49 ServiceException (org.b3log.latke.service.ServiceException)33 RepositoryException (org.b3log.latke.repository.RepositoryException)23 JSONException (org.json.JSONException)21 Test (org.testng.annotations.Test)16 Date (java.util.Date)9 ParseException (java.text.ParseException)8 EventException (org.b3log.latke.event.EventException)8 IOException (java.io.IOException)6 ArticleRepository (org.b3log.solo.repository.ArticleRepository)4 JSONArray (org.json.JSONArray)4 AbstractPlugin (org.b3log.latke.plugin.AbstractPlugin)3 PageRepository (org.b3log.solo.repository.PageRepository)3 URL (java.net.URL)2 Query (org.b3log.latke.repository.Query)2 OptionRepository (org.b3log.solo.repository.OptionRepository)2 TagArticleRepository (org.b3log.solo.repository.TagArticleRepository)2 TagRepository (org.b3log.solo.repository.TagRepository)2 MalformedURLException (java.net.MalformedURLException)1