Search in sources :

Example 56 with JSONObject

use of org.json.JSONObject in project solo by b3log.

the class ArchiveDateQueryServiceTestCase method init.

/**
     * Init.
     * 
     * @throws Exception exception
     */
@Test
public void init() throws Exception {
    final InitService initService = getInitService();
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
    requestJSONObject.put(User.USER_NAME, "Admin");
    requestJSONObject.put(User.USER_PASSWORD, "pass");
    initService.init(requestJSONObject);
    final UserQueryService userQueryService = getUserQueryService();
    Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
Also used : JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 57 with JSONObject

use of org.json.JSONObject in project solo by b3log.

the class ArticleMgmtServiceTestCase method cancelPublishArticle.

/**
     * Cancel Publish Article.
     * 
     * @throws Exception exception
     */
@Test(dependsOnMethods = "init")
public void cancelPublishArticle() throws Exception {
    final ArticleMgmtService articleMgmtService = getArticleMgmtService();
    final JSONObject requestJSONObject = new JSONObject();
    final JSONObject article = new JSONObject();
    requestJSONObject.put(Article.ARTICLE, article);
    article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com");
    article.put(Article.ARTICLE_TITLE, "article4 title");
    article.put(Article.ARTICLE_ABSTRACT, "article4 abstract");
    article.put(Article.ARTICLE_CONTENT, "article4 content");
    article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2, tag3");
    article.put(Article.ARTICLE_PERMALINK, "article4 permalink");
    article.put(Article.ARTICLE_IS_PUBLISHED, true);
    article.put(Common.POST_TO_COMMUNITY, true);
    article.put(Article.ARTICLE_SIGN_ID, "1");
    article.put(Article.ARTICLE_COMMENTABLE, true);
    article.put(Article.ARTICLE_VIEW_PWD, "");
    final String articleId = articleMgmtService.addArticle(requestJSONObject);
    Assert.assertNotNull(articleId);
    final ArticleQueryService articleQueryService = getArticleQueryService();
    final JSONObject paginationRequest = Requests.buildPaginationRequest("1/10/20");
    JSONArray articles = articleQueryService.getArticles(paginationRequest).optJSONArray(Article.ARTICLES);
    int articleCount = articles.length();
    Assert.assertNotEquals(articleCount, 0);
    articleMgmtService.cancelPublishArticle(articleId);
    articles = articleQueryService.getArticles(paginationRequest).optJSONArray(Article.ARTICLES);
    Assert.assertEquals(articles.length(), articleCount - 1);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.testng.annotations.Test)

Example 58 with JSONObject

use of org.json.JSONObject in project solo by b3log.

the class ArticleMgmtServiceTestCase method init.

/**
     * Init.
     * 
     * @throws Exception exception
     */
@Test
public void init() throws Exception {
    final InitService initService = getInitService();
    final JSONObject requestJSONObject = new JSONObject();
    requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
    requestJSONObject.put(User.USER_NAME, "Admin");
    requestJSONObject.put(User.USER_PASSWORD, "pass");
    initService.init(requestJSONObject);
    final UserQueryService userQueryService = getUserQueryService();
    Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
Also used : JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 59 with JSONObject

use of org.json.JSONObject in project solo by b3log.

the class ArticleMgmtServiceTestCase method removeArticle.

/**
     * Remove Article.
     * 
     * @throws Exception exception
     */
@Test(dependsOnMethods = "init")
public void removeArticle() throws Exception {
    final ArticleMgmtService articleMgmtService = getArticleMgmtService();
    final JSONObject requestJSONObject = new JSONObject();
    final JSONObject article = new JSONObject();
    requestJSONObject.put(Article.ARTICLE, article);
    article.put(Article.ARTICLE_AUTHOR_EMAIL, "test@gmail.com");
    article.put(Article.ARTICLE_TITLE, "article3 title");
    article.put(Article.ARTICLE_ABSTRACT, "article3 abstract");
    article.put(Article.ARTICLE_CONTENT, "article3 content");
    article.put(Article.ARTICLE_TAGS_REF, "tag1, tag2, tag3");
    article.put(Article.ARTICLE_PERMALINK, "article3 permalink");
    article.put(Article.ARTICLE_IS_PUBLISHED, true);
    article.put(Common.POST_TO_COMMUNITY, true);
    article.put(Article.ARTICLE_SIGN_ID, "1");
    article.put(Article.ARTICLE_COMMENTABLE, true);
    article.put(Article.ARTICLE_VIEW_PWD, "");
    final String articleId = articleMgmtService.addArticle(requestJSONObject);
    Assert.assertNotNull(articleId);
    articleMgmtService.removeArticle(articleId);
    final ArticleQueryService articleQueryService = getArticleQueryService();
    final JSONObject updated = articleQueryService.getArticleById(articleId);
    Assert.assertNull(updated);
}
Also used : JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 60 with JSONObject

use of org.json.JSONObject in project solo by b3log.

the class ArticleQueryServiceTestCase method getArticlesByArchiveDate.

/**
     * Get Archives By Archive Date.
     * 
     * @throws Exception exception
     */
@Test(dependsOnMethods = "init")
public void getArticlesByArchiveDate() throws Exception {
    final ArchiveDateQueryService archiveDateQueryService = getArchiveDateQueryService();
    final List<JSONObject> archiveDates = archiveDateQueryService.getArchiveDates();
    Assert.assertNotNull(archiveDates);
    Assert.assertEquals(archiveDates.size(), 1);
    final JSONObject archiveDate = archiveDates.get(0);
    final ArticleQueryService articleQueryService = getArticleQueryService();
    List<JSONObject> articles = articleQueryService.getArticlesByArchiveDate(archiveDate.getString(Keys.OBJECT_ID), 1, Integer.MAX_VALUE);
    Assert.assertNotNull(articles);
    Assert.assertEquals(articles.size(), 1);
    articles = articleQueryService.getArticlesByArchiveDate("not found", 1, Integer.MAX_VALUE);
    Assert.assertNotNull(articles);
    Assert.assertTrue(articles.isEmpty());
}
Also used : JSONObject(org.json.JSONObject) 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