This is an automated email from the ASF dual-hosted git repository.

jeb pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-html.git


The following commit(s) were added to refs/heads/master by this push:
     new 32e8140  SLING-7751 Adding unit test to validate char encoding is 
being supported on implementation.
32e8140 is described below

commit 32e81401e3b57764896f6a12700b8b2e37ae5098
Author: JE Bailey <[email protected]>
AuthorDate: Mon Jun 25 10:58:46 2018 -0400

    SLING-7751 Adding unit test to validate char encoding is being supported
    on implementation.
---
 .../sling/commons/html/TagsoupHtmlParserTest.java  | 74 ++++++++++++++++++++++
 src/test/resources/note.xml                        | 23 +++++++
 2 files changed, 97 insertions(+)

diff --git 
a/src/test/java/org/apache/sling/commons/html/TagsoupHtmlParserTest.java 
b/src/test/java/org/apache/sling/commons/html/TagsoupHtmlParserTest.java
new file mode 100644
index 0000000..e64affe
--- /dev/null
+++ b/src/test/java/org/apache/sling/commons/html/TagsoupHtmlParserTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.sling.commons.html;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+
+import org.apache.sling.commons.html.internal.TagsoupHtmlParser;
+import org.junit.Before;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class TagsoupHtmlParserTest {
+    
+    TagsoupHtmlParser htmlParser;
+    InputStream stream;
+    
+    /*
+     * Japanese (google) translation of 'Don't forget me this weekend!' 
+     * standard text of xml sample note.xml
+     */
+    private static final String MESSAGE ="この週末私を忘れないで!";
+    
+    @Before
+    public void setup() {
+        stream = getClass().getResourceAsStream("/note.xml");
+        htmlParser = new TagsoupHtmlParser();
+    }
+
+    @Test
+    public void testEncodingSupport() throws SAXException {
+        htmlParser.parse(stream, "UTF-8", new DefaultHandler() {
+            @Override
+            public void characters(char[] ch, int start, int length) throws 
SAXException {
+                String message = new String(ch, start, length).trim();
+                if (!message.isEmpty()) {
+                    assertTrue(message.equals(MESSAGE));
+                }
+            }
+        });
+    }
+    
+    @Test
+    public void testEncodingSupportFailure() throws SAXException {
+        htmlParser.parse(stream, "ISO8859-1", new DefaultHandler() {
+            @Override
+            public void characters(char[] ch, int start, int length) throws 
SAXException {
+                String message = new String(ch, start, length).trim();
+                if (!message.isEmpty()) {
+                    assertTrue(!message.equals(MESSAGE));
+                }
+            }
+        });
+    }
+
+}
diff --git a/src/test/resources/note.xml b/src/test/resources/note.xml
new file mode 100644
index 0000000..0e5ecb0
--- /dev/null
+++ b/src/test/resources/note.xml
@@ -0,0 +1,23 @@
+<?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.
+-->
+<note>
+  <!-- Japanese translation of 'Don't forget me this weekend!' -->
+  <body>この週末私を忘れないで!</body>
+</note>
\ No newline at end of file

Reply via email to