Search in sources :

Example 1 with ContainsPredicate

use of io.undertow.predicate.ContainsPredicate in project undertow by undertow-io.

the class PredicatedHandlersParserTestCase method testParsedPredicatedHandler1.

@Test
public void testParsedPredicatedHandler1() {
    String value = "contains(value='a', search=b) -> dump-request";
    List<PredicatedHandler> ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
    Assert.assertEquals(1, ret.size());
    HttpHandler handler = ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
    Assert.assertTrue(handler instanceof RequestDumpingHandler);
    ContainsPredicate predicate = (ContainsPredicate) ret.get(0).getPredicate();
    Assert.assertEquals("a", predicate.getAttribute().readAttribute(null));
    Assert.assertArrayEquals(new String[] { "b" }, predicate.getValues());
    value = "contains(value='a', search={b}) -> dump-request";
    ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
    Assert.assertEquals(1, ret.size());
    handler = ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
    Assert.assertTrue(handler instanceof RequestDumpingHandler);
    predicate = (ContainsPredicate) ret.get(0).getPredicate();
    Assert.assertEquals("a", predicate.getAttribute().readAttribute(null));
    Assert.assertArrayEquals(new String[] { "b" }, predicate.getValues());
    value = "contains[value='a', search={b, c}] -> dump-request";
    ret = PredicatedHandlersParser.parse(value, getClass().getClassLoader());
    Assert.assertEquals(1, ret.size());
    handler = ret.get(0).getHandler().wrap(ResponseCodeHandler.HANDLE_200);
    Assert.assertTrue(handler instanceof RequestDumpingHandler);
    predicate = (ContainsPredicate) ret.get(0).getPredicate();
    Assert.assertEquals("a", predicate.getAttribute().readAttribute(null));
    Assert.assertArrayEquals(new String[] { "b", "c" }, predicate.getValues());
}
Also used : HttpHandler(io.undertow.server.HttpHandler) ContainsPredicate(io.undertow.predicate.ContainsPredicate) RequestDumpingHandler(io.undertow.server.handlers.RequestDumpingHandler) HttpString(io.undertow.util.HttpString) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Aggregations

ContainsPredicate (io.undertow.predicate.ContainsPredicate)1 HttpHandler (io.undertow.server.HttpHandler)1 RequestDumpingHandler (io.undertow.server.handlers.RequestDumpingHandler)1 UnitTest (io.undertow.testutils.category.UnitTest)1 HttpString (io.undertow.util.HttpString)1 Test (org.junit.Test)1