All Downloads are FREE. Search and download functionalities are using the official Maven repository.

test.java.pro.verron.officestamper.test.BasicPowerpointTest Maven / Gradle / Ivy

Go to download

Office-stamper is a Java template engine for docx documents, forked from org.wickedsource.docx-stamper

There is a newer version: 2.6.0
Show newest version
package pro.verron.officestamper.test;

import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.PresentationMLPackage;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;

import static pro.verron.officestamper.preset.ExperimentalStampers.pptxStamper;
import static pro.verron.officestamper.test.IOStreams.getInputStream;
import static pro.verron.officestamper.test.IOStreams.getOutputStream;

class BasicPowerpointTest {
    @Test
    void testStamper()
            throws IOException, Docx4JException {
        var stamper = pptxStamper();
        var templateStream = TestUtils.getResource(Path.of("powerpoint-base.pptx"));

        record Person(String name) {}
        var context = new Person("Bart");
        PresentationMLPackage load = PresentationMLPackage.load(templateStream);
        OutputStream outputStream = getOutputStream();
        stamper.stamp(load, context, outputStream);
        InputStream inputStream = getInputStream(outputStream);
        PresentationMLPackage presentationMLPackage = PresentationMLPackage.load(inputStream);
        Assertions.assertEquals("""
                        Hello
                        Bart
                        """,
                Stringifier.stringifyPowerpoint(presentationMLPackage));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy