Commit 2eb64965 authored by Liang Ding's avatar Liang Ding

#12593

parent f76eaa2d
......@@ -103,22 +103,6 @@ public class CategoryProcessor {
@Inject
private StatisticMgmtService statisticMgmtService;
/**
* Gets category URI from the specified URI.
*
* @param requestURI the specified request URI
* @return category URI
*/
private static String getCategoryURI(final String requestURI) {
final String path = requestURI.substring((Latkes.getContextPath() + "/category/").length());
if (path.contains("/")) {
return path.substring(0, path.indexOf("/"));
} else {
return path.substring(0);
}
}
/**
* Shows articles related with a category with the specified context.
*
......
......@@ -95,7 +95,17 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
public Enumeration getHeaderNames() {
throw new UnsupportedOperationException("Not supported yet.");
return new Enumeration() {
@Override
public boolean hasMoreElements() {
return false;
}
@Override
public Object nextElement() {
return null;
}
};
}
@Override
......@@ -221,7 +231,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
public String getCharacterEncoding() {
throw new UnsupportedOperationException("Not supported yet.");
return "mock character encoding";
}
@Override
......@@ -236,7 +246,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
public String getContentType() {
throw new UnsupportedOperationException("Not supported yet.");
return "mock content type";
}
@Override
......@@ -315,7 +325,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
public String getRemoteHost() {
throw new UnsupportedOperationException("Not supported yet.");
return "mock remote host";
}
@Override
......@@ -355,22 +365,22 @@ public class MockHttpServletRequest implements HttpServletRequest {
@Override
public int getRemotePort() {
throw new UnsupportedOperationException("Not supported yet.");
return 0;
}
@Override
public String getLocalName() {
throw new UnsupportedOperationException("Not supported yet.");
return "mock local name";
}
@Override
public String getLocalAddr() {
throw new UnsupportedOperationException("Not supported yet.");
return "mock local addr";
}
@Override
public int getLocalPort() {
throw new UnsupportedOperationException("Not supported yet.");
return 0;
}
@Override
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.processor;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.MockHttpServletRequest;
import org.b3log.solo.MockHttpServletResponse;
import org.b3log.solo.model.Category;
import org.b3log.solo.model.Option;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.BufferedReader;
import java.io.StringReader;
/**
* {@link CategoryProcessor} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Dec 11, 2018
* @since 2.9.8
*/
@Test(suiteName = "processor")
public class CategoryProcessorTestCase extends AbstractTestCase {
/**
* Init.
*
* @throws Exception exception
*/
@Test
public void init() throws Exception {
super.init();
}
/**
* showCategoryArticles.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void showCategoryArticles() throws Exception {
MockHttpServletRequest request = mockRequest();
request.setRequestURI("/console/category/");
request.setMethod("POST");
final JSONObject requestJSON = new JSONObject();
requestJSON.put(Category.CATEGORY_T_TAGS, "Solo");
requestJSON.put(Category.CATEGORY_TITLE, "分类1");
requestJSON.put(Category.CATEGORY_URI, "cate1");
final BufferedReader reader = new BufferedReader(new StringReader(requestJSON.toString()));
request.setReader(reader);
mockAdminLogin(request);
MockHttpServletResponse response = mockResponse();
mockDispatcherServletService(request, response);
request = mockRequest();
request.setRequestURI("/category/cate1");
request.setMethod("GET");
request.setAttribute(Keys.TEMAPLTE_DIR_NAME, Option.DefaultPreference.DEFAULT_SKIN_DIR_NAME);
response = mockResponse();
mockDispatcherServletService(request, response);
final String content = response.body();
Assert.assertTrue(StringUtils.contains(content, "<title>分类1 - Admin 的个人博客</title>"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment