blob: 9b85b6a9d75de07cc8d4f7fba2ef977228d3bbb7 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
// //
// Copyright (c) 2000-2019 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 //
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: EPTF_DsRestAPI_Test_Testcases
//
// Purpose:
// This module contains testcases for testing EPTF DsRestAPI.
//
// Module Parameters:
// -
// Module depends on:
// <EPTF_DsRestAPI_Test_Definitions>
// <EPTF_CLL_DsRestAPI_Definitions>
// <EPTF_CLL_DsRestAPI_Functions>
// <EPTF_CLL_DsRestAPI_DSServer_Functions>
// <EPTF_DsRestAPI_Test_Functions>
// <EPTF_CLL_Base_Functions>
// <EPTF_CLL_DsRestAPI_DSServer_Definitions>
// <EPTF_CLL_Common_Definitions>
// <TCCFileIO_Functions>
// <TCCConversion_Functions>
//
// Current Owner:
// Tamas Kis (ekistam)
//
// Last Review Date:
// -
//
// Detailed Comments:
// -
///////////////////////////////////////////////////////////
module EPTF_DsRestAPI_Test_Testcases {
//=========================================================================
// Import Part
//=========================================================================
import from EPTF_DsRestAPI_Test_Definitions all;
import from EPTF_CLL_DsRestAPI_Functions all;
import from EPTF_CLL_DsRestAPI_DSServer_Functions all;
import from EPTF_CLL_DsRestAPI_Timeline_Definitions all;
import from EPTF_CLL_DsRestAPI_Timeline_Functions all;
import from EPTF_DsRestAPI_Test_Functions all;
import from EPTF_CLL_DataSource_Definitions all;
import from EPTF_CLL_DataSource_Functions all;
import from EPTF_CLL_Variable_Definitions all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_DsRestAPI_DSServer_Definitions all;
import from EPTF_CLL_Common_Definitions all;
import from TCCFileIO_Functions all;
import from TCCConversion_Functions all;
import from TCCEnv_Functions all;
//=========================================================================
// Module parameters
//=========================================================================
modulepar charstring tsp_DsRestAPI_Test_messagesDir := "JSON_reqRespSymLink";
modulepar charstring tsp_DsRestAPI_Test_sendDSRequestScript := "DsRestAPI_stdout.py";
//=========================================================================
// Functions
//=========================================================================
private external function ef_DsRestAPI_enc_ContentList(in EPTF_DsRestAPI_ContentAndChildrenListWrapper pl_par) return octetstring with { extension "prototype(convert) encode(JSON) errorbehavior(ALL:WARNING)" }
private external function ef_DsRestAPI_Test_dec_RequestList(in octetstring pl_request) return EPTF_DsRestAPI_Requests with { extension "prototype(convert) decode(JSON)" }
private external function ef_DsRestAPI_Test_enc_RequestList(in EPTF_DsRestAPI_Requests pl_request) return octetstring with { extension "prototype(convert) encode(JSON)" };
private external function ef_DsRestAPI_Test_dec_Timeline(in octetstring pl_timeline) return DsRestAPI_Test_Timeline with { extension "prototype(convert) decode(JSON)" };
//=========================================================================
// Testcases
//=========================================================================
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_init
//
// Purpose:
// to test f_EPTF_DsRestAPI_init_CT() function
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function
// - calls f_EPTF_Base_stop() function
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_init() runs on DsRestAPI_Test_CT {
f_EPTF_Base_init_CT("DsRestAPI_Test_init");
f_EPTF_DsRestAPI_init_CT("DsRestAPI_Test_init");
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_manual
//
// Purpose:
// to test f_EPTF_DsRestAPI_init_CT() function
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function
// - calls f_EPTF_Base_stop() function
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_manual() runs on DsRestAPI_Test_CT {
f_EPTF_Base_init_CT("DsRestAPI_Test_init");
f_EPTF_DsRestAPI_init_CT("DsRestAPI_Test_init");
f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort, tsp_EPTF_DsRestAPI_HTTPServer_directory, tsp_EPTF_DsRestAPI_customizableApp_directory, tsp_EPTF_DsRestAPI_API_directory);
f_EPTF_Base_wait4Shutdown();
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_JSON_encoder
//
// Purpose:,
// this testcase indicates if the TITAN built-in JSON encoder is wrong
//
// Requirement:
// -
//
// Action:
// - encodes and checks a simple request (getData) and an answer (contentList)
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_JSON_encoder() runs on DsRestAPI_Test_CT {
var EPTF_DsRestAPI_RqWrapper vl_getDataRequest := {
requests := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorEntityGroups,
params := {},
children := {},
selection := {}
}
}
}
}
var charstring vl_getDataRequestString := "{\"requests\":[{\"getData\":{\"source\":\""&c_DsRestAPI_Test_DataSource_sourceId&"\",\"element\":\""&c_DsRestAPI_Test_iteratorEntityGroups&"\",\"params\":[],\"children\":[],\"selection\":[]}}]}";
var octetstring vl_getDataRequestOct := ef_DsRestAPI_Test_enc_Requests(vl_getDataRequest);
if(char2oct(vl_getDataRequestString) != vl_getDataRequestOct){
setverdict(fail,"Encoded value: ", oct2char(vl_getDataRequestOct), " is wrong. It should be: ", vl_getDataRequestString);
f_EPTF_Base_stop(none);
}
var EPTF_DsRestAPI_ContentAndChildrenListWrapper vl_contentList := {
contentList := {
{
list := {
{ node := {val := c_DsRestAPI_Test_entityGroup_0, tp := 10} },
{ node := {val := c_DsRestAPI_Test_entityGroup_1, tp := 10} }
}
}
}
};
var charstring vl_contentListString := "{\"contentList\":[{\"list\":[{\"node\":{\"val\":\""&c_DsRestAPI_Test_entityGroup_0&"\",\"tp\":10}},{\"node\":{\"val\":\""&c_DsRestAPI_Test_entityGroup_1&"\",\"tp\":10}}]}]}";
var octetstring vl_contentListOct := ef_DsRestAPI_enc_ContentList(vl_contentList);
if(char2oct(vl_contentListString) != vl_contentListOct){
setverdict(fail,"Encoded value: ", oct2char(vl_contentListOct), " is wrong. It should be: ", vl_contentListString);
f_EPTF_Base_stop(none);
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_DSServer
//
// Purpose:
// to test DSServer functionality of DsRestAPI using the TTCN3 JSON API
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_DSServer_init_CT() function
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_DSServer() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_DSServer",self);
timer t1 := 1.0;
t1.start;
t1.timeout;
///////////////////////////////////////////
// test when the answer is a list (c_DsRestAPI_Test_iteratorEntityGroups - LEVEL 0)
///////////////////////////////////////////
var EPTF_DsRestAPI_RqWrapper vl_getDataRequest := {
requests := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorEntityGroups,
params := {},
children := {},
selection := omit
}
}
}
}
// using the Titan built-in JSON encoder via external function
var octetstring vl_getDataRequestOct := ef_DsRestAPI_Test_enc_Requests(vl_getDataRequest);
var EPTF_DsRestAPI_ContentAndChildrenListWrapper vl_expectedContentList := {
contentList := {
{
list := {
{ node := {val := c_DsRestAPI_Test_entityGroup_0, tp := 10} }, // 10:charstringlistType
{ node := {val := c_DsRestAPI_Test_entityGroup_1, tp := 10} }
}
}
}
};
// using the Titan built-in JSON encoder via external function which comes from module EPTF_CLL_DsRestAPI_DSServer_Definitions
var octetstring vl_expectedContentListOct := ef_DsRestAPI_enc_ContentList(vl_expectedContentList);
var octetstring vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processJSONRequest(vl_getDataRequestOct);
if(vl_getDataAnswer != vl_expectedContentListOct) {
setverdict(fail,"The value of the answer is wrong: ", oct2char(vl_getDataAnswer), ". It should be: ", oct2char(vl_expectedContentListOct));
f_EPTF_Base_stop(none);
}
///////////////////////////////////////////
// test when the answer is a list (c_DsRestAPI_Test_iteratorTrafficCases - LEVEL 2)
///////////////////////////////////////////
for(var integer j := 0; j < sizeof(v_DsRestAPI_Test_entityGroups); j := j + 1){
for(var integer i := 0; i < sizeof(v_DsRestAPI_Test_scenarios); i := i + 1){
vl_getDataRequest := c_empty_getDataRequest;
vl_getDataRequest := {
requests := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorTrafficCases,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := v_DsRestAPI_Test_entityGroups[j] },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := v_DsRestAPI_Test_scenarios[i] }
},
children := {},
selection := omit
}
}
}
};
vl_getDataRequestOct := ef_DsRestAPI_Test_enc_Requests(vl_getDataRequest);
vl_expectedContentList := c_empty_expectedContentList;
vl_expectedContentList := {
contentList := {
{
list := {
{ node := {val := c_DsRestAPI_Test_trafficCase_0, tp := 10} },
{ node := {val := c_DsRestAPI_Test_trafficCase_1, tp := 10} }
}
}
}
};
vl_expectedContentListOct := ef_DsRestAPI_enc_ContentList(vl_expectedContentList);
vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processJSONRequest(vl_getDataRequestOct);
if(vl_getDataAnswer != vl_expectedContentListOct) {
setverdict(fail,"The value of the answer is wrong: ", oct2char(vl_getDataAnswer), ". It should be: ", oct2char(vl_expectedContentListOct));
f_EPTF_Base_stop(none);
}
}
}
///////////////////////////////////////////
// sending one getData, answer not list (c_DsRestAPI_Test_dataElementEGrpType - LEVEL 0)
///////////////////////////////////////////
for(var integer i := 0; i < sizeof(v_DsRestAPI_Test_entityGroups); i := i + 1){
vl_getDataRequest := c_empty_getDataRequest;
vl_getDataRequest := {
requests := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementEGrpType,
params := { { paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := v_DsRestAPI_Test_entityGroups[i] } },
children := {},
selection := omit
}
}
}
};
vl_getDataRequestOct := ef_DsRestAPI_Test_enc_Requests(vl_getDataRequest);
vl_expectedContentList := c_empty_expectedContentList;
vl_expectedContentList := {
contentList := {
{
node := {val := "entityType_"&int2str(i), tp := 4} // 4:charstringType
}
}
};
vl_expectedContentListOct := ef_DsRestAPI_enc_ContentList(vl_expectedContentList);
vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processJSONRequest(vl_getDataRequestOct);
if(vl_getDataAnswer != vl_expectedContentListOct) {
setverdict(fail,"The value of the answer is wrong: ", oct2char(vl_getDataAnswer), ". It should be: ", oct2char(vl_expectedContentListOct));
f_EPTF_Base_stop(none);
}
}
///////////////////////////////////////////
// sending three getData, answer is not list
// (c_DsRestAPI_Test_dataElementEGrpType & c_DsRestAPI_Test_dataElementEGrpSize &
// c_DsRestAPI_Test_dataElementScStart & c_DsRestAPI_Test_dataElementTcStop)
///////////////////////////////////////////
for(var integer i := 0; i < sizeof(v_DsRestAPI_Test_entityGroups); i := i + 1){
for(var integer k := 0; k < sizeof(v_DsRestAPI_Test_scenarios); k := k + 1){
for(var integer j :=0; j<sizeof(v_DsRestAPI_Test_trafficCases); j:=j+1) {
vl_getDataRequest := c_empty_getDataRequest;
vl_getDataRequest := {
requests := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementEGrpType,
params := { { paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := v_DsRestAPI_Test_entityGroups[i] } },
children := {},
selection := omit
}
},
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementEGrpSize,
params := { { paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := v_DsRestAPI_Test_entityGroups[i] } },
children := {},
selection := omit
}
},
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementScStart,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := v_DsRestAPI_Test_entityGroups[i] },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := v_DsRestAPI_Test_scenarios[k] }
},
children := {},
selection := omit
}
},
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementTcStop,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := v_DsRestAPI_Test_entityGroups[i] },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := v_DsRestAPI_Test_scenarios[k] },
{ paramName := c_DsRestAPI_Test_paramNameTrafficCase, paramValue := v_DsRestAPI_Test_trafficCases[j] }
},
children := {},
selection := omit
}
}
}
};
vl_getDataRequestOct := ef_DsRestAPI_Test_enc_Requests(vl_getDataRequest);
var boolean vl_valueSc := false;
var boolean vl_valueTc := false;
if(k rem 2 == 0){
vl_valueSc := true;
}
if(j rem 2 == 0){
vl_valueTc := true;
}
vl_expectedContentList := c_empty_expectedContentList;
vl_expectedContentList := {
contentList := {
{
node := {val := "entityType_"&int2str(i), tp := 4} // 4:charstringType
},
{
node := {val := int2str(i), tp := 1} // 1:intType
},
{
node := {val := log2str(vl_valueSc), tp := 3} // 3:boolType
},
{
node := {val := log2str(vl_valueTc), tp := 3} // 3:boolType
}
}
};
vl_expectedContentListOct := ef_DsRestAPI_enc_ContentList(vl_expectedContentList);
vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processJSONRequest(vl_getDataRequestOct);
if(vl_getDataAnswer != vl_expectedContentListOct) {
setverdict(fail,"The value of the answer is wrong: ", oct2char(vl_getDataAnswer), ". It should be: ", oct2char(vl_expectedContentListOct));
f_EPTF_Base_stop(none);
}
}
}
}
///////////////////////////////////////////
// sending getData tree (list,list,list)
///////////////////////////////////////////
vl_getDataRequest := c_empty_getDataRequest;
vl_getDataRequest := {
requests := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorEntityGroups,
params := {},
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorScenarios,
params := { { paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 } },
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorTrafficCases,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := c_DsRestAPI_Test_scenario_0 }
},
children := {},
selection := omit
}
}
},
selection := omit
}
}
},
selection := omit
}
}
}
};
vl_getDataRequestOct := ef_DsRestAPI_Test_enc_Requests(vl_getDataRequest);
vl_expectedContentList := c_empty_expectedContentList;
vl_expectedContentList := {
contentList := {
{ list := {
{ node := {
val := c_DsRestAPI_Test_entityGroup_0,
tp := 10,
childVals := {
{ list := {
{ node := {
val := c_DsRestAPI_Test_scenario_0,
tp := 10,
childVals := {
{ list := {
{ node := {val := c_DsRestAPI_Test_trafficCase_0, tp := 10, childVals := omit } },
{ node := {val := c_DsRestAPI_Test_trafficCase_1, tp := 10, childVals := omit } }
}
}
}
}
},
{ node := {
val := c_DsRestAPI_Test_scenario_1,
tp := 10,
childVals := {
{ list := {
{ node := {val := c_DsRestAPI_Test_trafficCase_0, tp := 10, childVals := omit } },
{ node := {val := c_DsRestAPI_Test_trafficCase_1, tp := 10, childVals := omit } }
}
}
}
}
}
}
}
}
}
},
{ node := {
val := c_DsRestAPI_Test_entityGroup_1,
tp := 10,
childVals := {
{ list := {
{ node := {
val := c_DsRestAPI_Test_scenario_0,
tp := 10,
childVals := {
{ list := {
{ node := {val := c_DsRestAPI_Test_trafficCase_0, tp := 10, childVals := omit } },
{ node := {val := c_DsRestAPI_Test_trafficCase_1, tp := 10, childVals := omit } }
}
}
}
}
},
{ node := {
val := c_DsRestAPI_Test_scenario_1,
tp := 10,
childVals := {
{ list := {
{ node := {val := c_DsRestAPI_Test_trafficCase_0, tp := 10, childVals := omit } },
{ node := {val := c_DsRestAPI_Test_trafficCase_1, tp := 10, childVals := omit } }
}
}
}
}
}
}
}
}
}
}
}
}
}
};
vl_expectedContentListOct := ef_DsRestAPI_enc_ContentList(vl_expectedContentList);
vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processJSONRequest(vl_getDataRequestOct);
if(vl_getDataAnswer != vl_expectedContentListOct) {
setverdict(fail,"The value of the answer is wrong: ", oct2char(vl_getDataAnswer), ". It should be: ", oct2char(vl_expectedContentListOct));
f_EPTF_Base_stop(none);
}
///////////////////////////////////////////
// sending getData tree (list,list,node,list)
///////////////////////////////////////////
vl_getDataRequest := c_empty_getDataRequest;
vl_getDataRequest := {
requests := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorEntityGroups,
params := {},
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorScenarios,
params := { { paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 } },
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementScStart,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := c_DsRestAPI_Test_scenario_0 }
},
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorDummy,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := c_DsRestAPI_Test_scenario_0 }
},
children := {},
selection := omit
}
}
},
selection := omit
}
}
},
selection := omit
}
}
},
selection := omit
}
}
}
};
vl_getDataRequestOct := ef_DsRestAPI_Test_enc_Requests(vl_getDataRequest);
vl_expectedContentList := c_empty_expectedContentList;
vl_expectedContentList := {
contentList := {
{
list := {
{
node := {
val := "EntityGroup_0",
tp := 10,
childVals := {
{
list := {
{
node := {
val := "Scenario_0",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
},
{
node := {
val := "Scenario_1",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
{
node := {
val := "EntityGroup_1",
tp := 10,
childVals := {
{
list := {
{
node := {
val := "Scenario_0",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
},
{
node := {
val := "Scenario_1",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
};
vl_expectedContentListOct := ef_DsRestAPI_enc_ContentList(vl_expectedContentList);
vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processJSONRequest(vl_getDataRequestOct);
if(vl_getDataAnswer != vl_expectedContentListOct) {
setverdict(fail,"The value of the answer is wrong: ", oct2char(vl_getDataAnswer), ". It should be: ", oct2char(vl_expectedContentListOct));
f_EPTF_Base_stop(none);
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_DSServer
//
// Purpose:
// to test DSServer functionality of DsRestAPI using the TTCN3 API
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_DSServer_init_CT() function
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_DSServer_TTCNFunction() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_DSServer",self);
timer t1 := 1.0;
t1.start;
t1.timeout;
var EPTF_DsRestAPI_Requests vl_getDataRequest := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorEntityGroups,
params := {},
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorScenarios,
params := { { paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 } },
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementScStart,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := c_DsRestAPI_Test_scenario_0 }
},
children := {
{ getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_iteratorDummy,
params := {
{ paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 },
{ paramName := c_DsRestAPI_Test_paramNameScenario, paramValue := c_DsRestAPI_Test_scenario_0 }
},
children := {}
}
}
}
}
}
}
}
}
}
}
}
};
// encode and decode the request so Titan fills in the omits :)
vl_getDataRequest := ef_DsRestAPI_Test_dec_RequestList(ef_DsRestAPI_Test_enc_RequestList(vl_getDataRequest));
var EPTF_DsRestAPI_ContentList vl_expectedContentList := {
{
list := {
{
node := {
val := "EntityGroup_0",
tp := 10,
childVals := {
{
list := {
{
node := {
val := "Scenario_0",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
},
{
node := {
val := "Scenario_1",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
}
}
}
}
}
},
{
node := {
val := "EntityGroup_1",
tp := 10,
childVals := {
{
list := {
{
node := {
val := "Scenario_0",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
},
{
node := {
val := "Scenario_1",
tp := 10,
childVals := {
{
node := {
val := "true",
tp := 3,
childVals := {
{
list := {
{
node := {
val := "Dummy_0",
tp := 10,
childVals := omit
}
},
{
node := {
val := "Dummy_1",
tp := 10,
childVals := omit
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
};
var EPTF_DsRestAPI_ContentList vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processRequest(vl_getDataRequest);
if(vl_getDataAnswer != vl_expectedContentList) {
setverdict(fail,"The value of the answer is wrong: ", log2str(vl_getDataAnswer), ". It should be: ", log2str(vl_expectedContentList));
f_EPTF_Base_stop(none);
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_DSServer_JSON
//
// Purpose:
// to test DSServer functionality of DsRestAPI using JSON strings
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_DSServer_init_CT() function
// - it reads the content of the directory defined by tsp_DsRestAPI_Test_messagesDir in order to have request/response in JSON string format
// - it creates getData requests from the JSON strings and then sends them to DataSource
// - compares the response with the expected JSON string
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_DSServer_JSON() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_DSServer_JSON",self);
timer t1 := 1.0;
t1.start;
t1.timeout;
var DsRestAPI_Test_reqRespList vl_reqRespList := {};
const charstring vl_reqPostfix := ".request";
const charstring vl_respPostfix := ".response";
// check and get the content of the directory
if(f_FIO_fileOrDirExists(tsp_DsRestAPI_Test_messagesDir)){
var EPTF_CharstringList vl_contentOfDir := {};
vl_contentOfDir := ef_EPTF_DsRestAPI_Test_getDirContent(tsp_DsRestAPI_Test_messagesDir);
var integer vl_contentOfDirSize := sizeof(vl_contentOfDir);
// get requests
var EPTF_CharstringList vl_requests := {};
for(var integer i := 0; i < vl_contentOfDirSize; i := i + 1){
if(lengthof(regexp(vl_contentOfDir[i], "((*)("&vl_reqPostfix&"))",0)) > 0){
vl_requests[sizeof(vl_requests)] := vl_contentOfDir[i];
}
}
// get corresponding responses
for(var integer i := 0; i < sizeof(vl_requests); i := i + 1){
var charstring vl_prefix := regexp(vl_requests[i], "(*)("&vl_reqPostfix&")",0);
for(var integer j := 0; j < vl_contentOfDirSize; j := j + 1){
if(vl_contentOfDir[j] == vl_prefix&vl_respPostfix){
vl_reqRespList[sizeof(vl_reqRespList)] := {
requestFileName := vl_requests[i],
responseFileName := vl_contentOfDir[j]
}
}
}
}
if(sizeof(vl_reqRespList) > 0){
// send requests and check asnwers based on the expected responses
for(var integer i := 0; i < sizeof(vl_reqRespList); i := i + 1){
f_EPTF_DsRestAPI_Test_getDSfromFile();
// whole string what is read from the file
var charstring vl_requestFileContent := f_EPTF_DsRestAPI_Test_getFileContent(tsp_DsRestAPI_Test_messagesDir&"/"&vl_reqRespList[i].requestFileName);
var charstring vl_responseFileContent := f_EPTF_DsRestAPI_Test_getFileContent(tsp_DsRestAPI_Test_messagesDir&"/"&vl_reqRespList[i].responseFileName);
// java script objects in string
var charstring vl_requestString := ef_EPTF_DsRestAPI_Test_getJSON(vl_requestFileContent);
var charstring vl_responseString := ef_EPTF_DsRestAPI_Test_getJSON(vl_responseFileContent);
// octetstrings
var octetstring vl_requestOct := char2oct(vl_requestString);
var octetstring vl_responseStringOct := char2oct(vl_responseString);
// decode then encode the expected response octetstring in order to have the same format what the getData answer has
var EPTF_DsRestAPI_ContentAndChildrenListWrapper vl_decodedResponse := ef_DsRestAPI_Test_dec_ContentList(vl_responseStringOct);
var octetstring vl_responseOct := ef_DsRestAPI_enc_ContentList(vl_decodedResponse);
if(vl_requestOct != ''O and vl_responseOct != ''O){
var octetstring vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processJSONRequest(vl_requestOct);
if(vl_responseOct != vl_getDataAnswer) {
setverdict(fail, vl_reqRespList[i].responseFileName & ": The value of the answer is wrong: ", oct2char(vl_getDataAnswer), ". It should be: ", oct2char(vl_responseOct));
f_EPTF_Base_stop(none);
}
}
}
}else{
setverdict(inconc,"There is not any request/response in directory: ",tsp_DsRestAPI_Test_messagesDir);
f_EPTF_Base_stop(none);
}
}else{
setverdict(inconc,"The directory does not exist: ", tsp_DsRestAPI_Test_messagesDir);
f_EPTF_Base_stop(none);
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_DSServer_JSONviaHTTP
//
// Purpose:
// to test DSServer functionality of DsRestAPI sending JSON strings via HTTP
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_DSServer_init_CT() function
// - it reads the content of the directory defined by tsp_DsRestAPI_Test_messagesDir in order to have request/response in JSON string format
// - it creates getData requests from the JSON strings and then sends them to HTTP server of DsRestAPI
// - compares the response with the expected JSON string
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_DSServer_JSONviaHTTP() runs on DsRestAPI_Test_CT {
f_PutEnv("PYTHONDONTWRITEBYTECODE", "True");
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_DSServer_JSON"); // component name should be the same as in tc_EPTF_DsRestAPI_Test_DSServer_JSON, because response contains PTC name
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_DSServer_JSON",self);
f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort);
timer t1 := 1.0;
t1.start;
t1.timeout;
var DsRestAPI_Test_reqRespList vl_reqRespList := {};
const charstring vl_reqPostfix := ".request";
const charstring vl_respPostfix := ".response";
// check and get the content of the directory
if(f_FIO_fileOrDirExists(tsp_DsRestAPI_Test_messagesDir)){
var EPTF_CharstringList vl_contentOfDir := {};
vl_contentOfDir := ef_EPTF_DsRestAPI_Test_getDirContent(tsp_DsRestAPI_Test_messagesDir);
var integer vl_contentOfDirSize := sizeof(vl_contentOfDir);
// get requests
var EPTF_CharstringList vl_requests := {};
for(var integer i := 0; i < vl_contentOfDirSize; i := i + 1){
if(lengthof(regexp(vl_contentOfDir[i], "((*)("&vl_reqPostfix&"))",0)) > 0){
vl_requests[sizeof(vl_requests)] := vl_contentOfDir[i];
}
}
// get corresponding responses
for(var integer i := 0; i < sizeof(vl_requests); i := i + 1){
var charstring vl_prefix := regexp(vl_requests[i], "(*)("&vl_reqPostfix&")",0);
for(var integer j := 0; j < vl_contentOfDirSize; j := j + 1){
if(vl_contentOfDir[j] == vl_prefix&vl_respPostfix){
vl_reqRespList[sizeof(vl_reqRespList)] := {
requestFileName := vl_requests[i],
responseFileName := vl_contentOfDir[j]
}
}
}
}
if(sizeof(vl_reqRespList) > 0){
// send requests and check asnwers based on the expected responses
for(var integer i := 0; i < sizeof(vl_reqRespList); i := i + 1){
f_EPTF_DsRestAPI_Test_getDSfromFile();
// whole string what is read from the file
var charstring vl_requestFileContent := f_EPTF_DsRestAPI_Test_getFileContent(tsp_DsRestAPI_Test_messagesDir&"/"&vl_reqRespList[i].requestFileName);
var charstring vl_responseFileContent := f_EPTF_DsRestAPI_Test_getFileContent(tsp_DsRestAPI_Test_messagesDir&"/"&vl_reqRespList[i].responseFileName);
// java script objects in string
var charstring vl_requestString := ef_EPTF_DsRestAPI_Test_getJSON(vl_requestFileContent);
var charstring vl_responseString := ef_EPTF_DsRestAPI_Test_getJSON(vl_responseFileContent);
// decode then encode the expected response string
var EPTF_DsRestAPI_ContentAndChildrenListWrapper vl_decodedResponse := ef_DsRestAPI_Test_dec_ContentList(char2oct(vl_responseString));
var charstring vl_encodedResponseString := oct2char(ef_DsRestAPI_enc_ContentList(vl_decodedResponse));
// create then execute command
var charstring vl_commandToExecute := "./"&tsp_DsRestAPI_Test_sendDSRequestScript&" "&int2str(tsp_EPTF_DsRestAPI_HTTPServer_RemotePort)&" '"&vl_requestString&"'";
var charstring vl_stdout := "";
var charstring vl_stderr := "";
if(f_EPTF_Base_executeShell(vl_commandToExecute, vl_stdout, vl_stderr) != 0){
log("STD ERROR: ",vl_stderr);
}
vl_stdout := f_stripWhitespaces(vl_stdout); // remove "\n" from the end of string
if(vl_encodedResponseString != vl_stdout) {
setverdict(fail, vl_reqRespList[i].responseFileName & ": The value of the answer is wrong: ", vl_stdout, ". It should be: ", vl_encodedResponseString);
f_EPTF_Base_stop(none);
}
}
}else{
setverdict(inconc,"There is not any request/response in directory: ",tsp_DsRestAPI_Test_messagesDir);
f_EPTF_Base_stop(none);
}
}else{
setverdict(inconc,"The directory does not exist: ", tsp_DsRestAPI_Test_messagesDir);
f_EPTF_Base_stop(none);
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_symlinkCreation
//
// Purpose:
// to test runtime symlink creation functionality of DsRestAPI
//
// Requirement:
// -
//
// Action:
// - creates the user defined WebGUI directory structure
// - calls f_EPTF_DsRestAPI_init_CT() function which calls the f_EPTF_DsRestAPI_createSymlinks
// - f_EPTF_DsRestAPI_createSymlinks removes the already existing symlinks then creates new ones
// - checks whether the newly created symlinks exist and sets the verdict accordingly
// - calls f_EPTF_Base_stop which does the cleanup
// - during the cleanup the newly created symlinks are removed
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_symlinkCreation() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_symlinkCreation");
f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort, tsp_EPTF_DsRestAPI_HTTPServer_directory, tsp_EPTF_DsRestAPI_customizableApp_directory, tsp_EPTF_DsRestAPI_API_directory);
// they are the same as v_customApp_dir_symlink and v_API_dir_symlink in EPTF_DsRestAPI_CT
var charstring vl_DsRestAPI_HTTPServer_directory := tsp_EPTF_DsRestAPI_HTTPServer_directory;
if(vl_DsRestAPI_HTTPServer_directory[lengthof(vl_DsRestAPI_HTTPServer_directory)-1] != "/"){
vl_DsRestAPI_HTTPServer_directory := vl_DsRestAPI_HTTPServer_directory&"/"
}
var charstring vl_customApp_dir_symlink := vl_DsRestAPI_HTTPServer_directory&"CustomizableContent/CustomizableApp";
var charstring vl_API_dir_symlink := vl_DsRestAPI_HTTPServer_directory&"Utils/DsRestAPI";
// config is no longer linked
//var charstring vl_config_symlink := vl_DsRestAPI_HTTPServer_directory&"CustomizableContent/config.cfg";
if(not f_FIO_fileOrDirExists(vl_customApp_dir_symlink) or not f_FIO_fileOrDirExists(vl_API_dir_symlink)/* or not f_FIO_fileOrDirExists(vl_config_symlink)*/) {
setverdict(fail, "Symlinks creation was unsuccessful:\n" &
vl_customApp_dir_symlink & " " & log2str(f_FIO_fileOrDirExists(vl_customApp_dir_symlink)) & "\n" &
vl_API_dir_symlink & " " & log2str(f_FIO_fileOrDirExists(vl_API_dir_symlink))/* & "\n" &
vl_config_symlink & " " & log2str(f_FIO_fileOrDirExists(vl_config_symlink))*/
);
f_EPTF_Base_stop(none);
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_emptySymlinkCreation
//
// Purpose:
// to test runtime symlink creation functionality of DsRestAPI when symlinks do not have to be created
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function which calls the f_EPTF_DsRestAPI_createSymlinks
// - calls f_EPTF_DsRestAPI_start() function
// - calls f_EPTF_Base_stop which does the cleanup
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_emptySymlinkCreation() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_symlinkCreation");
f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort);
timer t_wait := 1.0;
t_wait.start;
t_wait.timeout;
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_TimelineCollect
//
// Purpose:
// to test the DsRestAPI timeline collection
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function
// - calls f_EPTF_DsRestAPI_start() function
// - calls f_EPTF_DsRestAPI_Timeline_start() function
// - calls f_EPTF_Base_stop which does the cleanup
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_TimelineCollectAndClear() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect", self);
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect");
if (0 != f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort)) {
setverdict(fail, "Failed to start DsRestAPI");
f_EPTF_Base_stop(none);
}
// wait for dummy DS and DsRestAPI to start
timer t_wait := 1.0;
t_wait.start;
t_wait.timeout;
f_EPTF_DsRestAPI_Timeline_start();
// this will start collecting the entity size of EntityGroup_0 (and return an empty timeline)
f_EPTF_DataSource_getDataValue_nonblocking(
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
// wait for some time
timer t_wait4collection := 7.0;
t_wait4collection.start;
t_wait4collection.timeout;
var EPTF_Var_DirectContent vl_content := {intVal := 5};
f_EPTF_DataSource_setDataValue_nonblocking(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Test_DataSource_sourceId,
pl_element := c_DsRestAPI_Test_dataElementEGrpSize,
pl_params := {{c_DsRestAPI_Test_paramNameEntityGroup, c_DsRestAPI_Test_entityGroup_0}}
);
// wait for some time
t_wait4collection.start;
t_wait4collection.timeout;
// this will now return the timeline
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
if (ischosen(vl_content.charstringVal)) {
var DsRestAPI_Test_Timeline vl_timeline := ef_DsRestAPI_Test_dec_Timeline(char2oct(vl_content.charstringVal));
if (sizeof(vl_timeline.x) == sizeof(vl_timeline.y) and sizeof(vl_timeline.x) > 1 and vl_timeline.tp == 1) {
if (str2int(vl_timeline.y[0]) == 0 and str2int(vl_timeline.y[sizeof(vl_timeline.y) - 1]) == 5) {
setverdict(pass);
} else {
setverdict(fail, "Returned timeline is wrong, the first element should be 0, and the last one should be 5, but it is: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, tp != 1, or size of x and y are not equal or they are empty: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, it is not a JSON string: " & log2str(vl_content));
}
// Clear timeline and test if it is empty.
vl_content := {intVal := 1};
f_EPTF_DataSource_setDataValue_nonblocking(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementClear
);
// Check if it is not running
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementRunning
);
if (vl_content != {boolVal := false}) {
setverdict(fail, "Timeline should not be running after being cleared.");
f_EPTF_Base_stop(none);
}
// Check if the timeline is now empty
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
if (ischosen(vl_content.charstringVal)) {
var DsRestAPI_Test_Timeline vl_timeline := ef_DsRestAPI_Test_dec_Timeline(char2oct(vl_content.charstringVal));
if (sizeof(vl_timeline.x) == sizeof(vl_timeline.y) and sizeof(vl_timeline.x) == 0) {
setverdict(pass);
} else {
setverdict(fail, "Returned timeline is wrong, size of x and y are not 0: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, it is not a JSON string: " & log2str(vl_content));
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_TimelineAppend
//
// Purpose:
// to test the DsRestAPI timeline append from file
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function
// - calls f_EPTF_DsRestAPI_start() function with symlink creation which also loads the TimelineRequest.json
// - calls f_EPTF_DsRestAPI_Timeline_start() function
// - calls f_EPTF_Base_stop which does the cleanup
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_TimelineAppendAndCollect() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect", self);
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect");
if (0 != f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort, tsp_EPTF_DsRestAPI_HTTPServer_directory, tsp_EPTF_DsRestAPI_customizableApp_directory, tsp_EPTF_DsRestAPI_API_directory)) {
setverdict(fail, "Failed to start DsRestAPI");
f_EPTF_Base_stop(none);
}
// wait for dummy DS and DsRestAPI to start
timer t_wait := 1.0;
t_wait.start;
t_wait.timeout;
// timeline will now start collecting the egrpsize of egrp_0
f_EPTF_DsRestAPI_Timeline_start();
// wait for some time
timer t_wait4collection := 7.0;
t_wait4collection.start;
t_wait4collection.timeout;
var EPTF_Var_DirectContent vl_content := {intVal := 5};
f_EPTF_DataSource_setDataValue_nonblocking(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Test_DataSource_sourceId,
pl_element := c_DsRestAPI_Test_dataElementEGrpSize,
pl_params := {{c_DsRestAPI_Test_paramNameEntityGroup, c_DsRestAPI_Test_entityGroup_0}}
);
// wait for some time
t_wait4collection.start;
t_wait4collection.timeout;
// this will now return the timeline
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
if (ischosen(vl_content.charstringVal)) {
var DsRestAPI_Test_Timeline vl_timeline := ef_DsRestAPI_Test_dec_Timeline(char2oct(vl_content.charstringVal));
if (sizeof(vl_timeline.x) == sizeof(vl_timeline.y) and sizeof(vl_timeline.x) > 1 and vl_timeline.tp == 1) {
if (str2int(vl_timeline.y[0]) == 0 and str2int(vl_timeline.y[sizeof(vl_timeline.y) - 1]) == 5) {
setverdict(pass);
} else {
setverdict(fail, "Returned timeline is wrong, the first element should be 0, and the last one should be 5, but it is: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, tp != 1, or size of x and y are not equal or they are empty: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, it is not a JSON string: " & log2str(vl_content));
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_TimelineMaxpoints
//
// Purpose:
// to test the DsRestAPI timeline collection with maxpoints set
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function
// - calls f_EPTF_DsRestAPI_start() function
// - calls f_EPTF_DsRestAPI_Timeline_start() function
// - calls f_EPTF_Base_stop which does the cleanup
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_TimelineMaxpoints() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect", self);
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect");
if (0 != f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort)) {
setverdict(fail, "Failed to start DsRestAPI");
f_EPTF_Base_stop(none);
}
// wait for dummy DS and DsRestAPI to start
timer t_wait := 1.0;
t_wait.start;
t_wait.timeout;
f_EPTF_DsRestAPI_Timeline_start();
// this will start collecting the entity size of EntityGroup_0 (and return an empty timeline)
f_EPTF_DataSource_getDataValue_nonblocking(
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_DsRestAPI_Timeline_paramNamePeriod, "1.0"},
{c_DsRestAPI_Timeline_paramNameMaxpoints, "1"},
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
// this will start collecting the entity size of EntityGroup_0 with different maxpoints (and return an empty timeline)
f_EPTF_DataSource_getDataValue_nonblocking(
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_DsRestAPI_Timeline_paramNamePeriod, "0.01"},
{c_DsRestAPI_Timeline_paramNameMaxpoints, "0"},
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
// wait for some time
timer t_wait4collection := 7.0;
t_wait4collection.start;
t_wait4collection.timeout;
// this will now return the timeline
var EPTF_Var_DirectContent vl_content;
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_DsRestAPI_Timeline_paramNamePeriod, "1.0"},
{c_DsRestAPI_Timeline_paramNameMaxpoints, "1"},
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
if (ischosen(vl_content.charstringVal)) {
var DsRestAPI_Test_Timeline vl_timeline := ef_DsRestAPI_Test_dec_Timeline(char2oct(vl_content.charstringVal));
if (sizeof(vl_timeline.x) == sizeof(vl_timeline.y) and sizeof(vl_timeline.x) == 1 and vl_timeline.tp == 1) {
if (str2int(vl_timeline.y[0]) == 0) {
setverdict(pass);
} else {
setverdict(fail, "Returned timeline is wrong, the first element should be 0, but it is: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, tp != 1, or size of x and y are not 1: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, it is not a JSON string: " & log2str(vl_content));
}
// this will now return the timeline with maxpoints = 0
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementTimeline,
pl_params := {
{c_DsRestAPI_Timeline_paramNamePeriod, "0.01"},
{c_DsRestAPI_Timeline_paramNameMaxpoints, "0"},
{c_EPTF_DataSource_paramNameSource, c_DsRestAPI_Test_DataSource_sourceId},
{c_EPTF_DataSource_paramNameElement, c_DsRestAPI_Test_dataElementEGrpSize},
{c_EPTF_DataSource_paramNameParamName, c_DsRestAPI_Test_paramNameEntityGroup},
{c_EPTF_DataSource_paramNameParamValue, c_DsRestAPI_Test_entityGroup_0}
}
);
if (ischosen(vl_content.charstringVal)) {
var DsRestAPI_Test_Timeline vl_timeline := ef_DsRestAPI_Test_dec_Timeline(char2oct(vl_content.charstringVal));
if (sizeof(vl_timeline.x) == sizeof(vl_timeline.y) and sizeof(vl_timeline.x) > c_DsRestAPI_Timeline_maxpoints and vl_timeline.tp == 1) {
if (str2int(vl_timeline.y[0]) == 0) {
setverdict(pass);
} else {
setverdict(fail, "Returned timeline is wrong, the first element should be 0, but it is: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, tp != 1, or size of x and y are not > " & int2str(c_DsRestAPI_Timeline_maxpoints) & ": " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, it is not a JSON string: " & log2str(vl_content));
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_TimelineStart
//
// Purpose:
// to test the DsRestAPI timeline start / stop / running
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function
// - calls f_EPTF_DsRestAPI_start() function
// - calls f_EPTF_DsRestAPI_Timeline_start() function
// - calls f_EPTF_Base_stop which does the cleanup
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_TimelineStart() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect", self);
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect");
if (0 != f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort)) {
setverdict(fail, "Failed to start DsRestAPI");
f_EPTF_Base_stop(none);
}
// wait for dummy DS and DsRestAPI to start
timer t_wait := 1.0;
t_wait.start;
t_wait.timeout;
var EPTF_Var_DirectContent vl_content;
// Check if timeline is not running by default.
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementRunning
);
if (vl_content != {boolVal := false}) {
setverdict(fail, "Timeline should not be running without calling f_EPTF_DsRestAPI_Timeline_start.");
f_EPTF_Base_stop(none);
}
// Start timeline
f_EPTF_DsRestAPI_Timeline_start();
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementRunning
);
if (vl_content != {boolVal := true}) {
setverdict(fail, "Timeline should be running after calling f_EPTF_DsRestAPI_Timeline_start.");
f_EPTF_Base_stop(none);
}
// Stop timeline
vl_content := {boolVal := false};
f_EPTF_DataSource_setDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementRunning
);
f_EPTF_DataSource_getDataValue(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Timeline_DataSource_sourceId,
pl_element := c_DsRestAPI_Timeline_dataElementRunning
);
if (vl_content != {boolVal := false}) {
setverdict(fail, "Timeline should not be running after being stopped.");
f_EPTF_Base_stop(none);
}
f_EPTF_Base_stop(pass);
}
///////////////////////////////////////////////////////////
// Testcase: tc_EPTF_DsRestAPI_Test_TimelineWithDsRestAPI
//
// Purpose:
// to test the DsRestAPI timeline with JSON requests
//
// Requirement:
// -
//
// Action:
// - calls f_EPTF_DsRestAPI_init_CT() function
// - calls f_EPTF_DsRestAPI_start() function with symlink creation which also loads the TimelineRequest.json
// - calls f_EPTF_DsRestAPI_Timeline_start() function
// - calls f_EPTF_Base_stop which does the cleanup
//
// Expected Result:
// - pass
///////////////////////////////////////////////////////////
testcase tc_EPTF_DsRestAPI_Test_TimelineWithDsRestAPI() runs on DsRestAPI_Test_CT {
f_EPTF_DsRestAPI_Test_DS_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect", self);
f_EPTF_DsRestAPI_init_CT("tc_EPTF_DsRestAPI_Test_TimelineCollect");
if (0 != f_EPTF_DsRestAPI_start(tsp_EPTF_DsRestAPI_HTTPServer_RemoteAddress, tsp_EPTF_DsRestAPI_HTTPServer_RemotePort, tsp_EPTF_DsRestAPI_HTTPServer_directory, tsp_EPTF_DsRestAPI_customizableApp_directory, tsp_EPTF_DsRestAPI_API_directory)) {
setverdict(fail, "Failed to start DsRestAPI");
f_EPTF_Base_stop(none);
}
// wait for dummy DS and DsRestAPI to start
timer t_wait := 1.0;
t_wait.start;
t_wait.timeout;
// timeline will now start collecting the egrpsize of egrp_0
f_EPTF_DsRestAPI_Timeline_start();
// wait for some time
timer t_wait4collection := 7.0;
t_wait4collection.start;
t_wait4collection.timeout;
var EPTF_Var_DirectContent vl_content := {intVal := 5};
f_EPTF_DataSource_setDataValue_nonblocking(
pl_dataValue := vl_content,
pl_source := c_DsRestAPI_Test_DataSource_sourceId,
pl_element := c_DsRestAPI_Test_dataElementEGrpSize,
pl_params := {{c_DsRestAPI_Test_paramNameEntityGroup, c_DsRestAPI_Test_entityGroup_0}}
);
// wait for some time
t_wait4collection.start;
t_wait4collection.timeout;
var EPTF_DsRestAPI_Requests vl_getDataRequest := {
{
getData := {
source := c_DsRestAPI_Test_DataSource_sourceId,
element := c_DsRestAPI_Test_dataElementEGrpSize,
params := { { paramName := c_DsRestAPI_Test_paramNameEntityGroup, paramValue := c_DsRestAPI_Test_entityGroup_0 } },
// If there are no omits, JSON encode will not fill them, instead timeline will be omit
timeline := {omit, omit, omit}
}
}
};
// encode and decode the request so Titan fills in the omits :)
vl_getDataRequest := ef_DsRestAPI_Test_dec_RequestList(ef_DsRestAPI_Test_enc_RequestList(vl_getDataRequest));
var EPTF_DsRestAPI_ContentList vl_getDataAnswer := f_EPTF_DsRestAPI_DSServer_processRequest(vl_getDataRequest);
if (sizeof(vl_getDataAnswer) == 1 and ischosen(vl_getDataAnswer[0].node) and vl_getDataAnswer[0].node.tp == 4) {
var DsRestAPI_Test_Timeline vl_timeline := ef_DsRestAPI_Test_dec_Timeline(char2oct(vl_getDataAnswer[0].node.val));
if (sizeof(vl_timeline.x) == sizeof(vl_timeline.y) and sizeof(vl_timeline.x) > 1 and vl_timeline.tp == 1) {
if (str2int(vl_timeline.y[0]) == 0 and str2int(vl_timeline.y[sizeof(vl_timeline.y) - 1]) == 5) {
setverdict(pass);
} else {
setverdict(fail, "Returned timeline is wrong, the first element should be 0, and the last one should be 5, but it is: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, tp != 1, or size of x and y are not equal or they are empty: " & log2str(vl_timeline));
}
} else {
setverdict(fail, "Returned timeline is wrong, it is not a JSON string: " & log2str(vl_getDataAnswer));
}
f_EPTF_Base_stop(pass);
}
//=========================================================================
// Control
//=========================================================================
control {
execute(tc_EPTF_DsRestAPI_Test_init());
execute(tc_EPTF_DsRestAPI_Test_JSON_encoder());
execute(tc_EPTF_DsRestAPI_Test_DSServer());
execute(tc_EPTF_DsRestAPI_Test_DSServer_TTCNFunction());
execute(tc_EPTF_DsRestAPI_Test_DSServer_JSON());
execute(tc_EPTF_DsRestAPI_Test_DSServer_JSONviaHTTP());
execute(tc_EPTF_DsRestAPI_Test_symlinkCreation());
execute(tc_EPTF_DsRestAPI_Test_emptySymlinkCreation());
execute(tc_EPTF_DsRestAPI_Test_TimelineStart());
execute(tc_EPTF_DsRestAPI_Test_TimelineAppendAndCollect());
execute(tc_EPTF_DsRestAPI_Test_TimelineCollectAndClear());
execute(tc_EPTF_DsRestAPI_Test_TimelineMaxpoints());
execute(tc_EPTF_DsRestAPI_Test_TimelineWithDsRestAPI());
}
} // module