Skip to content

Commit

Permalink
Create/Delete applications
Browse files Browse the repository at this point in the history
  • Loading branch information
svrnm committed Nov 8, 2017
1 parent 4cc6036 commit d6feacb
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 20 deletions.
14 changes: 14 additions & 0 deletions adc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,20 @@ register application_list List all applications available on the controller
describe application_list << EOF
List all applications available on the controller. This command requires no further arguments.
EOF
function application_create {
apiCall -X POST -d "{\"name\": \"\${n}\", \"description\": \"\"}" "/controller/restui/allApplications/createApplication?applicationType=\${t}" "$@"
}
register application_create Create a new application
describe application_create << EOF
Create a new application. Provide a name and a type (APM or WEB) as parameter.
EOF
function application_delete {
apiCall -X POST -d "\${a}" "/controller/restui/allApplications/deleteApplication" "$@"
}
register application_delete Delete an application
describe application_delete << EOF
Delete an application. Provide application id as parameter.
EOF
function application_export {
local APPLICATION_ID=$*
if [[ $APPLICATION_ID =~ ^[0-9]+$ ]]; then
Expand Down
11 changes: 11 additions & 0 deletions commands/application/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

function application_create {
apiCall -X POST -d "{\"name\": \"\${n}\", \"description\": \"\"}" "/controller/restui/allApplications/createApplication?applicationType=\${t}" "$@"
}

register application_create Create a new application

describe application_create << EOF
Create a new application. Provide a name and a type (APM or WEB) as parameter.
EOF
11 changes: 11 additions & 0 deletions commands/application/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

function application_delete {
apiCall -X POST -d "\${a}" "/controller/restui/allApplications/deleteApplication" "$@"
}

register application_delete Delete an application

describe application_delete << EOF
Delete an application. Provide application id as parameter.
EOF
2 changes: 2 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ source ./commands/portal/login.sh
source ./commands/portal/download.sh

source ./commands/application/list.sh
source ./commands/application/create.sh
source ./commands/application/delete.sh
source ./commands/application/export.sh

source ./commands/bt/list.sh
Expand Down
61 changes: 41 additions & 20 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ function assert_equals {
fi
}

function assert_empty {
TEST_COUNTER=$TEST_COUNTER+1
if [[ -z "$1" ]]; then
SUCCESS_COUNTER=$SUCCESS_COUNTER+1
echo -en "\033[0;32m.\033[0m"
else
echo -e "\n\033[0;31mTest failed: \033[0;33m$1\033[0;31m is not an empty string."
fi
}

function assert_contains_substring {
TEST_COUNTER=$TEST_COUNTER+1
if [[ $2 == *$1* ]]; then
Expand Down Expand Up @@ -50,36 +60,47 @@ assert_contains_substring "Login Successful" "`${ADC} controller login`"
assert_contains_substring "<available>true</available>" "`${ADC} controller status`"
assert_regex "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" "`${ADC} controller version`"

##### List different entities #####
assert_contains_substring "<applications>" "`${ADC} application list`"
assert_contains_substring "<tiers>" "`${ADC} tier list -a 5`"
assert_contains_substring "<business-transactions>" "`${ADC} bt list -a 5`"

##### Error handling #####
assert_equals "Error" "`env CONFIG_HTTP_TIMEOUT=1 ./adc.sh -H 127.0.0.2:8009 controller ping`"

##### Database Collector Create, List, Get, Delete #####
CREATE="`${ADC} dbmon create -i adc_test_collector -h localhost -n db -u user -a "Default Database Agent" -t DB2 -p 1555 -s password`"
assert_contains_substring '"name" : "adc_test_collector",' "$CREATE"
assert_contains_substring '"name" : "adc_test_collector",' "`${ADC} dbmon list`"
if [[ $CREATE =~ \"id\"\ \:\ ([0-9]+) ]] ; then
COLLECTOR_ID=${BASH_REMATCH[1]}
assert_contains_substring '"name" : "adc_test_collector",' "`${ADC} dbmon get $COLLECTOR_ID`"
assert_contains_substring '"status" : "SUCCESS",' "`${ADC} dbmon delete $COLLECTOR_ID`"
fi
##### Create a test application
APPNAME="ADC_TEST_APPLICATION_${RANDOM}"
CREATE_APPLICATION="`${ADC} application create -t APM -n "$APPNAME"`"
assert_contains_substring "\"name\" : \"${APPNAME}\"," "$CREATE_APPLICATION"
if [[ $CREATE_APPLICATION =~ \"id\"\ \:\ ([0-9]+) ]] ; then
APPLICATION_ID=${BASH_REMATCH[1]}


##### List different entities #####
assert_contains_substring "<applications>" "`${ADC} application list`"
assert_contains_substring "<tiers>" "`${ADC} tier list -a $APPLICATION_ID`"
assert_contains_substring "<business-transactions>" "`${ADC} bt list -a $APPLICATION_ID`"

##### Database Collector Create, List, Get, Delete #####
CREATE_DBMON="`${ADC} dbmon create -i adc_test_collector -h localhost -n db -u user -a "Default Database Agent" -t DB2 -p 1555 -s password`"
assert_contains_substring '"name" : "adc_test_collector",' "$CREATE_DBMON"
assert_contains_substring '"name" : "adc_test_collector",' "`${ADC} dbmon list`"
if [[ $CREATE_DBMON =~ \"id\"\ \:\ ([0-9]+) ]] ; then
COLLECTOR_ID=${BASH_REMATCH[1]}
assert_contains_substring '"name" : "adc_test_collector",' "`${ADC} dbmon get $COLLECTOR_ID`"
assert_contains_substring '"status" : "SUCCESS",' "`${ADC} dbmon delete $COLLECTOR_ID`"
fi

##### Error handling #####
assert_equals "Error" "`env CONFIG_HTTP_TIMEOUT=1 ./adc.sh -H 127.0.0.2:8009 controller ping`"

##### Delete the test application
assert_empty "`${ADC} application delete $APPLICATION_ID`"
fi
#### END TESTS ####

declare -i PERCENTAGE

PERCENTAGE=$((($SUCCESS_COUNTER*100)/($TEST_COUNTER)))

if [ $PERCENTAGE -eq 100 ]; then
echo -e "\033[0;32m"
echo -e "\033[0;32m"
elif [ $PERCENTAGE -ge 80 ]; then
echo -e "\033[0;33m"
echo -e "\033[0;33m"
else
echo -e "\033[0;31m"
echo -e "\033[0;31m"
fi

rm $COOKIE_PATH
Expand Down

0 comments on commit d6feacb

Please sign in to comment.