API test cases for /core/services
Change-Id: Icbba49162d07707298e1b0a6e8607e61879b3756
diff --git a/src/test/cord-api/Properties/RestApiProperties.py b/src/test/cord-api/Properties/RestApiProperties.py
index 8daa483..9cc30be 100644
--- a/src/test/cord-api/Properties/RestApiProperties.py
+++ b/src/test/cord-api/Properties/RestApiProperties.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
SERVER_IP = '10.128.100.9'
-SERVER_PORT = '8888'
+SERVER_PORT = '8080'
USER = 'padmin@vicci.org'
PASSWD = 'letmein'
TENANT_SUBSCRIBER = '/api/tenant/cord/subscriber/'
@@ -8,3 +8,4 @@
UTILS_SYNCHRONIZER = '/api/utility/synchronizer/'
UTILS_LOGIN = '/api/utility/login/'
CORE_USERS = '/api/core/users/'
+CORE_SERVICES = '/api/core/services/'
diff --git a/src/test/cord-api/Tests/ServiceTest.txt b/src/test/cord-api/Tests/ServiceTest.txt
new file mode 100644
index 0000000..4a31ad8
--- /dev/null
+++ b/src/test/cord-api/Tests/ServiceTest.txt
@@ -0,0 +1,94 @@
+*** Settings ***
+Documentation Test suite for Service verification
+Suite Setup Read InputFile
+Test Template Verify Service functionality
+Library Collections
+Library String
+Library OperatingSystem
+Library XML
+Library RequestsLibrary
+Library ../Framework/utils/utils.py
+Library ../Framework/restApi.py
+
+*** Variables ***
+${USER} admin
+${PASSWORD} admin
+${PATHFILE} ${CURDIR}/data/Service.json
+${PATHFILE2} ${CURDIR}/data/putService.json
+
+*** Test Cases *** TYPE LISTINDEX
+Test Post Service-1 CREATE 0
+
+Test Get Service-1 RETRIEVE 0
+
+Test Edit Service-1 PUT 0
+
+Test Delete Service-1 DELETE 0
+
+Test Post Service-2 CREATE 1
+
+Test Get Service-2 RETRIEVE 1
+
+Test Edit Service-2 PUT 1
+
+Test Delete Service-2 DELETE 1
+
+*** Keywords ***
+Read InputFile
+ ${serviceList}= utils.jsonToList ${PATHFILE} ServiceInfo
+ Set Suite Variable ${slist} ${serviceList}
+ ${putServiceList}= utils.jsonToList ${PATHFILE2} ServiceInfo
+ Set Suite Variable ${putList} ${putServiceList}
+
+Verify Service functionality
+ [Arguments] ${type} ${listIndex}
+ Run Keyword If "${type}" == "CREATE" Test Post Service API ${listIndex}
+ Run Keyword If "${type}" == "RETRIEVE" Test Get Service API ${listIndex}
+ Run Keyword If "${type}" == "PUT" Test Edit Service API ${listIndex}
+ Run Keyword If "${type}" == "DELETE" Test Delete Service API ${listIndex}
+
+Test Post Service API
+ [Arguments] ${listIndex}
+ ${serviceList} = Get Variable Value ${slist}
+ ${serviceDict}= utils.listToDict ${serviceList} ${listIndex}
+ ${api_result}= restApi.ApiPost CORE_SERVICES ${serviceDict}
+ Should Be True ${api_result}
+
+Test Get Service API
+ [Arguments] ${listIndex}
+ ${json_result}= restApi.ApiGet CORE_SERVICES
+ Log ${json_result}
+ ${serviceList}= Get Variable Value ${slist}
+ ${serviceDict}= utils.listToDict ${serviceList} ${listIndex}
+ ${name}= utils.getFieldValueFromDict ${serviceDict} name
+ ${getJsonDict}= utils.getDictFromListOfDict ${json_result} name ${name}
+ ${test_result}= utils.compare_dict ${serviceDict} ${getJsonDict}
+ Should Be True ${test_result}
+
+Test Edit Service API
+ [Arguments] ${listIndex}
+ ${get_result}= restApi.ApiGet CORE_SERVICES
+ ${putServiceList}= Get Variable Value ${putList}
+ ${putServiceDict}= utils.listToDict ${putServiceList} ${listIndex}
+ ${name}= utils.getFieldValueFromDict ${putServiceDict} name
+ ${serviceDict}= utils.getDictFromListofDict ${get_result} name ${name}
+ ${serviceID}= utils.getFieldValueFromDict ${serviceDict} id
+ ${api_result}= restApi.ApiPut CORE_SERVICES ${putServiceDict} ${serviceID}
+ Should Be True ${api_result}
+ ${getResultAfterPut}= restApi.ApiGet CORE_SERVICES ${serviceID}
+ ${test_result}= utils.compare_dict ${putServiceDict} ${getResultAfterPut}
+ Should Be True ${test_result}
+
+Test Delete Service API
+ [Arguments] ${listIndex}
+ ${json_result}= restApi.ApiGet CORE_SERVICES
+ ${serviceList}= Get Variable Value ${slist}
+ ${serviceDict}= utils.listToDict ${serviceList} ${listIndex}
+ ${name}= utils.getFieldValueFromDict ${serviceDict} name
+ Log ${name}
+ ${serviceDict}= utils.getDictFromListofDict ${json_result} name ${name}
+ Log ${serviceDict}
+ ${serviceId}= utils.getFieldValueFromDict ${serviceDict} id
+ Log ${serviceId}
+ ${test_result}= restApi.ApiDelete CORE_SERVICES ${serviceId}
+ Should Be True ${test_result}
diff --git a/src/test/cord-api/Tests/data/Service.json b/src/test/cord-api/Tests/data/Service.json
new file mode 100644
index 0000000..0dd5193
--- /dev/null
+++ b/src/test/cord-api/Tests/data/Service.json
@@ -0,0 +1,13 @@
+{
+ "ServiceInfo":
+ [
+ {
+ "name": "test-service-1",
+ "description": "Test service No.1"
+ },
+ {
+ "name": "test-service-2",
+ "description": "Test service No.2"
+ }
+ ]
+}
diff --git a/src/test/cord-api/Tests/data/putService.json b/src/test/cord-api/Tests/data/putService.json
new file mode 100644
index 0000000..8a962a7
--- /dev/null
+++ b/src/test/cord-api/Tests/data/putService.json
@@ -0,0 +1,13 @@
+{
+ "ServiceInfo":
+ [
+ {
+ "name": "test-service-1",
+ "description": "Test service No.1 - Edited"
+ },
+ {
+ "name": "test-service-2",
+ "description": "Test service No.2 - Edited"
+ }
+ ]
+}