This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/23019 ) Change subject: remsim: factor-out HTTP_Adapter.ttcn ...................................................................... remsim: factor-out HTTP_Adapter.ttcn There are other test suites (like osmo-cbc) which can reuse some of the HTTP utility code that was developed within the remsim test suite Change-Id: I87a728272d47649e4faa628fad44d6f8673c8169 --- A library/HTTP_Adapter.ttcn M remsim/RemsimServer_Tests.ttcn M remsim/gen_links.sh 3 files changed, 103 insertions(+), 82 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/19/23019/1 diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn new file mode 100644 index 0000000..a9d0d83 --- /dev/null +++ b/library/HTTP_Adapter.ttcn @@ -0,0 +1,101 @@ +module HTTP_Adapter { + +/* HTTP Adapter component, originally part of Integration Tests for osmo-remsim-server + * (C) 2019 by Harald Welte <laforge at gnumonks.org> + * All rights reserved. + * + * Released under the terms of GNU General Public License, Version 2 or + * (at your option) any later version. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This test suite tests osmo-remsim-server by attaching to the external interfaces + * such as RSPRO for simulated clients + bankds and RSRES (REST backend interface). + */ + +import from HTTPmsg_Types all; +import from HTTPmsg_PortType all; + +type component http_CT { + port HTTPmsg_PT HTTP; + var charstring g_http_host; + var integer g_http_port; +}; + +function f_http_init(charstring host, integer http_port) runs on http_CT { + map(self:HTTP, system:HTTP); + g_http_host := host; + g_http_port := http_port; +} + +template (value) Connect ts_HTTP_Connect(template (value) charstring hostname, + template (value) integer http_port := 80, + template (value) boolean use_ssl := false) := { + hostname := hostname, + portnumber := http_port, + use_ssl := use_ssl +} +template (value) Close ts_HTTP_Close := { client_id := omit }; + +template (value) HeaderLines ts_HTTP_Header(charstring body) := { + { header_name := "Content-Type", header_value := "application/json" }, + { header_name := "Content-Length", header_value := int2str(lengthof(body)) } +} + +template (value) HTTPMessage ts_HTTP_Req(charstring url, + charstring method := "GET", + charstring body := "", + integer v_maj := 1, integer v_min := 1) := { + request := { + client_id := omit, + method := method, + uri := url, + version_major := v_maj, + version_minor := v_min, + header := ts_HTTP_Header(body), + body := body + } +} + +template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := { + response := { + client_id := ?, + version_major := ?, + version_minor := ?, + statuscode := sts, + statustext := ?, + header := ?, + body := ? + } +}; + +template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299)); + +/* run a HTTP request and return the response */ +function f_http_transact(charstring url, charstring method := "GET", + charstring body := "", template HTTPMessage exp := tr_HTTP_Resp2xx) +runs on http_CT return HTTPMessage { + var HTTPMessage resp; + timer T := 2.0; + + HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port)); + //HTTP.receive(Connect_result:?); + HTTP.send(ts_HTTP_Req(url, method, body)); + T.start; + alt { + [] HTTP.receive(exp) -> value resp { + setverdict(pass); + } + [] HTTP.receive(tr_HTTP_Resp) -> value resp { + setverdict(fail, "Unexpected HTTP response ", resp); + } + [] T.timeout { + setverdict(fail, "Timeout waiting for HTTP response"); + self.stop; + } + } + HTTP.send(ts_HTTP_Close); + return resp; +} + +} diff --git a/remsim/RemsimServer_Tests.ttcn b/remsim/RemsimServer_Tests.ttcn index 1ca5ce9..fd7a1a4 100644 --- a/remsim/RemsimServer_Tests.ttcn +++ b/remsim/RemsimServer_Tests.ttcn @@ -24,90 +24,9 @@ import from HTTPmsg_Types all; import from HTTPmsg_PortType all; +import from HTTP_Adapter all; import from JSON_Types all; -type component http_CT { - port HTTPmsg_PT HTTP; - var charstring g_http_host; - var integer g_http_port; -}; - -function f_http_init(charstring host, integer http_port) runs on http_CT { - map(self:HTTP, system:HTTP); - g_http_host := host; - g_http_port := http_port; -} - -template (value) Connect ts_HTTP_Connect(template (value) charstring hostname, - template (value) integer http_port := 80, - template (value) boolean use_ssl := false) := { - hostname := hostname, - portnumber := http_port, - use_ssl := use_ssl -} -template (value) Close ts_HTTP_Close := { client_id := omit }; - -template (value) HeaderLines ts_HTTP_Header(charstring body) := { - { header_name := "Content-Type", header_value := "application/json" }, - { header_name := "Content-Length", header_value := int2str(lengthof(body)) } -} - -template (value) HTTPMessage ts_HTTP_Req(charstring url, - charstring method := "GET", - charstring body := "", - integer v_maj := 1, integer v_min := 1) := { - request := { - client_id := omit, - method := method, - uri := url, - version_major := v_maj, - version_minor := v_min, - header := ts_HTTP_Header(body), - body := body - } -} - -template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := { - response := { - client_id := ?, - version_major := ?, - version_minor := ?, - statuscode := sts, - statustext := ?, - header := ?, - body := ? - } -}; - -template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299)); - -/* run a HTTP request and return the response */ -function f_http_transact(charstring url, charstring method := "GET", - charstring body := "", template HTTPMessage exp := tr_HTTP_Resp2xx) -runs on http_CT return HTTPMessage { - var HTTPMessage resp; - timer T := 2.0; - - HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port)); - //HTTP.receive(Connect_result:?); - HTTP.send(ts_HTTP_Req(url, method, body)); - T.start; - alt { - [] HTTP.receive(exp) -> value resp { - setverdict(pass); - } - [] HTTP.receive(tr_HTTP_Resp) -> value resp { - setverdict(fail, "Unexpected HTTP response ", resp); - } - [] T.timeout { - setverdict(fail, "Timeout waiting for HTTP response"); - self.stop; - } - } - HTTP.send(ts_HTTP_Close); - return resp; -} - /* run a HTTP GET on specified URL expecting json in RSRES format as response */ function f_rsres_get(charstring url, template integer exp_sts := 200) runs on http_CT return JsRoot { diff --git a/remsim/gen_links.sh b/remsim/gen_links.sh index 995abfb..b25375b 100755 --- a/remsim/gen_links.sh +++ b/remsim/gen_links.sh @@ -42,6 +42,7 @@ FILES+="IPA_Types.ttcn IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn IPA_CodecPort_CtrlFunctDef.cc IPA_Emulation.ttcnpp IPA_CodecPort.ttcn " #RSL_Types.ttcn RSL_Emulation.ttcn " FILES+="Osmocom_CTRL_Types.ttcn Osmocom_CTRL_Functions.ttcn Osmocom_CTRL_Adapter.ttcn " FILES+="Native_Functions.ttcn Native_FunctionDefs.cc " +FILES+="HTTP_Adapter.ttcn " FILES+="VPCD_Types.ttcn VPCD_CodecPort.ttcn VPCD_CodecPort_CtrlFunct.ttcn VPCD_CodecPort_CtrlFunctDef.cc VPCD_Adapter.ttcn " gen_links $DIR $FILES -- To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/23019 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ttcn3-hacks Gerrit-Branch: master Gerrit-Change-Id: I87a728272d47649e4faa628fad44d6f8673c8169 Gerrit-Change-Number: 23019 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge at osmocom.org> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210222/fdc35044/attachment.htm>