Skip to content

Commit

Permalink
Merge branch '3.1' into 3.2
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml

Signed-off-by: Richard Lea <chigix@zoho.com>
  • Loading branch information
chigix committed Dec 13, 2016
2 parents f3d20ba + a051a62 commit 1db3ab0
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 19 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.chigix</groupId>
<artifactId>netty-router</artifactId>
<version>3.2.0-beta</version>
<version>3.2.0-beta1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -44,13 +44,13 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.3</version>
<version>2.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
<version>2.7</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public RoutingPathMatched match(String path) {
* @return Returns {@code null} if there is no {@link Pattern} matched in
* this router.In addtion, the pattern with ":*" would also not be matched
* in any cases.
* @throws IllegalArgumentException
*/
public String generatePath(String name, Object... params) {
if (params.length == 0) {
Expand All @@ -181,7 +182,7 @@ public String generatePath(String name, Object... params) {
throw new IllegalArgumentException(MessageFormat.format("Missing value for params: {0}", params[params.length - 1]));
}
final Map map = new HashMap();
for (int i = 0; i < params.length; i++) {
for (int i = 0; i < params.length; i += 2) {
final String key = params[i].toString();
final String value = params[i + 1].toString();
map.put(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
package io.netty.handler.codec.http.router;

import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.router.testutil.Log4jUtil;
import io.netty.util.CharsetUtil;
import java.io.ByteArrayOutputStream;
import junit.framework.Assert;
import org.apache.logging.log4j.Level;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -46,14 +51,15 @@ public void tearDown() {
*/
@Test
public void testAdd() {
ByteArrayOutputStream result = new ByteArrayOutputStream();
Log4jUtil.catchLogMessages(result, Level.ALL);
System.out.println("add");
Routing pattern = null;
RoutingPathMatcher instance = new RoutingPathMatcher();
RoutingPathMatcher expResult = null;
RoutingPathMatcher result = instance.add(pattern);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
RoutingPathMatcher matcher = new RoutingPathMatcher();
Routing routing_before_delete = new Routing(new RoutingConfig.SimplePathGet("BEFORE_DELETE", "/before/delete"), HttpMethod.GET);
Routing routing_tobe_delete = new Routing(new RoutingConfig.SimplePathGet("BEFORE_DELETE", "/tobe/delete"), HttpMethod.GET);
Routing routing_after_delete = new Routing(new RoutingConfig.SimplePathGet("AFTER_DELETE", "/after/delete"), HttpMethod.GET);
matcher.add(routing_before_delete).add(routing_tobe_delete).add(routing_after_delete);
Assert.assertEquals("There is Routing Override occured in same name: BEFORE_DELETE", new String(result.toByteArray(), CharsetUtil.UTF_8).trim());
}

/**
Expand Down Expand Up @@ -95,14 +101,24 @@ public void testMatch() {
@Test
public void testGeneratePath() {
System.out.println("generatePath");
String name = "";
Object[] params = null;
RoutingPathMatcher instance = new RoutingPathMatcher();
String expResult = "";
String result = instance.generatePath(name, params);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
RoutingPathMatcher matcher = new RoutingPathMatcher();
Routing plain_path_routing_1 = new Routing(new RoutingConfig.SimplePathGet("plain_path_routing_1", "/tester/plain/get"), HttpMethod.GET);
Routing single_var_routing_1 = new Routing(new RoutingConfig.SimplePathGet("single_var_routing_1", "/tester/var/:var1"), HttpMethod.GET);
Routing dual_var_routing_1 = new Routing(new RoutingConfig.SimplePathGet("dual_var_routing_1", "/tester/var/:var1/var/:var2"), HttpMethod.GET);
matcher.add(plain_path_routing_1).add(single_var_routing_1).add(dual_var_routing_1);
assertEquals("/tester/plain/get", matcher.generatePath("plain_path_routing_1"));
try {
matcher.generatePath("plain_path_routing_1", 123);
fail("Miss IllegalArgumentException thrown.");
} catch (IllegalArgumentException e) {
}
assertEquals("/tester/var/123/var/BANKAI", matcher.generatePath("dual_var_routing_1", "var1", 123, "var2", "BANKAI"));
try {
matcher.generatePath("dual_var_routing_1", "var1", 123, "var2");
fail("Miss IllegalArgumentException thrown.");
} catch (Exception e) {
}
assertEquals("/tester/var/123", matcher.generatePath("single_var_routing_1", "var1", 123));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* This file is part of the netty-router package.
*
* (c) Richard Lea <chigix@zoho.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package io.netty.handler.codec.http.router.testutil;

import java.io.OutputStream;
import java.io.PrintWriter;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.WriterAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.layout.PatternLayout;

/**
*
* @author Richard Lea <chigix@zoho.com>
*/
public class Log4jUtil {

/**
* Try to get all messages through Log4j via adding a one-time used
* appender.
* http://logging.apache.org/log4j/2.x/manual/customconfig.html#AppendingToWritersAndOutputStreams
*
* @param out
* @param level
*/
public static void catchLogMessages(OutputStream out, Level level) {
LoggerContext ctx = LoggerContext.getContext(false);
Configuration conf = ctx.getConfiguration();
PatternLayout layout = PatternLayout.createDefaultLayout();
Appender appender = WriterAppender.createAppender(layout, null, new PrintWriter(out), "LogCatcher", false, true);
appender.start();
conf.addAppender(appender);
for (LoggerConfig loggerConf : conf.getLoggers().values()) {
loggerConf.addAppender(appender, level, null);
}
conf.getRootLogger().addAppender(appender, level, null);
}

}

0 comments on commit 1db3ab0

Please # to comment.