#!/bin/bash

# -----------------------------------------------------------------------------------
# autopkgtest smoke: Tests the default webapp server responds and tomcat-native loads
# -----------------------------------------------------------------------------------

set -e

# Ensure that the service has started
systemctl restart tomcat10

# Wait a little for the service to be ready
sleep 2

# Check that the default webapp responds
if ! curl -fsS http://localhost:8080 | grep -q "It works !"; then
    echo "Smoke test failed: Webpage did not respond as expected"; exit 1
fi

# Check to see if the tomcat-native library loaded successfully
if ! journalctl -u tomcat10 | grep -q "Loaded Apache Tomcat Native library"; then
    echo "Smoke test failed: Could not load tomcat-native library"; exit 1
fi

# Tests successfully completed!
echo "Smoke tests passed: Webpage accessible with tomcat-native"
