Search in sources :

Example 1 with MockResponse

use of org.b3log.solo.MockResponse in project solo by 88250.

the class ArticleConsoleTestCase method updateArticle.

/**
 * updateArticle.
 *
 * @throws Exception exception
 */
public void updateArticle() throws Exception {
    final JSONObject article = getArticleRepository().getFirst(new Query());
    final MockRequest request = mockRequest();
    request.setRequestURI("/console/article/");
    request.setMethod("PUT");
    final JSONObject requestJSON = new JSONObject();
    requestJSON.put(Article.ARTICLE, article);
    request.setJSON(requestJSON);
    mockAdminLogin(request);
    final MockResponse response = mockResponse();
    mockDispatcher(request, response);
    final String content = response.getString();
    Assert.assertTrue(StringUtils.contains(content, "\"code\":0"));
}
Also used : MockResponse(org.b3log.solo.MockResponse) JSONObject(org.json.JSONObject) Query(org.b3log.latke.repository.Query) MockRequest(org.b3log.solo.MockRequest)

Example 2 with MockResponse

use of org.b3log.solo.MockResponse in project solo by 88250.

the class ArticleConsoleTestCase method removeArticle.

/**
 * removeArticle.
 *
 * @throws Exception exception
 */
@Test(dependsOnMethods = "updateArticle")
public void removeArticle() throws Exception {
    final JSONObject article = getArticleRepository().getFirst(new Query());
    final String articleId = article.optString(Keys.OBJECT_ID);
    final MockRequest request = mockRequest();
    request.setRequestURI("/console/article/" + articleId);
    request.setMethod("DELETE");
    mockAdminLogin(request);
    final MockResponse response = mockResponse();
    mockDispatcher(request, response);
    final String content = response.getString();
    Assert.assertTrue(StringUtils.contains(content, "\"code\":0"));
}
Also used : MockResponse(org.b3log.solo.MockResponse) JSONObject(org.json.JSONObject) Query(org.b3log.latke.repository.Query) MockRequest(org.b3log.solo.MockRequest) Test(org.testng.annotations.Test)

Example 3 with MockResponse

use of org.b3log.solo.MockResponse in project solo by 88250.

the class ArticleConsoleTestCase method cancelTopArticle.

/**
 * cancelTopArticle.
 *
 * @throws Exception exception
 */
public void cancelTopArticle() throws Exception {
    final JSONObject article = getArticleRepository().getFirst(new Query());
    final String articleId = article.optString(Keys.OBJECT_ID);
    final MockRequest request = mockRequest();
    request.setRequestURI("/console/article/canceltop/" + articleId);
    request.setMethod("PUT");
    mockAdminLogin(request);
    final MockResponse response = mockResponse();
    mockDispatcher(request, response);
    final String content = response.getString();
    Assert.assertTrue(StringUtils.contains(content, "\"code\":0"));
}
Also used : MockResponse(org.b3log.solo.MockResponse) JSONObject(org.json.JSONObject) Query(org.b3log.latke.repository.Query) MockRequest(org.b3log.solo.MockRequest)

Example 4 with MockResponse

use of org.b3log.solo.MockResponse in project solo by 88250.

the class CategoryConsoleTestCase method getCategory.

/**
 * getCategory.
 *
 * @throws Exception exception
 */
@Test(dependsOnMethods = "addCategory")
public void getCategory() throws Exception {
    final JSONObject category = getCategoryQueryService().getByTitle("分类1");
    final MockRequest request = mockRequest();
    request.setRequestURI("/console/category/" + category.optString(Keys.OBJECT_ID));
    request.setMethod("GET");
    mockAdminLogin(request);
    final MockResponse response = mockResponse();
    mockDispatcher(request, response);
    final String content = response.getString();
    Assert.assertTrue(StringUtils.contains(content, "code\":0"));
}
Also used : MockResponse(org.b3log.solo.MockResponse) JSONObject(org.json.JSONObject) MockRequest(org.b3log.solo.MockRequest) Test(org.testng.annotations.Test)

Example 5 with MockResponse

use of org.b3log.solo.MockResponse in project solo by 88250.

the class CategoryConsoleTestCase method changeOrder.

/**
 * changeOrder.
 *
 * @throws Exception exception
 */
@Test(dependsOnMethods = "getCategories")
public void changeOrder() throws Exception {
    final JSONObject category = getCategoryQueryService().getByTitle("新的分类1");
    final MockRequest request = mockRequest();
    request.setRequestURI("/console/category/order/");
    request.setMethod("PUT");
    final JSONObject requestJSON = new JSONObject();
    requestJSON.put(Keys.OBJECT_ID, category.optString(Keys.OBJECT_ID));
    requestJSON.put(Common.DIRECTION, "up");
    request.setJSON(requestJSON);
    mockAdminLogin(request);
    final MockResponse response = mockResponse();
    mockDispatcher(request, response);
    final String content = response.getString();
    Assert.assertTrue(StringUtils.contains(content, "code\":0"));
}
Also used : MockResponse(org.b3log.solo.MockResponse) JSONObject(org.json.JSONObject) MockRequest(org.b3log.solo.MockRequest) Test(org.testng.annotations.Test)

Aggregations

MockRequest (org.b3log.solo.MockRequest)71 MockResponse (org.b3log.solo.MockResponse)71 JSONObject (org.json.JSONObject)34 Test (org.testng.annotations.Test)31 Query (org.b3log.latke.repository.Query)23 Cookie (org.b3log.latke.http.Cookie)1