freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [26/36] incubator-freemarker git commit: FREEMARKER-55: adding unit test for theme function.
Date Wed, 13 Sep 2017 09:49:27 GMT
FREEMARKER-55: adding unit test for theme 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/9987acfe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/9987acfe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/9987acfe

Branch: refs/heads/3
Commit: 9987acfe0f399ad81d0373a8e7ee81e47674f614
Parents: a274d2a
Author: Woonsan Ko <woonsan@apache.org>
Authored: Tue Sep 12 11:33:39 2017 -0400
Committer: Woonsan Ko <woonsan@apache.org>
Committed: Tue Sep 12 11:33:39 2017 -0400

----------------------------------------------------------------------
 .../org/apache/freemarker/spring/model/ThemeFunction.java   | 2 ++
 .../apache/freemarker/spring/model/ThemeFunctionTest.java   | 9 +++++++--
 .../views/test/model/theme-function-basic-usages.ftl        | 5 +++++
 .../spring/example/mvc/users/UsersTheme-default.properties  | 1 +
 4 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/9987acfe/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/ThemeFunction.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/ThemeFunction.java
b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/ThemeFunction.java
index b03055e..4f201ad 100644
--- a/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/ThemeFunction.java
+++ b/freemarker-spring/src/main/java/org/apache/freemarker/spring/model/ThemeFunction.java
@@ -48,6 +48,8 @@ import org.springframework.web.servlet.support.RequestContext;
  * ${spring.theme("styleSheet")!}
  *
  * &lt;link rel="stylesheet" href="${spring.theme('styleSheet')}" type="text/css" /&gt;
+ * 
+ * &lt;div id="user" class="${spring.theme('userClass', 'selected')}"&gt;...&lt;/div&gt;
  * </PRE>
  * <P>
  * <EM>Note:</EM> Unlike Spring Framework's <code>&lt;spring:theme
/&gt;</code> JSP Tag Library, this function

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/9987acfe/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/ThemeFunctionTest.java
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/ThemeFunctionTest.java
b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/ThemeFunctionTest.java
index 637ca5f..ed00f5e 100644
--- a/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/ThemeFunctionTest.java
+++ b/freemarker-spring/src/test/java/org/apache/freemarker/spring/model/ThemeFunctionTest.java
@@ -30,6 +30,7 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.MessageSource;
 import org.springframework.http.MediaType;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -62,11 +63,15 @@ public class ThemeFunctionTest {
 
     @Test
     public void testThemeFunctionBasicUsages() throws Exception {
+        final MessageSource defaultThemeMessageSource = themeSource.getTheme("default").getMessageSource();
+
         final Integer userId = userRepository.getUserIds().iterator().next();
         mockMvc.perform(get("/users/{userId}/", userId).param("viewName", "test/model/theme-function-basic-usages")
                 .accept(MediaType.parseMediaType("text/html"))).andExpect(status().isOk())
                 .andExpect(content().contentTypeCompatibleWith("text/html")).andDo(print())
-                .andExpect(xpath("//link[@rel='stylesheet']/@href").string(
-                        themeSource.getTheme("default").getMessageSource().getMessage("styleSheet",
null, null)));
+                .andExpect(xpath("//link[@rel='stylesheet']/@href")
+                        .string(defaultThemeMessageSource.getMessage("styleSheet", null,
null)))
+                .andExpect(xpath("//div[@id='user']/@class")
+                        .string(defaultThemeMessageSource.getMessage("userClass", new Object[]
{ "selected" }, null)));
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/9987acfe/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/theme-function-basic-usages.ftl
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/theme-function-basic-usages.ftl
b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/theme-function-basic-usages.ftl
index bc50875..efb503a 100644
--- a/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/theme-function-basic-usages.ftl
+++ b/freemarker-spring/src/test/resources/META-INF/web-resources/views/test/model/theme-function-basic-usages.ftl
@@ -22,5 +22,10 @@
 <link rel="stylesheet" href="${spring.theme('styleSheet')}" type="text/css" />
 </head>
 <body>
+
+  <div id="user" class="${spring.theme('userClass', 'selected')}">
+    ${user.firstName!} ${user.lastName!}
+  </div>
+
 </body>
 </html>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/9987acfe/freemarker-spring/src/test/resources/org/apache/freemarker/spring/example/mvc/users/UsersTheme-default.properties
----------------------------------------------------------------------
diff --git a/freemarker-spring/src/test/resources/org/apache/freemarker/spring/example/mvc/users/UsersTheme-default.properties
b/freemarker-spring/src/test/resources/org/apache/freemarker/spring/example/mvc/users/UsersTheme-default.properties
index 1d7bcc2..b89d3a0 100644
--- a/freemarker-spring/src/test/resources/org/apache/freemarker/spring/example/mvc/users/UsersTheme-default.properties
+++ b/freemarker-spring/src/test/resources/org/apache/freemarker/spring/example/mvc/users/UsersTheme-default.properties
@@ -1 +1,2 @@
 styleSheet=/themes/style/default.css
+userClass=user-{0}


Mime
View raw message