Search in sources :

Example 51 with JSONObject

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);
}
Also used : JSONObject(org.json.JSONObject) ArchiveDateArticleRepository(org.b3log.solo.repository.ArchiveDateArticleRepository) Test(org.testng.annotations.Test)

Example 52 with JSONObject

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);
}
Also used : JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) ArchiveDateArticleRepository(org.b3log.solo.repository.ArchiveDateArticleRepository) Test(org.testng.annotations.Test)

Example 53 with JSONObject

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());
}
Also used : ArchiveDateRepository(org.b3log.solo.repository.ArchiveDateRepository) JSONObject(org.json.JSONObject) Transaction(org.b3log.latke.repository.Transaction) Test(org.testng.annotations.Test)

Example 54 with JSONObject

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));
}
Also used : ArchiveDateRepository(org.b3log.solo.repository.ArchiveDateRepository) JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 55 with JSONObject

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"));
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArticleRepository(org.b3log.solo.repository.ArticleRepository) Test(org.testng.annotations.Test)

Aggregations

JSONObject (org.json.JSONObject)4075 JSONException (org.json.JSONException)1601 JSONArray (org.json.JSONArray)1156 Test (org.junit.Test)526 IOException (java.io.IOException)456 ArrayList (java.util.ArrayList)402 HashMap (java.util.HashMap)290 Test (org.testng.annotations.Test)175 File (java.io.File)145 Date (java.util.Date)144 ServiceException (org.b3log.latke.service.ServiceException)125 Bundle (android.os.Bundle)109 VolleyError (com.android.volley.VolleyError)104 Map (java.util.Map)96 BufferedReader (java.io.BufferedReader)93 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)92 InputStreamReader (java.io.InputStreamReader)90 List (java.util.List)85 Response (com.android.volley.Response)84 InputStream (java.io.InputStream)73