#!/bin/sh
# Compile and run a small program against the installed library: the jar
# loads, reports its version, and the configuration and DNS placeholder
# APIs work.  No network access.
set -e
dir="${AUTOPKGTEST_TMP:-$(mktemp -d)}"
cat > "$dir/Smoke.java" <<'JAVA'
import com.subgraph.orchid.ApplicationProperties;
import com.subgraph.orchid.config.TorConfigImpl;
import com.subgraph.orchid.sockets.OrchidSocketFactory;

public class Smoke {
    public static void main(String[] args) {
        String version = ApplicationProperties.getVersion();
        System.out.println("Orchid " + version);
        if (version == null || version.equals("0.0.0")) {
            throw new AssertionError("no version");
        }
        if (!new TorConfigImpl().getSafeLogging()) {
            throw new AssertionError("SafeLogging must be on by default");
        }
        if (!OrchidSocketFactory.unresolvedAddress("example.org").toString().startsWith("example.org/")) {
            throw new AssertionError("placeholder lost its host name");
        }
    }
}
JAVA
javac -cp /usr/share/java/orchid.jar -d "$dir" "$dir/Smoke.java"
java -cp "$dir:/usr/share/java/orchid.jar" Smoke
# The POM in the Maven repository has the same version as the jar.
version=$(java -cp "$dir:/usr/share/java/orchid.jar" Smoke | sed -n 's/^Orchid //p')
test -f "/usr/share/maven-repo/org/mhatta/orchid/$version/orchid-$version.pom"
grep -q "<version>$version</version>" "/usr/share/maven-repo/org/mhatta/orchid/$version/orchid-$version.pom"
