Package org.b3log.solo.repository

Examples of org.b3log.solo.repository.TagRepository


     *
     * @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();
    }
View Full Code Here


     *
     * @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(found.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT),
                            0);
        Assert.assertEquals(found.getInt(Tag.TAG_REFERENCE_COUNT), 1);

        final JSONObject notFound = tagRepository.getByTitle("");
        Assert.assertNull(notFound);
    }
View Full Code Here

     *
     * @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(mostUsedTags.size(), 2);

        mostUsedTags = tagRepository.getMostUsedTags(1);
        Assert.assertNotNull(mostUsedTags);
        Assert.assertEquals(mostUsedTags.size(), 1);
        Assert.assertEquals(mostUsedTags.get(0).getInt(
                Tag.TAG_PUBLISHED_REFERENCE_COUNT), 3);
    }
View Full Code Here

     */
    @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(tags.size(), 1);

        tags = tagRepository.getByArticleId("not found");
        Assert.assertNotNull(tags);
        Assert.assertEquals(tags.size(), 0);
    }
View Full Code Here

     *
     * @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();
    }
View Full Code Here

     *
     * @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(found.getInt(Tag.TAG_PUBLISHED_REFERENCE_COUNT),
                            0);
        Assert.assertEquals(found.getInt(Tag.TAG_REFERENCE_COUNT), 1);

        final JSONObject notFound = tagRepository.getByTitle("");
        Assert.assertNull(notFound);
    }
View Full Code Here

     *
     * @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(mostUsedTags.size(), 2);

        mostUsedTags = tagRepository.getMostUsedTags(1);
        Assert.assertNotNull(mostUsedTags);
        Assert.assertEquals(mostUsedTags.size(), 1);
        Assert.assertEquals(mostUsedTags.get(0).getInt(
                Tag.TAG_PUBLISHED_REFERENCE_COUNT), 3);
    }
View Full Code Here

     */
    @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(tags.size(), 1);

        tags = tagRepository.getByArticleId("not found");
        Assert.assertNotNull(tags);
        Assert.assertEquals(tags.size(), 0);
    }
View Full Code Here

TOP

Related Classes of org.b3log.solo.repository.TagRepository

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.