BASE_URL="http://localhost:1902" echo "==========================================" echo "GATEWAY API TESTS" echo "==========================================" echo "1. Listing all Gateways" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getGateways" | jq -c '.[]') GATEWAY_IDS=() IFS=$'\n' for r in $LIST do echo "$r" GATEWAY_IDS+=($(echo "$r" | jq -r '.id')) done sleep 1 if [ ${#GATEWAY_IDS[@]} -gt 1 ]; then echo -e "\n\n2. Updating Gateway ${GATEWAY_IDS[1]}" curl -X PUT "$BASE_URL/reslevis/updateGateway/${GATEWAY_IDS[1]}" \ -H "Content-Type: application/json" \ -d "{ \"id\": \"${GATEWAY_IDS[1]}\", \"name\": \"GU-100-Updated\", \"mac\": \"AA:BB:CC:DD:EE:FF\", \"status\": \"online\", \"model\": \"MG3\", \"ip\": \"127.0.0.1\", \"position\": \"unknown\", \"x\": 1, \"y\": 1, \"notes\": \"some description\", \"floor\": \"second\", \"building\": \"hospital\" }" sleep 1 echo -e "\n\n3. Listing Gateways after update" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getGateways" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done sleep 1 echo -e "\n\n4. Deleting Gateway ${GATEWAY_IDS[1]}" curl -X DELETE "$BASE_URL/reslevis/removeGateway/${GATEWAY_IDS[1]}" sleep 1 echo -e "\n\n5. Verifying Delete (List again)..." LIST=$(curl -s -X GET "$BASE_URL/reslevis/getGateways" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done else echo "Not enough gateways to test update/delete" fi echo -e "\n\n==========================================" echo "ZONE API TESTS" echo "==========================================" echo "6. Listing all Zones" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getZones" | jq -c '.[]') ZONE_IDS=() IFS=$'\n' for r in $LIST do echo "$r" ZONE_IDS+=($(echo "$r" | jq -r '.id')) done sleep 1 if [ ${#ZONE_IDS[@]} -gt 0 ]; then echo -e "\n\n7. Updating Zone ${ZONE_IDS[0]}" curl -X PUT "$BASE_URL/reslevis/updateZone" \ -H "Content-Type: application/json" \ -d "{ \"id\": \"${ZONE_IDS[0]}\", \"name\": \"Zone-Updated\", \"groups\": [\"security\", \"logistics\"] }" sleep 1 echo -e "\n\n8. Listing Zones after update" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getZones" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done sleep 1 echo -e "\n\n9. Deleting Zone ${ZONE_IDS[0]}" curl -X DELETE "$BASE_URL/reslevis/removeZone/${ZONE_IDS[0]}" sleep 1 echo -e "\n\n10. Verifying Delete (List again)..." LIST=$(curl -s -X GET "$BASE_URL/reslevis/getZones" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done else echo "No zones to test update/delete" fi echo -e "\n\n==========================================" echo "TRACKERZONE API TESTS" echo "==========================================" echo "11. Listing all TrackerZones" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getTrackerZones" | jq -c '.[]') TRACKERZONE_IDS=() IFS=$'\n' for r in $LIST do echo "$r" TRACKERZONE_IDS+=($(echo "$r" | jq -r '.id')) done sleep 1 if [ ${#TRACKERZONE_IDS[@]} -gt 0 ]; then echo -e "\n\n12. Updating TrackerZone ${TRACKERZONE_IDS[0]}" curl -X PUT "$BASE_URL/reslevis/updateTrackerZone" \ -H "Content-Type: application/json" \ -d "{ \"id\": \"${TRACKERZONE_IDS[0]}\", \"name\": \"TrackerZone-Updated\" }" sleep 1 echo -e "\n\n13. Listing TrackerZones after update" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getTrackerZones" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done sleep 1 echo -e "\n\n14. Deleting TrackerZone ${TRACKERZONE_IDS[0]}" curl -X DELETE "$BASE_URL/reslevis/removeTrackerZone/${TRACKERZONE_IDS[0]}" sleep 1 echo -e "\n\n15. Verifying Delete (List again)..." LIST=$(curl -s -X GET "$BASE_URL/reslevis/getTrackerZones" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done else echo "No trackerzones to test update/delete" fi echo -e "\n\n==========================================" echo "TRACKER API TESTS" echo "==========================================" echo "16. Listing all Trackers" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getTrackers" | jq -c '.[]') TRACKER_IDS=() IFS=$'\n' for r in $LIST do echo "$r" TRACKER_IDS+=($(echo "$r" | jq -r '.id')) done sleep 1 if [ ${#TRACKER_IDS[@]} -gt 0 ]; then echo -e "\n\n17. Updating Tracker ${TRACKER_IDS[0]}" curl -X PUT "$BASE_URL/reslevis/updateTracker" \ -H "Content-Type: application/json" \ -d "{ \"id\": \"${TRACKER_IDS[0]}\", \"name\": \"Tracker-Updated\", \"battery\": 85, \"status\": \"inactive\" }" sleep 1 echo -e "\n\n18. Listing Trackers after update" LIST=$(curl -s -X GET "$BASE_URL/reslevis/getTrackers" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done sleep 1 echo -e "\n\n19. Deleting Tracker ${TRACKER_IDS[0]}" curl -X DELETE "$BASE_URL/reslevis/removeTracker/${TRACKER_IDS[0]}" sleep 1 echo -e "\n\n20. Verifying Delete (List again)..." LIST=$(curl -s -X GET "$BASE_URL/reslevis/getTrackers" | jq -c '.[]') IFS=$'\n' for r in $LIST do echo "$r" done else echo "No trackers to test update/delete" fi echo -e "\n\n==========================================" echo "ALL TESTS COMPLETED" echo "=========================================="