Uploaded image for project: 'Byteman'
  1. Byteman
  2. BYTEMAN-440

Unable to modify the return types properties for complex return types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • Samples
    • Hide

      Running this rule to modify return property did not work as expected to modify the properties of the return type.

      a.btm:

      IMPORT org.springframework.http.ResponseEntity
      IMPORT org.springframework.hateoas.Resource
      IMPORT org.springframework.hateoas.Resources
      IMPORT org.springframework.http.HttpStatus
      IMPORT com.vmware.mangle.mysql.model.security.User
       
      RULE a
      CLASS com.vmware.mangle.services.controller.UserManagementController
      METHOD getCurrentUser
      AT EXIT
      IF TRUE
      DO
      ResponseEntity<Resource<User>> responseEntity = $!;
      HttpStatus httpStatus = responseEntity.getStatusCode();
       
      if (httpStatus == HttpStatus.OK)

      { ResponseEntity<Resource<User>> newResponseEntity = new ResponseEntity<>(responseEntity.getBody(), HttpStatus.BAD_REQUEST); $! = newResponseEntity; }

      ENDRULE

      Show
      Running this rule to modify return property did not work as expected to modify the properties of the return type. a.btm: IMPORT org.springframework.http.ResponseEntity IMPORT org.springframework.hateoas.Resource IMPORT org.springframework.hateoas.Resources IMPORT org.springframework.http.HttpStatus IMPORT com.vmware.mangle.mysql.model.security.User   RULE a CLASS com.vmware.mangle.services.controller.UserManagementController METHOD getCurrentUser AT EXIT IF TRUE DO ResponseEntity<Resource<User>> responseEntity = $!; HttpStatus httpStatus = responseEntity.getStatusCode();   if (httpStatus == HttpStatus.OK) { ResponseEntity<Resource<User>> newResponseEntity = new ResponseEntity<>(responseEntity.getBody(), HttpStatus.BAD_REQUEST); $! = newResponseEntity; } ENDRULE
    • Compatibility/Configuration
    • Medium

      I'm able to modify return type properties at runtime for primitive types and also direct pojo classes.
      Working return types:
      Method that returns types given below are working as expected.
      primitives: boolean, string, integer
      pojo
      public class Test

      { private Integer id; private String text; private Boolean type; }

      a.btm:
      RULE a
      CLASS com.test.ClassA
      METHOD methodOne
      AT EXIT
      IF true
      DO
      <RULE ACTION> // 3 rule actions that's working as expecting
      ENDRULE

      Rule actions working for below 3 return types:
      $!="manipulatedString"; // if method returns string type with value "string", this rule will modify to manipulatedString 
                          (OR)
      $!=5; // if method returns integer type with value in "2", this rule will modify to 5 
      ENDRULE                    (OR)

      $!.setId(100);
      $!.setText("modifiedText");
      $!.setType(true);  // if method returns type of class Test with value in {"id": 1, "text": "originalText", "type": false}, this rule will modify to {"id": 100, "text": "modifiedText", "type": true}, 

      However, the same rule convention is not working for complex return types ie. ResponseEntity<Resource<User>> where the expectation is change one of the properties of ResponseEntity Or Resource Or User.
      a.btm:

      IMPORT org.springframework.http.ResponseEntity
      IMPORT org.springframework.hateoas.Resource
      IMPORT org.springframework.hateoas.Resources
      IMPORT org.springframework.http.HttpStatus
      IMPORT com.vmware.mangle.mysql.model.security.User
       
      RULE a
      CLASS com.vmware.mangle.services.controller.UserManagementController
      METHOD getCurrentUser
      AT EXIT
      IF TRUE
      DO
      ResponseEntity<Resource<User>> responseEntity = $!;
      HttpStatus httpStatus = responseEntity.getStatusCode();
       
      if (httpStatus == HttpStatus.OK)

      { ResponseEntity<Resource<User>> newResponseEntity = new ResponseEntity<>(responseEntity.getBody(), HttpStatus.BAD_REQUEST); $! = newResponseEntity; }

      ENDRULE

              rhn-engineering-adinn Andrew Dinn
              prathibavk Prathiba V K (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated: