Package com.sun.jersey.api.uri

Examples of com.sun.jersey.api.uri.UriTemplate


*/
public class PathTemplateTest {

    @Test
    public void testBasicOperations() throws Exception {
        UriTemplate tmpl = new PathTemplate("/{id : \\d+}/test");
        assertEquals(
            "getNumberOfTemplateVariables() returned invalid number",
            1,
            tmpl.getNumberOfTemplateVariables()
        );
        assertEquals(
            "getNumberOfExplicitRegexes() returned invalid number",
            1,
            tmpl.getNumberOfExplicitRegexes()
        );
    }
View Full Code Here


*/
public class PathPatternTest {

    @Test
    public void testSimplePattern() throws Exception {
        PathPattern pattern = new PathPattern(new UriTemplate("/test"));
        assertNull(pattern.match("doesn't match"));
        assertNotNull(pattern.match("/test/me"));
    }
View Full Code Here

    }

    @Test
    public void testSimplePatternWithRightHandSide() throws Exception {
        PathPattern pattern = new PathPattern(
            new UriTemplate("/test/"),
            "/abc.*"
        );
        assertNull("Why matched?", pattern.match("/test/me"));
        assertNotNull("Why not matched?", pattern.match("/test/abc-should_work"));
    }
View Full Code Here

        new PathPattern(null, "/abc.*");
    }

    @Test
    public void testSetsAndGetsUriTemplate() throws Exception {
        UriTemplate tmpl = new UriTemplate("/test");
        PathPattern pattern = new PathPattern(tmpl);
        assertEquals(
            "We just injected the value, why it is different?",
            tmpl,
            pattern.getTemplate()
View Full Code Here

*/
public class RootResourceClassesRuleTest {

    @Test
    public void testExpectsPositiveAcceptance() throws Exception {
        UriTemplate template = new UriTemplate("/test/{name}/{id}");
        Object foo = new ResourceDbl();
        Map<PathPattern, UriRule> map = new HashMap<PathPattern, UriRule>();
        map.put(new PathPattern(template), new ResourceObjectRule(template, foo));
        UriRule rule = new RootResourceClassesRule(map);
        assertFalse(rule.accept("/test", foo, UriRuleContextDbl.make()));
View Full Code Here

        }
    }

    @Test
    public void testSavesAndRetrievesTemplate() throws Exception {
        UriTemplate template = new UriTemplate("/test/{name}/{id}");
        BaseRule rule = new FooRule(template);
        assertEquals(template, rule.getTemplate());
    }
View Full Code Here

      assertThat(param.getValue(), is(URI.create("/whee/1")));
    }
   
    @Test
    public void itIsMatchableAgainsUriTemplates() throws Exception {
      final UriTemplate template = new UriTemplate("/whee/{id}");
     
      assertThat(param.match(template), is((Map<String, String>) ImmutableMap.of("id", "1")));
      assertThat(param.match(template, "id"), is("1"));
    }
View Full Code Here

        }
        // check sub-resource locators for ambiguities
        Map<UriTemplate, String> srlUriTemplates = new HashMap<UriTemplate, String>();
        Map<UriTemplate, String> srlUriTemplatesWithSlash = new HashMap<UriTemplate, String>();
        for (AbstractSubResourceLocator srl : resource.getSubResourceLocators()) {
            UriTemplate srlUriTemplate = new UriTemplate(srl.getPath().getValue());
            UriTemplate srlUriTemplateWithSlash =
                    srlUriTemplate.endsWithSlash() ? srlUriTemplate : new UriTemplate(srl.getPath().getValue() + '/');
            if (srlUriTemplates.containsKey(srlUriTemplate)) {
                issueList.add(new ResourceModelIssue(
                        resource,
                        ImplMessages.AMBIGUOUS_SRLS(resource.getResourceClass(), srlUriTemplate.getTemplate(), srlUriTemplates.get(srlUriTemplate)),
                        true));
            } else {
                if (srlUriTemplatesWithSlash.containsKey(srlUriTemplateWithSlash)) {
                    issueList.add(new ResourceModelIssue(
                            resource,
                            ImplMessages.AMBIGUOUS_SRLS(resource.getResourceClass(), srlUriTemplate.getTemplate(), srlUriTemplatesWithSlash.get(srlUriTemplate)),
                            true));
                } else {
                    srlUriTemplatesWithSlash.put(srlUriTemplateWithSlash, srlUriTemplate.getTemplate());
                }
                srlUriTemplates.put(srlUriTemplate, srlUriTemplate.getTemplate());
            }
        }

        // check resource methods for ambiguities
        findOutMTAmbiguities(resource, resource.getResourceMethods(), new ResourceMethodAmbiguityErrMsgGenerator<AbstractResourceMethod>() {

            void generateInErrMsg(AbstractResource resource, AbstractResourceMethod arm1, AbstractResourceMethod arm2, MediaType mt) {
                issueList.add(new ResourceModelIssue(
                        resource,
                        ImplMessages.AMBIGUOUS_RMS_IN(resource.getResourceClass(), arm1.getHttpMethod(), mt, arm1.getMethod().getName(), arm2.getMethod().getName(), arm1.getSupportedInputTypes(), arm2.getSupportedInputTypes()),
                        true));
            }
            ;

            void generateOutErrMsg(AbstractResource resource, AbstractResourceMethod arm1, AbstractResourceMethod arm2, MediaType mt) {
                issueList.add(new ResourceModelIssue(
                        resource,
                        ImplMessages.AMBIGUOUS_RMS_OUT(resource.getResourceClass(), arm1.getHttpMethod(), mt, arm1.getMethod().getName(), arm2.getMethod().getName(), arm1.getSupportedOutputTypes(), arm2.getSupportedOutputTypes()),
                        true));
            }
            ;
        });

        // check sub-resource methods for ambiguities
        findOutMTAmbiguities(resource, resource.getSubResourceMethods(), new ResourceMethodAmbiguityErrMsgGenerator<AbstractSubResourceMethod>() {

            boolean isConflictingPaths(String path1, String path2) {
                UriTemplate t1 = new UriTemplate(path1);
                UriTemplate t2 = new UriTemplate(path2);
                if (t1.equals(t2)) {
                    return true;
                } else {
                    if (t1.endsWithSlash()) {
                        return (!t2.endsWithSlash()) && t1.equals(new UriTemplate(path2 + "/"));
                    } else {
                        return t2.endsWithSlash() && t2.equals(new UriTemplate(path1 + "/"));
                    }
                }
            }
            ;
View Full Code Here

            }

            ComponentInjector ci = new ComponentInjector(injectableFactory, o.getClass());
            ci.inject(o);

            UriTemplate t = new PathTemplate(ar.getPath().getValue());

            ensureTemplateUnused(t, ar, uriTemplatesUsed);

            ResourceClass r = getResourceClass(ar);
            rootResources.add(r.resource);

            PathPattern p = new PathPattern(t);

            rulesMap.put(p, new RightHandPathRule(
                        resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT),
                        t.endsWithSlash(),
                        new ResourceObjectRule(t, o)));
        }
       
        for (Class<?> c : classes) {
            AbstractResource ar = getAbstractResource(c);
            if (!ar.isRootResource()) {
                LOGGER.warning("The class, " + c + ", registered as a root resource class " +
                        "of the ResourceConfig is not a root resource class" +
                        ". This class will be ignored");
                continue;
            }
            // TODO this should be moved to the validation
            // as such classes are not root resource classes
            int modifiers = c.getModifiers();
            if (Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers)) {
                LOGGER.warning("The " + c + ", registered as a root resource class " +
                        "of the ResourceConfig cannot be instantiated" +
                        ". This class will be ignored");
                continue;
            } else if (Modifier.isInterface(modifiers)) {
                LOGGER.warning("The " + c + ", registered as a root resource class " +
                        "of the ResourceConfig cannot be instantiated" +
                        ". This interface will be ignored");
                continue;
            }

            UriTemplate t = new PathTemplate(ar.getPath().getValue());
            ensureTemplateUnused(t, ar, uriTemplatesUsed);

            ResourceClass r = getResourceClass(ar);
            rootResources.add(r.resource);

            PathPattern p = new PathPattern(t);

            rulesMap.put(p, new RightHandPathRule(
                    resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT),
                    t.endsWithSlash(),
                    new ResourceClassRule(t, c)));
        }

        createWadlResource(rootResources, rulesMap, wadlFactory);
View Full Code Here

            return;
        }

        // Preload wadl resource runtime meta data
        getResourceClass(WadlResource.class);
        UriTemplate t = new PathTemplate("application.wadl");
        PathPattern p = new PathPattern(t);

        rulesMap.put(p, new RightHandPathRule(
                resourceConfig.getFeature(ResourceConfig.FEATURE_REDIRECT),
                false,
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.uri.UriTemplate

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.