1

I tried initially

DATA: cl_rest_bo_list TYPE REF TO zcl_rm_rest_bulk_orders.
CREATE OBJECT cl_rest_bo_list.
cl_rest_bo_list->request->if_http_request~set_method( 'GET' ).
cl_rest_bo_list->do_request( ).

This resulted into an abend, accessing request which was not initialized.

Then I tried to instantiate the request and the response

DATA: cl_rest_bo_list TYPE REF TO zcl_rm_rest_bulk_orders.
DATA: cl_request  TYPE REF TO cl_http_request.
DATA: cl_response TYPE REF TO cl_http_response.
CREATE OBJECT cl_rest_bo_list.
CREATE OBJECT cl_request.
CREATE OBJECT cl_response.
request->if_http_request~set_method( 'GET' ).
cl_rest_bo_list->request = cl_request.
cl_rest_bo_list->response = cl_response.    
cl_rest_bo_list->do_request( ).

This, at least, does not abend, but the set_method return error code here and does not actually set the method.

  system-call ict
    did
      ihttp_scid_set_request_method
    parameters
      m_c_msg                            " > c handle
      method                             " > method
      m_last_error.                      " < return code

Since Google does not know about ihttp_scid_set_request_method, I am pretty sure that I am doing this wrong. Maybe there is no provision to instantiate BSP controllers, though I am not sure what this means for ABAP Unit testing BSP controllers.

As a solution for now I have lifted all business logic into a separate method which gets called/tested without trouble. Still, if anybody knows how to instantiate CL_BSP_CONTROLLER2 classes, that would be great.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
tomdemuyt
  • 4,572
  • 2
  • 31
  • 60
  • Sorry, not clear on what you are trying to achieve. Are you trying to access a resource on the web using an http client request or are you trying to provide a service? – mydoghasworms Feb 22 '13 at 06:11
  • I am trying to access a resource straight from the BSP controller without using a http client. – tomdemuyt Feb 22 '13 at 13:33
  • OK, so based on the answer below and reading your question again, if you want to unit test your controller, the only 'interface' to it is the request you send the ICF and the response you get. That is the cleanest way to instantiate the BSP controller. (As vwegert points out, the controller receives its data from the ICF. Separating business logic out of there is a good move). So yes, you can instantiate a BSP controller by sending an HTTP request using any client, be that scripted or otherwise. Problem then is accessing the controller at runtime, but what do you hope to get out of it? – mydoghasworms Feb 22 '13 at 14:00
  • If I need to instantiate through HTTP request, then the point of accessing the controller is indeed moot. – tomdemuyt Feb 22 '13 at 14:14

1 Answers1

2

As far as I know, the BSP controller can only be instantiated from within the ICF processing because it retrieves information about the call from the kernel. I'm not sure why you would want to install unit tests for the UI in the first place, unless you didn't separate the UI and the business logic as your comment about "lifting" suggests....

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • The controller only does data in JSON format, it's more of a separation of controller and business logic. – tomdemuyt Feb 22 '13 at 13:32
  • @tomdemuyt: Then why are you using a BSP controller instead of an ICF HTTP handler class? This might save you some overhead... – vwegert Feb 22 '13 at 14:20
  • "To the man who only has a hammer, everything he encounters begins to look like a nail." Thanks for mentioning the ICF HTTP handler class. – tomdemuyt Feb 22 '13 at 15:20
  • @tomdemuyt Happy hammering day, then :-) – vwegert Feb 22 '13 at 19:09