Browse Source

Add java hello world test for openjdk

Joe Ferguson 8 years ago
parent
commit
630fde105d

+ 4 - 3
test/config.sh

@@ -98,8 +98,6 @@ imageTests+=(
 		hylang-sh
 		hylang-hello-world
 	'
-	[java]='
-	'
 	[jetty]='
 		jetty-hello-web
 	'
@@ -129,6 +127,9 @@ imageTests+=(
 		nuxeo-conf
 		nuxeo-basics
 	'
+	[openjdk]='
+		java-hello-world
+	'
 	[percona]='
 	'
 	[perl]='
@@ -194,7 +195,7 @@ imageTests+=(
 	'
 	[swift]='
 		swift-hello-world
-  '
+	'
 	[tomcat]='
 		tomcat-hello-world
 	'

+ 9 - 0
test/tests/java-hello-world/container.java

@@ -0,0 +1,9 @@
+public class container {
+	/**
+	 * Simple "hello world" to test the java can compile and/or run
+	 */
+	public static void main(String[] args) {
+		System.out.println("Hello World!");
+		System.exit(0);
+	}
+}

+ 1 - 0
test/tests/java-hello-world/expected-std-out.txt

@@ -0,0 +1 @@
+Hello World!

+ 1 - 0
test/tests/java-hello-world/run.sh

@@ -0,0 +1 @@
+../run-java-in-container.sh

+ 23 - 2
test/tests/run-in-container.sh

@@ -1,9 +1,30 @@
 #!/bin/bash
-set -e
+set -eo pipefail
 
 # NOT INTENDED TO BE USED AS A TEST "run.sh" DIRECTLY
 # SEE OTHER "run-*-in-container.sh" SCRIPTS FOR USAGE
 
+# arguments to docker
+args=()
+opts="$(getopt -o '+' --long 'docker-arg:' -- "$@")"
+eval set -- "$opts"
+
+while true; do
+	flag="$1"
+	shift
+	case "$flag" in
+		--docker-arg) args+=( "$1" ) && shift ;;
+		--) break ;;
+		*)
+			{
+				echo "error: unknown flag: $flag"
+				#usage
+			} >&2
+			exit 1
+			;;
+	esac
+done
+
 testDir="$1"
 shift
 
@@ -29,7 +50,7 @@ WORKDIR $workdir
 ENTRYPOINT ["$entrypoint"]
 EOD
 
-args=( --rm )
+args+=( --rm )
 
 # there is strong potential for nokogiri+overlayfs failure
 # see https://github.com/docker-library/ruby/issues/55

+ 28 - 0
test/tests/run-java-in-container.sh

@@ -0,0 +1,28 @@
+#!/bin/bash
+set -e
+
+testDir="$(readlink -f "$(dirname "$BASH_SOURCE")")"
+runDir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
+
+image="$1"
+# TODO make this work for ibmjava too (jre or sfj -> sdk)
+jdk="${image/jre/jdk}"
+
+volume="$(docker volume create)"
+trap "docker volume rm '$volume' >/dev/null 2>&1" EXIT
+
+# jdk image to build java class
+"$runDir/run-in-container.sh" \
+	--docker-arg "--volume=$volume:/container/" \
+	-- \
+	"$testDir" \
+	"$jdk" \
+	sh -c 'javac -d /container/ ./container.java'
+
+# jre image to run class
+"$runDir/run-in-container.sh" \
+	--docker-arg "--volume=$volume:/container/" \
+	-- \
+	"$testDir" \
+	"$image" \
+	sh -c 'exec java -cp /container/ container'