|
9 | 9 | package io.netty.handler.codec.http.router; |
10 | 10 |
|
11 | 11 | import io.netty.handler.codec.http.HttpMethod; |
| 12 | +import io.netty.handler.codec.http.router.testutil.Log4jUtil; |
| 13 | +import io.netty.util.CharsetUtil; |
| 14 | +import java.io.ByteArrayOutputStream; |
| 15 | +import junit.framework.Assert; |
| 16 | +import org.apache.logging.log4j.Level; |
12 | 17 | import org.junit.After; |
13 | 18 | import org.junit.AfterClass; |
14 | 19 | import org.junit.Before; |
@@ -46,14 +51,15 @@ public void tearDown() { |
46 | 51 | */ |
47 | 52 | @Test |
48 | 53 | public void testAdd() { |
| 54 | + ByteArrayOutputStream result = new ByteArrayOutputStream(); |
| 55 | + Log4jUtil.catchLogMessages(result, Level.ALL); |
49 | 56 | System.out.println("add"); |
50 | | - Routing pattern = null; |
51 | | - RoutingPathMatcher instance = new RoutingPathMatcher(); |
52 | | - RoutingPathMatcher expResult = null; |
53 | | - RoutingPathMatcher result = instance.add(pattern); |
54 | | - assertEquals(expResult, result); |
55 | | - // TODO review the generated test code and remove the default call to fail. |
56 | | - fail("The test case is a prototype."); |
| 57 | + RoutingPathMatcher matcher = new RoutingPathMatcher(); |
| 58 | + Routing routing_before_delete = new Routing(new RoutingConfig.SimplePathGet("BEFORE_DELETE", "/before/delete"), HttpMethod.GET); |
| 59 | + Routing routing_tobe_delete = new Routing(new RoutingConfig.SimplePathGet("BEFORE_DELETE", "/tobe/delete"), HttpMethod.GET); |
| 60 | + Routing routing_after_delete = new Routing(new RoutingConfig.SimplePathGet("AFTER_DELETE", "/after/delete"), HttpMethod.GET); |
| 61 | + matcher.add(routing_before_delete).add(routing_tobe_delete).add(routing_after_delete); |
| 62 | + Assert.assertEquals("There is Routing Override occured in same name: BEFORE_DELETE", new String(result.toByteArray(), CharsetUtil.UTF_8).trim()); |
57 | 63 | } |
58 | 64 |
|
59 | 65 | /** |
@@ -95,14 +101,24 @@ public void testMatch() { |
95 | 101 | @Test |
96 | 102 | public void testGeneratePath() { |
97 | 103 | System.out.println("generatePath"); |
98 | | - String name = ""; |
99 | | - Object[] params = null; |
100 | | - RoutingPathMatcher instance = new RoutingPathMatcher(); |
101 | | - String expResult = ""; |
102 | | - String result = instance.generatePath(name, params); |
103 | | - assertEquals(expResult, result); |
104 | | - // TODO review the generated test code and remove the default call to fail. |
105 | | - fail("The test case is a prototype."); |
| 104 | + RoutingPathMatcher matcher = new RoutingPathMatcher(); |
| 105 | + Routing plain_path_routing_1 = new Routing(new RoutingConfig.SimplePathGet("plain_path_routing_1", "/tester/plain/get"), HttpMethod.GET); |
| 106 | + Routing single_var_routing_1 = new Routing(new RoutingConfig.SimplePathGet("single_var_routing_1", "/tester/var/:var1"), HttpMethod.GET); |
| 107 | + Routing dual_var_routing_1 = new Routing(new RoutingConfig.SimplePathGet("dual_var_routing_1", "/tester/var/:var1/var/:var2"), HttpMethod.GET); |
| 108 | + matcher.add(plain_path_routing_1).add(single_var_routing_1).add(dual_var_routing_1); |
| 109 | + assertEquals("/tester/plain/get", matcher.generatePath("plain_path_routing_1")); |
| 110 | + try { |
| 111 | + matcher.generatePath("plain_path_routing_1", 123); |
| 112 | + fail("Miss IllegalArgumentException thrown."); |
| 113 | + } catch (IllegalArgumentException e) { |
| 114 | + } |
| 115 | + assertEquals("/tester/var/123/var/BANKAI", matcher.generatePath("dual_var_routing_1", "var1", 123, "var2", "BANKAI")); |
| 116 | + try { |
| 117 | + matcher.generatePath("dual_var_routing_1", "var1", 123, "var2"); |
| 118 | + fail("Miss IllegalArgumentException thrown."); |
| 119 | + } catch (Exception e) { |
| 120 | + } |
| 121 | + assertEquals("/tester/var/123", matcher.generatePath("single_var_routing_1", "var1", 123)); |
106 | 122 | } |
107 | 123 |
|
108 | 124 | } |
0 commit comments