#!/bin/bash

source /var/onap_tests/_test_base
source /var/onap/vid

covered_functions=(
"clone_all_vid_repos" "compile_all_vid_repos" "get_vid_images" "install_vid"
)

# test_clone_all_vid_repos() - Verifies that VID repositories are retrieved properly
function test_clone_all_vid_repos {
    clone_all_vid_repos

    asserts_file_exist $vid_src_folder/pom.xml
    asserts_file_exist $vid_src_folder/asdcclient/pom.xml
}

# test_compile_all_vid_repos() - Verifies that VID source code is compiled properly
function test_compile_all_vid_repos {
    clone_all_vid_repos
    compile_all_vid_repos

    asserts_file_exist $vid_src_folder/asdcclient/target/asdcclient-1.0.2-SNAPSHOT.jar
    asserts_file_exist $vid_src_folder/epsdk-app-onap/target/vid.war
    asserts_file_exist $vid_src_folder/vid-app-common/target/vid-common.war
}

# test_get_vid_images() - Verifies that VID Docker images are built properly
function test_get_vid_images {
    clone_all_vid_repos
    get_vid_images

    asserts_image openecomp/vid
    asserts_image mariadb:10
}

# test_install_vid() - Verifies taht VID services are up and running
function test_install_vid {
    clone_all_vid_repos
    get_vid_images
    install_vid

    vid_image=`docker images | grep vid | grep latest| awk '{print $1 ":" $2}'`
    asserts_image_running $vid_image
}

if [ "$1" != '*' ]; then
    unset covered_functions
    covered_functions=$1
fi
main "${covered_functions[@]}"