Created
March 23, 2015 15:09
-
-
Save leolux/0675612cc442f569faae to your computer and use it in GitHub Desktop.
"/some/path/*" should match "/some/path/wibble" but not "/some/pathwibble"
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 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