Commit 298f85dd authored by Liang Ding's avatar Liang Ding

修复测试

parent 98635ad7
......@@ -246,12 +246,6 @@ public final class Server extends BaseServer {
}
}
Dispatcher.startRequestHandler = new BeforeRequestHandler();
Dispatcher.HANDLERS.add(1, new SkinHandler());
Dispatcher.HANDLERS.add(2, new InitCheckHandler());
Dispatcher.HANDLERS.add(3, new PermalinkHandler());
Dispatcher.endRequestHandler = new AfterRequestHandler();
routeProcessors();
final Latkes.RuntimeDatabase runtimeDatabase = Latkes.getRuntimeDatabase();
......@@ -410,6 +404,12 @@ public final class Server extends BaseServer {
}
public static void routeProcessors() {
Dispatcher.startRequestHandler = new BeforeRequestHandler();
Dispatcher.HANDLERS.add(1, new SkinHandler());
Dispatcher.HANDLERS.add(2, new InitCheckHandler());
Dispatcher.HANDLERS.add(3, new PermalinkHandler());
Dispatcher.endRequestHandler = new AfterRequestHandler();
routeConsoleProcessors();
routeIndexProcessors();
Dispatcher.mapping();
......
......@@ -47,7 +47,7 @@ import java.util.List;
* Solo initialization service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.5.2.39, Apr 6, 2020
* @version 1.5.2.40, Apr 30, 2020
* @since 0.4.0
*/
@Service
......@@ -133,7 +133,7 @@ public class InitService {
/**
* Flag of init status.
*/
private static boolean inited;
public static boolean inited;
/**
* Flag of printed init prompt.
......
......@@ -19,7 +19,6 @@ import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.Response;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Discoverer;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.jdbc.util.Connections;
import org.b3log.latke.repository.jdbc.util.JdbcRepositories;
......@@ -40,13 +39,12 @@ import org.testng.annotations.BeforeMethod;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.util.Collection;
/**
* Abstract test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 4.0.0.0, Feb 9, 2020
* @version 4.0.0.1, Apr 30, 2020
* @since 2.9.7
*/
public abstract class AbstractTestCase {
......@@ -56,6 +54,11 @@ public abstract class AbstractTestCase {
*/
private BeanManager beanManager;
static {
Latkes.init();
Server.routeProcessors();
}
/**
* Before class.
* <ol>
......@@ -67,10 +70,7 @@ public abstract class AbstractTestCase {
*/
@BeforeClass
public void beforeClass() throws Exception {
Latkes.init();
final Collection<Class<?>> classes = Discoverer.discover("org.b3log.solo");
BeanManager.start(classes);
System.out.println("before class");
beanManager = BeanManager.getInstance();
final Connection connection = Connections.getConnection();
......@@ -78,6 +78,7 @@ public abstract class AbstractTestCase {
connection.close();
JdbcRepositories.initAllTables();
InitService.inited = false;
initSolo();
}
......@@ -147,8 +148,6 @@ public abstract class AbstractTestCase {
*/
public MockDispatcher mockDispatcher(final Request request, final Response response) {
final MockDispatcher ret = new MockDispatcher();
ret.init();
Server.routeProcessors();
ret.handle(request, response);
return ret;
......
......@@ -25,5 +25,6 @@ public class MockRequest extends Request {
public MockRequest(final FullHttpRequest req) {
super(null, req);
req.headers().set("X-Forwarded-For", "127.0.0.1");
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ import org.testng.annotations.Test;
* {@link ErrorProcessor} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.3, Feb 22, 2019
* @version 1.0.1.4, Apr 30, 2020
* @since 1.7.0
*/
@Test(suiteName = "processor")
......@@ -33,11 +33,11 @@ public class ErrorProcessorTestCase extends AbstractTestCase {
*/
public void showErrorPage() {
final MockRequest request = mockRequest();
request.setRequestURI("/error/403");
request.setRequestURI("/notfound");
final MockResponse response = mockResponse();
mockDispatcher(request, response);
final String content = response.getString();
Assert.assertTrue(StringUtils.contains(content, "<title>403 Forbidden! - Solo 的个人博客</title>"));
Assert.assertTrue(StringUtils.contains(content, "<title>404 Not Found! - Solo 的个人博客</title>"));
}
}
......@@ -14,32 +14,16 @@ package org.b3log.solo.processor;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.Response;
import org.b3log.latke.http.function.Handler;
import org.b3log.latke.http.handler.InvokeHandler;
import org.b3log.latke.http.handler.RouteHandler;
import java.util.ArrayList;
import java.util.List;
/**
* Mock dispatcher for unit tests.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.0, Feb 9, 2020
* @version 2.0.0.1, Apr 30, 2020
* @since 1.7.0
*/
public class MockDispatcher {
/**
* Handlers
*/
private static final List<Handler> HANDLERS = new ArrayList<>();
public void init() {
HANDLERS.add(new RouteHandler());
HANDLERS.add(new InvokeHandler());
}
public void handle(final Request req, final Response resp) {
Dispatcher.handle(req, resp);
}
......
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