Package org.apache.sling.servlets.resolver.helper

Examples of org.apache.sling.servlets.resolver.helper.WeightedResource


    public void testCreateLocationResourceGET() {

        final MockResource res0 = new MockResource(null, SCRIPT_BASE, "foo:bar");

        // this resource has no extension, we require one
        final WeightedResource lr0 = createLocationResource(res0, "GET", null,
            "html");
        assertNull(lr0);

        // this resource has no extension, we require one
        final WeightedResource lr1 = createLocationResource(res0, "GET", null,
            "foo");
        assertNull(lr1);
    }
View Full Code Here


        final MockResource res1 = new MockResource(null, SCRIPT_BASE + ".esp",
            "foo:bar");

        // allow simple name for GET and html
        final WeightedResource lr10 = createLocationResource(res1, "GET", null,
            "html");
        assertNotNull(lr10);
        assertEquals(0, lr10.getNumSelectors());
        assertEquals(WeightedResource.WEIGHT_PREFIX, lr10.getMethodPrefixWeight());

        // this resource has no extension, we require one
        final WeightedResource lr11 = createLocationResource(res1, "GET", null,
            "foo");
        assertNull(lr11);
    }
View Full Code Here

    public void testCreateLocationResourceGETHtmlEsp() {
        final MockResource res2 = new MockResource(null, SCRIPT_BASE
            + ".html.esp", "foo:bar");

        // allow simple name for GET and html
        final WeightedResource lr20 = createLocationResource(res2, "GET", null,
            "html");
        assertNotNull(lr20);
        assertEquals(0, lr20.getNumSelectors());
        assertEquals(WeightedResource.WEIGHT_PREFIX+WeightedResource.WEIGHT_EXTENSION, lr20.getMethodPrefixWeight());

        // script does not match for .foo request
        final WeightedResource lr21 = createLocationResource(res2, "GET", null,
            "foo");
        assertNull(lr21);
    }
View Full Code Here

    public void testCreateLocationResourceGETFooEsp() {
        final MockResource res3 = new MockResource(null, SCRIPT_BASE
            + ".foo.esp", "foo:bar");

        // script does not match for .html request
        final WeightedResource lr30 = createLocationResource(res3, "GET", null,
            "html");
        assertNull(lr30);

        // allow simple name for GET and foo
        final WeightedResource lr31 = createLocationResource(res3, "GET", null,
            "foo");
        assertNotNull(lr31);
        assertEquals(0, lr31.getNumSelectors());
        assertEquals(WeightedResource.WEIGHT_PREFIX+WeightedResource.WEIGHT_EXTENSION, lr31.getMethodPrefixWeight());
    }
View Full Code Here

        final MockResource res0 = new MockResource(null, SCRIPT_BASE + ".GET",
            "foo:bar");

        // side-effect: .GET is assumed to be the script extension
        final WeightedResource lr0 = createLocationResource(res0, "GET", null,
            "html");
        assertNotNull(lr0);
        assertEquals(WeightedResource.WEIGHT_PREFIX, lr0.getMethodPrefixWeight());

        // this resource has no extension, we require one
        final WeightedResource lr1 = createLocationResource(res0, "GET", null,
            "foo");
        assertNull(lr1);
    }
View Full Code Here

    public void testCreateLocationResourceGETGETEsp() {
        final MockResource res1 = new MockResource(null, SCRIPT_BASE
            + ".GET.esp", "foo:bar");

        // GET would be the extension and is not allowed like this
        final WeightedResource lr10 = createLocationResource(res1, "GET", null,
            "html");
        assertNull(lr10);

        // GET would be the extension and is not allowed like this
        final WeightedResource lr11 = createLocationResource(res1, "GET", null,
            "foo");
        assertNull(lr11);
    }
View Full Code Here

            }
        };
        final ResourceCollectorGet locationUtil = new ResourceCollectorGet(request);
        final int methodPrefixWeight = locationUtil.calculatePrefixMethodWeight(scriptResource, LOCATION_PREFIX, true);
        if (methodPrefixWeight != ResourceCollectorGet.WEIGHT_NO_MATCH) {
            return new WeightedResource(0, scriptResource, 0, methodPrefixWeight);
        }
       
        return null;
    }
View Full Code Here

import junit.framework.TestCase;

public class WeightedResourceTest extends TestCase {

    public void testEquality() {
        WeightedResource lr1 = new WeightedResource(0, null, 0, WeightedResource.WEIGHT_NONE);
        WeightedResource lr2 = new WeightedResource(0, null, 0, WeightedResource.WEIGHT_NONE);
       
        // expect same objects to be equal
        assertTrue(lr1.equals(lr1));
       
        // expect different instances to not be equal
        assertFalse(lr1.equals(lr2));
        assertFalse(lr2.equals(lr1));
        assertFalse(lr1.equals(null));
        assertFalse(lr2.equals(null));
    }
View Full Code Here

        assertFalse(lr1.equals(null));
        assertFalse(lr2.equals(null));
    }
   
    public void testCompareToSelectors() {
        WeightedResource lr1 = new WeightedResource(0, null, 1, WeightedResource.WEIGHT_NONE);
        WeightedResource lr2 = new WeightedResource(1, null, 0, WeightedResource.WEIGHT_NONE);
       
        // expect the same objects to compare equal
        assertEquals(0, lr1.compareTo(lr1));
        assertEquals(0, lr2.compareTo(lr2));
       
        assertTrue(lr1.compareTo(lr2) < 0);
        assertTrue(lr2.compareTo(lr1) > 0);
    }
View Full Code Here

        assertTrue(lr1.compareTo(lr2) < 0);
        assertTrue(lr2.compareTo(lr1) > 0);
    }
   
    public void testCompareToPrefix() {
        WeightedResource lr1 = new WeightedResource(0, null, 2, WeightedResource.WEIGHT_PREFIX);
        WeightedResource lr2 = new WeightedResource(1, null, 2, WeightedResource.WEIGHT_NONE);
       
        // expect the same objects to compare equal
        assertEquals(0, lr1.compareTo(lr1));
        assertEquals(0, lr2.compareTo(lr2));
       
        assertTrue(lr1.compareTo(lr2) < 0);
        assertTrue(lr2.compareTo(lr1) > 0);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.servlets.resolver.helper.WeightedResource

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.