Hi, guys, my name is Karthik and I am from Automation Dotcom, and welcome to part 22 of our API testing
with the and Australian workforce.
And in this video, we're going to talk about contract API testing with a pattern using Lombok.
And before writing this part, I would strongly recommend to watch Part 21 because this video is going
to be a complete continuation of our previous video, Lombok Project.
Lombok Spillar is a useful mechanism for using builder pattern without writing boilerplate code, and
we can apply this annotation to a class or even a method.
And again, guys, if you remember in our previous videos, No.
Part 21 video we wrote and discussed about builder pattern and we saw the importance of having builder
pattern and how it eliminates the problem with the telescopic constructors, with the poggio classes.
But we also saw that there was a lot of boilerplate cause like you can write a static builder class
and then you can write the getters and set an operation for each and every podell classes.
So if the object is going to be very, very complex, then you probably have to write the same kind
of code for each and every poggio classes that makes or introduce a lot of boilerplate code writing.
And that is the reason this Lombok plugin is going to be very, very handy, because the Lumberg plugin
gives a way that how you can reduce it by coding.
So the first and foremost thing that we been doing for working with Lumberg plugin is to install the
Lumberg itself, as you can see in here, as a Mabon dependency.
So once we install this Lumberg plugin, but then can also install the plugin within our intelligent
idy or any idea of your choice.
So this way it reduces so much of the coding that you are currently doing in the existing core business
that we are discussing in our previous video.
So the current Podio class for the pause that we have is going to look something like this.
As you can see, we have a post class and then we also have a better class and then we call this particular
code in our code and we worked with it.
But we also know that in our earlier videos, we had complex classes like address and locations and
things of that nature.
But now in order to simplify things for the post class, if we install this particular beta pattern,
the only two annotation that we need to be using is the add data and add builder for the first class.
That's it.
This is the only thing that we need to be doing within our code or within our Poggio class, and that
where this is going to eliminate so much of our coding that we are doing all these days.
Guys, you can see that the code has now tremendously reduced from around 70 lines of code to just three
lines of code or maybe five lines of code.
That's it.
This is the only thing that we need to be doing for our class.
And this way it increases a lot of readability and removes the boilerplate code that we have written
all these days.
So let's quickly see everything in action and understand how things work so far that I'm not flip to
my intelligent idee.
All right.
So now I'm an intelligent idee.
And before I started this video, I have also installed the plugin within my intelligent ID.
So if you go to the settings and then to the plugin, you can see that I have already installed the
Lombok plugin, which I'm really not going to be doing as of now at this particular point.
I'm just going to cancel that.
But just make sure that you install this particular plugin with an intelligent idee so that you can
start working with it.
But within our project, with our Pumbaa XML file, we don't really have the Lumberg plugin Mabon dependency.
So we need to somehow install Lumberg within our project as a dependency.
So for doing that, I'm just going to go over here, I'm going to search for Lombok Mavin, this one.
I think this is the latest version.
I'm just gonna copy it and then I'm going to come all the way over here on this particular dependency,
the same serried and you can see that the the dependency has been resolved.
And there you go.
So now we have this particular class with the builder class.
So what I'm going to do is I'm just going to rename the speaker Podio class folder or the package so
that I can make use of the builder pattern.
And you can see that because I want to check in the code in the GitHub repo.
This is going to create so much of confusion.
So I'm just going to show this in an explorer and I'm going to make a copy of this.
I'm it over here and I'm gonna call this aspergillus without further.
And this is Podio with Better, the one which you have is going to be popular with Builder, basically
leave it and we can see that we still have got these guys over here.
So I'm just going to call this as possible.
Let's rename this to Without Valdo.
Copy this paste over here.
And the address is OK.
And the location.
The posts and the login body, so you can see that this is going to be a separate package, which we
are not going to be using at all.
But just for your reference, because the students who are going to be learning the earlier videos are
going to find this particular class missing within the GitHub repo just for their reference, like how
we evolved with the speaker code.
I'm just going to hold this guy as it is over here.
But the code that we're going to be changing are these cards that you are seeing over here.
So what I'm going to do is I'm going to use this particular builder pattern.
So as I told you, the 50 lines of code or maybe fifty five lines of code is going to be completely
synched into.
As you can see here, that's the data.
And you can see that it is telling me which particular dependence that it will be using.
So I'm just going to hit all the enter and I'm going to use the Lembke Mabern dependency basically going
to say it.
And you can see that pretty much good to go now and now.
If I go to the posts of this particular.
Or you can see that it's showing us at this particular theater just fine, because we also need to add
the at Baylor over here.
So once I add this, if I go back in here.
You can see that the Savar will now throw us an error, which is fine, but the builder that you can
see in here is going to be this builder.
So you can see that builders, builders actually coming from the Lumberg and the VA.
I can change it to post, basically.
And this one I can pertain to post as well, and you can see that this is throwing as an editor, the
reason being I don't really have to use this particular new keyword in here.
You can see that the court will now completely transform into something like this.
And you may be wondering like what is the big deal with this particular piece of court and what's really
happening?
And you can see that within this particular assertions, I just called the post start, get out there
and it is automatically coming as well.
And within this picture, postcards, basically, I have not even written any of the letters or the
SEDAR, but even if I hit the dot, you can see that it automatically brings me all the getters and
setters.
So how is this actually coming in with the Lombok plug in, how it is generating all these kind of steps?
So basically, if you see the structure of this particular class, once they enter this particular data,
it automatically added the get author and the set and also the builder's class over here, which is
pretty cool.
Now, let's say if I just remove this particular builder, you can see that the builder has been completely
gone.
And once I removed the data, you can see that it now becomes just like and class with just three properties.
So the Lombok plugin actually generate all these cool stuff for us automatically with the plugin, which
is which is already installed in our intelligent idee.
And now this Lombok plug in is we are doing all the magic for us.
And now how I can transform this code is going to be even more fascinating.
So now if I just go back to my posts, I can even simplify this bigger piece of code, something like
maybe I don't really even need to a better pattern because I don't really have to go through all those
problems.
Now, I just kind of call this book a postcard class, like how I used to do for the earlier core that
which was that without builder pattern.
So I can just call the same code here.
Maybe I don't even require this book a piece of code from here.
I can just call this a postcard get body.
And then you can see that this particular code that we were using before is now going to be legal as
well, which is pretty cool.
So now I can just call the post class, but still it is going to use the same builder pattern.
As you can see.
It automatically brings that get author, get title, get it set author and surtitles and all that stuff,
including the builder pattern.
Now everything is working fine without any problem.
Right.
And now if I try to execute this particular piece of code, we will be getting an error here and you
can see that it is going to tell us that there is no default constructor.
As you can see, it is trying to bind and and it wouldn't be able to construct an instance of the Podio
of the posts.
So it's going to be the same matter that we discussed in our part 13 of this, cause we're just going
to be adding a default constructor, but it doesn't really make any sense while using the Lombok plugin
to do that.
So basically, you can see that with the with the Podemos post class.
We have used this builder pattern, but you don't really require it because you have not used any one
of those option or hear it in our code.
So probably you can just remove the builder alone because we're just using the getter and setter operation.
We will talk about how we can even extend this accord with the builder pattern in our next video.
But as of now, you can see that this particular code doesn't require that particular stuff.
So I can probably just leave this guy as it is because I'm just going to call the get an operation.
That's what I'm too much interested in.
And now if I try to execute this bigger piece of code, you can see that the scenario got tested and
the test has got passed, which is pretty cool.
So this is how we can actually use the Lombok plugin to do a greater job for us.
So this reduces too much of our codings that we were doing all these days so we can even reduce the
dialogue in operation that we were doing before using the Lombok plugin.
So I'm just going to get rid of this and I'm going to put the data.
There you go.
And use the.
Used to Lombok, that's it, and you can see that it has been reduced tremendously and also I can use
the Lombok for the location as well.
So I'm not going to remove this.
I'm going to put data here.
That's it, and you can see that it's done and similarly for the address, I can remove all of them
for here and I can put that data and there you go.
So we're done.
So now we have the address, location and body, very, very super simple called then compared to the
code that we were writing so big all these days.
Right.
So this code is now reduced tremendously.
And now if I tried to even execute the complex operation code over here.
You can see that the test has got passed successfully, so this way you can see that we can reduce tremendous
number of coatings using the Lombok plug in and with the Lumberg package itself.
And this is a keen observer pattern as well, because he even farther with the situation, suffusing
builder patterns, because we have not used that builder yet.
We will be discussing about that, how we can set it in a body or maybe in the header, and then how
we can extend that particular piece of code in much greater detail.
So, once again, thank you very much watching this video and have a great day.