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

Examples of org.apache.wink.common.internal.uritemplate.UriTemplateProcessor$Variable


        hashMap = new HashMap<String, Object>();
        assertEquals("instantiate template7", "food()", template7.expand(hashMap));
    }

    public void testUnreservedMatch() {
        UriTemplateProcessor template = new BitWorkingUriTemplateProcessor("/prefix/{varA}");
        UriTemplateMatcher matcher = template.matcher();
        MultivaluedMap<String, String> result = matcher.match("/prefix/a.b");
        assertNotNull("match ok .", result);
        assertEquals("match size .", 1, result.size());
        assertEquals("varA", "a.b", result.getFirst("varA"));
View Full Code Here


        assertEquals("match size ~", 1, result.size());
        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"));
View Full Code Here

        assertEquals("varA", "%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D", result
            .getFirst("varA"));
    }

    public void testDecodedMatchedValues() {
        UriTemplateProcessor templateVar = new BitWorkingUriTemplateProcessor("/var/{var}");
        String[][] var = {{"var", "enc%3Aoded"}};
        assertMatchTemplate(templateVar, "/var/enc%3Aoded", var);

        UriTemplateProcessor templateJoin =
            new BitWorkingUriTemplateProcessor("/join/{-join|;|join}");
        String[][] join = {{"join", "enc%3Aoded"}};
        assertMatchTemplate(templateJoin, "/join/join=enc%3Aoded", join);

        UriTemplateProcessor templateList =
            new BitWorkingUriTemplateProcessor("/list/{-list|/|list}");
        String[][] list1 = {{"list", "enc%3Aoded"}};
        assertMatchTemplate(templateList, "/list/enc%3Aoded", list1);
        String[][] list2 = {{"list", "enc%3Aoded", "enc%3Aoded"}};
        assertMatchTemplate(templateList, "/list/enc%3Aoded/enc%3Aoded", list2);

        UriTemplateProcessor templatePrefix =
            new BitWorkingUriTemplateProcessor("/prefix{-prefix|/|prefix}");
        String[][] prefix1 = {{"prefix", "enc%3Aoded"}};
        assertMatchTemplate(templatePrefix, "/prefix/enc%3Aoded", prefix1);
        String[][] prefix2 = {{"prefix", "enc%3Aoded", "enc%3Aoded"}};
        assertMatchTemplate(templatePrefix, "/prefix/enc%3Aoded/enc%3Aoded", prefix2);

        UriTemplateProcessor templateSuffix =
            new BitWorkingUriTemplateProcessor("/suffix/{-suffix|/|suffix}");
        String[][] suffix1 = {{"suffix", "enc%3Aoded"}};
        assertMatchTemplate(templateSuffix, "/suffix/enc%3Aoded/", suffix1);
        String[][] suffix2 = {{"suffix", "enc%3Aoded", "enc%3Aoded"}};
        assertMatchTemplate(templateSuffix, "/suffix/enc%3Aoded/enc%3Aoded/", suffix2);
View Full Code Here

        String[][] suffix2 = {{"suffix", "enc%3Aoded", "enc%3Aoded"}};
        assertMatchTemplate(templateSuffix, "/suffix/enc%3Aoded/enc%3Aoded/", suffix2);
    }

    public void testEncodedSubstitutedValues() {
        UriTemplateProcessor templateVar = new BitWorkingUriTemplateProcessor("/var/{var}");
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("var", "enc:oded");
        assertEquals("values encoded", "/var/enc%3Aoded", templateVar.expand(hashMap));

        UriTemplateProcessor templateJoin =
            new BitWorkingUriTemplateProcessor("/join/{-join|;|join}");
        hashMap = new HashMap<String, Object>();
        hashMap.put("join", "enc:oded");
        assertEquals("values encoded", "/join/join=enc%3Aoded", templateJoin.expand(hashMap));

        UriTemplateProcessor templateList =
            new BitWorkingUriTemplateProcessor("/list/{-list|/|list}");
        hashMap = new HashMap<String, Object>();
        hashMap.put("list", new String[] {"enc:oded"});
        assertEquals("values encoded", "/list/enc%3Aoded", templateList.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("list", new String[] {"enc:oded", "enc:oded"});
        assertEquals("values encoded", "/list/enc%3Aoded/enc%3Aoded", templateList.expand(hashMap));

        UriTemplateProcessor templatePrefix =
            new BitWorkingUriTemplateProcessor("/prefix{-prefix|/|prefix}");
        hashMap = new HashMap<String, Object>();
        hashMap.put("prefix", "enc:oded");
        assertEquals("values encoded", "/prefix/enc%3Aoded", templatePrefix.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("prefix", new String[] {"enc:oded", "enc:oded"});
        assertEquals("values encoded", "/prefix/enc%3Aoded/enc%3Aoded", templatePrefix
            .expand(hashMap));

        UriTemplateProcessor templateSuffix =
            new BitWorkingUriTemplateProcessor("/suffix/{-suffix|/|suffix}");
        hashMap = new HashMap<String, Object>();
        hashMap.put("suffix", "enc:oded");
        assertEquals("values encoded", "/suffix/enc%3Aoded/", templateSuffix.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("suffix", new String[] {"enc:oded", "enc:oded"});
        assertEquals("values encoded", "/suffix/enc%3Aoded/enc%3Aoded/", templateSuffix
            .expand(hashMap));
    }
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testGetVariableNames() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor(
                                               "/prefix/{varA}/root/{variableB}/suffix/{Variable345}");
        Set<String> expectedResult = new HashSet<String>();
        expectedResult.add("varA");
        expectedResult.add("variableB");
        expectedResult.add("Variable345");
        assertEquals("variable name", expectedResult, template.getVariableNames());
    }
View Full Code Here

        expectedResult.add("Variable345");
        assertEquals("variable name", expectedResult, template.getVariableNames());
    }

    public void testMatch() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor("/prefix/{varA}/root/{variableB}/suffix");
        UriTemplateMatcher matcher = template.matcher();
        MultivaluedMap<String, String> result = matcher.match("/prefix/aaaaaa/root/BbBbB/suffix");
        assertNotNull("match ok", result);
        assertEquals("match size", 2, result.size());
        assertEquals("varA", "aaaaaa", result.getFirst("varA"));
        assertEquals("variableB", "BbBbB", result.getFirst("variableB"));
View Full Code Here

        assertEquals("varA", "aaaaaa", result.getFirst("varA"));
        assertEquals("variableB", "BbBbB", result.getFirst("variableB"));
    }

    public void testMatchVariableDoubleUsage() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor("/prefix/{varA}/root/{varA}/suffix");
        UriTemplateMatcher matcher = template.matcher();
        MultivaluedMap<String, String> result = matcher.match("/prefix/aaaaaa/root/aaaaaa/suffix");
        assertNotNull("match ok", result);
        assertEquals("match size", 1, result.size());
        assertEquals("varA", "aaaaaa", result.getFirst("varA"));
    }
View Full Code Here

        assertEquals("match size", 1, result.size());
        assertEquals("varA", "aaaaaa", result.getFirst("varA"));
    }

    public void testMatchNegative() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor("/prefix/{variable}/suffix");
        UriTemplateMatcher matcher = template.matcher();
        assertNull("not matching", matcher.match("aprefix/value/suffix"));
    }
View Full Code Here

        UriTemplateMatcher matcher = template.matcher();
        assertNull("not matching", matcher.match("aprefix/value/suffix"));
    }

    public void testInstantiate() {
        UriTemplateProcessor templateA =
            new BitWorkingUriTemplateProcessor("/part1/{variable}/part2");
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("variable", "value");
        assertEquals("instantiate template", "/part1/value/part2", templateA.expand(hashMap));
    }
View Full Code Here

        hashMap.put("variable", "value");
        assertEquals("instantiate template", "/part1/value/part2", templateA.expand(hashMap));
    }

    public void testInstantiateDefaultValue() {
        UriTemplateProcessor templateA =
            new BitWorkingUriTemplateProcessor("/part1/{variable=default_value}/part2");

        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("variable", "my_value");
        assertEquals("instantiate template with some value", "/part1/my_value/part2", templateA
            .expand(hashMap));

        hashMap = new HashMap<String, Object>();
        hashMap.put("variable", (String)null);
        assertEquals("instantiate template with default value if null",
                     "/part1/default_value/part2",
                     templateA.expand(hashMap));

        hashMap = new HashMap<String, Object>();
        assertEquals("instantiate template with default value if not-defined",
                     "/part1/default_value/part2",
                     templateA.expand(hashMap));
    }
View Full Code Here

TOP

Related Classes of org.apache.wink.common.internal.uritemplate.UriTemplateProcessor$Variable

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.