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

修复测试

parent 98635ad7
...@@ -246,12 +246,6 @@ public final class Server extends BaseServer { ...@@ -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(); routeProcessors();
final Latkes.RuntimeDatabase runtimeDatabase = Latkes.getRuntimeDatabase(); final Latkes.RuntimeDatabase runtimeDatabase = Latkes.getRuntimeDatabase();
...@@ -410,6 +404,12 @@ public final class Server extends BaseServer { ...@@ -410,6 +404,12 @@ public final class Server extends BaseServer {
} }
public static void routeProcessors() { 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(); routeConsoleProcessors();
routeIndexProcessors(); routeIndexProcessors();
Dispatcher.mapping(); Dispatcher.mapping();
......
...@@ -47,7 +47,7 @@ import java.util.List; ...@@ -47,7 +47,7 @@ import java.util.List;
* Solo initialization service. * Solo initialization service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 0.4.0
*/ */
@Service @Service
...@@ -133,7 +133,7 @@ public class InitService { ...@@ -133,7 +133,7 @@ public class InitService {
/** /**
* Flag of init status. * Flag of init status.
*/ */
private static boolean inited; public static boolean inited;
/** /**
* Flag of printed init prompt. * Flag of printed init prompt.
......
...@@ -19,7 +19,6 @@ import org.b3log.latke.http.Dispatcher; ...@@ -19,7 +19,6 @@ import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.Request; import org.b3log.latke.http.Request;
import org.b3log.latke.http.Response; import org.b3log.latke.http.Response;
import org.b3log.latke.ioc.BeanManager; import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Discoverer;
import org.b3log.latke.model.User; import org.b3log.latke.model.User;
import org.b3log.latke.repository.jdbc.util.Connections; import org.b3log.latke.repository.jdbc.util.Connections;
import org.b3log.latke.repository.jdbc.util.JdbcRepositories; import org.b3log.latke.repository.jdbc.util.JdbcRepositories;
...@@ -40,13 +39,12 @@ import org.testng.annotations.BeforeMethod; ...@@ -40,13 +39,12 @@ import org.testng.annotations.BeforeMethod;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.sql.Connection; import java.sql.Connection;
import java.util.Collection;
/** /**
* Abstract test case. * Abstract test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 2.9.7
*/ */
public abstract class AbstractTestCase { public abstract class AbstractTestCase {
...@@ -56,6 +54,11 @@ public abstract class AbstractTestCase { ...@@ -56,6 +54,11 @@ public abstract class AbstractTestCase {
*/ */
private BeanManager beanManager; private BeanManager beanManager;
static {
Latkes.init();
Server.routeProcessors();
}
/** /**
* Before class. * Before class.
* <ol> * <ol>
...@@ -67,10 +70,7 @@ public abstract class AbstractTestCase { ...@@ -67,10 +70,7 @@ public abstract class AbstractTestCase {
*/ */
@BeforeClass @BeforeClass
public void beforeClass() throws Exception { public void beforeClass() throws Exception {
Latkes.init(); System.out.println("before class");
final Collection<Class<?>> classes = Discoverer.discover("org.b3log.solo");
BeanManager.start(classes);
beanManager = BeanManager.getInstance(); beanManager = BeanManager.getInstance();
final Connection connection = Connections.getConnection(); final Connection connection = Connections.getConnection();
...@@ -78,6 +78,7 @@ public abstract class AbstractTestCase { ...@@ -78,6 +78,7 @@ public abstract class AbstractTestCase {
connection.close(); connection.close();
JdbcRepositories.initAllTables(); JdbcRepositories.initAllTables();
InitService.inited = false;
initSolo(); initSolo();
} }
...@@ -147,8 +148,6 @@ public abstract class AbstractTestCase { ...@@ -147,8 +148,6 @@ public abstract class AbstractTestCase {
*/ */
public MockDispatcher mockDispatcher(final Request request, final Response response) { public MockDispatcher mockDispatcher(final Request request, final Response response) {
final MockDispatcher ret = new MockDispatcher(); final MockDispatcher ret = new MockDispatcher();
ret.init();
Server.routeProcessors();
ret.handle(request, response); ret.handle(request, response);
return ret; return ret;
......
...@@ -25,5 +25,6 @@ public class MockRequest extends Request { ...@@ -25,5 +25,6 @@ public class MockRequest extends Request {
public MockRequest(final FullHttpRequest req) { public MockRequest(final FullHttpRequest req) {
super(null, 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; ...@@ -22,7 +22,7 @@ import org.testng.annotations.Test;
* {@link ErrorProcessor} test case. * {@link ErrorProcessor} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 1.7.0
*/ */
@Test(suiteName = "processor") @Test(suiteName = "processor")
...@@ -33,11 +33,11 @@ public class ErrorProcessorTestCase extends AbstractTestCase { ...@@ -33,11 +33,11 @@ public class ErrorProcessorTestCase extends AbstractTestCase {
*/ */
public void showErrorPage() { public void showErrorPage() {
final MockRequest request = mockRequest(); final MockRequest request = mockRequest();
request.setRequestURI("/error/403"); request.setRequestURI("/notfound");
final MockResponse response = mockResponse(); final MockResponse response = mockResponse();
mockDispatcher(request, response); mockDispatcher(request, response);
final String content = response.getString(); 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; ...@@ -14,32 +14,16 @@ package org.b3log.solo.processor;
import org.b3log.latke.http.Dispatcher; import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.Request; import org.b3log.latke.http.Request;
import org.b3log.latke.http.Response; 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. * Mock dispatcher for unit tests.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 1.7.0
*/ */
public class MockDispatcher { 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) { public void handle(final Request req, final Response resp) {
Dispatcher.handle(req, 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