Search in sources :

Example 31 with JSONObject

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

the class OptionMgmtServiceTestCase method remove.

/**
     * Remove.
     * 
     * @throws Exception exception
     */
@Test
public void remove() throws Exception {
    final OptionMgmtService optionMgmtService = getOptionMgmtService();
    final JSONObject option = new JSONObject();
    option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
    option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST);
    option.put(Option.OPTION_VALUE, 0L);
    final String id = optionMgmtService.addOrUpdateOption(option);
    Assert.assertNotNull(id);
    optionMgmtService.removeOption(id);
    final JSONObject opt = getOptionQueryService().getOptionById(id);
    Assert.assertNull(opt);
}
Also used : JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 32 with JSONObject

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

the class OptionMgmtServiceTestCase method update.

/**
     * Update.
     * 
     * @throws Exception exception
     */
@Test
public void update() throws Exception {
    final OptionMgmtService optionMgmtService = getOptionMgmtService();
    JSONObject option = new JSONObject();
    option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
    option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST);
    option.put(Option.OPTION_VALUE, 0L);
    // Add
    final String id = optionMgmtService.addOrUpdateOption(option);
    System.out.println(id);
    Assert.assertNotNull(id);
    option = new JSONObject();
    option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
    option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST);
    option.put(Option.OPTION_VALUE, 1L);
    // Update
    optionMgmtService.addOrUpdateOption(option);
    final JSONObject opt = getOptionQueryService().getOptionById(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
    Assert.assertEquals(opt.getInt(Option.OPTION_VALUE), 1L);
}
Also used : JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 33 with JSONObject

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

the class OptionQueryServiceTestCase method get.

/**
     * Gets.
     * 
     * @throws Exception exception
     */
@Test
public void get() throws Exception {
    // Check
    final OptionQueryService optionQueryService = getOptionQueryService();
    JSONObject options = optionQueryService.getOptions(Option.CATEGORY_C_BROADCAST);
    Assert.assertNull(options);
    // Add one
    final OptionMgmtService optionMgmtService = getOptionMgmtService();
    final JSONObject option = new JSONObject();
    option.put(Keys.OBJECT_ID, Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
    option.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_BROADCAST);
    option.put(Option.OPTION_VALUE, 0L);
    final String id = optionMgmtService.addOrUpdateOption(option);
    Assert.assertNotNull(id);
    // Check again
    options = optionQueryService.getOptions(Option.CATEGORY_C_BROADCAST);
    Assert.assertNotNull(options);
}
Also used : JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 34 with JSONObject

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

the class PageMgmtServiceTestCase method updatePage.

/**
     * Update Page.
     * 
     * @throws Exception exception
     */
@Test(dependsOnMethods = "init")
public void updatePage() throws Exception {
    final PageMgmtService pageMgmtService = getPageMgmtService();
    JSONObject requestJSONObject = new JSONObject();
    final JSONObject page = new JSONObject();
    requestJSONObject.put(Page.PAGE, page);
    page.put(Page.PAGE_CONTENT, "page3 content");
    page.put(Page.PAGE_PERMALINK, "page3 permalink");
    page.put(Page.PAGE_TITLE, "page3 title");
    page.put(Page.PAGE_COMMENTABLE, true);
    page.put(Page.PAGE_TYPE, "page");
    page.put(Page.PAGE_OPEN_TARGET, "_self");
    final String pageId = pageMgmtService.addPage(requestJSONObject);
    Assert.assertNotNull(pageId);
    final PageQueryService pageQueryService = getPageQueryService();
    JSONObject result = pageQueryService.getPage(pageId);
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getJSONObject(Page.PAGE).getString(Page.PAGE_TITLE), "page3 title");
    page.put(Page.PAGE_TITLE, "updated page3 title");
    pageMgmtService.updatePage(requestJSONObject);
    result = pageQueryService.getPage(pageId);
    Assert.assertNotNull(result);
    Assert.assertEquals(result.getJSONObject(Page.PAGE).getString(Page.PAGE_TITLE), "updated page3 title");
}
Also used : JSONObject(org.json.JSONObject) Test(org.testng.annotations.Test)

Example 35 with JSONObject

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

the class PageMgmtServiceTestCase 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)

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