added additional tests
This commit is contained in:
@ -0,0 +1,62 @@
|
|||||||
|
package de.muehlencord.shared.pdf.test;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.pdf.ConfigurationException;
|
||||||
|
import de.muehlencord.shared.pdf.PDFDocument;
|
||||||
|
import de.muehlencord.shared.pdf.PDFFont;
|
||||||
|
import de.muehlencord.shared.pdf.PDFPaperSize;
|
||||||
|
import de.muehlencord.shared.pdf.PDFTableContent;
|
||||||
|
import de.muehlencord.shared.pdf.PDFTemplate;
|
||||||
|
import de.muehlencord.shared.pdf.TemplateException;
|
||||||
|
import freemarker.template.Configuration;
|
||||||
|
import freemarker.template.Template;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author joern.muehlencord
|
||||||
|
*/
|
||||||
|
public class GsonSerialisation {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerialisation() throws ConfigurationException, TemplateException, IOException {
|
||||||
|
|
||||||
|
PDFDocument doc = new PDFDocument(PDFPaperSize.A4);
|
||||||
|
doc.addFont("helv12", new PDFFont("Helvetica", 12, 2));
|
||||||
|
|
||||||
|
PDFTableContent userList = new PDFTableContent(doc, doc.getFontByAlias("helv12"),40F, 692F);
|
||||||
|
userList.addColumn(50, 300);
|
||||||
|
userList.addListRow("users", "user")
|
||||||
|
.setCellValue("${user.firstName}")
|
||||||
|
.setCellValue("${user.lastName}");
|
||||||
|
doc.addContent(userList);
|
||||||
|
|
||||||
|
// System.out.println ("*******");
|
||||||
|
// System.out.println (doc.toJson());
|
||||||
|
String jsonString = doc.getTemplateString();
|
||||||
|
File file = new File("c:/temp/users.ftlh");
|
||||||
|
FileUtils.writeStringToFile(file, jsonString, "UTF-8");
|
||||||
|
|
||||||
|
System.out.println ("*******");
|
||||||
|
System.out.println (jsonString);
|
||||||
|
System.out.println ("*******");
|
||||||
|
|
||||||
|
Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
|
||||||
|
cfg.setDirectoryForTemplateLoading(new File("c:/temp"));
|
||||||
|
cfg.setDefaultEncoding("UTF-8");
|
||||||
|
Template template = cfg.getTemplate("users.ftlh");
|
||||||
|
PDFTemplate pdfDoc = new PDFTemplate(template);
|
||||||
|
List<User> users = new LinkedList<>();
|
||||||
|
users.add (new User ("John", "Doe"));
|
||||||
|
users.add (new User ("Jane", "Roe"));
|
||||||
|
pdfDoc.addToDatamodel("users", users);
|
||||||
|
pdfDoc.create("c:/temp/users.pdf");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
32
pdf/src/test/java/de/muehlencord/shared/pdf/test/User.java
Normal file
32
pdf/src/test/java/de/muehlencord/shared/pdf/test/User.java
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package de.muehlencord.shared.pdf.test;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author joern.muehlencord
|
||||||
|
*/
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private final String firstName;
|
||||||
|
|
||||||
|
@Expose
|
||||||
|
private final String lastName;
|
||||||
|
|
||||||
|
public User(String firstName, String lastName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user