How to validate a json schema in rest assured

Steps:

1. Check the response of your api.

2. Use a json schema generator online, to generate a schema for the json you are using

3. In src/test/resources create a .json file and paste that schema

4. Use validatableResponse interface to validate the schema

5. import hamcreshmatchers, 

6.Import jsonschemavalidator to validate the schema

import io.restassured.module.jsv.JsonSchemaValidator;

import io.restassured.path.json.JsonPath;

import org.hamcrest.Matchers;

Response r1=RestAssured.given()

.baseUri(“http://xxx.x.x.1:8090/api/collections/books/records“)

.when()

.get();

ValidatableResponse r2=r1

.then()

.assertThat()

.statusCode(200)

.body(JsonSchemaValidator.matchesJsonSchemaInClasspath(“firstjsonschema.json”));

System.out.println(r2);

r2.body(“items[0].bookname”, Matchers.equalTo(“The Bhagavat Gita”));

How to create a JWT token and use it

  • Library : Rest Assured
  • Framwork : BDD, Cucumber, Page Object Model
  • Language : JAVA
  • IDE: Eclipse
  • API : Pocketbase

Steps :

  1. Create a collection in Pocketbase – Books

Create some fields like these

{

   “id”:”test123″,

    “bookname”: “Algorithms”,

    “price”:100,

    “sellername”:”local”

    “sold”: false

}

2. Now go to edit collection>API rules>>>Here you can edit the behaviour of the api.

Now, I want this api to create a record, only when they are authorised user. 

So I set this in the create rule>> @request.auth.id != “”

Save changes.

3. Steps for Pocketbase:

So in pocketbase I have setup a users collection. Where I’ll see Auth with password.

Steps for rest assured

I need to use the JWT token to create any record in the books collection.

  1. Make a post call to(api/collections/users/auth-with-password) and get the token
  2. Use> jsonPath().getString(“token”) > to get the value of the token field
  3. Now make a post call to > api/collections/books/records
  4. In headers give the token value >> header(“Authorization”,”Bearer “+ jwttokenValue)

Now go to edit collection>API rules>>>Here you can edit the behaviour of the api.

Now, I want this api to create a record, only when they are authorised user. 

So I set this in the create rule>> @request.auth.id != “”

Save changes.

Steps for pocketable:

So in pocketbase I have setup a users collection. Where I’ll see Auth with password.

Steps for rest assured

I need to use the JWT token to create any record in the books collection.

  1. Make a post call to(api/collections/users/auth-with-password) and get the token
  2. Use> jsonPath().getString(“token”) > to get the value of the token field
  3. Now make a post call to > api/collections/books/records

• 4. In headers give the token value >> header(“Authorization”,”Bearer “+ jwttokenValue)

Easy Cabbage Stir Fry – Chinese style

Ingredients

  • Onions – Finely Chopped
  • Garlic – Chopped/Crushed
  • Cabbage – Sliced as thinly as possible
  • Carrots – thinly sliced
  • Green beans – Sliced lengthwise
  • Bellpapers – Sliced
  • Green peas – A Handful
  • Salt/
  • Pepper / Sichuan Peppercorn/ Choice of herbs

Optional Seasoning:

  • Soya sauce
  • chilli sauce
  • fish sauce

Steps:

  • Heat oil/butter
  • Cook onions till translucent
  • Add garlic and cook for another minute
  • Add other veggies and stir
  • Stir..stir..stir
  • Add salt and other herbs…and done

Bengali Style – Banana stem tossed with grated coconut

This dish is simple and authentic Bengali style. I Love it.

Important Notes

1. Remove the outer layers of the stem. Use only core.
2. Peel the core thoroughly, or there will be too much fibre.

Steps:

  • Chop the ‘Thor’ and pressure cook for 1 siti, along with salt and turmeric.
  • Drain the water and cool
  • Heat Mustard Oil
  • Now, put kalonji and whole red chilli, until it smells good
  • Put the boiled thor bits, and start stirring
  • Cook until its soft and add sugar,salt as needed
  • Put grated coconut at this point and stir for some time more
  • This should taste on the sweeter side

Bake Lemon bars – The way we like it

Equipment
– Baking pan 8×8

Ingredients List (Makes 16 bars)

For Shortbread Crust

For Lemon Filling

Steps to make shortbread crust

  1. Preheat the oven to 350°F. Grease an 8×8-inch baking dish and line it with parchment paper on all sides. Leave an overhang on at least two sides of the pan to help you remove the bars after baking.
  2. Whisk together the flour, powdered sugar, and salt in a large bowl. Add the melted butter and vanilla and use a spatula to mix until a greasy dough forms. Transfer the dough to the prepared pan and use your hands to press it evenly over the bottom and ⅛-inch up the sides.
  3. Bake the crust for 18 to 20 minutes, or until lightly browned around the edges. Remove from the oven and dock with a fork.

Steps to Make the Lemon Filling

  1. Place the sugar in a large bowl. If using the lemon zest, add it to the bowl and use your fingers to work it into the sugar to release its fragrant oils.
  2. Add the flour and whisk to combine, then whisk in the eggs followed by the lemon juice.
  3. Pour over the hot crust and bake for 20 to 25 minutes, or until the filling is set. It should no longer jiggle when you gently shake the pan.
  4. Remove from the oven and let cool for 1 hour at room temperature. Transfer to the refrigerator and chill for another 2 hours.
  5. Dust the chilled bars with powdered sugar, slice, and serve.

Bake a Cake – Date, No suger, Whole Wheat

Ingredients 

For soaking:

  • ▢2 cup (300 gm) dates / khajur without pit
  • ▢1 cup (255 ml) milk, hot

For the cake batter:

  • ▢¾ cup (190 ml) olive oil
  • ▢¼ cup (60 ml) curd/yogurt
  • ▢2 cup (260 gm) wheat flour/atta
  • ▢1 tsp baking powder
  • ▢½ tsp baking soda
  • ▢½ cup milk
  • ▢½ cup (60 gm) walnuts
  • ▢5 dates / khajur, chopped
  1. Soak dates in hot milk until soft- Then bled to make a smooth paste
  2. Take the blended dates and paste into a large mixing bowl
  3. Add in ¾ cup olive oil and ¼ cup curd.
  4. Blend well
  5. Place the sieve and add 2 cup wheat flour, 1 tsp baking powder and ½ tsp baking soda.
  6. Blend and mix well until the mixture is combined.
  7. Further, add ½ cup walnuts and 5 dates.
  8. Mix by combining using the cut-and-fold method.
  9. Transfer the batter to the cake tray or bread mould.
  10. Decorate with chopped nuts
  11. Place the cake tray into the preheated oven. bake the cake at 180 degrees Celsius or 356 degrees Fahrenheit for 45 minutes.
  12. Finally, Serve