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

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


        assertEquals("instantiate template3", "telegram:hellostopbabystopgostophomestop", template3
            .expand(hashMap));
    }

    public void testJoinOperator() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor("people%3F{-join|&|var1,var2}");
        String[][] allNull = { {"var1", null}, {"var2", null}};
        String[][] firstEmpty = { {"var1", ""}, {"var2", null}};
        String[][] john = { {"var1", "john"}, {"var2", null}};
        String[][] allDefined = { {"var1", "mary"}, {"var2", "kate"}};

        assertMatchTemplate(template, "people%3F/", allNull);
        assertMatchTemplate(template, "people%3F", allNull);
        assertMatchTemplate(template, "people%3Fvar1", null);
        assertMatchTemplate(template, "people%3Fvar1&", null);
        assertMatchTemplate(template, "people%3Fvar1=", firstEmpty);
        assertMatchTemplate(template, "people%3Fvar1=john", john);
        assertMatchTemplate(template, "people%3Fvar1=mary&var2=kate", allDefined);
        assertMatchTemplate(template, "people%3Fvar2=kate&var1=mary", allDefined);
        assertMatchTemplate(template, "people%3Fvar3=jin", null);

        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("var1", "");
        assertEquals("instantiate template", "people%3Fvar1=", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var1", "jay");
        assertEquals("instantiate template", "people%3Fvar1=jay", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var2", "joe");
        assertEquals("instantiate template", "people%3Fvar2=joe", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var1", "mary");
        hashMap.put("var2", "kate");
        assertEquals("instantiate template", "people%3Fvar1=mary&var2=kate", template
            .expand(hashMap));
        hashMap = new HashMap<String, Object>();
        hashMap.put("var3", "joe");
        assertEquals("instantiate template", "people%3F", template.expand(hashMap));
        hashMap = new HashMap<String, Object>();
        assertEquals("instantiate template", "people%3F", template.expand(hashMap));

        try {
            hashMap = new HashMap<String, Object>();
            hashMap.put("var1", new String[] {"joe", "max"});
            template.expand(hashMap);
            fail("variable must not be a list");
        } catch (IllegalArgumentException expected) {
        }

    }
View Full Code Here


        }

    }

    public void testNegOperator() {
        UriTemplateProcessor template =
            new BitWorkingUriTemplateProcessor("artifacts{-neg|;|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", (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", (String)null);
        hashMap.put("var2", (String)null);
        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", "");
        hashMap.put("var2", "");
        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("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("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));
    }
View Full Code Here

        expanded = processor.expand(values);
        assertEquals("/path2/xyz", expanded);
    }

    public void testNewNormalizedInstance() {
        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

                // Get Categories that are supported by this collection resource
                List<Categories> collectionCategories =
                    getCollectionCategories(record, resourceRegistry, uriInfo);

                UriTemplateProcessor template = record.getTemplateProcessor();
                Set<MediaType> consumes = getCollectionConsumes(metadata);
                Set<MediaType> produces = getCollectionProduces(metadata);
                ServiceDocumentCollectionData sd =
                    new ServiceDocumentCollectionData(metadata.getWorkspaceName(), metadata
                        .getCollectionTitle(), template.toString(), consumes, collectionCategories,
                                                      produces);
                collections.add(sd);
            }
        }
View Full Code Here

     * @return String Categories Document base URI
     */
    private static String getCategoriesDocBaseUri(Categories cats, ResourceRecord record) {
        String categoriesDocBaseUri = null;
        MultivaluedMap<String, String> templateParams = cats.getTemplateParameters();
        UriTemplateProcessor template = record.getTemplateProcessor();
        categoriesDocBaseUri = template.expand(templateParams);
        return categoriesDocBaseUri;
    }
View Full Code Here

        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

        } catch (IllegalArgumentException e) {
        } // 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

TOP

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

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.