LibMec_Functions.ttcn 4.14 KB
Newer Older
Yann Garcia's avatar
Yann Garcia committed
module LibMec_Functions {
  
  // Libcommon
  import from LibCommon_Time all;
  import from LibCommon_VerdictControl all;
  import from LibCommon_Sync all;
  
  // LibHttp
  import from LibItsHttp_TypesAndValues all;
  import from LibItsHttp_Templates all;
  import from LibItsHttp_TestSystem 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
    
  } // 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
  
  group altsteps {

    altstep a_default_requests() runs on HttpComponent {
      [] 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
    } // End of altstep a_default_requests
    
    altstep a_default_responses() runs on HttpComponent {
      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
    } // End of altstep a_default_responses
    
  } // end of group altsteps
  
} // End of module LibMec_Functions