Make Tiles 3 the default implementation in spring-webmvc
Move spring-webmvc-tiles3 content to spring-webmvc, and create a spring-webmvc-tiles2 module with Tiles 2 support. Its allows View Resolution to configure Tiles 3 instead of Tiles 2. Issue: SPR-7093
This commit is contained in:
committed by
Rossen Stoyanchev
parent
92402e7715
commit
a26b1ef8d9
@@ -89,8 +89,8 @@ import org.springframework.web.servlet.view.InternalResourceView;
|
||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
|
||||
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
|
||||
import org.springframework.web.servlet.view.tiles2.TilesConfigurer;
|
||||
import org.springframework.web.servlet.view.tiles2.TilesViewResolver;
|
||||
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
|
||||
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE tiles-definitions PUBLIC
|
||||
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
|
||||
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
|
||||
|
||||
<tiles-definitions>
|
||||
|
||||
<definition name="test" template="/WEB-INF/tiles/test.jsp"/>
|
||||
|
||||
</tiles-definitions>
|
||||
@@ -14,39 +14,53 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.view.tiles2;
|
||||
package org.springframework.web.servlet.view.tiles3;
|
||||
|
||||
import org.apache.tiles.context.TilesRequestContext;
|
||||
import org.apache.tiles.access.TilesAccess;
|
||||
import org.apache.tiles.impl.BasicTilesContainer;
|
||||
import org.apache.tiles.servlet.context.ServletTilesRequestContext;
|
||||
import org.apache.tiles.servlet.context.ServletUtil;
|
||||
import static org.junit.Assert.*;
|
||||
import org.apache.tiles.request.ApplicationContext;
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.servlet.ServletRequest;
|
||||
import org.apache.tiles.request.servlet.ServletUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* */
|
||||
* Test fixture for {@link TilesConfigurer}.
|
||||
*
|
||||
* @author Nicolas Le Bas
|
||||
*/
|
||||
public class TilesConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void simpleBootstrap() {
|
||||
MockServletContext sc = new MockServletContext();
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
|
||||
TilesConfigurer tc = new TilesConfigurer();
|
||||
tc.setDefinitions("/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml");
|
||||
tc.setDefinitions("/org/springframework/web/servlet/view/tiles3/tiles-definitions.xml");
|
||||
tc.setCheckRefresh(true);
|
||||
tc.setServletContext(sc);
|
||||
tc.setServletContext(servletContext);
|
||||
tc.afterPropertiesSet();
|
||||
|
||||
BasicTilesContainer container = (BasicTilesContainer) ServletUtil.getContainer(sc);
|
||||
TilesRequestContext requestContext = new ServletTilesRequestContext(
|
||||
container.getApplicationContext(), new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||
ApplicationContext tilesContext = ServletUtil.getApplicationContext(servletContext);
|
||||
|
||||
BasicTilesContainer container = (BasicTilesContainer) TilesAccess.getContainer(tilesContext);
|
||||
Request requestContext = new ServletRequest(container.getApplicationContext(),
|
||||
new MockHttpServletRequest(), new MockHttpServletResponse());
|
||||
assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext));
|
||||
|
||||
tc.destroy();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
public static class AppConfig {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.servlet.view.tiles3;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.render.Renderer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link TilesViewResolver}.
|
||||
*
|
||||
* @author mick semb wever
|
||||
*/
|
||||
public class TilesViewResolverTests {
|
||||
|
||||
private TilesViewResolver viewResolver;
|
||||
|
||||
private Renderer renderer;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
wac.setServletContext(new MockServletContext());
|
||||
wac.refresh();
|
||||
|
||||
this.renderer = mock(Renderer.class);
|
||||
|
||||
this.viewResolver = new TilesViewResolver();
|
||||
this.viewResolver.setRenderer(this.renderer);
|
||||
this.viewResolver.setApplicationContext(wac);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolve() throws Exception {
|
||||
given(this.renderer.isRenderable(eq("/template.test"), isA(Request.class))).willReturn(true);
|
||||
given(this.renderer.isRenderable(eq("/nonexistent.test"), isA(Request.class))).willReturn(false);
|
||||
|
||||
assertTrue(this.viewResolver.resolveViewName("/template.test", Locale.ITALY) instanceof TilesView);
|
||||
assertNull(this.viewResolver.resolveViewName("/nonexistent.test", Locale.ITALY));
|
||||
|
||||
verify(this.renderer).isRenderable(eq("/template.test"), isA(Request.class));
|
||||
verify(this.renderer).isRenderable(eq("/nonexistent.test"), isA(Request.class));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.web.servlet.view.tiles3;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.tiles.request.Request;
|
||||
import org.apache.tiles.request.render.Renderer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.test.MockServletContext;
|
||||
import org.springframework.web.context.support.StaticWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Test fixture for {@link TilesView}.
|
||||
*
|
||||
* @author mick semb wever
|
||||
*/
|
||||
public class TilesViewTests {
|
||||
|
||||
private static final String VIEW_PATH = "template.test";
|
||||
|
||||
private TilesView view;
|
||||
|
||||
private Renderer renderer;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockServletContext servletContext = new MockServletContext();
|
||||
StaticWebApplicationContext wac = new StaticWebApplicationContext();
|
||||
wac.setServletContext(servletContext);
|
||||
wac.refresh();
|
||||
|
||||
request = new MockHttpServletRequest();
|
||||
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
|
||||
|
||||
response = new MockHttpServletResponse();
|
||||
|
||||
renderer = mock(Renderer.class);
|
||||
|
||||
view = new TilesView();
|
||||
view.setServletContext(servletContext);
|
||||
view.setRenderer(renderer);
|
||||
view.setUrl(VIEW_PATH);
|
||||
view.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRender() throws Exception {
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
model.put("modelAttribute", "modelValue");
|
||||
view.render(model, request, response);
|
||||
assertEquals("modelValue", request.getAttribute("modelAttribute"));
|
||||
verify(renderer).render(eq(VIEW_PATH), isA(Request.class));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user