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:31 UTC
[30/36] incubator-freemarker git commit: FREEMARKER-55: adding unit
test for bind directive.
FREEMARKER-55: adding unit test for bind directive.
Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/7a93fa0a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/7a93fa0a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/7a93fa0a
Branch: refs/heads/3
Commit: 7a93fa0ac9d5594080b3b8749976f80030de6e4f
Parents: 4672252
Author: Woonsan Ko <wo...@apache.org>
Authored: Tue Sep 12 15:02:44 2017 -0400
Committer: Woonsan Ko <wo...@apache.org>
Committed: Tue Sep 12 15:02:44 2017 -0400
----------------------------------------------------------------------
.../spring/model/BindDirectiveTest.java | 73 ++++++++++++++++++++
.../spring/model/EvalFunctionTest.java | 5 --
.../test/model/bind-directive-basic-usages.ftl | 55 +++++++++++++++
3 files changed, 128 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7a93fa0a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/BindDirectiveTest.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/BindDirectiveTest.java b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/BindDirectiveTest.java
new file mode 100644
index 0000000..cd1af42
--- /dev/null
+++ b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/BindDirectiveTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.User;
+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 BindDirectiveTest {
+
+ @Autowired
+ private WebApplicationContext wac;
+
+ @Autowired
+ private UserRepository userRepository;
+
+ private MockMvc mockMvc;
+
+ @Before
+ public void setUp() {
+ mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
+ }
+
+ @Test
+ public void testMessageFunctionBasicUsages() throws Exception {
+ final Integer userId = userRepository.getUserIds().iterator().next();
+ final User user = userRepository.getUser(userId);
+ mockMvc.perform(get("/users/{userId}.", userId).param("viewName", "test/model/bind-directive-basic-usages")
+ .accept(MediaType.parseMediaType("text/html"))).andExpect(status().isOk())
+ .andExpect(content().contentTypeCompatibleWith("text/html")).andDo(print())
+ .andExpect(xpath("//input[@name='email']/@value").string(user.getEmail()))
+ .andExpect(xpath("//input[@name='firstName']/@value").string(user.getFirstName()))
+ .andExpect(xpath("//input[@name='lastName']/@value").string(user.getLastName()))
+ .andExpect(xpath("//div[@id='statusValueNotReachable']/text()").string(""));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7a93fa0a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/EvalFunctionTest.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/EvalFunctionTest.java b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/EvalFunctionTest.java
index 953b571..be6f6dd 100644
--- a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/EvalFunctionTest.java
+++ b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/EvalFunctionTest.java
@@ -53,14 +53,9 @@ public class EvalFunctionTest {
private MockMvc mockMvc;
- private long startTimeMillis;
-
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
-
- startTimeMillis = System.currentTimeMillis();
- System.setProperty("EvalFunctionTest.startTimeMillis", Long.toString(startTimeMillis));
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7a93fa0a/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/bind-directive-basic-usages.ftl
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/bind-directive-basic-usages.ftl b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/bind-directive-basic-usages.ftl
new file mode 100644
index 0000000..2f0e535
--- /dev/null
+++ b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/bind-directive-basic-usages.ftl
@@ -0,0 +1,55 @@
+<#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>
+
+<table class="table">
+ <tbody>
+ <tr>
+ <th>E-Mail</th>
+ <td>
+ <@spring.bind "user.email"; status>
+ <input type="text" name="email" value="${status.value!}" />
+ </...@spring.bind>
+ </td>
+ </tr>
+ <tr>
+ <th>First Name</th>
+ <td>
+ <@spring.bind "user.firstName"; status>
+ <input type="text" name="firstName" value="${status.value!}" />
+ </...@spring.bind>
+ </td>
+ </tr>
+ <tr>
+ <th>Last Name</th>
+ <td>
+ <@spring.bind "user.lastName"; status>
+ <input type="text" name="lastName" value="${status.value!}" />
+ </...@spring.bind>
+ </td>
+ </tr>
+ </tbody>
+</table>
+
+<div id="statusValueNotReachable"><#if status??>${status.value!}</#if></div>
+
+</body>
+</html>