Search in sources :

Example 1 with TagRepository

use of org.b3log.solo.repository.TagRepository in project solo by b3log.

the class TagRepositoryImplTestCase method getMostUsedTags.

/**
     * Get Most Used Tags.
     *
     * @throws Exception exception
     */
@Test(dependsOnMethods = "add")
public void getMostUsedTags() throws Exception {
    final TagRepository tagRepository = getTagRepository();
    final JSONObject tag = new JSONObject();
    tag.put(Tag.TAG_TITLE, "tag title2");
    tag.put(Tag.TAG_REFERENCE_COUNT, 3);
    tag.put(Tag.TAG_PUBLISHED_REFERENCE_COUNT, 3);
    final Transaction transaction = tagRepository.beginTransaction();
    tagRepository.add(tag);
    transaction.commit();
    List<JSONObject> mostUsedTags = tagRepository.getMostUsedTags(3);
    Assert.assertNotNull(mostUsedTags);
    Assert.assertEquals(2, mostUsedTags.size());
    mostUsedTags = tagRepository.getMostUsedTags(1);
    Assert.assertNotNull(mostUsedTags);
    Assert.assertEquals(1, mostUsedTags.size());
    Assert.assertEquals(3, mostUsedTags.get(0).getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT));
}
Also used : JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) TagRepository(org.b3log.solo.repository.TagRepository) Test(org.testng.annotations.Test)

Example 2 with TagRepository

use of org.b3log.solo.repository.TagRepository in project solo by b3log.

the class TagRepositoryImplTestCase method getByTitle.

/**
     * Get By Title.
     *
     * @throws Exception exception
     */
@Test(dependsOnMethods = "add")
public void getByTitle() throws Exception {
    final TagRepository tagRepository = getTagRepository();
    final JSONObject found = tagRepository.getByTitle("tag title1");
    Assert.assertNotNull(found);
    Assert.assertEquals(found.getString(Tag.TAG_TITLE), "tag title1");
    Assert.assertEquals(0, found.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT));
    Assert.assertEquals(1, found.getInt(Tag.TAG_REFERENCE_COUNT));
    final JSONObject notFound = tagRepository.getByTitle("");
    Assert.assertNull(notFound);
}
Also used : JSONObject(org.json.JSONObject) TagRepository(org.b3log.solo.repository.TagRepository) Test(org.testng.annotations.Test)

Example 3 with TagRepository

use of org.b3log.solo.repository.TagRepository 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)

Example 4 with TagRepository

use of org.b3log.solo.repository.TagRepository in project solo by b3log.

the class TagRepositoryImplTestCase method getByArticleId.

/**
     * Get By ArticleId.
     *
     * @throws Exception exception
     */
@Test(dependsOnMethods = "add")
public void getByArticleId() throws Exception {
    addTagArticle();
    final TagRepository tagRepository = getTagRepository();
    List<JSONObject> tags = tagRepository.getByArticleId("article1 id");
    Assert.assertNotNull(tags);
    Assert.assertEquals(1, tags.size());
    tags = tagRepository.getByArticleId("not found");
    Assert.assertNotNull(tags);
    Assert.assertEquals(0, tags.size());
}
Also used : JSONObject(org.json.JSONObject) TagRepository(org.b3log.solo.repository.TagRepository) Test(org.testng.annotations.Test)

Aggregations

TagRepository (org.b3log.solo.repository.TagRepository)4 JSONObject (org.json.JSONObject)4 Test (org.testng.annotations.Test)4 Transaction (org.b3log.latke.repository.Transaction)2