Package org.apache.wink.common.internal.uritemplate

Examples of org.apache.wink.common.internal.uritemplate.JaxRsUriTemplateProcessor$JaxRsTemplateExpander


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

    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));

View Full Code Here


        assertEquals("value%20a", varValues.get(0));
        assertEquals("abab", varValues.get(1));
    }

    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"));
View Full Code Here

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

    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

        assertTrue(matcher.isExactMatch());

    }

    public void testIllegalStates() {
        JaxRsUriTemplateProcessor processor = new JaxRsUriTemplateProcessor();
        assertNull(processor.getTemplate());

        // not yet compiled
        try {
            processor.matcher();
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            processor.expand(new MultivaluedMapImpl<String, String>());
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            processor.getPatternString();
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        try {
            processor.getVariableNames();
            fail("expected IllegalStateException to be thrown");
        } catch (IllegalStateException e) {
        }

        // compiled but not matched
        processor.compile("/path1/{var1}");
        UriTemplateMatcher matcher = processor.matcher();
        assertFalse(matcher.matches("/path2"));

        try {
            matcher.getVariables(false);
            fail("expected IllegalStateException to be thrown");
View Full Code Here

        }
    }

    public void testBadUserRegex() {
        try {
            new JaxRsUriTemplateProcessor("path/{var:?.*}");
            fail("expected PatternSyntaxException to be thrown");
        } catch (PatternSyntaxException e) {
        }
    }
View Full Code Here

        }
    }

    public void testBadTemplateForm() {
        try {
            new JaxRsUriTemplateProcessor("/path{/{var:?.*}");
            fail("expected IllegalArgumentException to be thrown");
        } catch (IllegalArgumentException e) {
        }

        try {
            new JaxRsUriTemplateProcessor("/path{}/{var:?.*}");
            fail("expected IllegalArgumentException to be thrown");
        } catch (IllegalArgumentException e) {
        }
    }
View Full Code Here

        } catch (IllegalArgumentException e) {
        }
    }

    public void testCompareTo() {
        JaxRsUriTemplateProcessor p1 = new JaxRsUriTemplateProcessor();
        JaxRsUriTemplateProcessor p2 = new JaxRsUriTemplateProcessor();

        p1.compile("/path1/path2");
        p2.compile("/path1/path2");
        assertTrue(p1.compareTo(p2) == 0);

        p1.compile("/path2/path1");
        p2.compile("/path1/path2");
        assertTrue(p1.compareTo(p2) == 0);

        p1.compile("/path1/path2/path3");
        p2.compile("/path1/path2");
        assertTrue(p1.compareTo(p2) > 0);

        p1.compile("/path1/path2");
        p2.compile("/path1/path2/path3");
        assertTrue(p1.compareTo(p2) < 0);

        p1.compile("/path1/path2/{var1}");
        p2.compile("/path1/path2/{var1}");
        assertTrue(p1.compareTo(p2) == 0);

        p1.compile("/path1/path2/{var1}");
        p2.compile("/path1/path2/{variable1}");
        assertTrue(p1.compareTo(p2) == 0);

        p1.compile("/path1/path2/{var1}");
        p2.compile("/path1/{variable1}/path2");
        assertTrue(p1.compareTo(p2) == 0);

        p1.compile("/path1/path2/path3/{var1}");
        p2.compile("/path1/path2/{var1}");
        assertTrue(p1.compareTo(p2) > 0);

        p1.compile("/path1/path2/{var1}");
        p2.compile("/path1/path2/path3/{var1}");
        assertTrue(p1.compareTo(p2) < 0);

        p1.compile("/path1/path2/{var1}/{var2}");
        p2.compile("/path1/path2/{var1}");
        assertTrue(p1.compareTo(p2) > 0);

        p1.compile("/path1/path2/{var1}");
        p2.compile("/path1/path2/{var1}/{var2}");
        assertTrue(p1.compareTo(p2) < 0);

        p1.compile("/path1/path2/path3/{var1}");
        p2.compile("/path1/path2/{var1}/{var2}");
        assertTrue(p1.compareTo(p2) > 0);

        p1.compile("/path1/path2/{var1}/{var2}");
        p2.compile("/path1/path2/path3/{var1}");
        assertTrue(p1.compareTo(p2) < 0);

        p1.compile("/path1/path2/{var1}/{var2:.*}");
        p2.compile("/path1/path2/{var1}/{var2:.*}");
        assertTrue(p1.compareTo(p2) == 0);

        p1.compile("/path1/path2/{var1}/{var2:.*}");
        p2.compile("/path1/path2/{var1}/{var2}");
        assertTrue(p1.compareTo(p2) > 0);

        p1.compile("/path1/path2/{var1}/{var2}");
        p2.compile("/path1/path2/{var1}/{var2:.*}");
        assertTrue(p1.compareTo(p2) < 0);

        p1.compile("/path1/path2/{var1:.*}/{var2}");
        p2.compile("/path1/path2/{var1}/{var2:.*}");
        assertTrue(p1.compareTo(p2) == 0);
    }
View Full Code Here

     * @param testPath    The match path
     */
    private UriTemplateMatcher match(String requestPath, String testPath) {

        if (processor == null) {
            processor = new JaxRsUriTemplateProcessor(testPath);
        }

        UriTemplateMatcher matcher = processor.matcher();
        return matcher.matches(requestPath) ? matcher : null;
    }
View Full Code Here

     */
    public UriTemplateMatcher match(String requestPath, String testPath) {

        if (processor == null) {
            // processor = new BitWorkingUriTemplateProcessor(testPath);
            processor = new JaxRsUriTemplateProcessor(testPath);
        }

        UriTemplateMatcher matcher = processor.matcher();
        return matcher.matches(requestPath) ? matcher : null;
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.common.internal.uritemplate.JaxRsUriTemplateProcessor$JaxRsTemplateExpander

Copyright © 2018 www.massapicom. 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.