import os
import re
import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_oracle_java8_is_installed(host):
    oracle_java8 = host.package("oracle-java8-installer")
    assert oracle_java8.is_installed
    assert oracle_java8.version.startswith("8u")


def test_jenkins_is_installed(host):
    cmd = host.run("java -jar /usr/share/jenkins/jenkins.war --version")
    assert cmd.rc == 0
    pattern = re.compile("^[\\d.]+$")
    assert pattern.match(cmd.stdout)


def test_apache2_is_installed(host):
    apache2 = host.package("apache2")
    assert apache2.is_installed
    assert apache2.version.startswith("2.")


def test_jenkins_log_file_download(host):
    cmd = host.run("wget http://localhost/logs/jenkins/jenkins.log")
    assert cmd.rc == 0
    jenkins_log_file = host.file("jenkins.log")
    assert jenkins_log_file.exists
    assert jenkins_log_file.contains("INFO: Jenkins is fully up and running")

@@ -187,23 +187,16 @@
 ef test_
-oracle_
 java8_is
@@ -217,23 +217,16 @@
 t):%0A    
-oracle_
 java8 = 
@@ -244,29 +244,20 @@
 e(%22o
-racle-java8-installer
+penjdk-8-jdk
 %22)%0A 
@@ -262,31 +262,24 @@
 %0A    assert 
-oracle_
 java8.is_ins
@@ -300,15 +300,8 @@
 ert 
-oracle_
 java

replace oracle jdk with openjdk