I am trying to validate my json response in my rest assured tests and i get the following error in my schema. not sure how to resolve this. any help will be appreciated :) thank you.
error:
io.restassured.module.jsv.JsonSchemaValidationException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('s' (code 115)): was expecting double-quote to start field name
at [Source: java.io.StringReader#54c622a7; line: 1, column: 3]
schema:
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
"required": [
"status"
],
"properties": {
"status": {
"$id": "#/properties/status",
"type": "string",
"title": "The Status Schema",
"default": "",
"examples": [
"PROCESSING"
],
"pattern": "^(.*)$"
}
}
}
method:
Assert.assertThat(bookingResponse, matchesJsonSchemaInClasspath("book-response-schema.json"));
Related
I'm very new to Using AVRO Schema and I have a use case where I need to validate AVRO schema data with regular expressions. I mean the field value can allow Numbers OR only allow Alphabets OR AlphaNumeric values OR fixed min-max length etc. I tried like below but it's not working. if any idea please assist me for the same .
AVRO schema is :
{
"type": "record",
"name": "Employee",
"namespace": "com.test.avro",
"fields": [
{
"name": "empId",
"type": "string",
"pattern": "[1-9]"
},
{
"name": "empName",
"type": "string",
"pattern": "[a-zA-Z]"
},
{
"name": "createdDate",
"type": "string",
"pattern": "^[1-9]$"
},
{
"name": "mobile",
"type": "string",
"pattern": "^[1-9]*$"
}
]
}
Thanks in Advance.
I need to share and unshare the content in alfresco using Rest API,
I read the sharedLinks documentation but I don't know how to retrieve the document url I want to share.
This endpoint return an object with this properties :
{
"entry": {
"id": "string",
"expiresAt": "2022-03-23T18:16:00.603Z",
"nodeId": "string",
"name": "string",
"title": "string",
"description": "string",
"modifiedAt": "2022-03-23T18:16:00.603Z",
"modifiedByUser": {
"displayName": "string",
"id": "string"
},
"sharedByUser": {
"displayName": "string",
"id": "string"
},
"content": {
"mimeType": "string",
"mimeTypeName": "string",
"sizeInBytes": 0,
"encoding": "string"
},
"allowableOperations": [
"string"
],
"allowableOperationsOnTarget": [
"string"
],
"isFavorite": true,
"properties": {},
"aspectNames": [
"string"
],
"path": {
"elements": [
{
"id": "string",
"name": "string",
"nodeType": "string",
"aspectNames": [
"string"
]
}
],
"name": "string",
"isComplete": true
}
}
}
How can i retrieve the path from the response?
Is there another way to get the effective complete shared link for a document ?
The response returns you an ID of the share link.
Example: "id": "riqJ3xV3M4RNxJm6Haa7-w"
Use this ID to access the share link :
https://your.alfresco.domaine/share/s/riqJ3xV3M4RNxJm6Haa7-w
You can also use this web service : emailSharedLink to send an email with the link to the shared document.
I am trying to create Body-parameter(JSON) for my POST Api , which is a JSON request . All I have is the JSON Schema . I am trying to come up with a list of different JSON test data covering Positive and negative flows for it .
Is there any option to generate / create the JSON data programmatic using Java ? . I have attached a small Json schema (just for understanding purpose) but my actual schema is more complicated with lot of Array's and Nested Json's .
My Json Schema :
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "The Root Schema",
"description": "The root schema comprises the entire JSON document.",
"required": [
"FirstName",
"LastName",
"Age",
"Interest"
],
"properties": {
"FirstName": {
"$id": "#/properties/FirstName",
"type": "string",
"title": "The Firstname Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Vijay"
]
},
"LastName": {
"$id": "#/properties/LastName",
"type": "string",
"title": "The Lastname Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Karthik"
]
},
"Age": {
"$id": "#/properties/Age",
"type": "integer",
"title": "The Age Schema",
"description": "An explanation about the purpose of this instance.",
"default": 0,
"examples": [
30
]
},
"Interest": {
"$id": "#/properties/Interest",
"type": "array",
"title": "The Interest Schema",
"description": "An explanation about the purpose of this instance.",
"default": [],
"items": {
"$id": "#/properties/Interest/items",
"type": "string",
"title": "The Items Schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"Food",
"movie",
"Learning",
"VideoGames"
]
}
}
}
}enter code here
My TestData looks like :
{
"FirstName":"Vivi",
"LastName":"Karrri",
"Age":30,
"Interest":["Food","movie","Learning","VideoGames"]
}
Any suggestions how can we achive this ?
Note : I am using Springboot and I have complete POJO for the request object
You can generate fake java-objects and then map them to JSON.
POJOs
If you already have the POJOs matching the schema, then we can skip this step.
If no, to generate a POJO from the schema, for example, can be used this library:
jsonschema2pojo.
Fake objects
Generating of objects with fake data can be done with a special library, some of them are listed here:
easy-random
podam
java-faker
Generating JSON
It's prettry simple and can be done with Jackson:
ObjectMapper objectMapper = new ObjectMapper();
ObjectWriter prettyPrinter = objectMapper.writerWithDefaultPrettyPrinter();
String json = prettyPrinter.writeValueAsString(yourFakeObject);
If you have json schema then you can directly generate a sample JSON message from it.
https://github.com/jignesh-dhua/json-generator
I use com.github.fge.jsonschema.main.JsonSchema to validate json.
This is json schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Team data",
"description": "Validation schema",
"type": "object",
"additionalProperties": false,
"required": [
],
"properties": {
"name": {
"type": "string",
"minLength": 2,
"maxLength": 255,
"description": "Name"
}
}
}
And this is json to validate against schema:
{"name" : "name"}
This is valid when I use online validator to check, but in test I get an error:
Caused by: com.github.fge.jsonschema.core.exceptions.InvalidSchemaException: fatal: invalid JSON Schema, cannot continue
Syntax errors:
[ {
"level" : "error",
"message" : "array must have at least one element",
"domain" : "syntax",
"schema" : {
"loadingURI" : "#",
"pointer" : ""
},
"keyword" : "required"
} ]
level: "fatal"
at com.github.fge.jsonschema.processors.validation.InstanceValidator.process(InstanceValidator.java:114) ~[json-schema-validator-2.2.10.jar:?]
at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:56) ~[json-schema-validator-2.2.10.jar:?]
at com.github.fge.jsonschema.processors.validation.ValidationProcessor.process(ValidationProcessor.java:34) ~[json-schema-validator-2.2.10.jar:?]
at com.github.fge.jsonschema.core.processing.ProcessingResult.of(ProcessingResult.java:79) ~[json-schema-core-1.2.10.jar:?]
at com.github.fge.jsonschema.main.JsonSchemaImpl.doValidate(JsonSchemaImpl.java:77) ~[json-schema-validator-2.2.10.jar:?]
at com.github.fge.jsonschema.main.JsonSchemaImpl.validate(JsonSchemaImpl.java:100) ~[json-schema-validator-2.2.10.jar:?]
at com.github.fge.jsonschema.main.JsonSchemaImpl.validate(JsonSchemaImpl.java:110) ~[json-schema-validator-2.2.10.jar:?]...
I can't see where the error is.
Well, the error seems to be in your scheme instead of in the file to validate. The required property is of the array type, but the array has no element.
The validation succeeds when you either remove the property required, or provide at least one string element indicating which properties should be required:
"required": [
"name"
]
Since Draft 4 of the JSON Schema documentation, the array must have at least one element.
I am very new to Talend Open Studio for DI. I am trying to read data from the below JSON File :
{
"data": [
{
"id": "X999_Y999",
"from": {
"name": "Tom Brady", "id": "X12"
},
"message": "Looking forward to 2010!",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/X999/posts/Y999"
},
{
"name": "Like",
"link": "http://www.facebook.com/X999/posts/Y999"
}
],
"type": "status",
"created_time": "2010-08-02T21:27:44+0000",
"updated_time": "2010-08-02T21:27:44+0000"
},
{
"id": "X998_Y998",
"from": {
"name": "Peyton Manning", "id": "X18"
},
"message": "Where's my contract?",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/X998/posts/Y998"
},
{
"name": "Like",
"link": "http://www.facebook.com/X998/posts/Y998"
}
],
"type": "status",
"created_time": "2010-08-02T21:27:44+0000",
"updated_time": "2010-08-02T21:27:44+0000"
}
]
}
I want to load three attributes into my table ( id, actions_name and actions_link). So, in the first step (tFileInputJSON) - I tried to do a Loop Json query as below:
Here, am able to extract the rows as I needed. But, then I used a tExtractJSONField to extract individual fields under "actions" for each "id" using XPath expressions as below:
I tried several other ways to extract the fields but could not do this. Also, not able to find any correct post in stack overflow and talent forums very relevant to my question. Could somebody please help?
Arrange the job like ,
tFileInputJSON is like,
tExtractJSONFields is like,
Then you will get output as,