GithubHelp home page GithubHelp logo

Comments (10)

authorjapps avatar authorjapps commented on July 29, 2024 1

Hello @chemckenna , Can you put the entire Scenario file or content here to have a look?

Is it possible to push the JSON scenario to a github repo ?

or

Do a fork of this repo and create a branch, then push this scenario to a Kafka integration-testing module "kafka-testing" ?

"kafka-testing/src/test/resources/kafka/more"

from zerocode.

chemckenna avatar chemckenna commented on July 29, 2024 1

Hi again @authorjapps . Thanks for your help here.

I've tried out your suggestion and it does move things along.

Using

      body:
        user_identifiers:
          - ${$.create_user.response.body.uid}

I get the following result:

  "body" : {
    "user_identifiers" : [ "1000331006" ]
  }

while using your suggestion:

      body:
        user_identifiers:
          - (int)${$.create_user.response.body.uid}

I get:

  "body" : {
    "user_identifiers" : 1000331005
  }

where I no longer have an array (which I need).

I'll play around with it to see if I can get it to work as I need it to and report back.

from zerocode.

nirmalchandra avatar nirmalchandra commented on July 29, 2024 1

I am picking this, will get the PR out soon I can.

from zerocode.

chemckenna avatar chemckenna commented on July 29, 2024

Hi @authorjapps - thanks for getting back to me.

Is this useful?

---
scenarioName: GIVEN- the /usermgmt/v1/user endpoint, WHEN- I invoke POST requests to create users and user groups,
  THEN- I will receive a 200 / 201 responses and add the user to a user group.
ignoreStepFailures: true
steps:
  # Use Stepfile to complete Authorisation.
  - stepFile: "${JSON.FILE:reusable_content/stepfiles/get_authorisation.json}"

  - name: create_user
    url: "${restful.authentication.endpoint.host}/usermgmt/v1/user"
    method: POST
    request:
      headers:
        Authorization: "${token_response}"
      body:
        username: add_user_to_user_group_user
        internal_user: false
        displayName: add_user_to_user_group user
        authenticator: default
        user_roles:
          - User
    verify:
      status: 201
      body:
        uid: "$NOT.NULL"
        message: "success"

  - name: check_user_details
    url: "${restful.authentication.endpoint.host}/usermgmt/v1/user/add_user_to_user_group_user"
    method: GET
    request:
      headers:
        Authorization: "${token_response}"
      body:
        username: add_user_to_user_group_user
        internal_user: false
        displayName: add_user_to_user_group user
        authenticator: default
        user_roles:
          - User
    verify:
      status: 200
      body:
        uid: ${$.create_user.response.body.uid}
        username: add_user_to_user_group_user
        user_roles:
          - user_role
        role: User

  - name: create_user_group
    url: "${restful.authentication.endpoint.host}/usermgmt/v2/groups"
    method: POST
    request:
      headers:
        Authorization: "${token_response}"
      body:
        name: add_user_to_user_group_group
        description: add_user_to_user_group group
        account_id: 1
        role_identifiers:
          - admin
    verify:
      status: 201
      body:
        group_id: "$NOT.NULL"
        name: add_user_to_user_group_group
        description: add_user_to_user_group group
        created_by: admin
        message: Created

  - name: add_user_to_user_group_step
    url: "${restful.authentication.endpoint.host}/usermgmt/v2/groups/${$.create_user_group.response.body.group_id}/members"
    method: POST
    request:
      headers:
        Authorization: "${token_response}"
        Content-Type: application/json
      body:
        user_identifiers:
          - ${$.create_user.response.status}
    verify:
      status: 200
      body:
        group_id: ${$.create_user_group.response.body.group_id}
        message: success

where I end up sending the following payload for test step add_user_to_user_group_step:

"body" : {
    "user_identifiers" : [ "201" ]
  }

If I use some custom code where I know I return an integer, I also see the array entry as a string.

  - name: convertStringToInteger
    url: abc.xyz.abc.convertstringtoint.ConvertStringToInt
    method: convertToInt
    request: "${$.create_user.response.body.uid}"
    verify: "$NOT.NULL"

and replace ${$.create_user.response.status} with ${$.convertStringToInteger.response} in test step add_user_to_user_group_step, I get:

  "body" : {
    "user_identifiers" : [ "1000330999" ]
  }

Thanks.

from zerocode.

authorjapps avatar authorjapps commented on July 29, 2024

Hello @chemckenna,
I thought the below type-cast would have helped. Give it a try.
This might have been already mentioned in the documentation/Wiki pages somewhere for sure.
Please let me know if it is missing, I will try to add it, probably make it more searchable.
Raised #569 to address the doc requirement.

"anyField" : "${$.create_user.response.status}" <--- Always gives a String

and

"anyField" : "(int)${$.create_user.response.status}" <--- Gives an Integer

Also, is it possible to put a JSON equivalent of your Test Scenario for readability purposes instead of YML?

from zerocode.

chemckenna avatar chemckenna commented on July 29, 2024

Using

      body:
        {
          "user_identifiers": [
            "(int)${$.create_user.response.body.uid}"
          ]
        }

results in the same:

  "body" : {
    "user_identifiers" : 1000331010
  }

while

      body:
        {
          "user_identifiers": [
            (int)${$.create_user.response.body.uid}
          ]
        }

not unexpectedly gives:

com.fasterxml.jackson.databind.JsonMappingException: while parsing a flow sequence
 in 'reader', line 111, column 31:
              "user_identifiers": [
                                  ^
expected ',' or ']', but got {
 in 'reader', line 112, column 19:
                (int)${$.create_user.response.body.uid}
                      ^

from zerocode.

chemckenna avatar chemckenna commented on July 29, 2024

I'm not sure if this is what you are looking for, but here is my test scenario converted to JSON:

{
  "scenarioName": "GIVEN- the /usermgmt/v1/user endpoint, WHEN- I invoke POST requests to add users and user groups, THEN- I will receive a 200 / 201 responses and add the user to a user group.",
  "ignoreStepFailures": true,
  "steps": [
    {
      "stepFile": "${JSON.FILE:reusable_content/stepfiles/get_authorisation.json}"
    },
    {
      "name": "create_user",
      "url": "${restful.authentication.endpoint.host}/usermgmt/v1/user",
      "method": "POST",
      "request": {
        "headers": {
          "Authorization": "${token_response}"
        },
        "body": {
          "username": "add_user_to_user_group_user",
          "internal_user": false,
          "displayName": "add_user_to_user_group user",
          "authenticator": "default",
          "user_roles": [
            "User"
          ]
        }
      },
      "verify": {
        "status": 201,
        "body": {
          "uid": "$NOT.NULL",
          "message": "success"
        }
      }
    },
    {
      "name": "check_user_details",
      "url": "${restful.authentication.endpoint.host}/usermgmt/v1/user/add_user_to_user_group_user",
      "method": "GET",
      "request": {
        "headers": {
          "Authorization": "${token_response}"
        },
        "body": {
          "username": "add_user_to_user_group_user",
          "internal_user": false,
          "displayName": "add_user_to_user_group user",
          "authenticator": "default",
          "user_roles": [
            "User"
          ]
        }
      },
      "verify": {
        "status": 200,
        "body": {
          "uid": "${$.create_user.response.body.uid}",
          "username": "add_user_to_user_group_user",
          "user_roles": [
            "zen_user_role"
          ],
          "role": "User"
        }
      }
    },
    {
      "name": "create_user_group",
      "url": "${restful.authentication.endpoint.host}/usermgmt/v2/groups",
      "method": "POST",
      "request": {
        "headers": {
          "Authorization": "${token_response}"
        },
        "body": {
          "name": "test_user_group_1",
          "description": "add_user_to_user_group group",
          "account_id": 1,
          "role_identifiers": [
            "slm_admin"
          ]
        }
      },
      "verify": {
        "status": 201,
        "body": {
          "group_id": "$NOT.NULL",
          "name": "test_user_group_1",
          "description": "add_user_to_user_group group",
          "created_by": "admin",
          "message": "Created"
        }
      }
    },
    {
      "name": "add_user_to_user_group_step",
      "url": "${restful.authentication.endpoint.host}/usermgmt/v2/groups/${$.create_user_group.response.body.group_id}/members",
      "method": "POST",
      "request": {
        "headers": {
          "Authorization": "${token_response}",
          "Content-Type": "application/json"
        },
        "body": {
          "user_identifiers": [
            "(int)${$.create_user.response.body.uid}"
          ]
        }
      },
      "verify": {
        "status": 200,
        "body": {
          "group_id": "${$.create_user_group.response.body.group_id}",
          "message": "success"
        }
      }
    }
  ]
}

where we can swap in and out the examples given in my previous comments.

from zerocode.

authorjapps avatar authorjapps commented on July 29, 2024

@chemckenna
Apologies for the delay.
Yes, that looks like a defect in this below method and needs a fix:

// Here is applies the "integerFunction" to the field value
org.jsmart.zerocode.core.utils.FieldTypeConversionUtils#digTypeCast
// TODO : Single dimensional array to be fixed. Then it will start working

Will get fixed this soon.
Just checking if any collaborators are ready to pick this.
@M3lkior just checking in case you are fine to pick this.

from zerocode.

nirmalchandra avatar nirmalchandra commented on July 29, 2024

@chemckenna , please have a look at the Integration Test(as well as the unit tests) in the above PR which I have covered with the code fix. Hope this addresses your case and unblocks you.

// Look at the Step -> "assert_array_elements_1D_array" --> "ids" field

 {
            "name": "assert_array_elements_1D_array",
            "url": "http://localhost:9998/home/accounts/1",
            "operation": "GET",
            "request": {},
            "assertions": {
                "status": 200,
                "body": {
                    "ids": [
                        "(int)${$.another_get_call.response.body.id}"
                    ],
                    "name": "HBSC",
                    "current": true
                }
            }
        }

from zerocode.

authorjapps avatar authorjapps commented on July 29, 2024

Version 1.3.34 onwards has the fix.
Link:
https://github.com/authorjapps/zerocode/releases/tag/zerocode-tdd-parent-1.3.34

from zerocode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.