Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLING-7751 Adding unit test to validate char encoding is being supported
on implementation.
- Loading branch information
JE Bailey
committed
Jun 25, 2018
1 parent
9d8ec40
commit 32e8140
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/test/java/org/apache/sling/commons/html/TagsoupHtmlParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |