Created
August 25, 2015 09:30
-
-
Save jirkapenzes/1c5f6b88886d6b9d0498 to your computer and use it in GitHub Desktop.
Route Matcher Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.topmonks.monkbox.engine; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.Parameterized; | |
import java.util.Arrays; | |
/** | |
* @author Jirka Penzes ([email protected]) | |
*/ | |
@RunWith(value = Parameterized.class) | |
public class RouteMatcherTest { | |
private final String baseRoute; | |
private final String route; | |
private final boolean expected; | |
public RouteMatcherTest(String baseRoute, String route, boolean expected) { | |
this.baseRoute = baseRoute; | |
this.route = route; | |
this.expected = expected; | |
} | |
@Parameterized.Parameters(name = "{index}: matches({0}, {1}) => {2}") | |
public static Iterable<Object[]> data() { | |
return Arrays.asList(new Object[][]{ | |
{"v1/test", "v1/test", true}, | |
{"v1/test", "v1/TEST", true}, | |
{"v1/TEST", "v1/test", true}, | |
{"v1/test", "v1/test/t", false}, | |
{"v1/test", "v1/", false}, | |
{"v1/test/{id}", "v1/test/1", true}, | |
{"v1/test/{id}", "v1/TEST/1", true}, | |
{"v1/test/{id}", "v1/test/10", true}, | |
{"v1/test/{id}", "v1/test/10/x", false}, | |
{"v1/test{id}", "v1/test", true}, | |
{"v1/{id}/test", "v1/1/test", true}, | |
{"v1/dev/{id}/test", "v1/dev/1/test", true}, | |
{"v1/dev/{id}/dev/test", "v1/dev/1/dev/test", true}, | |
{"v1/{id}/test", "v1/test", false}, | |
{"v1/{id1}/test/{id2}", "v1/1/test/2", true}, | |
{"v1/{id1}/test/{id2}/test2", "v1/1/test/1/test2", true}, | |
{"v1/{id1}/test/{id2}/test2", "v1/1/test/2/test2", true}, | |
{"v1/{id1}/{id2}", "v1/1/2", true}, | |
{"v1/test/{id1}", "v1/test/1/2", false} | |
}); | |
} | |
@Test | |
public void should_match_route_by_base_route() throws Exception { | |
Assert.assertEquals(expected, RouteMatcher.match(baseRoute, route)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment