Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add initial demo/complex tests
Might fail if xpath is not installed.
mederly committed Sep 28, 2018
1 parent 27acbc6 commit 7c3c892
Showing 3 changed files with 86 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Jenkinsfile
@@ -34,7 +34,7 @@ pipeline {
steps {
script {
try {
sh '(docker image ls ; echo Destroying ; bin/destroy.sh ; docker image ls) 2>&1 | tee debug' // temporary
sh '(ls -l ; docker ps -a ; docker image ls ; echo Destroying ; bin/destroy.sh ; docker image ls) 2>&1 | tee debug' // temporary
sh './download-midpoint 2>&1 | tee -a debug'
sh 'bin/rebuild.sh 2>&1 | tee -a debug'
//sh 'echo Build output ; cat debug'
@@ -54,6 +54,8 @@ pipeline {
sh 'bin/test.sh 2>&1 | tee debug'
sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug'
sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug'
sh '(echo Checking if xpath is present ; xpath || true ) 2>&1 | tee -a debug'
sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug'
// sh 'echo Test output ; cat debug'
} catch (error) {
def error_details = readFile('./debug')
60 changes: 60 additions & 0 deletions demo/complex/tests/main.bats
@@ -0,0 +1,60 @@
#!/usr/bin/env bats

load ../../../common
load ../../../library

@test "000 Cleanup before running the tests" {
# skip
run docker-compose down -v
}

@test "010 Initialize and start the composition" {
# skip
docker-compose up -d
wait_for_midpoint_start complex_midpoint-server_1
# TODO wait for shibboleth, grouper-ui, (also something other?)
}

@test "010 Check midPoint health" {
check_health
}

@test "020 Check Grouper health" {
skip TODO
}

@test "100 Get 'administrator'" {
check_health
get_and_check_object users 00000000-0000-0000-0000-000000000002 administrator
}

@test "110 And and get 'test110'" {
check_health
echo "<user><name>test110</name></user>" >/tmp/test110.xml
add_object users /tmp/test110.xml
rm /tmp/test110.xml
search_and_check_object users test110
# TODO delete user after
}

@test "200 Upload objects" {
check_health
pwd >&2
./upload-objects
search_and_check_object objectTemplates template-org-course
search_and_check_object objectTemplates template-org-department
search_and_check_object objectTemplates template-role-affiliation
search_and_check_object objectTemplates template-role-generic-group
# TODO check other objects that were uploaded
}

@test "210 Test resource" {
test_resource 0a37121f-d515-4a23-9b6d-554c5ef61272
test_resource 6dcb84f5-bf82-4931-9072-fbdf87f96442
test_resource 13660d60-071b-4596-9aa1-5efcd1256c04
test_resource 4d70a0da-02dd-41cf-b0a1-00e75d3eaa15
}

@test "999 Clean up" {
docker-compose down -v
}
27 changes: 23 additions & 4 deletions library.bash
@@ -62,8 +62,8 @@ function get_and_check_object () {
# TODO Returns the OID in OID variable
# it can be found in the following HTTP reader returned: Location: "https://localhost:8443/midpoint/ws/rest/users/85e62669-d36b-41ce-b4f1-1ffdd9f66262"
function add_object () {
TYPE=$1
FILE=$2
local TYPE=$1
local FILE=$2
echo "Adding to $TYPE from $FILE..."
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE" -d @$FILE || return 1
#TODO check the returned XML
@@ -95,8 +95,8 @@ EOF

# Searches for object with a given name and verifies it was found
function search_and_check_object () {
TYPE=$1
NAME=$2
local TYPE=$1
local NAME=$2
search_objects_by_name $TYPE $NAME || return 1
if (grep -q "<name>$NAME</name>" <$SEARCH_RESULT_FILE); then
echo "Object $TYPE/'$NAME' is OK"
@@ -109,3 +109,22 @@ function search_and_check_object () {
return 1
fi
}

# Tests a resource
function test_resource () {
local OID=$1
local TMPFILE=$(mktemp /tmp/test.resource.XXXXXX)
local TMPFILE_ERR=$(mktemp /tmp/test.resource.err.XXXXXX)

curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/resources/$OID/test" >$TMPFILE || (rm $TMPFILE $TMPFILE_ERR ; return 1)
if [[ $(xpath -q -e "*/status/text()" < $TMPFILE) == "success" ]]; then
echo "Resource $OID test succeeded"
rm $TMPFILE
return 0
else
echo "Resource $OID test failed"
cat $TMPFILE
rm $TMPFILE
return 1
fi
}

0 comments on commit 7c3c892

Please sign in to comment.