Examples of BitWorkingUriTemplateProcessor


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

        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

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

        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

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

        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

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

        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

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

                     templateA.expand(hashMap));
    }

    public void testInstantiateNegative() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor("/part1/{variableA}/part2/{variableB}");
        try {
            HashMap<String, Object> hashMap = new HashMap<String, Object>();
            hashMap.put("variableA", "value");
            template.expand(hashMap);
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException expected) {
        }
    }
View Full Code Here

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

        }
    }

    public void testCreateNegative() {
        try {
            new BitWorkingUriTemplateProcessor(null);
            fail("NPE expected");
        } catch (NullPointerException expected) {
        }
        try {
            new BitWorkingUriTemplateProcessor("{unclosedVariableStill/goes/on");
            fail("IllegalArgumentException expected");
        } catch (IllegalArgumentException expected) {
        }
        try {
            new BitWorkingUriTemplateProcessor("artifacts{}");
            fail("no variable in expansion");
        } catch (IllegalArgumentException e) {
        } // ok
    }
View Full Code Here

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

    }

    public void testPathParameters() {

        UriTemplateProcessor feedTemplate1 =
            new BitWorkingUriTemplateProcessor(
                                               "artifacts{-prefix|;datetime=|datetime}{-prefix|;lc=|lc}{-prefix|;approved=|approved}");
        UriTemplateProcessor feedTemplate2 =
            new BitWorkingUriTemplateProcessor(
                                               "artifacts{-opt|;|datetime,lc,approved}{-join|;|datetime,lc,approved}");
        UriTemplateProcessor entryTemplate1 =
            new BitWorkingUriTemplateProcessor(
                                               feedTemplate1.getTemplate() + "/{artifact}{-prefix|;rev=|revision}");
        UriTemplateProcessor entryTemplate2 =
            new BitWorkingUriTemplateProcessor(
                                               feedTemplate2.getTemplate() + "/{artifact}{-prefix|;rev=|revision}");

        String[][] allNull = { {"datetime", null}, {"lc", null}, {"approved", null}};
        String[][] dateEmpty = { {"datetime", ""}, {"lc", null}, {"approved", null}};
        String[][] date = { {"datetime", "date"}, {"lc", null}, {"approved", null}};
View Full Code Here

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

                            all);
    }

    public void testListOperator() {
        UriTemplateProcessor template1 =
            new BitWorkingUriTemplateProcessor("locations/{-list|/|var}");
        UriTemplateProcessor template2 =
            new BitWorkingUriTemplateProcessor("locations{-opt|/|var}{-list|/|var}");
        UriTemplateProcessor template3 =
            new BitWorkingUriTemplateProcessor("telegram:{-list|stop|var}");
        String[][] empty = {{"var", ""}};
        String[][] a = {{"var", "a"}};
        String[][] ab = {{"var", "a", "b"}};
        String[][] ab_ = {{"var", "a", "b", ""}};
        String[][] a_c = {{"var", "a", "", "c"}};
        String[][] _bc = {{"var", "", "b", "c"}};
        String[][] message = {{"var", "hello", "baby", "go", "home"}};

        assertMatchTemplate(template1, "locations", null);
        assertMatchTemplate(template2, "locations", empty);
        assertMatchTemplate(template1, "locations/", empty);
        assertMatchTemplate(template2, "locations/", empty);
        assertMatchTemplate(template1, "locations/a", a);
        assertMatchTemplate(template2, "locations/a", a);
        assertMatchTemplate(template1, "locations/a/b", ab);
        assertMatchTemplate(template2, "locations/a/b", ab);
        assertMatchTemplate(template2, "locations/a/b/", ab_);
        assertMatchTemplate(template2, "locations/a//c", a_c);
        assertMatchTemplate(template2, "locations//b/c", _bc);
        assertMatchTemplate(template3, "telegram:hellostopbabystopgostophome", message);

        try {
            new BitWorkingUriTemplateProcessor("locations/{-list|/|var1,var2}");
            fail("only one variable is allowed");
        } catch (IllegalArgumentException expected) {
        }

        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {});
        assertEquals("instantiate template1", "locations/", template1.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {});
        assertEquals("instantiate template2", "locations", template2.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d"});
        assertEquals("instantiate template1", "locations/d", template1.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d"});
        assertEquals("instantiate template2", "locations/d", template2.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d", "e"});
        assertEquals("instantiate template1", "locations/d/e", template1.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d", "e"});
        assertEquals("instantiate template2", "locations/d/e", template2.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d", "", "e"});
        assertEquals("instantiate template1", "locations/d//e", template1.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d", "", "e"});
        assertEquals("instantiate template2", "locations/d//e", template2.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"", "d", "e"});
        assertEquals("instantiate template1", "locations//d/e", template1.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"", "d", "e"});
        assertEquals("instantiate template2", "locations//d/e", template2.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d", "e", ""});
        assertEquals("instantiate template1", "locations/d/e/", template1.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"d", "e", ""});
        assertEquals("instantiate template2", "locations/d/e/", template2.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", new String[] {"hello", "baby", "go", "home"});
        assertEquals("instantiate template3", "telegram:hellostopbabystopgostophome", template3
            .expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var", "value");
        assertEquals("instantiate template1", "locations/value", template1.expand(hashMap));
    }
View Full Code Here

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

        assertEquals("instantiate template1", "locations/value", template1.expand(hashMap));
    }

    public void testOptOperator() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor("artifacts{-opt|;|var1,var2}");
        String[][] empty = {};

        assertMatchTemplate(template, "artifact/", null);
        assertMatchTemplate(template, "artifacts", empty);
        assertMatchTemplate(template, "artifacts;", empty);
        assertMatchTemplate(template, "artifacts;;", null);

        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("var1", "somevalue");
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", "somevalue");
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var1", "");
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", "");
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var1", (String)null);
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", (String)null);
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var1", "");
        hashMap.put("var2", "");
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var1", (String)null);
        hashMap.put("var2", (String)null);
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        assertEquals("instantiate template", "artifacts", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", new String[] {});
        assertEquals("instantiate template", "artifacts", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", new String[] {null});
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", new String[] {""});
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", new String[] {"a", "b"});
        assertEquals("instantiate template", "artifacts;", template.expand(hashMap));

        try {
            new BitWorkingUriTemplateProcessor("artifacts{-opt|;|}");
            fail("no variable in operator");
        } catch (IllegalArgumentException e) {
        } // ok
    }
View Full Code Here

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

        } catch (IllegalArgumentException e) {
        } // ok
    }

    public void testSuffixOperator() {
        UriTemplateProcessor template = new BitWorkingUriTemplateProcessor("/{-suffix|/|var}cat");
        UriTemplateProcessor template3 =
            new BitWorkingUriTemplateProcessor("telegram:{-suffix|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("/{-suffix|/|var1,var2}cat");
            fail("-suffix accepts only one variable");
        } catch (IllegalArgumentException e) {
        } // ok
        assertMatchTemplate(template, "/animals/domestic/cat", domesticAnimalsVar);
        assertMatchTemplate(template3, "telegram:hellostopbabystopgostophomestop", 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:hellostopbabystopgostophomestop", template3
            .expand(hashMap));
    }
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.