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

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


                     "/part1/default_value/part2",
                     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


        } // ok
    }

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

                            "artifacts;lc=lc;approved=stage;datetime=date/13;rev=7",
                            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

        hashMap.put("var", "value");
        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) {
View Full Code Here

        } 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

        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

                                   List<MethodMetadata> subResourceLocators,
                                   SubResources subResources,
                                   boolean isLocator) {
        for (MethodMetadata subResourceLocator : subResourceLocators) {
            SubResource subResource = resourcesObjectFactory.createSubResource();
            UriTemplateProcessor uriTemplate = record.getTemplateProcessor();
            subResource.setUri(SLASH + uriTemplate.getTemplate() + subResourceLocator.getPath());
            if (isLocator) {
                subResource.setType("Locator"); //$NON-NLS-1$
            } else {
                subResource.setType("Method"); //$NON-NLS-1$
                subResource.setMethod(subResourceLocator.getHttpMethod().toString());
View Full Code Here

        Map<String, Resource> uri2ResourceMap = new HashMap<String, Resource>();

        for (MethodMetadata subResourceLocator : subResourceLocators) {

            UriTemplateProcessor uriTemplate = record.getTemplateProcessor();
            String uri = SLASH + uriTemplate.getTemplate() + subResourceLocator.getPath();
            org.apache.wink.common.internal.model.admin.Methods xmlSRL =
                createXMLSubResourceLocatorMethod(subResourceLocator);
            addResourceMethods(uri2ResourceMap, uri, xmlSRL);
        }

        // Add all Sub Resource Locators as resources
        resources.getResource().addAll(uri2ResourceMap.values());

        uri2ResourceMap.clear();
        for (MethodMetadata subResourceMethod : subResourceMethods) {
            UriTemplateProcessor uriTemplate = record.getTemplateProcessor();
            String uri = SLASH + uriTemplate.getTemplate() + SLASH + subResourceMethod.getPath();
            org.apache.wink.common.internal.model.admin.Methods xmlSRM =
                createXMLSubResourceMethod(subResourceMethod);
            addResourceMethods(uri2ResourceMap, uri, xmlSRM);
        }
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.