You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2017/09/13 09:49:30 UTC
[29/36] incubator-freemarker git commit: FREEMARKER-55: Adding unit
test for url function.
FREEMARKER-55: Adding unit test for url function.
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/4672252e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/4672252e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/4672252e
Branch: refs/heads/3
Commit: 4672252edb58455d4727ad8e233c892ddf0fe5fb
Parents: e4598db
Author: Woonsan Ko <wo...@apache.org>
Authored: Tue Sep 12 14:25:49 2017 -0400
Committer: Woonsan Ko <wo...@apache.org>
Committed: Tue Sep 12 14:25:49 2017 -0400
----------------------------------------------------------------------
.../spring/model/UrlFunctionTest.java | 76 ++++++++++++++++++++
.../test/model/url-function-basic-usages.ftl | 62 ++++++++++++++++
2 files changed, 138 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4672252e/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/UrlFunctionTest.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/UrlFunctionTest.java b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/UrlFunctionTest.java
new file mode 100644
index 0000000..c2e1ce3
--- /dev/null
+++ b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/UrlFunctionTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.freemarker.spring.model;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.xpath;
+
+import org.apache.freemarker.spring.example.mvc.users.UserRepository;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration("classpath:META-INF/web-resources")
+@ContextConfiguration(locations = { "classpath:org/apache/freemarker/spring/example/mvc/users/users-mvc-context.xml" })
+public class UrlFunctionTest {
+
+ @Autowired
+ private WebApplicationContext wac;
+
+ @Autowired
+ private UserRepository userRepository;
+
+ private MockMvc mockMvc;
+
+ @Before
+ public void setUp() {
+ mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
+ }
+
+ @Test
+ public void testThemeFunctionBasicUsages() throws Exception {
+ final Integer userId = userRepository.getUserIds().iterator().next();
+ mockMvc.perform(get("/users/").param("viewName", "test/model/url-function-basic-usages")
+ .accept(MediaType.parseMediaType("text/html"))).andExpect(status().isOk())
+ .andExpect(content().contentTypeCompatibleWith("text/html")).andDo(print())
+ .andExpect(xpath("//h2[@id='usersListHeader']//a/@href", userId).string("/users/"))
+ .andExpect(xpath("//h3[@id='usersListHeaderWithSortParams']//a/@href", userId)
+ .string("/users/?sortField=birthDate&sortDirection=descending"))
+ .andExpect(xpath("//h2[@id='otherAppsUsersListHeader']//a/@href", userId).string("/otherapp/users/"))
+ .andExpect(xpath("//h3[@id='otherAppsUsersListHeaderWithSortParams']//a/@href", userId)
+ .string("/otherapp/users/?sortField=birthDate&sortDirection=descending"))
+ .andExpect(xpath("//div[@id='user-%s']//a[@class='userIdLink']/@href", userId).string("/users/" + userId + "/"))
+ .andExpect(xpath("//div[@id='user-%s']//a[@class='userNameLink']/@href", userId).string("/users/" + userId + "/"))
+ .andExpect(xpath("//div[@id='freeMarkerManualUrl']//a/@href", userId)
+ .string("http://freemarker.org/docs/index.html"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4672252e/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/url-function-basic-usages.ftl
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/url-function-basic-usages.ftl b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/url-function-basic-usages.ftl
new file mode 100644
index 0000000..870ba3c
--- /dev/null
+++ b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/url-function-basic-usages.ftl
@@ -0,0 +1,62 @@
+<#ftl outputFormat="HTML">
+<#--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<html>
+<body>
+
+<h2 id="usersListHeader">
+ <#assign pathInfo="/users/" />
+ <a href="${spring.url(pathInfo)}">Users List</a>
+</h2>
+
+<h3 id="usersListHeaderWithSortParams">
+ <#assign pathInfo="/users/" />
+ <a href="${spring.url(pathInfo, sortField='birthDate', sortDirection='descending')}">Users List</a>
+</h3>
+
+<h2 id="otherAppsUsersListHeader">
+ <#assign pathInfo="/users/" />
+ <a href="${spring.url(pathInfo, context='/otherapp')}">Users List</a>
+</h2>
+
+<h3 id="otherAppsUsersListHeaderWithSortParams">
+ <#assign pathInfo="/users/" />
+ <a href="${spring.url(pathInfo, context='/otherapp', sortField='birthDate', sortDirection='descending')}">Users List</a>
+</h3>
+
+<ul>
+ <#list users as user>
+ <li>
+ <div id="user-${user.id!}">
+ <#assign pathInfo="/users/{userId}/" />
+ <a class="userIdLink" href="${spring.url(pathInfo, userId=user.id?string)}">${user.id!}</a>
+ <#assign pathInfo="/users/${user.id}/" />
+ <a class="userNameLink" href="${spring.url(pathInfo)}">${user.firstName!} ${user.lastName!}</a>
+ </div>
+ </li>
+ </#list>
+</ul>
+
+<div id="freeMarkerManualUrl">
+ <#assign pathInfo="http://freemarker.org/docs/index.html" />
+ <a href="${spring.url(pathInfo)}">Apache FreeMarker Manual</a>
+</div>
+
+</body>
+</html>