Changeset 3609

Show
Ignore:
Timestamp:
11/02/08 15:05:31 (4 years ago)
Author:
michael
Message:

Allow child resources to find their parents. Refs #4, spent 0.25

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/java/org/sarugo/restlet/jpa/EntityFinder.java

    r3607 r3609  
    55 
    66import org.restlet.Finder; 
    7 import org.restlet.Handler; 
    87import org.restlet.Route; 
    98import org.restlet.data.Request; 
     
    109108     */ 
    110109    @Override 
    111     protected Handler findTarget(Request request, Response response) { 
     110    protected EntityResource findTarget(Request request, Response response) { 
    112111        EntityResource resource = initResource(); 
    113112        if (resource != null) { 
  • trunk/src/main/java/org/sarugo/restlet/jpa/EntityInstanceFinder.java

    r3607 r3609  
    218218    } 
    219219 
     220    /** Gets the parent resource for the given request. */ 
     221    public EntityInstance getParentResource(Request request, Response response) { 
     222        return (EntityInstance) getParent().findTarget(request, response); 
     223    } 
     224 
    220225    /** 
    221226     * Passes the request to children if possible or handles directly if no 
  • trunk/src/test/java/org/sarugo/restlet/jpa/URLMappingTests.java

    r3606 r3609  
    5858 
    5959    public void testGetEntity() { 
    60         FooEntity found = (FooEntity) router.getEntity("/foo/" + foo.id); 
    61         assertEquals(foo.id, found.id); 
     60        FooEntity foundFoo = (FooEntity) router.getEntity("/foo/" + foo.id); 
     61        assertEquals(foo.id, foundFoo.id); 
     62        foundFoo = (FooEntity) router.getEntity("/foo/" + foo.id + 120485); 
     63        assertNull(foundFoo); 
     64        foundFoo = (FooEntity) router.getEntity("/fool/" + foo.id); 
     65        assertNull(foundFoo); 
    6266        BarEntity foundBar = (BarEntity) router.getEntity("/foo/" + foo.id 
    6367                + "/bar/" + bar.id);