blob: adf6e0aa5c0f57f684c3ca2456876f71d380e9eb [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2020 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
// File: LeshanTestSuite.ttcn
// Description:
// Rev: <RnXnn>
// Prodnr: CNL 113 910
// Updated: 2020-02-06
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
module LeshanTestSuite
{
import from IoT_FT_Framework_Definitions all;
import from IoT_FT_Framework_Functions all;
import from IFW_CoAP_Peer_TestSteps all;
import from IFW_HTTP_Client_Definitions all;
import from IFW_HTTP_Client_TestSteps all;
import from CoAP_Types all;
import from HTTPmsg_Types all;
import from LightweightM2M_Types all;
import from LightweightM2M_CoAP_Binding all;
testcase tc_Leshan_checkHttpInterface() runs on IFW_MAIN_CT
{
setverdict(pass);
var integer http_client := f_IFW_addComponent(HTTP_CLIENT, "http_client");
f_IFW_HttpClient_setRemote(http_client, "http_server");
f_IFW_initComponents();
f_HTTP_setCommonRequestHeaders(http_client);
f_IFW_HttpClient_setMessageToSend(http_client, valueof(t_HTTP_request("GET", "/api/objectspecs")));
f_IFW_HttpClient_send(http_client);
f_IFW_HttpClient_receive(http_client);
f_handleVerdict(f_IFW_HttpClient_check(http_client, tr_HTTP_response(200)));
f_IFW_cleanUp();
}
testcase tc_COAP_register() runs on IFW_MAIN_CT
{
setverdict(pass);
var integer iot_client := f_IFW_addComponent(COAP_PEER, "iot_client");
var integer http_client := f_IFW_addComponent(HTTP_CLIENT, "http_client");
f_IFW_CoapPeer_setRemote(iot_client, "coap_server");
f_IFW_HttpClient_setRemote(http_client, "http_server");
f_IFW_initComponents();
f_COAP_register(iot_client);
f_HTTP_setCommonRequestHeaders(http_client);
f_IFW_HttpClient_setMessageToSend(http_client,
valueof(t_HTTP_request("GET", "/api/clients/"&"client_"&int2str(iot_client)))
);
f_IFW_HttpClient_send(http_client);
f_IFW_HttpClient_receive(http_client);
f_handleVerdict(f_IFW_HttpClient_check(http_client, tr_HTTP_response(200)));
f_COAP_deregister(iot_client);
f_IFW_cleanUp();
}
testcase tc_COAP_read() runs on IFW_MAIN_CT
{
setverdict(pass);
var integer iot_client := f_IFW_addComponent(COAP_PEER, "iot_client");
var integer http_client := f_IFW_addComponent(HTTP_CLIENT, "http_client");
f_IFW_CoapPeer_setRemote(iot_client, "coap_server");
f_IFW_HttpClient_setRemote(http_client, "http_server");
f_IFW_initComponents();
f_COAP_register(iot_client);
f_HTTP_setCommonRequestHeaders(http_client);
f_IFW_HttpClient_setMessageToSend(http_client,
valueof(t_HTTP_request(
"GET",
"/api/clients/"&"client_"&int2str(iot_client)&"/1/0/6?format=JSON")
)
);
f_IFW_HttpClient_send(http_client);
f_IFW_CoapPeer_receive(iot_client);
f_handleVerdict(f_IFW_CoapPeer_check(iot_client, tr_COAP_READ_req));
f_IFW_CoapPeer_setMessageToSend(iot_client,
valueof(t_COAP_READ_resp),
USE_LAST_RECEIVED_MID,
USE_LAST_RECEIVED_TOKEN
);
f_IFW_CoapPeer_send(iot_client);
f_IFW_HttpClient_receive(http_client);
f_handleVerdict(f_IFW_HttpClient_check(http_client, tr_HTTP_response(200)))
f_COAP_deregister(iot_client);
f_IFW_cleanUp();
}
template CoAP_ReqResp tr_COAP_READ_req :=
{
header :=
{
version := 1,
msg_type := CONFIRMABLE,
code := METHOD_GET,
message_id := ?
},
token := ?,
options :=
{
{ uri_path := "1" },
{ uri_path := "0" },
{ uri_path := "6" },
{ accept := 1543 }
},
payload := omit
}
template CoAP_ReqResp t_COAP_READ_resp :=
{
header :=
{
version := 1,
msg_type := ACKNOWLEDGEMENT,
code := RESPONSE_CODE_Content,
message_id := 0
},
token := ''O,
options :=
{
{
content_format := 1543
}
},
payload := char2oct("{\"e\":[{\"n\":\"\",\"bv\":true}]}")
}
template LWM2M_PDU tr_LWM2M_READ_req :=
{
Read_ := {
path := { 1, 0, 6 },
accept := { 1543 }
}
}
template LWM2M_PDU t_LWM2M_READ_resp :=
{
Response := {
location := {},
code := 205,
contentFormat := 1543,
resources := {
{
id := -1,
objId := -1,
objInstId := -1,
val := { boolValue := true }
}
}
}
}
template HTTPMessage t_HTTP_request(in charstring p_method, in charstring p_uri) :=
{
request :=
{
client_id := omit,
method := p_method,
uri := p_uri,
version_major := 1,
version_minor := 1,
header :=
{
{"Accept", "application/json, text/plain, */*"},
{"Accept-Language", "en-US,en;q=0.5"},
{"Accept-Encoding", "gzip, deflate"},
{"Connection", "keep-alive"}
},
body := ""
}
}
template HTTPMessage tr_HTTP_response(in template integer p_respCode) :=
{
response :=
{
client_id := *,
version_major := ?,
version_minor := ?,
statuscode := p_respCode,
statustext := ?,
header := ?,
body := ?
}
}
function f_COAP_register(in integer p_clientIdx) runs on IFW_MAIN_CT
{
var CoAP_ReqResp v_coap_encoded;
f_enc_LWM2M_to_COAP(valueof(t_LwM2M_register(p_clientIdx)), v_coap_encoded);
f_IFW_CoapPeer_setMessageToSend(p_clientIdx, v_coap_encoded);
f_IFW_CoapPeer_send(p_clientIdx);
f_IFW_CoapPeer_receive(p_clientIdx);
f_handleVerdict(f_IFW_CoapPeer_check(p_clientIdx, t_COAP_registered));
f_IFW_CoapPeer_saveLocationPath(p_clientIdx);
}
template LWM2M_PDU t_LwM2M_register(in integer p_clientIdx) :=
{
Register :=
{
endpointClientName := "client_"&int2str(p_clientIdx),
lifetime := 60,
version := omit,
bindingMode := U,
smsNumber := omit,
objectsAndObjectInstances :=
{
{0, 0, omit},
{1, 0, omit},
{3, 0, omit}
}
}
}
template CoAP_ReqResp t_COAP_registered :=
{
header :=
{
version := 1,
msg_type := ACKNOWLEDGEMENT,
code := RESPONSE_CODE_Created,
message_id := ?
},
token := ''O,
options := {},
payload := omit
}
template LWM2M_PDU t_LWM2M_response(in template integer p_code) :=
{
Response :=
{
location := ?,
code := p_code,
contentFormat := *,
resources := ?
}
}
function f_COAP_deregister(in integer p_clientIdx) runs on IFW_MAIN_CT
{
var CoAP_ReqResp v_coap_encoded;
f_enc_LWM2M_to_COAP(valueof(t_LwM2M_deregister), v_coap_encoded);
f_IFW_CoapPeer_setMessageToSend(p_clientIdx, v_coap_encoded);
f_IFW_CoapPeer_addUriPath(p_clientIdx);
f_IFW_CoapPeer_send(p_clientIdx);
f_IFW_CoapPeer_receive(p_clientIdx);
f_handleVerdict(f_IFW_CoapPeer_check(p_clientIdx, t_COAP_deregistered));
}
template LWM2M_PDU t_LwM2M_deregister :=
{
Deregister :=
{
location := {}
}
}
template CoAP_ReqResp t_COAP_deregistered :=
{
header :=
{
version := 1,
msg_type := ACKNOWLEDGEMENT,
code := RESPONSE_CODE_Deleted,
message_id := ?
},
token := ''O,
options := {},
payload := omit
}
function f_handleVerdict(in boolean p_verdict)
{
if (p_verdict) { setverdict(pass) }
else { setverdict(fail) }
}
control
{
execute(tc_Leshan_checkHttpInterface());
execute(tc_COAP_register());
execute(tc_COAP_read());
}
}