Examples of UriTemplateMatcher


Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

        assertEquals("varA", "a~b", result.getFirst("varA"));
    }

    public void testReservedMatch() {
        UriTemplateProcessor template = new BitWorkingUriTemplateProcessor("/prefix/{varA}");
        UriTemplateMatcher matcher = template.matcher();
        MultivaluedMap<String, String> result = matcher.match("/prefix/a%3Ab");
        assertNotNull("match ok :", result);
        assertEquals("match size :", 1, result.size());
        assertEquals("varA", "a%3Ab", result.getFirst("varA"));

        // character ":" is reserved, however hp-soa requires to match it
        result = matcher.match("/prefix/a:b");
        assertNotNull("match ok :", result);
        assertEquals("match size :", 1, result.size());
        assertEquals("varA", "a:b", result.getFirst("varA"));

        result = matcher.match("/prefix/a%2Fb");
        assertNotNull("match ok /", result);
        assertEquals("match size /", 1, result.size());
        assertEquals("varA", "a%2Fb", result.getFirst("varA"));

        result = matcher.match("/prefix/%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D");
        assertNotNull("match ok ?#[]@!$&'()*+,;=", result);
        assertEquals("match size ?#[]@!$&'()*+,;=", 1, result.size());
        assertEquals("varA", "%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D", result
            .getFirst("varA"));
    }
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    // }
    private static void assertMatchTemplate(UriTemplateProcessor template,
                                            String uri,
                                            String[][] variables) {

        UriTemplateMatcher matcher = template.matcher();
        MultivaluedMap<String, String> varMap = matcher.match(uri);
        if (variables == null) {

            // must not match
            assertNull(varMap);
        } else {
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    }

    public void testMatches() {
        String template = "/path1/{var1}/path2{var2:[ab]*}/tail";
        JaxRsUriTemplateProcessor processor = new JaxRsUriTemplateProcessor(template);
        UriTemplateMatcher matcher = processor.matcher();
        assertEquals(template, processor.getTemplate());

        boolean matches = matcher.matches("/path1/value1/path2/tail");
        assertTrue(matches);
        matches = matcher.matches("/path1/value1/path2ab/tail");
        assertTrue(matches);
        matches = matcher.matches("/path1/value1/path2ababab/tail");
        assertTrue(matches);
        matches = matcher.matches("/path1/value2/path2/tail");
        assertTrue(matches);

        matches = matcher.matches("/path1/value1/path2c/tail");
        assertFalse(matches);
        matches = matcher.matches("/path2/value1/path2ab/tail");
        assertFalse(matches);
        matches = matcher.matches("/path1/value1/path2c/tailZ");
        assertFalse(matches);
    }
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    }

    public void testGetVariables() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/path2{var2:[ab]*}/{var1}");
        UriTemplateMatcher matcher = processor.matcher();
        matcher.matches("/path1/value%20a/path2abab/valueB/tail%20part");

        // variable value
        assertEquals("value a", matcher.getVariableValue("var1"));
        assertEquals("value%20a", matcher.getVariableValue("var1", false));
        assertEquals("abab", matcher.getVariableValue("var2"));
        assertEquals("abab", matcher.getVariableValue("var2", false));
        assertNull(matcher.getVariableValue("var3"));

        // variable values as list
        List<String> varValues = matcher.getVariableValues("var1");
        assertEquals(2, varValues.size());
        assertEquals("value a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
        varValues = matcher.getVariableValues("var1", false);
        assertEquals(2, varValues.size());
        assertEquals("value%20a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
        varValues = matcher.getVariableValues("var2");
        assertEquals(1, varValues.size());
        assertEquals("abab", varValues.get(0));

        // variable names set
        Set<String> variableNames = processor.getVariableNames();
        assertEquals(2, variableNames.size());
        assertTrue(variableNames.contains("var1"));
        assertTrue(variableNames.contains("var2"));

        // get all variables
        // decoded
        MultivaluedMap<String, String> allVariables = matcher.getVariables(true);
        assertEquals(2, allVariables.size());
        varValues = allVariables.get("var1");
        assertEquals(2, varValues.size());
        assertEquals("value a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
        varValues = allVariables.get("var2");
        assertEquals(1, varValues.size());
        assertEquals("abab", varValues.get(0));

        // encoded
        allVariables = matcher.getVariables(false);
        assertEquals(2, allVariables.size());
        varValues = allVariables.get("var1");
        assertEquals(2, varValues.size());
        assertEquals("value%20a", varValues.get(0));
        assertEquals("valueB", varValues.get(1));
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    }

    public void testTail() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/path2{var2:[ab]*}/{var3}");
        UriTemplateMatcher matcher = processor.matcher();
        matcher.matches("/path1/value%20a/path2abab/valueB/tail%20part");

        String tail = matcher.getTail();
        assertEquals("/tail part", tail);
        assertEquals("/tail%20part", matcher.getTail(false));

        matcher.matches("/path1/value%20a/path2abab/valueB/");
        tail = matcher.getTail();
        assertEquals("/", tail);

        matcher.matches("/path1/value%20a/path2abab/valueB");
        tail = matcher.getTail();
        assertEquals("", tail);
    }
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    }

    public void testHead() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/path2{var2:[ab]*}/{var3}");
        UriTemplateMatcher matcher = processor.matcher();
        matcher.matches("/path1/value%20a/path2abab/valueB/tail%20part");

        String head = matcher.getHead();
        assertEquals("/path1/value a/path2abab/valueB", head);
        assertEquals("/path1/value%20a/path2abab/valueB", matcher.getHead(false));

        matcher.matches("/path1/value%20a/path2abab/valueB/");
        head = matcher.getHead();
        assertEquals("/path1/value a/path2abab/valueB", head);

        matcher.matches("/path1/value%20a/path2abab/valueB");
        head = matcher.getHead();
        assertEquals("/path1/value a/path2abab/valueB", head);
    }
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    }

    public void testSameVariableTwice() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/path2{var1:[ab]*}/tail");
        UriTemplateMatcher matcher = processor.matcher();
        boolean matches = matcher.matches("/path1/value%20a/path2abab/tail");
        assertTrue(matches);
        assertEquals("value a", matcher.getVariableValue("var1"));
        assertEquals("value%20a", matcher.getVariableValue("var1", false));

        List<String> varValues = matcher.getVariableValues("var1");
        assertEquals(2, varValues.size());
        assertEquals("value a", varValues.get(0));
        assertEquals("abab", varValues.get(1));

        varValues = matcher.getVariableValues("var1", false);
        assertEquals(2, varValues.size());
        assertEquals("value%20a", varValues.get(0));
        assertEquals("abab", varValues.get(1));
    }
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    }

    public void testTemplateWithCapturingGroupsInRegex() {
        JaxRsUriTemplateProcessor processor =
            new JaxRsUriTemplateProcessor("/path1/{var1}/{var2:(a)(b)*}/path2/{var3}/tail");
        UriTemplateMatcher matcher = processor.matcher();
        boolean matches = matcher.matches("/path1/cc/abb/path2/dd/tail");
        assertTrue(matches);
        assertEquals("cc", matcher.getVariableValue("var1"));
        assertEquals("abb", matcher.getVariableValue("var2"));
        assertEquals("dd", matcher.getVariableValue("var3"));
        assertNull(matcher.getVariableValue("var4"));

        assertEquals(1, matcher.getVariableValues("var1").size());
        assertEquals(1, matcher.getVariableValues("var2").size());
        assertEquals(1, matcher.getVariableValues("var3").size());

        matches = matcher.matches("/path1/cc/bb/path2/dd/tail");
        assertFalse(matches);
    }
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

    public void testCompileMatchExpand() {
        JaxRsUriTemplateProcessor processor = new JaxRsUriTemplateProcessor();
        // 1
        processor.compile("/path1/{var1}");
        UriTemplateMatcher matcher = processor.matcher();
        boolean matches = matcher.matches("/path1/abc");
        assertTrue(matches);
        MultivaluedMap<String, String> values = new MultivaluedMapImpl<String, String>();
        values.add("var1", "xyz");
        String expanded = processor.expand(values);
        assertEquals("/path1/xyz", expanded);

        // 2
        processor.compile("/path2/{var1}");
        matcher = processor.matcher();
        matches = matcher.matches("/path1/abc");
        assertFalse(matches);
        matches = matcher.matches("/path2/abc");
        assertTrue(matches);
        values = new MultivaluedMapImpl<String, String>();
        values.add("var1", "xyz");
        expanded = processor.expand(values);
        assertEquals("/path2/xyz", expanded);
View Full Code Here

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateMatcher

        UriTemplateProcessor processor =
            JaxRsUriTemplateProcessor.newNormalizedInstance("/path1/path2/./../path3");
        assertEquals("path1/path3", processor.getTemplate());

        processor = (JaxRsUriTemplateProcessor)JaxRsUriTemplateProcessor.newNormalizedInstance("");
        UriTemplateMatcher matcher = processor.matcher();
        boolean matches = matcher.matches("");
        assertTrue(matches);
        assertTrue(matcher.isExactMatch());

        processor = (JaxRsUriTemplateProcessor)JaxRsUriTemplateProcessor.newNormalizedInstance("/");
        matcher = processor.matcher();
        matches = matcher.matches("");
        assertTrue(matches);
        assertTrue(matcher.isExactMatch());

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.