Comments (10)
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.
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.
I am picking this, will get the PR out soon I can.
from zerocode.
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.
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.
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.
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.
@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.
@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.
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)
- Support for JUnit5 and Java 17 HOT 2
- Zerocode JavaNullPointerException HOT 9
- Unable to use newer Java version than 15.0.2 HOT 1
- Load testing parameters HOT 1
- Getting "java.lang.RuntimeException: ZeroCode Step execution failed. Details:java.lang.NullPointerException"
- Does zerocode offer a test setup?
- Duplicate dependency for protobuf-java in pom.xml HOT 4
- File upload : How to do it using Zerocode HOT 6
- [Doc] Site Documentation content fixing HOT 10
- [Doc] Add documentation content for Mocking page
- warnings during maven build regarding missing version for maven-compiler-plugin HOT 6
- remove maven-compiler warnings with target Java 17 HOT 2
- Maven: Unused dependencies and test-only dependencies HOT 2
- Resolve JSON.CONTENT with JSON object or JSON array HOT 10
- How to iterate by reusing results of a previous step in current step? HOT 9
- How to disable console output of any required step ? HOT 18
- Is there any plan to have Java 17 support? HOT 4
- Loop on step level HOT 1
- Upgrade the libraries and make it compatible with Java8 HOT 5
- [java17]Create a new branch and point the PRs to this new branch HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zerocode.