LibMec_Functions.ttcn 6.99 KB
Newer Older
Yann Garcia's avatar
Yann Garcia committed
1
2
3
4
5
module LibMec_Functions {
  
  // Libcommon
  import from LibCommon_Sync all;
  
6
7
8
9
10
11
12
13
  // LibMec
  import from LibMec_Pixits all;
  
   // LibMec_UEidentityAPI
  import from UEidentityAPI_TypesAndValues all;
  import from UEidentityAPI_Templates all;
  import from UEidentityAPI_Pixits all;
  
Yann Garcia's avatar
Yann Garcia committed
14
15
16
17
  // LibHttp
  import from LibItsHttp_TypesAndValues all;
  import from LibItsHttp_Templates all;
  import from LibItsHttp_TestSystem all;
18
19
  import from LibItsHttp_Templates all;
  import from LibItsHttp_JsonTemplates all;
Yann Garcia's avatar
Yann Garcia committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  
  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
    
  } // 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 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
    
  } // End of group postambles
  
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
  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(
                                                      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")),
                                                      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 {
          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) {
              if (v_response.response.body.json_body.ueIdentityTagInfo.ueIdentityTags[v_i].state == UNREGISTERED) {
                v_result := 0;
              } else {
                v_result := 1;
              }
              break;
            }
          }
        }
        [] tc_ac.timeout {
        }
      } // End of 'alt' statement
      
      return v_result;
    } // End of function f_check_user_register_state
    
  } // End of group helpers 
  
Yann Garcia's avatar
Yann Garcia committed
125
126
127
  group altsteps {

    altstep a_default_requests() runs on HttpComponent {
Yann Garcia's avatar
Yann Garcia committed
128
129
130
131
132
      [] httpPort.receive(mw_http_request) {
        tc_ac.stop;
        log("*** " & testcasename() & ": FAIL: Server error: Receive request istead of response ***");
        f_selfOrClientSyncAndVerdictTestBody(c_tbDone, e_error);
      }
Yann Garcia's avatar
Yann Garcia committed
133
134
135
    } // End of altstep a_default_requests
    
    altstep a_default_responses() runs on HttpComponent {
Yann Garcia's avatar
Yann Garcia committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
      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);
      }
Yann Garcia's avatar
Yann Garcia committed
178
179
180
181
182
    } // End of altstep a_default_responses
    
  } // end of group altsteps
  
} // End of module LibMec_Functions