Author: awiner
Date: Wed Mar 11 01:04:21 2009
New Revision: 752334

URL: http://svn.apache.org/viewvc?rev=752334&view=rev
Log:
Add end-to-end tests covering template rewriting

Added:
    
incubator/shindig/trunk/java/server/src/test/resources/endtoend/templateRewriter.xml
   (with props)
Modified:
    
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java

Modified: 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java?rev=752334&r1=752333&r2=752334&view=diff
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
 (original)
+++ 
incubator/shindig/trunk/java/server/src/test/java/org/apache/shindig/server/endtoend/EndToEndTest.java
 Wed Mar 11 01:04:21 2009
@@ -28,6 +28,7 @@
 import com.gargoylesoftware.htmlunit.WebClient;
 import com.gargoylesoftware.htmlunit.html.DomNode;
 import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.json.JSONArray;
 import org.json.JSONObject;
@@ -35,17 +36,21 @@
 import org.junit.AfterClass;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.net.URLEncoder;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -99,7 +104,7 @@
 
   @Test
   public void messageBundlesRtl() throws Exception {
-    // Repeeat the messageBundle tests, but with the language set to "ar"
+    // Repeat the messageBundle tests, but with the language set to "ar"
     language = "ar";
 
     executeAllPageTests("messageBundle");
@@ -169,6 +174,50 @@
     assertEquals(expected.toString(), json.toString());
   }
 
+  @Test
+  public void testTemplateRewrite() throws Exception {
+    HtmlPage page = executePageTest("templateRewriter", null);
+    
+    // Verify that iteration attributes were processed
+    Element attrs = page.getElementById("attrs");
+    List<Element> attrsList = getChildrenByTagName(attrs, "li");
+    assertEquals(3, attrsList.size());
+    
+    Element element = page.getElementById("id0");
+    assertNotNull(element);
+    assertEquals("Jane", element.getTextContent().trim());
+
+    element = page.getElementById("id2");
+    assertNotNull(element);
+    assertEquals("Maija", element.getTextContent().trim());
+    
+    // Verify that the repeatTag was processed
+    Element repeat = page.getElementById("repeatTag");
+    List<Element> repeatList = getChildrenByTagName(repeat, "li");
+    assertEquals(1, repeatList.size());
+    assertEquals("George", repeatList.get(0).getTextContent().trim());
+    
+    // Verify that the ifTag was processed
+    Element ifTag = page.getElementById("ifTag");
+    List<Element> ifList = getChildrenByTagName(ifTag, "li");
+    assertEquals(3, ifList.size());
+    assertEquals(1, page.getElementsByTagName("b").getLength());
+    assertEquals(1, getChildrenByTagName(ifList.get(2), "b").size());
+  }
+
+  // HtmlUnits implementation of Element.getElementsByTagName() is just
+  // executing Document.getElementsByTagName()
+  private List<Element> getChildrenByTagName(Element parent, String name) {
+    List<Element> elements = Lists.newArrayList();
+    for (Node child = parent.getFirstChild(); child != null; child = 
child.getNextSibling()) {
+      if (child instanceof Element && name.equals(child.getNodeName())) {
+        elements.add((Element) child);
+      }
+    }
+    
+    return elements;
+  }
+
   @BeforeClass
   public static void setUpOnce() throws Exception {
     server = new EndToEndServer();

Added: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/templateRewriter.xml
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/server/src/test/resources/endtoend/templateRewriter.xml?rev=752334&view=auto
==============================================================================
--- 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/templateRewriter.xml
 (added)
+++ 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/templateRewriter.xml
 Wed Mar 11 01:04:21 2009
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<Module>
+  <ModulePrefs title="EndToEndTest">
+    <Require feature="opensocial-data" />
+    <Require feature="opensocial-templates">
+      <Param name="process-on-server">true</Param>     
+    </Require>
+  </ModulePrefs>
+  <Content type="html">
+    <![CDATA[
+      <script xmlns:os="http://ns.opensocial.org/2008/markup"; 
type="text/os-data">
+           <os:PeopleRequest key="friends" userId="@viewer" 
groupId="@friends"/>
+         </script>
+
+      <script type="text/os-template" 
xmlns:os="http://ns.opensocial.org/2008/markup";>
+        <ul id="attrs">
+          <li repeat="${friends}">
+            <span id="id${Context.Index}">${name.givenName}</span>
+          </li>
+        </ul>
+
+        <ul id="repeatTag">
+          <os:Repeat expression="${friends}" if="${Context.Index == 1}">
+            <li>${name.givenName}</li>
+          </os:Repeat>
+        </ul>
+
+        <ul id="ifTag">
+          <li repeat="${friends}">
+            <os:If condition="${Context.Index == 2}">
+              <b>${Cur.name.givenName}</b>
+            </os:If>
+          </li>
+        </ul>
+         </script>
+    ]]>
+  </Content>
+</Module>

Propchange: 
incubator/shindig/trunk/java/server/src/test/resources/endtoend/templateRewriter.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to