InsertAttributeModel { public void execute(boolean ignore, String preparer, String role, Object defaultValue, String defaultValueRole, String defaultValueType, String name, Attribute value, boolean flush, Request request, ModelBody modelBody) throws IOException { TilesContainer container = TilesAccess.getCurrentContainer(request); Deque<Object> composeStack = ComposeStackUtil.getComposeStack(request); Attribute attribute = resolveAttribute(container, ignore, preparer, role, defaultValue, defaultValueRole, defaultValueType, name, value, request); if (attribute != null) { composeStack.push(attribute); } modelBody.evaluateWithoutWriting(); container = TilesAccess.getCurrentContainer(request); if (attribute != null) { attribute = (Attribute) composeStack.pop(); } renderAttribute(container, ignore, attribute, request); if (flush) { request.getWriter().flush(); } } InsertAttributeModel();  InsertAttributeModel(AttributeResolver attributeResolver); void execute(boolean ignore, String preparer,
            String role, Object defaultValue, String defaultValueRole,
            String defaultValueType, String name, Attribute value,
            boolean flush, Request request, ModelBody modelBody);  }
@Test public void testExecute() throws IOException { TilesContainer container = createMock(TilesContainer.class); Request request = createMock(Request.class); Attribute attribute = new Attribute("myValue"); AttributeContext attributeContext = createMock(AttributeContext.class); Map<String, Object> requestScope = new HashMap<String, Object>(); requestScope.put(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container); ApplicationContext applicationContext = createMock(ApplicationContext.class); ModelBody modelBody = createMock(ModelBody.class); modelBody.evaluateWithoutWriting(); expect(request.getApplicationContext()).andReturn(applicationContext).times(2); expect(request.getContext("request")).andReturn(requestScope).anyTimes(); container.prepare("myPreparer", request); expect(resolver.computeAttribute(container, attribute, "myName", "myRole", false, "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", request)).andReturn(attribute); expect(container.startContext(request)).andReturn(attributeContext); container.endContext(request); container.render(attribute, request); replay(resolver, container, request, applicationContext, modelBody); model.execute(false, "myPreparer", "myRole", "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", "myName", attribute, false, request, modelBody); verify(resolver, container, request, applicationContext, modelBody); }
@Test public void testExecuteIgnore() throws IOException { TilesContainer container = createMock(TilesContainer.class); Request request = createMock(Request.class); AttributeContext attributeContext = createMock(AttributeContext.class); Map<String, Object> requestScope = new HashMap<String, Object>(); Deque<Object> composeStack = new ArrayDeque<Object>(); requestScope.put(ComposeStackUtil.COMPOSE_STACK_ATTRIBUTE_NAME, composeStack); requestScope.put(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container); ApplicationContext applicationContext = createMock(ApplicationContext.class); ModelBody modelBody = createMock(ModelBody.class); modelBody.evaluateWithoutWriting(); expect(request.getApplicationContext()).andReturn(applicationContext).times(2); expect(request.getContext("request")).andReturn(requestScope).anyTimes(); container.prepare("myPreparer", request); expect(resolver.computeAttribute(container, null, "myName", "myRole", true, "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", request)).andReturn(null); expect(container.startContext(request)).andReturn(attributeContext); container.endContext(request); replay(resolver, container, request, applicationContext, modelBody); model.execute(true, "myPreparer", "myRole", "myDefaultValue", "myDefaultValueRole", "myDefaultValueType", "myName", null, false, request, modelBody); verify(resolver, container, request, applicationContext, modelBody); }