Skip to content

Commit

Permalink
🐛 fixed (lets-blade#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Nov 11, 2017
1 parent b583876 commit 402cea7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/main/java/com/blade/server/netty/HttpServerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest fullHttpR
// write session
WebContext.set(new WebContext(request, response));

if (isStaticFile(uri)) {
staticFileHandler.handle(ctx, request, response);
return;
}

Route route = routeMatcher.lookupRoute(request.method(), uri);
if (null == route) {
if (isStaticFile(uri)) {
staticFileHandler.handle(ctx, request, response);
return;
}
log.warn("Not Found\t{}", uri);
throw new NotFoundException();
}
Expand Down
23 changes: 16 additions & 7 deletions src/test/java/com/blade/mvc/route/RouteTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.blade.mvc.route;

import com.blade.BaseTestCase;
import com.blade.mvc.http.HttpMethod;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -14,48 +15,48 @@
* @author biezhi
* @date 2017/9/19
*/
public class RouteTest {
public class RouteTest extends BaseTestCase {

private Route route;

@Before
public void before(){
public void before() {
route = new Route();
}

@Test
public void testBuildRoute(){
public void testBuildRoute() {
route.toString();
Route route2 = new Route(HttpMethod.GET, "/", null, null);
assertNotEquals(route, route2);
}

@Test
public void testSort(){
public void testSort() {
assertEquals(Integer.MAX_VALUE, route.getSort());

route.setSort(20);
assertEquals(20, route.getSort());
}

@Test
public void testPath(){
public void testPath() {
assertEquals(null, route.getPath());

route.setPath("/a");
assertEquals("/a", route.getPath());
}

@Test
public void testHttpMethod(){
public void testHttpMethod() {
assertEquals(null, route.getHttpMethod());

route = new Route(HttpMethod.DELETE, "/", null, null);
assertEquals(HttpMethod.DELETE, route.getHttpMethod());
}

@Test
public void testPathParams(){
public void testPathParams() {
assertEquals(0, route.getPathParams().size());

Map<String, String> map = new HashMap<>();
Expand All @@ -66,4 +67,12 @@ public void testPathParams(){
assertEquals(2, route.getPathParams().size());
assertEquals("jack", route.getPathParams().get("name"));
}

@Test
public void testRobotsRequest() throws Exception {
start(app.get("/:id", (req, res) -> req.pathInt("id")));
String body = bodyToString("/robots.txt");
System.out.println(body);
}

}

0 comments on commit 402cea7

Please sign in to comment.