/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

  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. */
  16. package org.b3log.solo.repository.impl;
  17. import junit.framework.Assert;
  18. import org.b3log.latke.Keys;
  19. import org.b3log.latke.repository.Transaction;
  20. import org.b3log.solo.AbstractTestCase;
  21. import org.b3log.solo.model.ArchiveDate;
  22. import org.b3log.solo.model.Article;
  23. import org.b3log.solo.repository.ArchiveDateArticleRepository;
  24. import org.json.JSONObject;
  25. import org.testng.annotations.Test;
  26. /**
  27. * {@link ArchiveDateArticleRepositoryImpl} test case.
  28. *
  29. * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
  30. * @version 1.0.0.0, Dec 31, 2011
  31. */
  32. @Test(suiteName = "repository")
  33. public class ArchiveDateArticleRepositoryImplTestCase extends AbstractTestCase {
  34. /**
  35. * Adds successfully.
  36. *
  37. * @throws Exception exception
  38. */
  39. @Test
  40. public void add() throws Exception {
  41. final ArchiveDateArticleRepository archiveDateArticleRepository =
  42. getArchiveDateArticleRepository();
  43. final JSONObject archiveDateArticle = new JSONObject();
  44. archiveDateArticle.put(ArchiveDate.ARCHIVE_DATE + "_"
  45. + Keys.OBJECT_ID, "archiveDateId");
  46. archiveDateArticle.put(Article.ARTICLE + "_"
  47. + Keys.OBJECT_ID, "articleId");
  48. final Transaction transaction = archiveDateArticleRepository.
  49. beginTransaction();
  50. archiveDateArticleRepository.add(archiveDateArticle);
  51. transaction.commit();
  52. final JSONObject found =
  53. archiveDateArticleRepository.getByArticleId("articleId");
  54. Assert.assertNotNull(found);
  55. final JSONObject notFound =
  56. archiveDateArticleRepository.getByArticleId("not found");
  57. Assert.assertNull(notFound);
  58. }
  59. /**
  60. * Get By ArchiveDate Id.
  61. *
  62. * @throws Exception exception
  63. */
  64. @Test(dependsOnMethods = "add")
  65. public void getByArchiveDateId() throws Exception {
  66. final ArchiveDateArticleRepository archiveDateArticleRepository =
  67. getArchiveDateArticleRepository();
  68. final JSONObject found =
  69. archiveDateArticleRepository.getByArchiveDateId(
  70. "archiveDateId", 1, Integer.MAX_VALUE);
  71. Assert.assertNotNull(found);
  72. final JSONObject notFound = archiveDateArticleRepository.
  73. getByArchiveDateId("not found", 1, Integer.MAX_VALUE);
  74. Assert.assertNotNull(notFound);
  75. }
  76. /**
  77. * Get By Archive Id.
  78. *
  79. * @throws Exception exception
  80. */
  81. @Test(dependsOnMethods = "add")
  82. public void getByArticleId() throws Exception {
  83. final ArchiveDateArticleRepository archiveDateArticleRepository =
  84. getArchiveDateArticleRepository();
  85. Assert.assertNotNull(
  86. archiveDateArticleRepository.getByArticleId("articleId"));
  87. Assert.assertNull(
  88. archiveDateArticleRepository.getByArticleId("not found"));
  89. }
  90. }