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:32 UTC

[31/36] incubator-freemarker git commit: FREEMARKER-55: Adding unit test for nestedPath directive.

FREEMARKER-55: Adding unit test for nestedPath 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/86a8a5f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/86a8a5f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/86a8a5f6

Branch: refs/heads/3
Commit: 86a8a5f6933ccf128cae0ca46ef116717aa949be
Parents: 7a93fa0
Author: Woonsan Ko <wo...@apache.org>
Authored: Tue Sep 12 15:06:04 2017 -0400
Committer: Woonsan Ko <wo...@apache.org>
Committed: Tue Sep 12 15:06:04 2017 -0400

----------------------------------------------------------------------
 .../spring/model/NestedPathDirectiveTest.java   | 72 ++++++++++++++++++++
 .../model/nestedpath-directive-basic-usages.ftl | 55 +++++++++++++++
 2 files changed, 127 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/86a8a5f6/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/NestedPathDirectiveTest.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/NestedPathDirectiveTest.java b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/NestedPathDirectiveTest.java
new file mode 100644
index 0000000..d02478f
--- /dev/null
+++ b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/NestedPathDirectiveTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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 NestedPathDirectiveTest {
+
+    @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/nestedpath-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()));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/86a8a5f6/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/nestedpath-directive-basic-usages.ftl
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/nestedpath-directive-basic-usages.ftl b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/nestedpath-directive-basic-usages.ftl
new file mode 100644
index 0000000..13849bf
--- /dev/null
+++ b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/nestedpath-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>
+
+<@spring.nestedPath "user">
+  <table class="table">
+    <tbody>
+      <tr>
+        <th>E-Mail</th>
+        <td>
+          <@spring.bind "email"; status>
+            <input type="text" name="email" value="${status.value!}" />
+          </...@spring.bind>
+        </td>
+      </tr>
+      <tr>
+        <th>First Name</th>
+        <td>
+          <@spring.bind "firstName"; status>
+            <input type="text" name="firstName" value="${status.value!}" />
+          </...@spring.bind>
+        </td>
+      </tr>
+      <tr>
+        <th>Last Name</th>
+        <td>
+          <@spring.bind "lastName"; status>
+            <input type="text" name="lastName" value="${status.value!}" />
+          </...@spring.bind>
+        </td>
+      </tr>
+    </tbody>
+  </table>
+</...@spring.nestedPath>
+
+</body>
+</html>