Newer
Older
module LibMec_Functions {
// Libcommon
import from LibCommon_Sync all;
YannGarcia
committed
// LibMec
import from LibMec_Pixits all;
YannGarcia
committed
// LibMec_UEidentityAPI
import from UEidentityAPI_TypesAndValues all;
import from UEidentityAPI_Templates all;
import from UEidentityAPI_Pixits all;
// LibHttp
import from LibItsHttp_TypesAndValues all;
import from LibItsHttp_Templates all;
import from LibItsHttp_TestSystem all;
YannGarcia
committed
import from LibItsHttp_Templates all;
import from LibItsHttp_JsonTemplates all;
group preambles {
/**
* @desc Setup HTTP pprotocol port
*/
function f_cf_01_http_up() runs on HttpComponent {
// Map ports
map(self:httpPort, system:httpPort);
// Connect
f_connect4SelfOrClientSync();
activate(a_cf_01_http_down());
activate(a_default_requests());
activate(a_default_responses());
} // End of function f_cf_01_http_up
/**
* @desc Setup HTTP pprotocol port
*/
function f_cf_01_http_notif_up() runs on HttpComponent {
// Map ports
map(self:httpPort_notif, system:httpPort_notif);
// Connect
f_connect4SelfOrClientSync();
activate(a_cf_01_http_notif_down());
activate(a_default_requests());
activate(a_default_responses());
} // End of function f_cf_01_http_notif_up
} // End of group preambles
group postambles {
/**
* @desc Shutdown HTTP pprotocol port
*/
function f_cf_01_http_down() runs on HttpComponent {
// Unmap ports
unmap(self:httpPort, system:httpPort);
// Disconnect ports
f_disconnect4SelfOrClientSync();
deactivate;
} // End of function f_cf_01_http_down
/**
* @desc Shutdown HTTP pprotocol port
*/
function f_cf_01_http_notif_down() runs on HttpComponent {
// Unmap ports
unmap(self:httpPort_notif, system:httpPort_notif);
// Disconnect ports
f_disconnect4SelfOrClientSync();
deactivate;
} // End of function f_cf_01_http_notif_down
/**
* @desc Default handling cf01 de-initialisation.
*/
altstep a_cf_01_http_down() runs on HttpComponent {
[] a_shutdown() {
f_cf_01_http_down();
log("*** a_cf_01_http_down: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***");
stop;
}
} // End of altstep a_cf_01_http_down
/**
* @desc Default handling cf01 de-initialisation.
*/
altstep a_cf_01_http_notif_down() runs on HttpComponent {
[] a_shutdown() {
f_cf_01_http_notif_down();
log("*** a_cf_01_http_notif_down: INFO: TEST COMPONENT NOW STOPPING ITSELF! ***");
stop;
}
} // End of altstep a_cf_01_http_notif_down
YannGarcia
committed
group helpers {
/**
* @desc Check if the user is registered or not
* @param
* @return 0 if unregistered, 1 if registered, -1 otherwise
*/
function f_check_user_register_state(
in UeIdentityTag p_ue_identity_tag := PX_UE_IDENTITY_TAG,
in HeaderLines p_headers
) runs on HttpComponent return integer {
var HttpMessage v_response;
var integer v_result := -1;
httpPort.send(
m_http_request(
m_http_request_get(
"/" & PICS_ROOT_API & PX_ME_APP_Q_UE_IDENTITY_ID_URI & oct2char(unichar2oct(PX_APP_INSTANCE_ID, "UTF-8")) & "/ue_identity_tag_info?ueIdentityTag=" & oct2char(unichar2oct(p_ue_identity_tag, "UTF-8")),
YannGarcia
committed
p_headers
)
)
);
// Test Body
tc_ac.start;
alt {
[] httpPort.receive(
mw_http_response(
mw_http_response_ok(
mw_http_message_body_json(
mw_body_json_ue_identity_tag_info(
mw_ue_identity_tag_info(
{ *, mw_ue_identity_tag_item(PX_UE_IDENTITY_TAG), * }
)))))) -> value v_response {
YannGarcia
committed
for (var integer v_i := 0; v_i < lengthof(v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags); v_i := v_i + 1) {
if (v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags[v_i].ueIdentityTag == p_ue_identity_tag) {
//log("Processing ", v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags[v_i].ueIdentityTag);
//log("State ", v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags[v_i].state);
YannGarcia
committed
if (v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags[v_i].state == UNREGISTERED) {
v_result := 0;
} else if (v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags[v_i].state == REGISTERED) {
YannGarcia
committed
v_result := 1;
} else if (v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags[v_i].state == INVALID_STATE) {
v_result := 2;
YannGarcia
committed
}
break;
}
}
}
[] tc_ac.timeout {
}
} // End of 'alt' statement
//log("<<< f_check_user_register_state: v_result: ", v_result);
YannGarcia
committed
return v_result;
} // End of function f_check_user_register_state
} // End of group helpers
group altsteps {
altstep a_default_requests() runs on HttpComponent {
[] httpPort.receive(mw_http_request) {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Server error: Receive request instead of response on httpPort ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort_notif.receive(mw_http_request) {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Server error: Receive unsollicited request on httpPort_notif ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
} // End of altstep a_default_requests
altstep a_default_responses() runs on HttpComponent {
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
var HttpMessage v_response;
[] httpPort.receive(
mw_http_response(
mw_http_response_ok(
mw_http_message_body_xml
))) {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Unexpected XML response ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort.receive(
mw_http_response(
mw_http_response_ok(
mw_http_message_body_json
))) {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Unexpected JSON response ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort.receive(
mw_http_response(
mw_http_response_ok(
mw_http_message_body_binary
))) {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Unexpected binary response ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort.receive(
mw_http_response(
mw_http_response_ko
)) -> value v_response {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Server error: " & int2str(v_response.response.statuscode) & "/" & v_response.response.statustext & " ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort.receive(mw_http_response) -> value v_response {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Server error: " & int2str(v_response.response.statuscode) & "/" & v_response.response.statustext & " ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort.receive {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Server error: Receive unsollicited message on httpPort ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort_notif.receive(mw_http_response) -> value v_response {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Server error: " & int2str(v_response.response.statuscode) & "/" & v_response.response.statustext & " on httpPort_notif ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
[] httpPort_notif.receive {
tc_ac.stop;
log("*** " & testcasename() & ": FAIL: Server error: Receive unsollicited message on httpPort_notif ***");
f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
}
} // End of altstep a_default_responses
} // end of group altsteps
} // End of module LibMec_Functions