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

Examples of org.apache.wink.common.internal.uritemplate.BitWorkingUriTemplateProcessor$BitWorkingOperator$Join


        hashMap.put("var2", new String[] {"a", "b"});
        assertEquals("instantiate template", "artifacts", template.expand(hashMap));
    }

    public void testPrefixOperator() {
        UriTemplateProcessor template = new BitWorkingUriTemplateProcessor("{-prefix|/|var}/cat");
        UriTemplateProcessor template3 =
            new BitWorkingUriTemplateProcessor("telegram:{-prefix|stop|var}");
        String[][] animalsVar = {{"var", "animals"}};
        String[][] noVar = {{"var", null}};
        String[][] emptyVar = {{"var", ""}};
        String[][] domesticAnimalsVar = {{"var", "animals", "domestic"}};
        String[][] message = {{"var", "hello", "baby", "go", "home"}};

        assertMatchTemplate(template, "/animals/cat", animalsVar);
        assertMatchTemplate(template, "/cat", noVar);
        assertMatchTemplate(template, "//cat", emptyVar);
        assertMatchTemplate(template, "/animals;cat", null);
        assertMatchTemplate(template, "animals/cat", null);
        try {
            new BitWorkingUriTemplateProcessor("/{-prefix|/|var1,var2}cat");
            fail("-prefix accepts only one variable");
        } catch (IllegalArgumentException e) {
        } // ok
        assertMatchTemplate(template, "/animals/domestic/cat", domesticAnimalsVar);
        assertMatchTemplate(template3, "telegram:stophellostopbabystopgostophome", message);

        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("var", "animals");
        assertEquals("instantiate template", "/animals/cat", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", "");
        assertEquals("instantiate template", "//cat", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        assertEquals("instantiate template", "/cat", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("", "");
        assertEquals("instantiate template", "/cat", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("", "pets");
        assertEquals("instantiate template", "/cat", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"animals", "domestic"});
        assertEquals("instantiate template", "/animals/domestic/cat", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"hello", "baby", "go", "home"});
        assertEquals("instantiate template3", "telegram:stophellostopbabystopgostophome", template3
            .expand(hashMap));
    }
View Full Code Here


            .expand(hashMap));
    }

    public void testOperatorInvalidSyntax() {
        try {
            new BitWorkingUriTemplateProcessor("/{-prefix}cat");
            fail("no pipe in operator");
        } catch (IllegalArgumentException e) {
        } // ok
        try {
            new BitWorkingUriTemplateProcessor("/{-prefix|/}cat");
            fail("only one pipe in operator");
        } catch (IllegalArgumentException e) {
        } // ok
        try {
            new BitWorkingUriTemplateProcessor("/{}/cat");
            fail("no variable name");
        } catch (IllegalArgumentException e) {
        } // ok
    }
View Full Code Here

        } // ok
    }

    public void testEncodedUri() {
        UriTemplateProcessor template1 =
            new BitWorkingUriTemplateProcessor("cars(old*new:good)my?{-join|&|car1,car2}");
        String[][] carsDefined = { {"car1", "Ford"}, {"car2", "Opel"}};
        assertMatchTemplate(template1, "cars(old*new:good)my?car1=Ford&car2=Opel", carsDefined);
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("car1", "Ford");
        hashMap.put("car2", "Opel");
        assertEquals("instantiate template1", "cars(old*new:good)my?car1=Ford&car2=Opel", template1
            .expand(hashMap));

        UriTemplateProcessor template2 =
            new BitWorkingUriTemplateProcessor("vegetables|{-list|?|vegs}");
        String[][] vegsDefined = {{"vegs", "carrot", "leek"}};
        assertMatchTemplate(template2, "vegetables|carrot?leek", vegsDefined);
        hashMap = new HashMap<String, Object>();
        hashMap.put("vegs", new String[] {"carrot", "leek"});
        assertEquals("instantiate template2", "vegetables|carrot?leek", template2.expand(hashMap));

        UriTemplateProcessor template3 =
            new BitWorkingUriTemplateProcessor("vegetables{-prefix|?|vegs}");
        assertMatchTemplate(template3, "vegetables?carrot?leek", vegsDefined);
        hashMap = new HashMap<String, Object>();
        hashMap.put("vegs", new String[] {"carrot", "leek"});
        assertEquals("instantiate template3", "vegetables?carrot?leek", template3.expand(hashMap));

        UriTemplateProcessor template4 =
            new BitWorkingUriTemplateProcessor("vegetables|{-suffix|?|vegs}");
        assertMatchTemplate(template4, "vegetables|carrot?leek?", vegsDefined);
        hashMap = new HashMap<String, Object>();
        hashMap.put("vegs", new String[] {"carrot", "leek"});
        assertEquals("instantiate template4", "vegetables|carrot?leek?", template4.expand(hashMap));

        UriTemplateProcessor template5 =
            new BitWorkingUriTemplateProcessor("translator({-join|?|czech,english})");
        String[][] translation = { {"czech", "pes"}, {"english", "dog"}};
        assertMatchTemplate(template5, "translator(english=dog?czech=pes)", translation);
        hashMap = new HashMap<String, Object>();
        hashMap.put("english", "dog");
        hashMap.put("czech", "pes");
        assertEquals("instantiate template5", "translator(czech=pes?english=dog)", template5
            .expand(hashMap));

        UriTemplateProcessor template6 =
            new BitWorkingUriTemplateProcessor("food{-opt|?|meat,milk}");
        String[][] empty = {};
        assertMatchTemplate(template6, "food?", empty);
        hashMap = new HashMap<String, Object>();
        hashMap.put("meat", "poultry");
        assertEquals("instantiate template6", "food?", template6.expand(hashMap));

        UriTemplateProcessor template7 =
            new BitWorkingUriTemplateProcessor("food{-neg|()|meat,milk}");
        assertMatchTemplate(template7, "food()", empty);
        hashMap = new HashMap<String, Object>();
        assertEquals("instantiate template7", "food()", template7.expand(hashMap));
    }
View Full Code Here

        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

        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

        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("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

TOP

Related Classes of org.apache.wink.common.internal.uritemplate.BitWorkingUriTemplateProcessor$BitWorkingOperator$Join

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.