PageRenderTime 42ms CodeModel.GetById 33ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/test/java/org/b3log/solo/repository/impl/ArchiveDateArticleRepositoryImplTestCase.java

http://github.com/b3log/b3log-solo
Java | 103 lines | 54 code | 13 blank | 36 comment | 0 complexity | b570b97aa47ddd7920940dd397cc3322 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1/*
  2 * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
  3 *
  4 * Licensed under the Apache License, Version 2.0 (the "License");
  5 * you may not use this file except in compliance with the License.
  6 * You may obtain a copy of the License at
  7 *
  8 *     http://www.apache.org/licenses/LICENSE-2.0
  9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed under the License is distributed on an "AS IS" BASIS,
 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13 * See the License for the specific language governing permissions and
 14 * limitations under the License.
 15 */
 16package org.b3log.solo.repository.impl;
 17
 18import junit.framework.Assert;
 19import org.b3log.latke.Keys;
 20import org.b3log.latke.repository.Transaction;
 21import org.b3log.solo.AbstractTestCase;
 22import org.b3log.solo.model.ArchiveDate;
 23import org.b3log.solo.model.Article;
 24import org.b3log.solo.repository.ArchiveDateArticleRepository;
 25import org.json.JSONObject;
 26import org.testng.annotations.Test;
 27
 28/**
 29 * {@link ArchiveDateArticleRepositoryImpl} test case.
 30 *
 31 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
 32 * @version 1.0.0.0, Dec 31, 2011
 33 */
 34@Test(suiteName = "repository")
 35public class ArchiveDateArticleRepositoryImplTestCase extends AbstractTestCase {
 36
 37    /**
 38     * Adds successfully.
 39     * 
 40     * @throws Exception exception
 41     */
 42    @Test
 43    public void add() throws Exception {
 44        final ArchiveDateArticleRepository archiveDateArticleRepository =
 45                getArchiveDateArticleRepository();
 46
 47        final JSONObject archiveDateArticle = new JSONObject();
 48
 49        archiveDateArticle.put(ArchiveDate.ARCHIVE_DATE + "_"
 50                               + Keys.OBJECT_ID, "archiveDateId");
 51        archiveDateArticle.put(Article.ARTICLE + "_"
 52                               + Keys.OBJECT_ID, "articleId");
 53
 54        final Transaction transaction = archiveDateArticleRepository.
 55                beginTransaction();
 56        archiveDateArticleRepository.add(archiveDateArticle);
 57        transaction.commit();
 58
 59        final JSONObject found =
 60                archiveDateArticleRepository.getByArticleId("articleId");
 61        Assert.assertNotNull(found);
 62
 63        final JSONObject notFound =
 64                archiveDateArticleRepository.getByArticleId("not found");
 65        Assert.assertNull(notFound);
 66    }
 67
 68    /**
 69     * Get By ArchiveDate Id.
 70     * 
 71     * @throws Exception exception
 72     */
 73    @Test(dependsOnMethods = "add")
 74    public void getByArchiveDateId() throws Exception {
 75        final ArchiveDateArticleRepository archiveDateArticleRepository =
 76                getArchiveDateArticleRepository();
 77
 78        final JSONObject found =
 79                archiveDateArticleRepository.getByArchiveDateId(
 80                "archiveDateId", 1, Integer.MAX_VALUE);
 81        Assert.assertNotNull(found);
 82
 83        final JSONObject notFound = archiveDateArticleRepository.
 84                getByArchiveDateId("not found", 1, Integer.MAX_VALUE);
 85        Assert.assertNotNull(notFound);
 86    }
 87
 88    /**
 89     * Get By Archive Id.
 90     * 
 91     * @throws Exception exception
 92     */
 93    @Test(dependsOnMethods = "add")
 94    public void getByArticleId() throws Exception {
 95        final ArchiveDateArticleRepository archiveDateArticleRepository =
 96                getArchiveDateArticleRepository();
 97
 98        Assert.assertNotNull(
 99                archiveDateArticleRepository.getByArticleId("articleId"));
100        Assert.assertNull(
101                archiveDateArticleRepository.getByArticleId("not found"));
102    }
103}