Skip to content

Instantly share code, notes, and snippets.

@leolux
Created March 23, 2015 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leolux/0675612cc442f569faae to your computer and use it in GitHub Desktop.
Save leolux/0675612cc442f569faae to your computer and use it in GitHub Desktop.
"/some/path/*" should match "/some/path/wibble" but not "/some/pathwibble"
package middleware.common;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.apex.ApexTestBase;
import java.util.UUID;
import org.junit.Test;
public class WildcardMatcherTest extends ApexTestBase {
@Test
public void testRoutePathWithEndingWildcard() throws Exception {
String path = "/some/path/";
router.route(path + "*").handler(
rc -> {
rc.response().setStatusCode(200)
.setStatusMessage(rc.request().path()).end();
});
testPathBegin(path);
}
private void testPathBegin(String path) throws Exception {
for (HttpMethod meth : METHODS) {
testPathBegin(meth, path);
}
}
private void testPathBegin(HttpMethod method, String path) throws Exception {
testRequest(method, path, 200, path);
testRequest(method, path + "wibble", 200, path + "wibble");
if (path.endsWith("/")) {
testRequest(method,
path.substring(0, path.length() - 1) + "wibble", 404,
"Not Found");
testRequest(method, path.substring(0, path.length() - 1)
+ "/wibble", 200, path.substring(0, path.length() - 1)
+ "/wibble");
} else {
testRequest(method, path + "/wibble", 200, path + "/wibble");
testRequest(method, path + "/wibble/floob", 200, path + "/wibble/floob");
testRequest(method, path.substring(0, path.length() - 1), 404,
"Not Found");
}
testRequest(method, "/", 404, "Not Found");
testRequest(method, "/" + UUID.randomUUID().toString(), 404,
"Not Found");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment