You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/10/07 19:19:09 UTC

svn commit: r1180111 - in /myfaces/core/branches/2.0.x/impl/src/test: java/org/apache/myfaces/context/PartialResponseWriterImplTest.java resources/org/apache/myfaces/context/ resources/org/apache/myfaces/context/nestedScriptCDATA.xml

Author: lu4242
Date: Fri Oct  7 17:19:09 2011
New Revision: 1180111

URL: http://svn.apache.org/viewvc?rev=1180111&view=rev
Log:
MYFACES-3339 Ajax embedded CDATA Sequence lost on the server once an ajax refresh is triggered

Added:
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/context/   (with props)
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/context/nestedScriptCDATA.xml
Modified:
    myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/context/PartialResponseWriterImplTest.java

Modified: myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/context/PartialResponseWriterImplTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/context/PartialResponseWriterImplTest.java?rev=1180111&r1=1180110&r2=1180111&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/context/PartialResponseWriterImplTest.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/context/PartialResponseWriterImplTest.java Fri Oct  7 17:19:09 2011
@@ -19,15 +19,28 @@
 
 package org.apache.myfaces.context;
 
-import org.apache.myfaces.shared.renderkit.html.HtmlResponseWriterImpl;
-import org.apache.myfaces.test.base.AbstractJsfTestCase;
-
-import javax.faces.context.PartialResponseWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.StringReader;
 import java.io.StringWriter;
-import java.util.logging.Level;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.logging.Logger;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.myfaces.shared.renderkit.html.HtmlResponseWriterImpl;
+import org.apache.myfaces.test.base.AbstractJsfTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
 /**
  * Test cases for our impl, which tests for the CDATA nesting
  *
@@ -39,6 +52,8 @@ public class PartialResponseWriterImplTe
 
     static Logger _log = Logger.getLogger(PartialResponseWriterImplTest.class.getName());
 
+    private final String filePath = this.getDirectory();
+    
     PartialResponseWriterImpl _writer;
     StringWriter _contentCollector;
     private static final String STD_UPDATE_RESULT = "<changes><update id=\"blaId\"><![CDATA[testing]]></update>";
@@ -52,7 +67,86 @@ public class PartialResponseWriterImplTe
         super.setUp();
         _contentCollector = new StringWriter(100);
     }
+    
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        _contentCollector = null;
+    }
+
+    private void checkOutput(File expected, String output) throws Exception
+    {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(false);
+        dbf.setCoalescing(true);
+        dbf.setIgnoringElementContentWhitespace(true);
+        dbf.setIgnoringComments(true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        Document doc1 = db.parse(expected.toURI().toString());
+        doc1.normalizeDocument();
+        InputSource is2 = new InputSource();
+        is2.setCharacterStream(new StringReader(output));
+        Document doc2 = db.parse(is2);
+        doc2.normalizeDocument();
+        assertTrue(doc1.isEqualNode(doc2));
+    }
+
+    /**
+     * Get the node path
+     */
+    public String getPath( Node node )
+    {
+        StringBuilder path = new StringBuilder();
 
+        do
+        {           
+            path.insert(0, node.getNodeName() );
+            path.insert( 0, "/" );
+        }
+        while( ( node = node.getParentNode() ) != null );
+
+        return path.toString();
+    }
+
+
+    protected URL getLocalFile(String name) throws FileNotFoundException
+    {
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        URL url = cl.getResource(this.filePath + "/" + name);
+        if (url == null)
+        {
+            throw new FileNotFoundException(cl.getResource("").getFile() + name
+                    + " was not found");
+        }
+        return url;
+    }
+    
+    protected String getDirectory()
+    {
+        return this.getClass().getName().substring(0,
+                this.getClass().getName().lastIndexOf('.')).replace('.', '/')
+                + "/";
+    }
+    
+    public void testNestedScriptCDATA() throws Exception {
+        _writer = createTestProbe();
+        try {
+            _writer.startDocument();
+            _writer.startUpdate("blaId");
+            _writer.startElement("script", null);
+            _writer.writeAttribute("type", "text/javascript", null);
+            _writer.write("\n// <![CDATA[\n");
+            _writer.write("var a && b;");
+            _writer.write("\n// ]]>\n");
+            _writer.endElement("script");
+            _writer.endUpdate();
+            _writer.endDocument();
+            
+            checkOutput(new File(getLocalFile("nestedScriptCDATA.xml").toURI()), _contentCollector.toString());
+        } catch (IOException e) {
+            fail(e.toString());
+        }
+    }
+    
     public void testBasicWriteTest() {
         _writer = createTestProbe();
         try {

Propchange: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/context/
------------------------------------------------------------------------------
    bugtraq:number = true

Added: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/context/nestedScriptCDATA.xml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/context/nestedScriptCDATA.xml?rev=1180111&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/context/nestedScriptCDATA.xml (added)
+++ myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/context/nestedScriptCDATA.xml Fri Oct  7 17:19:09 2011
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?><partial-response><changes><update id="blaId"><![CDATA[<script type="text/javascript">
+// <![CDATA[
+var a && b;
+// ]]><![CDATA[]]]]><![CDATA[>
+</script>]]></update></changes></partial-response>
\ No newline at end of file