Skip to content

Commit

Permalink
Merge pull request #212 from telefonicaid/merge/tc
Browse files Browse the repository at this point in the history
New TCs for UL20 commands
  • Loading branch information
gsevillano committed Jul 10, 2015
2 parents 0540895 + 3bb5007 commit 7d9f603
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Feature: Send UL20 Command
Feature: UL20 Command Send
As a device
I want to send commands to IoTAgent throught context broker for UL20
In order to assure IotAgent_UL20-Cbroker integration


@iot_cmd_ul20 @IDAS-20170
@iot_ul20 @iot_cmd_ul20 @IDAS-20170
Scenario Outline: Send a single command
Given a service with name "<service>" and protocol "<protocol>" created
And a device with device id "<device_id>", device name "<device_name>", command name "<command>" and command value "<cmd_value>" created
And a device with device id "<device_id>", device name "<device_name>", protocol "<protocol>", command name "<command>" and command value "<cmd_value>" created
When I send a command to the IoTAgent with service "<service>", device "<device_name>", command "<command>", entity_type "<ent_type>" and value "<value>"
Then the command of device "<device_name>" with response "<response>" and status "<status>" is received by context broker

Expand All @@ -16,14 +16,12 @@ Feature: Send UL20 Command
|dev1 |room1 |serviceul20 |IoTUL2 |attr_1_dev_1 |ping1 |dev1@%s |dev1@ping1 |OK | |
|dev1_1 |room1_1 |serviceul20 |IoTUL2 |attr_2_dev_1_1 |ping1_1#param1=value1 |dev1_1@%s#%s |dev1_1@ping1_1#param1=value1 |OK | |
|dev1_2 |room1_2 |serviceul20 |IoTUL2 |attr_3_dev_1_2 |ping1_2#p1=v1#p2=v2 |dev1_2@%s#%s#%s |dev1_2@ping1_2#p1=v1#p2=v2 |OK | |
# |dev1 |room1 |serviceul20 |IoTUL2 |attr_2_dev_1 |ping1_1#param1=value1 |dev1_1@%s#%s |dev1@ping1_1#param1=value1 |OK | |
# |dev1 |room1 |serviceul20 |IoTUL2 |attr_3_dev_1 |ping1_2#p1=v1#p2=v2 |dev1_2@%s#%s#%s |dev1@ping1_2#p1=v1#p2=v2 |OK | |


@iot_cmd_ul20 @IDAS-20236
@iot_ul20 @iot_cmd_ul20 @IDAS-20236
Scenario Outline: Send a pooling command
Given a service with name "<service>" and protocol "<protocol>" created
And a device with device id "<device_id>", device name "<device_name>", endpoint "<endpoint>", command name "<command>" and command value "<cmd_value>" created
And a device with device id "<device_id>", device name "<device_name>", endpoint "<endpoint>", protocol "<protocol>", command name "<command>" and command value "<cmd_value>" created
When I send a command to the IoTAgent with service "<service>", device "<device_name>", command "<command>", entity_type "<ent_type>" and value "<value>"
And I get the command and send the response "<response>" for device "<device_id>"
Then the command of device "<device_name>" with response "<response>" and status "<status>" is received by context broker
Expand All @@ -37,28 +35,29 @@ Feature: Send UL20 Command
|dev6_3 |room6_3 |serviceul20 |IoTUL2 |attr_1_dev_6_3 |ping6_3 |dev6_3@%s | |ping6_3_expired |delivered but no respond | |
|dev6_4 |room6_4 |serviceul20 |IoTUL2 |attr_1_dev_6_4 |ping6_4 |dev6_4@%s | |not_read |expired read | |

@iot_cmd_ul20 @IDAS-20169
@iot_ul20 @iot_cmd_ul20 @IDAS-20169
Scenario Outline: Send a wrong command
Given a service with name "<service>" and protocol "<protocol>" created
And a device with device id "<device_id>", device name "<device_name>", endpoint "<endpoint>", command name "<command>" and command value "<cmd_value>" created
And a device with device id "<device_id>", device name "<device_name>", endpoint "<endpoint>", protocol "<protocol>", command name "<command>" and command value "<cmd_value>" created
When I send a wrong command to the IoTAgent with service "<service>", device "<device_name>", command "<command>", value "<value>" and wrong "<wrong_field>"
Then the command of device "<device_name>" with response "<response>" and status "<status>" is received or NOT by context broker

Examples:
|device_id |device_name |service |protocol |command |value |cmd_value |endpoint |status |wrong_field |response |
|dev2 |room2 |serviceul20 |IoTUL2 |attr_1_dev_2 |ping2 |dev2@%s |http://10.95.213.159:5371/simulaClient/lightCommand |OK |simulator_type |no ul20 response command: |
|dev3 |room3 |serviceul20 |IoTUL2 |attr_1_dev_3 |ping3 |dev3@%s |http://192.168.1.1:9001 |error |nonexist_destination |http://192.168.1.1:9001/ [No route to host] |
|dev4 |room4 |serviceul20 |IoTUL2 |attr_1_dev_4 |ping4 |dev4@%s |http://192.0.0.1:9001 |error |unreachable_dest |http://192.0.0.1:9001/ [Connection timed out] |
|dev2_1 |room2_1 |serviceul20 |IoTUL2 |attr_2_dev_2_1 |ping2_1 |%s | |fail |wrong_command_format |this is not a valid command |
|dev2 |room2 |serviceul20 |IoTUL2 |attr_2_dev_2 |ping2_1 | | |fail |nonexistent_command |the device does not have implemented this command |
|dev11 |room11 |serviceul20 |IoTUL2 |attr_1_dev_11 |ping11 | | |fail |nonexistent_device |The device does not exist |
|dev5 |room5 |serviceMqtt | |attr_1_dev_5 |ping5 | | |fail |nonexistent_service |The service does not exist |
|device_id |device_name |service |protocol |command |value |cmd_value |endpoint |status |wrong_field |response |
|dev2 |room2 |serviceul20 |IoTUL2 |attr_1_dev_2 |ping2 |dev2@%s |http://10.95.213.159:5371/simulaClient/lightCommand |OK |simulator_type |no ul20 response command: |
|dev3 |room3 |serviceul20 |IoTUL2 |attr_1_dev_3 |ping3 |dev3@%s |http://192.168.1.1:9001 |error |nonexist_destination |http://192.168.1.1:9001/ [No route to host] |
# |dev4 |room4 |serviceul20 |IoTUL2 |attr_1_dev_4 |ping4 |dev4@%s |http://192.0.0.1:9001 |error |unreachable_dest |http://192.0.0.1:9001/ [Connection timed out] |
|dev4 |room4 |serviceul20 |IoTUL2 |attr_1_dev_4 |ping4 |dev4@%s |http://10.95.213.159:5371/simulaClient/lightCommand?delay=10 |error |unreachable_dest |http://10.95.213.159:5371/simulaClient/lightCommand delay=10 [Connection timed out]|
|dev2_1 |room2_1 |serviceul20 |IoTUL2 |attr_2_dev_2_1 |ping2_1 |%s | |fail |wrong_command_format |this is not a valid command |
|dev2 |room2 |serviceul20 |IoTUL2 |attr_2_dev_2 |ping2_1 | | |fail |nonexistent_command |the device does not have implemented this command |
|dev11 |room11 |serviceul20 |IoTUL2 |attr_1_dev_11 |ping11 | | |fail |nonexistent_device |The device does not exist |
|dev5 |room5 |serviceMqtt | |attr_1_dev_5 |ping5 | | |fail |nonexistent_service |Fiware-Service not accepted |


@iot_cmd_ul20 @IDAS-20171
@iot_ul20 @iot_cmd_ul20 @IDAS-20171
Scenario Outline: Send a command for a device with entity name
Given a service with name "<service>" and protocol "<protocol>" created
And a device with device id "<device_id>", entity type "<ent_type>", entity name "<ent_name>", command name "<command>" and command value "<cmd_value>" created
And a device with device id "<device_id>", entity type "<ent_type>", entity name "<ent_name>", protocol "<protocol>", command name "<command>" and command value "<cmd_value>" created
When I send a command to the IoTAgent with service "<service>", device "<device_name>", command "<command>", entity_type "<ent_type>" and value "<value>"
Then the command of device "<device_name>" with response "<response>", entity_type "<ent_type>" and status "<status>" is received by context broker

Expand Down
43 changes: 26 additions & 17 deletions tests/e2e_tests/component/iot_ul20/commands/send/setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from lettuce import step, world
from iotqautils.cbUtils import CBUtils
from iotqautils.gtwMeasures import Gw_Measures_Utils
from common.gw_configuration import CBROKER_URL,CBROKER_HEADER,GW_HOSTNAME,IOT_PORT,PATH_IOT_COMMAND,IOT_SERVER_ROOT,DEF_ENTITY_TYPE,PATH_UL20_COMMAND,TIMEOUT_COMMAND
from common.gw_configuration import CBROKER_URL,CBROKER_HEADER,GW_HOSTNAME,IOT_PORT,PATH_UL20_COMMAND,IOT_SERVER_ROOT,DEF_ENTITY_TYPE,PATH_UL20_SIMULATOR,TIMEOUT_COMMAND
from common.user_steps import UserSteps
import requests
import time,datetime

cb = CBUtils(instance=GW_HOSTNAME,port=IOT_PORT,path_update=PATH_IOT_COMMAND)
cb = CBUtils(instance=GW_HOSTNAME,port=IOT_PORT,path_update=PATH_UL20_COMMAND)
gw = Gw_Measures_Utils(server_root=IOT_SERVER_ROOT)
user_steps = UserSteps()

Expand All @@ -17,8 +17,8 @@ def service_created_precond(step, service_name, protocol):
world.protocol = protocol
user_steps.service_precond(service_name, protocol)

@step('a device with device id "([^"]*)", device name "([^"]*)", command name "([^"]*)" and command value "([^"]*)" created')
def device_created_precond(step, device_id, device_name, cmd_name, cmd_value):
@step('a device with device id "([^"]*)", device name "([^"]*)", protocol "([^"]*)", command name "([^"]*)" and command value "([^"]*)" created')
def device_created_precond(step, device_id, device_name, protocol, cmd_name, cmd_value):
replaces = {
"#": "|"
}
Expand All @@ -31,11 +31,11 @@ def device_created_precond(step, device_id, device_name, cmd_name, cmd_value):
"value": cmd_value
}
]
user_steps.device_precond(device_id, CBROKER_URL+PATH_UL20_COMMAND, command, device_name)
user_steps.device_precond(device_id, CBROKER_URL+PATH_UL20_SIMULATOR, protocol, command, device_name)
world.device_name=device_name

@step('a device with device id "([^"]*)", device name "([^"]*)", endpoint "([^"]*)", command name "([^"]*)" and command value "([^"]*)" created')
def device_with_endpoint_created_precond(step, device_id, device_name, endpoint, cmd_name, cmd_value):
@step('a device with device id "([^"]*)", device name "([^"]*)", endpoint "([^"]*)", protocol "([^"]*)", command name "([^"]*)" and command value "([^"]*)" created')
def device_with_endpoint_created_precond(step, device_id, device_name, endpoint, protocol, cmd_name, cmd_value):
replaces = {
"#": "|"
}
Expand All @@ -52,11 +52,11 @@ def device_with_endpoint_created_precond(step, device_id, device_name, endpoint,
if not "http://" in endpoint:
endpoint = CBROKER_URL + endpoint
if cmd_value:
user_steps.device_precond(device_id, endpoint, command, device_name)
user_steps.device_precond(device_id, endpoint, protocol, command, device_name)
world.device_name=device_name

@step('a device with device id "([^"]*)", entity type "([^"]*)", entity name "([^"]*)", command name "([^"]*)" and command value "([^"]*)" created')
def device_with_entity_values_created_precond(step, device_id, ent_type, ent_name, cmd_name, cmd_value):
@step('a device with device id "([^"]*)", entity type "([^"]*)", entity name "([^"]*)", protocol "([^"]*)", command name "([^"]*)" and command value "([^"]*)" created')
def device_with_entity_values_created_precond(step, device_id, ent_type, ent_name, protocol, cmd_name, cmd_value):
replaces = {
"#": "|"
}
Expand All @@ -69,7 +69,7 @@ def device_with_entity_values_created_precond(step, device_id, ent_type, ent_nam
"value": cmd_value
}
]
user_steps.device_precond(device_id, CBROKER_URL+PATH_UL20_COMMAND, command, ent_name, ent_type)
user_steps.device_precond(device_id, CBROKER_URL+PATH_UL20_SIMULATOR, protocol, command, ent_name, ent_type)
world.device_id=device_id

@step('I send a command to the IoTAgent with service "([^"]*)", device "([^"]*)", command "([^"]*)", entity_type "([^"]*)" and value "([^"]*)"')
Expand Down Expand Up @@ -151,8 +151,13 @@ def send_wrong_command(step, service, device_id, cmd_name, value, field):
# world.req_text=req.text
else:
world.code = 200
assert req.ok, 'ERROR: ' + str(req)
world.req_text=req.json()
if field=="nonexistent_service":
assert not req.ok, 'ERROR: ' + str(req)
world.req_text=req.text
world.code = 4000
else:
assert req.ok, 'ERROR: ' + str(req)
world.req_text=req.json()

@step('I get the command and send the response "([^"]*)" for device "([^"]*)"')
def send_response(step, response, device_id):
Expand Down Expand Up @@ -321,13 +326,17 @@ def check_NOT_command_cbroker(asset_name, response, cmd_type):
#print 'Metadatas {}'.format(metasElement)
assert assetElement != "{}".format(asset_name), 'ERROR: device: ' + str(asset_name) + " found in: " + str(contextElement)
print "Command is NOT received"
resp = world.req_text
if world.code==4000:
resp = world.req_text
assert response in resp
return
if world.code:
assert resp['errorCode']['code'] == world.code, 'ERROR: code error expected ' + str(world.code) + " received " + str(resp['errorCode']['code'])
resp = world.req_text['contextResponses'][0]
assert resp['statusCode']['code'] == str(world.code), 'ERROR: code error expected ' + str(world.code) + " received " + str(resp['statusCode']['code'])
if world.response:
assert resp['errorCode']['reasonPhrase'] == str(world.response), 'ERROR: text error expected ' + str(world.response) + " received " + resp['errorCode']['reasonPhrase']
assert resp['statusCode']['reasonPhrase'] == str(world.response), 'ERROR: text error expected ' + str(world.response) + " received " + resp['statusCode']['reasonPhrase']
else:
assert resp['errorCode']['reasonPhrase'] == response, 'ERROR: text error expected ' + response + " received " + resp['errorCode']['reasonPhrase']
assert resp['statusCode']['reasonPhrase'] == response, 'ERROR: text error expected ' + response + " received " + resp['statusCode']['reasonPhrase']

def check_timestamp (timestamp):
st = datetime.datetime.utcfromtimestamp(world.ts).strftime('%Y-%m-%dT%H:%M:%S')
Expand Down

0 comments on commit 7d9f603

Please sign in to comment.