-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update the scenario test and the junit smoke test, also include the r…
…esources for the test.
- Loading branch information
Showing
7 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
openpdf/src/test/java/com/lowagie/text/html/SAXmyHtmlHandlerTest.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,50 @@ | ||
package com.lowagie.text.html; | ||
import java.io.InputStream; | ||
|
||
import com.lowagie.text.Document; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
/** | ||
* This test class contains a series of smoke tests. The goal of these tests is not validate the generated document, | ||
* but to ensure no exception is thrown. | ||
*/ | ||
public class SAXmyHtmlHandlerTest { | ||
|
||
/** | ||
* Test scenario: a html file with a title will not generate. | ||
*/ | ||
@Test | ||
void testTitle_generate() { | ||
InputStream is = SAXmyHtmlHandlerTest.class.getClassLoader().getResourceAsStream("parseTitle.html"); | ||
parseHtml(is); | ||
} | ||
|
||
|
||
/** | ||
* Test scenario: a html file with a table will generate like html webpage. | ||
*/ | ||
@Test | ||
void testTable_generate() { | ||
InputStream is = SAXmyHtmlHandlerTest.class.getClassLoader().getResourceAsStream("parseTable.html"); | ||
parseHtml(is); | ||
} | ||
|
||
/** | ||
* Parse the input HTML file to PDF file. | ||
* @param is The input stream of the HTML file. | ||
*/ | ||
void parseHtml(InputStream is) { | ||
try { | ||
Document doc1 = new Document(); | ||
doc1.open(); | ||
HtmlParser.parse(doc1,is); | ||
assertNotNull(doc1, () -> is + " was not parsed successfully"); | ||
} catch (Exception e) { | ||
fail(() -> is + " resulted in " + e); | ||
} | ||
} | ||
} |
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,44 @@ | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<br/> | ||
<table> | ||
<tr> <!--test--> | ||
<td rowspan="4">line 1</td> | ||
<td rowspan="4">line 2</td> | ||
<td>line 3</td> | ||
<td>line 4</td> | ||
<td>line 5</td> | ||
<td>line 6</td> | ||
<td>line 7</td> | ||
<td>line 8</td> | ||
</tr> | ||
<tr> | ||
<td>line 3</td> | ||
<td>line 4</td> | ||
<td>line 5</td> | ||
<td>line 6</td> | ||
<td>line 7</td> | ||
<td>line 8</td> | ||
</tr> | ||
<tr> | ||
<td>line 3</td> | ||
<td>line 4</td> | ||
<td>line 5</td> | ||
<td>line 6</td> | ||
<td>line 7</td> | ||
<td>line 8</td> | ||
</tr> | ||
<tr> | ||
<td>line 3</td> | ||
<td>line 4</td> | ||
<td>line 5</td> | ||
<td>line 6</td> | ||
<td>line 7</td> | ||
<td>line 8</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<p>This is a test</p> | ||
<p>This is a test2</p> | ||
</body> | ||
</html> |
53 changes: 53 additions & 0 deletions
53
pdf-toolbox/src/test/java/com/lowagie/examples/html/ParseTableHtml.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,53 @@ | ||
/* | ||
* $Id: HelloHtml.java 3373 2008-05-12 16:21:24Z xlv $ | ||
* | ||
* This code is part of the 'OpenPDF Tutorial'. | ||
* You can find the complete tutorial at the following address: | ||
* https://github.com/LibrePDF/OpenPDF/wiki/Tutorial | ||
* | ||
* This code is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* | ||
*/ | ||
|
||
package com.lowagie.examples.html; | ||
|
||
import com.lowagie.text.Document; | ||
import com.lowagie.text.DocumentException; | ||
import com.lowagie.text.html.HtmlParser; | ||
import com.lowagie.text.pdf.PdfWriter; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Generates a simple table HTML page. | ||
* | ||
* @author chappyer | ||
*/ | ||
|
||
public class ParseTableHtml { | ||
|
||
/** | ||
* Generates an HTML page with a table | ||
* | ||
* @param args no arguments needed here | ||
*/ | ||
public static void main(String[] args) { | ||
System.out.println("Parse ParseTable"); | ||
|
||
// step 1: creation of a document-object | ||
try (Document document = new Document()) { | ||
PdfWriter.getInstance(document, Files.newOutputStream(Paths.get("parseTable.pdf"))); | ||
// step 2: we open the document | ||
document.open(); | ||
// step 3: parsing the HTML document to convert it in PDF | ||
HtmlParser.parse(document, ParseHelloHtml.class.getClassLoader().getResourceAsStream("com/lowagie/examples/html/parseTable.html")); | ||
} catch (DocumentException | IOException de) { | ||
System.err.println(de.getMessage()); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
pdf-toolbox/src/test/java/com/lowagie/examples/html/ParseTitleHtml.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,52 @@ | ||
/* | ||
* $Id: HelloHtml.java 3373 2008-05-12 16:21:24Z xlv $ | ||
* | ||
* This code is part of the 'OpenPDF Tutorial'. | ||
* You can find the complete tutorial at the following address: | ||
* https://github.com/LibrePDF/OpenPDF/wiki/Tutorial | ||
* | ||
* This code is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* | ||
*/ | ||
|
||
package com.lowagie.examples.html; | ||
|
||
import com.lowagie.text.Document; | ||
import com.lowagie.text.DocumentException; | ||
import com.lowagie.text.html.HtmlParser; | ||
import com.lowagie.text.pdf.PdfWriter; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Generates a simple HTML page which contains a title. | ||
* | ||
* @author chappyer | ||
*/ | ||
|
||
public class ParseTitleHtml { | ||
|
||
/** | ||
* Generates an HTML page which contains a title | ||
* | ||
* @param args no arguments needed here | ||
*/ | ||
public static void main(String[] args) { | ||
|
||
// step 1: creation of a document-object | ||
try (Document document = new Document()) { | ||
PdfWriter.getInstance(document, Files.newOutputStream(Paths.get("parseTitle.pdf"))); | ||
// step 2: we open the document | ||
document.open(); | ||
// step 3: parsing the HTML document to convert it in PDF | ||
HtmlParser.parse(document, ParseHelloHtml.class.getClassLoader().getResourceAsStream("com/lowagie/examples/html/parseTitle.html")); | ||
} catch (DocumentException | IOException de) { | ||
de.printStackTrace(); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
pdf-toolbox/src/test/resources/com/lowagie/examples/html/parseTable.html
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,16 @@ | ||
<html> | ||
<head> | ||
<title>Test</title> | ||
</head> | ||
<body> | ||
<table> | ||
<tr> | ||
<td>line 3</td> | ||
<td>line 4</td> | ||
<td>line 4</td> | ||
<td>line 4</td> | ||
<td>line 4</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
pdf-toolbox/src/test/resources/com/lowagie/examples/html/parseTitle.html
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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<title>Title</title> | ||
</head> | ||
<body> | ||
<p>This is a test</p> | ||
<p>This is a test2</p> | ||
</body> | ||
</html> |