diff --git a/pom.xml b/pom.xml index 8b1382c..9a9bea6 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ UTF-8 UTF-8 4.12.0 - 2.9.0 + 2.13.1 @@ -59,7 +59,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.0 + 3.4.0 attach-sources @@ -72,7 +72,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.3.1 + 3.12.0 attach-javadocs @@ -85,7 +85,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.2.8 sign-artifacts @@ -113,7 +113,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0 + 3.5.5 true @@ -153,13 +153,13 @@ com.squareup.okio okio - 3.7.0 + 3.12.0 compile com.google.code.gson gson - 2.9.0 + ${gson.version} compile @@ -189,7 +189,7 @@ commons-codec commons-codec - 1.15 + 1.21.0 test @@ -198,7 +198,7 @@ org.apache.maven.plugins maven-dependency-plugin - 2.5.1 + 3.10.0 copy-agent @@ -223,7 +223,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0 + 3.5.5 -javaagent:"${project.build.directory}/agents/jmockit-1.49.jar" @@ -231,7 +231,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.15.0 1.8 1.8 @@ -243,7 +243,7 @@ org.apache.maven.plugins maven-jar-plugin - 3.2.2 + 3.5.0 @@ -256,7 +256,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.7.0 true ossrh @@ -267,11 +267,24 @@ org.apache.felix maven-bundle-plugin - 3.5.1 + 5.1.9 true - !com.tinify.*,!org.bouncycastle.jsse.*,!com.experian.b2b.global.mvdam-project.*,!android.*,!javax.annotation.meta.*,!org.conscrypt.*;resolution:=optional,* + + !com.tinify.*, + !org.bouncycastle.jsse.*, + !com.experian.b2b.global.mvdam-project.*, + !android.*, + !dalvik.*, + !javax.annotation.meta.*, + !javax.lang.model.*, + !kotlin.reflect.jvm.internal.*, + !org.conscrypt.*, + !org.openjsse.*, + sun.misc;resolution:=optional, + sun.security.ssl;resolution:=optional, + * *;scope=compile|runtime @@ -283,7 +296,26 @@ org.apache.maven.plugins maven-dependency-plugin - 3.6.1 + 3.10.0 + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.5.5 + + + ${project.build.directory} + ${project.build.finalName} + + + + + + integration-test + verify + + + diff --git a/src/test/java/com/tinify/BundleManifestIT.java b/src/test/java/com/tinify/BundleManifestIT.java new file mode 100644 index 0000000..9c98be9 --- /dev/null +++ b/src/test/java/com/tinify/BundleManifestIT.java @@ -0,0 +1,77 @@ +package com.tinify; + +import org.junit.Test; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.jar.Attributes; + +import static org.junit.Assert.*; + +public class BundleManifestIT { + + private static final List FORBIDDEN_IMPORTS = Arrays.asList( + "org.openjsse.", + "dalvik.", + "android.", + "kotlin.reflect.jvm.internal" + ); + + private Manifest loadBundleManifest() throws IOException { + String buildDir = System.getProperty("project.build.directory", "target"); + String finalName = System.getProperty("project.build.finalName", "tinify-1.8.8"); + File jar = new File(buildDir, finalName + ".jar"); + assertTrue("Bundle JAR not found: " + jar.getAbsolutePath(), jar.exists()); + try (JarFile jarFile = new JarFile(jar)) { + return jarFile.getManifest(); + } + } + + @Test + public void bundleHasRequiredOsgiHeaders() throws IOException { + Attributes attrs = loadBundleManifest().getMainAttributes(); + + assertEquals("2", attrs.getValue("Bundle-ManifestVersion")); + assertNotNull("Missing Bundle-SymbolicName", attrs.getValue("Bundle-SymbolicName")); + assertNotNull("Missing Bundle-Version", attrs.getValue("Bundle-Version")); + assertNotNull("Missing Export-Package", attrs.getValue("Export-Package")); + } + + @Test + public void importPackageDoesNotContainUnresolvablePackages() throws IOException { + Attributes attrs = loadBundleManifest().getMainAttributes(); + String importPackage = attrs.getValue("Import-Package"); + assertNotNull("Missing Import-Package header", importPackage); + + for (String forbidden : FORBIDDEN_IMPORTS) { + assertFalse( + "Import-Package must not contain " + forbidden + " but was: " + importPackage, + importPackage.contains(forbidden) + ); + } + } + + @Test + public void exportPackageContainsTinify() throws IOException { + Attributes attrs = loadBundleManifest().getMainAttributes(); + String exportPackage = attrs.getValue("Export-Package"); + assertTrue( + "Export-Package must contain com.tinify", + exportPackage.contains("com.tinify") + ); + } + + @Test + public void bundleEmbedsDependencies() throws IOException { + Attributes attrs = loadBundleManifest().getMainAttributes(); + String bundleClassPath = attrs.getValue("Bundle-ClassPath"); + assertNotNull("Missing Bundle-ClassPath", bundleClassPath); + assertTrue("Bundle-ClassPath must contain okhttp", bundleClassPath.contains("okhttp")); + assertTrue("Bundle-ClassPath must contain gson", bundleClassPath.contains("gson")); + assertTrue("Bundle-ClassPath must contain okio", bundleClassPath.contains("okio")); + } +} diff --git a/src/test/java/com/tinify/ClientTest.java b/src/test/java/com/tinify/ClientTest.java index 77666d2..5385ba5 100644 --- a/src/test/java/com/tinify/ClientTest.java +++ b/src/test/java/com/tinify/ClientTest.java @@ -25,6 +25,7 @@ import java.util.logging.Logger; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; public class ClientTest { @@ -424,7 +425,8 @@ public void requestWithBadServerResponseRepeatedlyShouldThrowExceptionWithMessag new Client(key).request(Client.Method.POST, "/shrink"); fail("Expected an Exception to be thrown"); } catch (Exception e) { - assertEquals("Error while parsing response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ (HTTP 543/ParseError)", e.getMessage()); + assertTrue(e.getMessage().startsWith("Error while parsing response: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $")); + assertTrue(e.getMessage().endsWith("(HTTP 543/ParseError)")); } }