Changeset 3677
- Timestamp:
- 05/03/08 22:48:40 (4 years ago)
- Files:
-
- tags/0.1/src/main/java/org/sarugo/restlet/jpa/converter/ReferenceListConverter.java (deleted)
- trunk/ivy.xml (modified) (1 diff)
- trunk/src/main/java/org/sarugo/restlet/jpa/EntityHelper.java (modified) (2 diffs)
- trunk/src/main/java/org/sarugo/restlet/jpa/EntityRouter.java (modified) (13 diffs)
- trunk/src/main/java/org/sarugo/restlet/jpa/PersistenceApplication.java (modified) (2 diffs)
- trunk/src/main/java/org/sarugo/restlet/jpa/converter (copied) (copied from tags/0.1/src/main/java/org/sarugo/restlet/jpa/converter)
- trunk/src/main/java/org/sarugo/restlet/jpa/converter/Converter.java (added)
- trunk/src/main/java/org/sarugo/restlet/jpa/converter/FormEntityUpdateConverter.java (modified) (1 diff)
- trunk/src/main/java/org/sarugo/restlet/jpa/converter/JSONConverter.java (modified) (4 diffs)
- trunk/src/main/java/org/sarugo/restlet/jpa/converter/StringEntityConverter.java (modified) (1 diff)
- trunk/src/main/java/org/sarugo/restlet/jpa/resource/EntityInstance.java (modified) (2 diffs)
- trunk/src/test/java/org/sarugo/restlet/jpa/URLMappingTests.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ivy.xml
r3666 r3677 11 11 <dependency org="com.noelios.restlet" name="com.noelios.restlet.ext.simple" rev="1.1-M2" conf="test->default"/> 12 12 <dependency org="com.noelios.restlet" name="com.noelios.restlet.ext.net" rev="1.1-M2" conf="test->default"/> 13 <dependency org="com.sdicons.jsontools" name="jsontools-core" rev="1.5" conf="default"/> 13 14 <dependency org="javax.persistence" name="persistence-api" rev="1.0" conf="compile->default"/> 14 15 <dependency org="junit" name="junit" rev="3.8.1" conf="test->default"/> trunk/src/main/java/org/sarugo/restlet/jpa/EntityHelper.java
r3613 r3677 17 17 package org.sarugo.restlet.jpa; 18 18 19 import java.beans.PropertyEditor;20 import java.beans.PropertyEditorManager;21 import java.lang.reflect.Constructor;22 19 import java.lang.reflect.Field; 23 20 import java.lang.reflect.Method; … … 104 101 } 105 102 106 public static <T extends Object> T convertToType(Class<T> type,107 String value, EntityRouter router) {108 // Short cut for String types109 if (type.isAssignableFrom(String.class)) {110 return type.cast(value);111 }112 113 // Short cut for null114 if (value == null) {115 return null;116 }117 118 // Otherwise, check if the type is an enum119 if (type.isEnum()) {120 for (T constant : type.getEnumConstants()) {121 if (((Enum) constant).name().equals(value)) {122 return constant;123 }124 }125 return null;126 }127 128 // Otherwise, use JavaBean coercion129 try {130 PropertyEditor e = PropertyEditorManager.findEditor(type);131 e.setAsText(value);132 return type.cast(e.getValue());133 } catch (Exception e) {134 // Ignore135 }136 137 // Otherwise check if the type is an entity type138 if (router != null) {139 @SuppressWarnings("unchecked")140 T entity = (T) router.getEntity(value);141 if (entity != null) {142 return entity;143 }144 }145 146 // Otherwise, try a String constructor147 try {148 Constructor<T> c = type.getConstructor(String.class);149 return c.newInstance(value);150 } catch (Exception e) {151 // Ignore152 }153 154 // If all else failed, just return null155 return null;156 }157 158 103 } trunk/src/main/java/org/sarugo/restlet/jpa/EntityRouter.java
r3666 r3677 30 30 import org.restlet.Route; 31 31 import org.restlet.Router; 32 import org.restlet.data.Method;33 32 import org.restlet.data.Reference; 34 33 import org.restlet.data.Request; … … 74 73 private Reference baseRef; 75 74 76 private Template defaultRouteTemplate;75 private Template template; 77 76 78 77 /** … … 112 111 } 113 112 114 /** 115 * Convert an entity to a URL based on an attached {@link EntityFinder}. 116 * 117 * @param entity 118 * The entity to get a URL for. 119 * @return The entity's URL relative to this router. 120 * @see #attachEntity(String, EntityFinder) 121 */ 122 public String getEntityURL(Object entity) { 123 if (isChild()) { 124 return getParent().getEntityURL(entity); 125 } else { 126 return doGetEntityURL(entity); 127 } 128 } 129 130 private String doGetEntityURL(Object entity) { 113 String getEntityURL(Object entity) { 131 114 String url = null; 132 115 if (entity != null) { … … 140 123 // format the entity's URL 141 124 if (route == getDefaultRoute()) { 142 entityUrl = defaultRouteTemplate.format(attributes);125 entityUrl = template.format(attributes); 143 126 } else { 144 127 entityUrl = route.getTemplate().format(attributes); … … 149 132 // add the router's URL template if we have no default route 150 133 if (getDefaultRoute() == null) { 151 parentUrl = defaultRouteTemplate.format(attributes);134 parentUrl = template.format(attributes); 152 135 } 153 136 @SuppressWarnings("unchecked") … … 155 138 entity); 156 139 if (parentEntity != null) { 157 String parentEntityUrl = getParent(). doGetEntityURL(140 String parentEntityUrl = getParent().getEntityURL( 158 141 parentEntity); 159 142 if (parentEntityUrl == null) { … … 170 153 while (parent != null) { 171 154 if (parent.isChild()) { 172 parentUrl = parent.defaultRouteTemplate 173 .format(attributes) 155 parentUrl = parent.template.format(attributes) 174 156 + parentUrl; 175 157 } else if (parent.getBaseRef() != null) { … … 188 170 // otherwise check if our children can map the entity 189 171 for (EntityRouter child : children) { 190 url = child. doGetEntityURL(entity);172 url = child.getEntityURL(entity); 191 173 if (url != null) { 192 174 break; … … 198 180 } 199 181 200 /** 201 * Locate an entity instance of the given class by its URL. 202 * 203 * @param url 204 * The entity URL as returned by {@link #getEntityURL(Object)}. 205 * @return The entity instance matching the given URL, or null if none was 206 * found. 207 */ 208 public Object getEntity(String url) { 209 return getEntity(new Request(Method.GET, url)); 210 } 211 212 /** 213 * Locate an entity instance of the given class by its URL. 214 * 215 * @param url 216 * The entity URL as returned by {@link #getEntityURL(Object)}. 217 * @return The entity instance matching the given URL, or null if none was 218 * found. 219 */ 220 public Object getEntity(Request request) { 221 if (isChild()) { 222 return getParent().getEntity(request); 223 } else { 224 if (baseRef != null 225 && request.getResourceRef().toString(true, false) 226 .startsWith(baseRef.toString(true, false))) { 227 request.getResourceRef().setBaseRef(baseRef); 228 } 229 return doGetEntity(request); 230 } 231 } 232 233 private Object doGetEntity(Request request) { 182 Object getEntity(Request request) { 183 if (baseRef != null 184 && request.getResourceRef().toString(true, false).startsWith( 185 baseRef.toString(true, false))) { 186 request.getResourceRef().setBaseRef(baseRef); 187 } 234 188 Object entity = null; 235 189 Route next = (Route) getNext(request, new Response(request)); … … 287 241 } 288 242 request.getResourceRef().setBaseRef(baseRef); 289 entity = ((EntityRouter) target). doGetEntity(request);243 entity = ((EntityRouter) target).getEntity(request); 290 244 } 291 245 } … … 335 289 EntityRouter router = (EntityRouter) next; 336 290 Route route = super.attach(uriPattern, target); 337 router.set DefaultRouteTemplate(route.getTemplate());291 router.setTemplate(route.getTemplate()); 338 292 children.add(router); 339 293 return route; … … 381 335 } 382 336 383 p ublicEntityRouter getParent() {337 private EntityRouter getParent() { 384 338 return parent; 385 339 } 386 340 387 p ublicboolean isChild() {341 private boolean isChild() { 388 342 return parent != null; 389 343 } … … 393 347 } 394 348 395 public EntityRouter setBaseRef(String baseRef) { 396 return setBaseRef(new Reference(baseRef)); 397 } 398 399 public EntityRouter setBaseRef(Reference baseRef) { 349 public void setBaseRef(String baseRef) { 350 setBaseRef(new Reference(baseRef)); 351 } 352 353 public void setBaseRef(Reference baseRef) { 354 if (isChild()) { 355 throw new IllegalStateException( 356 "BaseRef is only applicable to the root entity router."); 357 } 400 358 this.baseRef = baseRef; 401 return this; 402 } 403 404 public void setDefaultRouteTemplate(Template template) { 405 defaultRouteTemplate = template; 359 } 360 361 private void setTemplate(Template template) { 362 this.template = template; 406 363 Route route = getDefaultRoute(); 407 364 if (route != null && route instanceof EntityRoute) { trunk/src/main/java/org/sarugo/restlet/jpa/PersistenceApplication.java
r3666 r3677 6 6 import org.restlet.Application; 7 7 import org.restlet.Context; 8 import org.restlet.data.Method; 9 import org.restlet.data.Request; 8 10 9 11 public class PersistenceApplication extends Application { … … 64 66 } 65 67 68 public String getEntityURL(Object entity) { 69 return entityRouter.getEntityURL(entity); 70 } 71 72 /** 73 * Locate an entity instance of the given class by its URL. 74 * 75 * @param url 76 * The entity URL as returned by {@link #getEntityURL(Object)}. 77 * @return The entity instance matching the given URL, or null if none was 78 * found. 79 */ 80 public Object getEntity(String url) { 81 return getEntity(new Request(Method.GET, url)); 82 } 83 84 /** 85 * Locate an entity instance of the given class by its URL. 86 * 87 * @param url 88 * The entity URL as returned by {@link #getEntityURL(Object)}. 89 * @return The entity instance matching the given URL, or null if none was 90 * found. 91 */ 92 public Object getEntity(Request request) { 93 return entityRouter.getEntity(request); 94 } 95 66 96 } trunk/src/main/java/org/sarugo/restlet/jpa/converter/FormEntityUpdateConverter.java
r2956 r3677 9 9 import java.text.ParseException; 10 10 import java.util.Date; 11 import java.util.logging.Level;12 11 13 12 import org.restlet.data.Form; 14 13 import org.restlet.data.MediaType; 15 import org.restlet.data.Status;16 14 import org.restlet.resource.Representation; 17 import org.restlet.resource.StringRepresentation; 18 import org.sarugo.restlet.jpa.PersistenceConverter; 19 import org.sarugo.restlet.jpa.PersistenceResource; 15 import org.sarugo.restlet.jpa.PersistenceApplication; 20 16 21 public class FormEntityUpdateConverter extends PersistenceConverter {17 public class FormEntityUpdateConverter extends Converter { 22 18 23 @Override 24 public boolean updateEntity(Object entity, PersistenceResource resource) { 25 Representation representation = resource.getRequest().getEntity(); 26 if (!MediaType.APPLICATION_WWW_FORM.equals(representation 27 .getMediaType())) { 28 return false; 29 } 30 Form data = resource.getRequest().getEntityAsForm(); 31 try { 32 for (PropertyDescriptor p : Introspector.getBeanInfo( 33 entity.getClass()).getPropertyDescriptors()) { 34 String value = data.getFirstValue(p.getName()); 35 if (value != null && p.getWriteMethod() != null) { 36 Object v = PersistenceConverter.convertToType(p 37 .getPropertyType(), value); 38 if (v != null) { 39 p.getWriteMethod().invoke(entity, v); 40 } else if (p.getPropertyType().isAssignableFrom(Date.class)) { 41 try { 42 p.getWriteMethod().invoke(entity, 43 Timestamp.valueOf(value)); 44 } catch (IllegalArgumentException e) { 45 p.getWriteMethod().invoke( 46 entity, 47 DateFormat.getDateTimeInstance().parse( 48 value)); 49 } 50 } else { 51 throw new ParseException("Unable to convert value \"" 52 + value + "\" to type " + p.getPropertyType(), 53 0); 54 } 55 } 56 } 57 } catch (IntrospectionException e) { 58 resource.getLogger().log(Level.WARNING, 59 "Unable to update entity from form.", e); 60 resource.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); 61 } catch (IllegalAccessException e) { 62 resource.getLogger().log(Level.WARNING, 63 "Unable to update entity from form.", e); 64 resource.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); 65 } catch (IllegalArgumentException e) { 66 resource.getLogger().log(Level.WARNING, 67 "Unable to update entity from form.", e); 68 resource.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); 69 } catch (InvocationTargetException e) { 70 resource.getLogger().log(Level.WARNING, 71 "Unable to update entity from form.", e); 72 resource.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); 73 } catch (ParseException e) { 74 resource.getLogger().log(Level.INFO, 75 "Unable to update entity from form.", e); 76 resource.getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); 77 resource.getResponse().setEntity( 78 new StringRepresentation(e.toString())); 79 } 80 return true; 81 } 19 public FormEntityUpdateConverter(PersistenceApplication application) { 20 super(application); 21 } 22 23 @Override 24 public MediaType getMediaType() { 25 return MediaType.APPLICATION_WWW_FORM; 26 } 27 28 @Override 29 public boolean updateEntity(Object entity, Representation representation) 30 throws ParseException { 31 if (!MediaType.APPLICATION_WWW_FORM.equals(representation 32 .getMediaType())) { 33 return false; 34 } 35 Form data = new Form(representation); 36 try { 37 for (PropertyDescriptor p : Introspector.getBeanInfo( 38 entity.getClass()).getPropertyDescriptors()) { 39 String value = data.getFirstValue(p.getName()); 40 if (value != null && p.getWriteMethod() != null) { 41 Object v = convertToTypeOrEntity(p.getPropertyType(), value); 42 if (v != null) { 43 p.getWriteMethod().invoke(entity, v); 44 } else if (p.getPropertyType().isAssignableFrom(Date.class)) { 45 try { 46 p.getWriteMethod().invoke(entity, 47 Timestamp.valueOf(value)); 48 } catch (IllegalArgumentException e) { 49 p.getWriteMethod().invoke( 50 entity, 51 DateFormat.getDateTimeInstance().parse( 52 value)); 53 } 54 } else { 55 throw new ParseException("Unable to convert value \"" 56 + value + "\" to type " + p.getPropertyType(), 57 0); 58 } 59 } 60 } 61 } catch (IntrospectionException e) { 62 throw new RuntimeException(e); 63 } catch (IllegalAccessException e) { 64 throw new RuntimeException(e); 65 } catch (IllegalArgumentException e) { 66 throw new RuntimeException(e); 67 } catch (InvocationTargetException e) { 68 throw new RuntimeException(e); 69 } 70 return true; 71 } 72 73 @Override 74 public Representation represent(Object entity) { 75 Form form = new Form(); 76 try { 77 for (PropertyDescriptor p : Introspector.getBeanInfo( 78 entity.getClass()).getPropertyDescriptors()) { 79 form.add(p.getName(), String.valueOf(p.getReadMethod().invoke( 80 entity))); 81 } 82 } catch (IntrospectionException e) { 83 throw new RuntimeException(e); 84 } catch (IllegalAccessException e) { 85 throw new RuntimeException(e); 86 } catch (IllegalArgumentException e) { 87 throw new RuntimeException(e); 88 } catch (InvocationTargetException e) { 89 throw new RuntimeException(e); 90 } 91 return form.getWebRepresentation(); 92 } 82 93 83 94 } trunk/src/main/java/org/sarugo/restlet/jpa/converter/JSONConverter.java
r2945 r3677 21 21 import java.beans.PropertyDescriptor; 22 22 import java.lang.reflect.InvocationTargetException; 23 import java. util.ArrayList;23 import java.text.ParseException; 24 24 import java.util.HashMap; 25 import java.util.List;26 25 import java.util.Map; 27 26 import java.util.logging.Level; … … 30 29 import org.restlet.resource.Representation; 31 30 import org.restlet.resource.StringRepresentation; 32 import org.restlet.resource.Variant; 33 import org.sarugo.restlet.jpa.PersistenceResource; 34 import org.sarugo.restlet.jpa.PersistenceConverter; 31 import org.sarugo.restlet.jpa.PersistenceApplication; 35 32 36 33 import com.sdicons.json.mapper.JSONMapper; 37 34 import com.sdicons.json.mapper.MapperException; 38 35 39 public class JSONConverter extends PersistenceConverter { 36 public class JSONConverter extends Converter { 37 38 public JSONConverter(PersistenceApplication application) { 39 super(application); 40 } 41 42 @Override 43 public MediaType getMediaType() { 44 return MediaType.APPLICATION_JSON; 45 } 46 47 @Override 48 public boolean updateEntity(Object entity, Representation representation) throws ParseException { 49 // TODO Auto-generated method stub 50 return false; 51 } 40 52 41 53 @Override 42 public void initEntityVariants(PersistenceResource resource) { 43 resource.getVariants().add(new Variant(MediaType.APPLICATION_JSON)); 44 } 45 46 @Override 47 public Representation getEntityRepresentation(Variant variant, 48 PersistenceResource resource) { 49 if (MediaType.APPLICATION_JSON.equals(variant.getMediaType())) { 54 public Representation represent(Object entity) { 50 55 try { 51 56 // Read each property from the entity and store in a map. … … 54 59 Map<String, Object> entityValues = new HashMap<String, Object>(); 55 60 for (PropertyDescriptor p : Introspector.getBeanInfo( 56 resource.getModel()).getPropertyDescriptors()) {61 entity.getClass()).getPropertyDescriptors()) { 57 62 if (p.getWriteMethod() != null && p.getReadMethod() != null) { 58 63 Object value = p.getReadMethod().invoke( 59 resource.getEntity());60 if (resource.getRouter().getName(value.getClass()) != null) { 61 // Convert "known" entities to URLs 62 value = resource.getEntityReference(value)63 .toString(false, false);64 entity); 65 // Convert "known" entities to URLs 66 String url = getApplication().getEntityURL(value); 67 if (url != null) { 68 value = url; 64 69 } 65 70 entityValues.put(p.getName(), value); … … 67 72 } 68 73 return new StringRepresentation(JSONMapper.toJSON(entityValues) 69 .render(true), variant.getMediaType());74 .render(true), getMediaType()); 70 75 } catch (MapperException e) { 71 resource.getLogger().log(Level.WARNING,76 getApplication().getLogger().log(Level.WARNING, 72 77 "Unable to map entity to JSON", e); 73 78 } catch (IntrospectionException e) { 74 resource.getLogger().log(Level.WARNING,79 getApplication().getLogger().log(Level.WARNING, 75 80 "Unable to map entity to JSON", e); 76 81 } catch (IllegalArgumentException e) { 77 resource.getLogger().log(Level.WARNING,82 getApplication().getLogger().log(Level.WARNING, 78 83 "Unable to map entity to JSON", e); 79 84 } catch (IllegalAccessException e) { 80 resource.getLogger().log(Level.WARNING,85 getApplication().getLogger().log(Level.WARNING, 81 86 "Unable to map entity to JSON", e); 82 87 } catch (InvocationTargetException e) { 83 resource.getLogger().log(Level.WARNING,88 getApplication().getLogger().log(Level.WARNING, 84 89 "Unable to map entity to JSON", e); 85 90 } 86 }87 return null;88 }89 90 @Override91 public void initEntityListVariants(PersistenceResource resource) {92 resource.getVariants().add(new Variant(MediaType.APPLICATION_JSON));93 }94 95 @Override96 public Representation getEntityListRepresentation(Variant variant,97 PersistenceResource resource) {98 if (MediaType.APPLICATION_JSON.equals(variant.getMediaType())) {99 try {100 List<String> urlList = new ArrayList<String>(resource101 .getEntities().size());102 for (Object entity : resource.getEntities()) {103 urlList.add(resource.getEntityURI(entity));104 }105 Map<String, Object> listObject = new HashMap<String, Object>(1, 1.0f);106 listObject.put("entities", urlList);107 return new StringRepresentation(JSONMapper.toJSON(listObject)108 .render(true), variant.getMediaType());109 } catch (MapperException e) {110 resource.getLogger().log(Level.WARNING,111 "Unable to map entity list to JSON", e);112 } catch (IllegalArgumentException e) {113 resource.getLogger().log(Level.WARNING,114 "Unable to map entity list to JSON", e);115 }116 }117 91 return null; 118 92 } trunk/src/main/java/org/sarugo/restlet/jpa/converter/StringEntityConverter.java
r2945 r3677 17 17 package org.sarugo.restlet.jpa.converter; 18 18 19 import java.text.ParseException; 20 19 21 import org.restlet.data.MediaType; 20 22 import org.restlet.resource.Representation; 21 23 import org.restlet.resource.StringRepresentation; 22 import org.restlet.resource.Variant; 23 import org.sarugo.restlet.jpa.PersistenceResource; 24 import org.sarugo.restlet.jpa.PersistenceConverter; 24 import org.sarugo.restlet.jpa.PersistenceApplication; 25 25 26 public class StringEntityConverter extends PersistenceConverter {26 public class StringEntityConverter extends Converter { 27 27 28 @Override 29 public void initEntityVariants(PersistenceResource resource) { 30 resource.getVariants().add(new Variant(MediaType.TEXT_PLAIN)); 31 } 28 public StringEntityConverter(PersistenceApplication application) { 29 super(application); 30 } 32 31 33 @Override 34 public Representation getEntityRepresentation(Variant variant, 35 PersistenceResource resource) { 36 if (MediaType.TEXT_PLAIN.equals(variant.getMediaType())) { 37 return new StringRepresentation(resource.getEntity().toString()); 38 } 39 return null; 40 } 32 @Override 33 public MediaType getMediaType() { 34 return MediaType.TEXT_PLAIN; 35 } 36 37 @Override 38 public Representation represent(Object entity) { 39 return new StringRepresentation(String.valueOf(entity)); 40 } 41 42 @Override 43 public boolean updateEntity(Object entity, Representation representation) 44 throws ParseException { 45 // TODO Auto-generated method stub 46 return false; 47 } 41 48 42 49 } trunk/src/main/java/org/sarugo/restlet/jpa/resource/EntityInstance.java
r3666 r3677 26 26 import org.restlet.resource.Resource; 27 27 import org.sarugo.restlet.jpa.EntityFinder; 28 import org.sarugo.restlet.jpa.EntityHelper;29 28 import org.sarugo.restlet.jpa.EntityRouter; 30 29 import org.sarugo.restlet.jpa.PersistenceApplication; 30 import org.sarugo.restlet.jpa.converter.Converter; 31 31 32 32 /** … … 95 95 String value = (String) attributes.get(finder.getIdAttribute()); 96 96 if (value != null) { 97 id = EntityHelper.convertToType(finder.getEntityIdClass(), value, 98 null); 97 id = Converter.convertToType(finder.getEntityIdClass(), value); 99 98 } 100 99 return id; trunk/src/test/java/org/sarugo/restlet/jpa/URLMappingTests.java
r3666 r3677 63 63 64 64 public void testGetEntityURL() { 65 assertEquals("/test/foo/" + foo.id, router.getEntityURL(foo));65 assertEquals("/test/foo/" + foo.id, app.getEntityURL(foo)); 66 66 assertEquals("/test/foo/" + foo.id + "/bar/" + bar.id, router 67 67 .getEntityURL(bar)); 68 68 Route barRoute = router.attach("/bar/{barId}", BarResource.class); 69 assertEquals("/bar/" + bar.id, router.getEntityURL(bar));69 assertEquals("/bar/" + bar.id, app.getEntityURL(bar)); 70 70 router.attach("/baz/{barId}", barRoute.getNext()); 71 assertEquals("/bar/" + bar.id, router.getEntityURL(bar));71 assertEquals("/bar/" + bar.id, app.getEntityURL(bar)); 72 72 router.setBaseRef("http://server/path"); 73 73 assertEquals("http://server/path/bar/" + bar.id, router … … 76 76 77 77 public void testGetEntity() { 78 FooEntity foundFoo = (FooEntity) router.getEntity("/test/foo/" + foo.id);78 FooEntity foundFoo = (FooEntity) app.getEntity("/test/foo/" + foo.id); 79 79 assertEquals(foo.id, foundFoo.id); 80 foundFoo = (FooEntity) router.getEntity("/test/foo/" + foo.id + 120485);80 foundFoo = (FooEntity) app.getEntity("/test/foo/" + foo.id + 120485); 81 81 assertNull(foundFoo); 82 foundFoo = (FooEntity) router.getEntity("/test/fool/" + foo.id);82 foundFoo = (FooEntity) app.getEntity("/test/fool/" + foo.id); 83 83 assertNull(foundFoo); 84 BarEntity foundBar = (BarEntity) router.getEntity("/test/foo/" + foo.id84 BarEntity foundBar = (BarEntity) app.getEntity("/test/foo/" + foo.id 85 85 + "/bar/" + bar.id); 86 86 assertEquals(bar.id, foundBar.id); 87 87 Route barRoute = router.attach("/bar/{barId}", BarResource.class); 88 foundBar = (BarEntity) router.getEntity("/bar/" + bar.id);88 foundBar = (BarEntity) app.getEntity("/bar/" + bar.id); 89 89 assertEquals(bar.id, foundBar.id); 90 90 router.attach("/baz/{barId}", barRoute.getNext()); 91 foundBar = (BarEntity) router.getEntity("/baz/" + bar.id);91 foundBar = (BarEntity) app.getEntity("/baz/" + bar.id); 92 92 assertEquals(bar.id, foundBar.id); 93 93 router.setBaseRef("http://server/path"); 94 foundBar = (BarEntity) router.getEntity("http://server/path/bar/"94 foundBar = (BarEntity) app.getEntity("http://server/path/bar/" 95 95 + bar.id); 96 96 assertEquals(bar.id, foundBar.id); 97 foundBar = (BarEntity) router.getEntity("/bar/" + bar.id);97 foundBar = (BarEntity) app.getEntity("/bar/" + bar.id); 98 98 assertEquals(bar.id, foundBar.id); 99 99 }
