Sha256: 16a1dff9fb318ecb0a4dfc8745d016b4758cf04cef774baeafbfaca3a313ff5a

Contents?: true

Size: 1.92 KB

Versions: 28

Compression:

Stored size: 1.92 KB

Contents

package org.embulk.plugin.jar;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.embulk.EmbulkTestRuntime;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class TestJarPluginLoader
{
    @Rule
    public TemporaryFolder temporaryFolder = new TemporaryFolder();

    @Rule
    public EmbulkTestRuntime testRuntime = new EmbulkTestRuntime();

    @Test
    public void test() throws Exception
    {
        final Path jarPath = createTemporaryJarFile();

        final JarBuilder jarBuilder = new JarBuilder();
        jarBuilder.addManifestV0(ExampleJarSpiV0.class.getName());
        jarBuilder.addClass(ExampleJarSpiV0.class);
        jarBuilder.build(jarPath);

        final Class<?> loadedClass;
        try (final JarPluginLoader loader = JarPluginLoader.load(jarPath, testRuntime.getPluginClassLoaderFactory())) {
            assertEquals(0, loader.getPluginSpiVersion());
            loadedClass = loader.getPluginMainClass();
        }

        final Object instanceObject = loadedClass.newInstance();
        assertTrue(instanceObject instanceof ExampleJarSpiV0);

        final ExampleJarSpiV0 instance = (ExampleJarSpiV0) instanceObject;
        assertEquals("foobar", instance.getTestString());
    }

    private Path createTemporaryJarFile() throws Exception
    {
        final String temporaryDirectoryString =
            System.getProperty("org.embulk.plugin.jar.TestJarPluginLoader.temporaryDirectory");

        final Path temporaryDirectoryPath;
        if (temporaryDirectoryString == null) {
            temporaryDirectoryPath = temporaryFolder.getRoot().toPath();
        }
        else {
            temporaryDirectoryPath = Paths.get(temporaryDirectoryString);
        }

        return Files.createTempFile(temporaryDirectoryPath, "testplugin", ".jar");
    }
}

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
embulk-0.8.29 embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java
embulk-0.8.29-java embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java
embulk-0.8.28 embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java
embulk-0.8.28-java embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java
embulk-0.8.27 embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java
embulk-0.8.27-java embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java
embulk-0.8.26 embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java
embulk-0.8.26-java embulk-core/src/test/java/org/embulk/plugin/jar/TestJarPluginLoader.java