use of org.json.JSONObject in project solo by b3log.
the class ArchiveDateArticleRepositoryImplTestCase method getByArchiveDateId.
/**
* Get By ArchiveDate Id.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "add")
public void getByArchiveDateId() throws Exception {
final ArchiveDateArticleRepository archiveDateArticleRepository = getArchiveDateArticleRepository();
final JSONObject found = archiveDateArticleRepository.getByArchiveDateId("archiveDateId", 1, Integer.MAX_VALUE);
Assert.assertNotNull(found);
final JSONObject notFound = archiveDateArticleRepository.getByArchiveDateId("not found", 1, Integer.MAX_VALUE);
Assert.assertNotNull(notFound);
}
use of org.json.JSONObject in project solo by b3log.
the class ArchiveDateArticleRepositoryImplTestCase method add.
/**
* Adds successfully.
*
* @throws Exception exception
*/
@Test
public void add() throws Exception {
final ArchiveDateArticleRepository archiveDateArticleRepository = getArchiveDateArticleRepository();
final JSONObject archiveDateArticle = new JSONObject();
archiveDateArticle.put(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID, "archiveDateId");
archiveDateArticle.put(Article.ARTICLE + "_" + Keys.OBJECT_ID, "articleId");
final Transaction transaction = archiveDateArticleRepository.beginTransaction();
archiveDateArticleRepository.add(archiveDateArticle);
transaction.commit();
final JSONObject found = archiveDateArticleRepository.getByArticleId("articleId");
Assert.assertNotNull(found);
final JSONObject notFound = archiveDateArticleRepository.getByArticleId("not found");
Assert.assertNull(notFound);
}
use of org.json.JSONObject in project solo by b3log.
the class ArchiveDateRepositoryImplTestCase method add.
/**
* Adds successfully.
*
* @throws Exception exception
*/
@Test
public void add() throws Exception {
final ArchiveDateRepository archiveDateRepository = getArchiveDateRepository();
final JSONObject archiveDate = new JSONObject();
archiveDate.put(ArchiveDate.ARCHIVE_TIME, DateUtils.parseDate("2011/12", new String[] { "yyyy/MM" }).getTime());
archiveDate.put(ArchiveDate.ARCHIVE_DATE_ARTICLE_COUNT, 1);
archiveDate.put(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT, 1);
final Transaction transaction = archiveDateRepository.beginTransaction();
archiveDateRepository.add(archiveDate);
transaction.commit();
final List<JSONObject> archiveDates = archiveDateRepository.getArchiveDates();
Assert.assertNotNull(archiveDates);
Assert.assertEquals(1, archiveDates.size());
}
use of org.json.JSONObject in project solo by b3log.
the class ArchiveDateRepositoryImplTestCase method getByArchiveDate.
/**
* Get By ArchiveDate.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "add")
public void getByArchiveDate() throws Exception {
final ArchiveDateRepository archiveDateRepository = getArchiveDateRepository();
final JSONObject archiveDate = archiveDateRepository.getByArchiveDate("2011/12");
Assert.assertNotNull(archiveDate);
System.out.println(archiveDate.toString(SoloServletListener.JSON_PRINT_INDENT_FACTOR));
}
use of org.json.JSONObject in project solo by b3log.
the class ArticleRepositoryImplTestCase method isPublished.
/**
* Is Published.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = { "add", "getMostViewCountArticles" })
public void isPublished() throws Exception {
final ArticleRepository articleRepository = getArticleRepository();
final JSONArray all = articleRepository.get(new Query()).getJSONArray(Keys.RESULTS);
Assert.assertNotNull(all);
final JSONObject article = all.getJSONObject(0);
Assert.assertTrue(articleRepository.isPublished(article.getString(Keys.OBJECT_ID)));
final JSONObject notPublished = articleRepository.getByPermalink("article permalink4");
Assert.assertNotNull(notPublished);
Assert.assertFalse(notPublished.getBoolean(Article.ARTICLE_IS_PUBLISHED));
Assert.assertFalse(articleRepository.isPublished("not found"));
}
Aggregations