TilesContextPropertyAccessorDelegateFactory implements
        PropertyAccessorDelegateFactory<Request> { public PropertyAccessor getPropertyAccessor(String propertyName, Request request) { PropertyAccessor retValue; if (propertyName.endsWith("Scope")) { String scopeName = propertyName.substring(0, propertyName.length() - ScopePropertyAccessor.SCOPE_SUFFIX_LENGTH); if (request.getContext(scopeName) != null) { return scopePropertyAccessor; } } if (beanInfo.getMappedDescriptors(Request.class) .containsKey(propertyName)) { retValue = objectPropertyAccessor; } else if (beanInfo.getMappedDescriptors(ApplicationContext.class) .containsKey(propertyName)) { retValue = applicationContextPropertyAccessor; } else { return anyScopePropertyAccessor; } return retValue; } TilesContextPropertyAccessorDelegateFactory(
            PropertyAccessor objectPropertyAccessor,
            PropertyAccessor applicationContextPropertyAccessor,
            PropertyAccessor anyScopePropertyAccessor,
            PropertyAccessor scopePropertyAccessor); PropertyAccessor getPropertyAccessor(String propertyName,
            Request request);  }
@Test public void testGetPropertyAccessorRequest() { PropertyAccessor objectPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationContextPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor requestScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor sessionScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationScopePropertyAccessor = createMock(PropertyAccessor.class); Request request = createMock(Request.class); replay(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); PropertyAccessorDelegateFactory<Request> factory = new TilesContextPropertyAccessorDelegateFactory( objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor); assertEquals(objectPropertyAccessor, factory.getPropertyAccessor("writer", request)); verify(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); }
@Test public void testGetPropertyAccessorApplication() { PropertyAccessor objectPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationContextPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor requestScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor sessionScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationScopePropertyAccessor = createMock(PropertyAccessor.class); Request request = createMock(Request.class); replay(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); PropertyAccessorDelegateFactory<Request> factory = new TilesContextPropertyAccessorDelegateFactory( objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor); assertEquals(applicationContextPropertyAccessor, factory.getPropertyAccessor("initParams", request)); verify(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); }
@Test public void testGetPropertyAccessorRequestScope() { PropertyAccessor objectPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationContextPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor requestScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor sessionScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationScopePropertyAccessor = createMock(PropertyAccessor.class); Request request = createMock(Request.class); Map<String, Object> map = new HashMap<String, Object>(); map.put("attribute", 1); replay(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); PropertyAccessorDelegateFactory<Request> factory = new TilesContextPropertyAccessorDelegateFactory( objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor); assertEquals(requestScopePropertyAccessor, factory.getPropertyAccessor("attribute", request)); verify(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); }
@Test public void testGetPropertyAccessorSessionScope() { PropertyAccessor objectPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationContextPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor requestScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor sessionScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationScopePropertyAccessor = createMock(PropertyAccessor.class); Request request = createMock(Request.class); Map<String, Object> map = new HashMap<String, Object>(); map.put("attribute", 1); replay(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); PropertyAccessorDelegateFactory<Request> factory = new TilesContextPropertyAccessorDelegateFactory( objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor); assertEquals(requestScopePropertyAccessor, factory.getPropertyAccessor("attribute", request)); verify(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request); }
@Test public void testGetPropertyAccessorApplicationScope() { PropertyAccessor objectPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationContextPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor requestScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor sessionScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationScopePropertyAccessor = createMock(PropertyAccessor.class); Request request = createMock(Request.class); ApplicationContext applicationContext = createMock(ApplicationContext.class); Map<String, Object> map = new HashMap<String, Object>(); map.put("attribute", 1); replay(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request, applicationContext); PropertyAccessorDelegateFactory<Request> factory = new TilesContextPropertyAccessorDelegateFactory( objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor); assertEquals(requestScopePropertyAccessor, factory.getPropertyAccessor("attribute", request)); verify(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request, applicationContext); }
@Test public void testGetPropertyAccessorRequestScopeDefault() { PropertyAccessor objectPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationContextPropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor requestScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor sessionScopePropertyAccessor = createMock(PropertyAccessor.class); PropertyAccessor applicationScopePropertyAccessor = createMock(PropertyAccessor.class); Request request = createMock(Request.class); ApplicationContext applicationContext = createMock(ApplicationContext.class); Map<String, Object> map = new HashMap<String, Object>(); map.put("anotherAttribute", 1); replay(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request, applicationContext); PropertyAccessorDelegateFactory<Request> factory = new TilesContextPropertyAccessorDelegateFactory( objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor); assertEquals(requestScopePropertyAccessor, factory.getPropertyAccessor("attribute", request)); verify(objectPropertyAccessor, applicationContextPropertyAccessor, requestScopePropertyAccessor, sessionScopePropertyAccessor, applicationScopePropertyAccessor, request, applicationContext); }