1
00:00:00,150 --> 00:00:05,550
Hi, guys, my name is Karthik and I am from Automation Dotcom, and welcome to Part 21 of our Appia

2
00:00:05,550 --> 00:00:06,630
testing with the rest assured.

3
00:00:06,630 --> 00:00:11,850
And of course and in this video, we are going to be talking about contact API testing with builder

4
00:00:11,850 --> 00:00:12,450
patterns.

5
00:00:12,810 --> 00:00:18,180
And again, guys, this video is not completely related to our previous videos that we have discussed.

6
00:00:18,360 --> 00:00:23,610
You can also watch this video in isolation, even if you have not watched the previous videos.

7
00:00:23,760 --> 00:00:28,970
But watching the previous videos is going to give you more confidence off the core that we have discussed.

8
00:00:29,100 --> 00:00:35,430
But in this video, we are going to talk about a separate concept, which is how you can maintain your

9
00:00:35,700 --> 00:00:42,360
Podio classes of our API and also how you maintain the contracts of the poggio classes that we have

10
00:00:42,360 --> 00:00:46,380
built all these days and our previous videos using builder patterns.

11
00:00:46,650 --> 00:00:52,380
So this is going to be a completely new topic that you're talking about, and we have fused that within

12
00:00:52,380 --> 00:00:53,810
our own API testing.

13
00:00:53,830 --> 00:00:59,310
The rest assured, of course, just to ensure that we don't miss this particular concept in our course.

14
00:00:59,370 --> 00:01:00,540
All right, let's get started.

15
00:01:00,690 --> 00:01:04,890
So before talking about the builder pattern itself, we are going to talk about the contract testing.

16
00:01:05,010 --> 00:01:10,740
And I have discussed about contract testing a lot in our weekly video series of YouTube.

17
00:01:10,740 --> 00:01:12,810
So you can go and watch that particular video.

18
00:01:12,990 --> 00:01:18,480
But I have discussed about contract testing and I can contract testing is immediately applicable anywhere

19
00:01:18,930 --> 00:01:25,290
that you have to, services that need to communicate that as an API client and a Web front end.

20
00:01:25,410 --> 00:01:30,730
Although a similar service is a common use case, contract testing really shines an environment with

21
00:01:30,750 --> 00:01:31,820
many services.

22
00:01:31,950 --> 00:01:37,260
So this is something very, very important for our kids as well, because as we know in our previous

23
00:01:37,260 --> 00:01:45,870
videos we discussed about the fake design server, which generates the JSON and we try to D.C. realize

24
00:01:45,870 --> 00:01:53,220
that and serialize those jasen files into a class file and from classifier to jasen file and all those

25
00:01:53,220 --> 00:01:53,910
things we did.

26
00:01:54,060 --> 00:01:59,460
But all these days, we just had an assumption that the APIs over that we have is always going to return

27
00:01:59,460 --> 00:02:03,960
as only this particular format of the jasen response.

28
00:02:04,060 --> 00:02:09,540
But what if something changes in the server side and our test will start to fail automatically because

29
00:02:09,540 --> 00:02:14,220
we don't really have any contract with the Jasen server, which is nothing.

30
00:02:14,220 --> 00:02:18,060
But the fact is answer in our case with the code that we are writing.

31
00:02:18,060 --> 00:02:23,790
So we need to make a contract between a fake design server and with our test score so that our test

32
00:02:23,790 --> 00:02:26,610
will always works without any problem.

33
00:02:26,610 --> 00:02:32,850
And if anything fails, then probably we'll know that which particular property of our Web server has

34
00:02:32,850 --> 00:02:36,360
changed and why our test is failing in this particular area.

35
00:02:36,480 --> 00:02:41,800
So these are something that is very, very important that we could probably understand while doing with

36
00:02:41,820 --> 00:02:42,770
the contract testing.

37
00:02:43,080 --> 00:02:46,730
So there are many different tools available in the market for doing contract testing.

38
00:02:46,740 --> 00:02:47,070
I don't know.

39
00:02:47,100 --> 00:02:49,890
The popular contract testing tool is packed.

40
00:02:50,070 --> 00:02:56,130
And once again, guys, I have discussed about Pact and how to use Pact Darknet in the EIA weekly video

41
00:02:56,140 --> 00:02:57,750
so you can go ahead and watch there.

42
00:02:57,750 --> 00:03:02,160
And again, I'm not going to be talking about the contract testing in this place because the whole topic

43
00:03:02,160 --> 00:03:03,520
is around builder patterns.

44
00:03:03,520 --> 00:03:04,680
So that's what we'll be discussing.

45
00:03:04,800 --> 00:03:10,350
But just to make you understand that there is a concept of contract testing, that's why I'm introducing

46
00:03:10,350 --> 00:03:11,490
you this in here.

47
00:03:11,700 --> 00:03:16,440
But building a pattern is what we are going to be focusing on, on how are we going to achieve contract

48
00:03:16,440 --> 00:03:18,480
testing with the builder patterns.

49
00:03:18,930 --> 00:03:25,260
So the builder is a design pattern designed to provide a flexible solution to various object creation

50
00:03:25,260 --> 00:03:27,750
problems in object oriented programming.

51
00:03:27,960 --> 00:03:33,780
The Builder Department allows the creation of different representations of an object using the same

52
00:03:33,780 --> 00:03:35,340
construction code.

53
00:03:35,520 --> 00:03:37,080
That is very, very important.

54
00:03:37,410 --> 00:03:40,290
And we'll talk about that in a minute in our next slide.

55
00:03:40,500 --> 00:03:48,280
But as you can see, the builder design patterns solves the problems, like how can a class creates

56
00:03:48,330 --> 00:03:55,350
different representations of a complex object and how can a class that includes creating a complex object

57
00:03:55,350 --> 00:03:56,340
be simplified?

58
00:03:56,620 --> 00:04:00,940
So if you don't really understand what these theories are talking about, I'll quickly show you a quote

59
00:04:00,990 --> 00:04:02,990
example so that you can understand what it is.

60
00:04:03,450 --> 00:04:05,970
So as you can see, we have a Podio class again.

61
00:04:05,970 --> 00:04:11,000
Poggio is nothing but a plain old Jawa object class of the post.

62
00:04:11,010 --> 00:04:14,970
Again, this particular class, we have already discussed no previous videos of this class.

63
00:04:15,150 --> 00:04:16,320
So please go and watch that.

64
00:04:16,320 --> 00:04:21,210
If you have not lost that, as you can see in here, we have this particular post class, which does

65
00:04:21,210 --> 00:04:26,940
have properties like private properties, and it has a constructor called Post and it has a go getter

66
00:04:27,120 --> 00:04:28,440
and of course, it has a setter.

67
00:04:28,680 --> 00:04:34,440
And if you could see here, there are just three properties available, private properties and only

68
00:04:34,650 --> 00:04:36,120
three getters are available.

69
00:04:36,120 --> 00:04:38,460
And there will be three separate methods available.

70
00:04:38,640 --> 00:04:40,980
And as you can see, there is only one construction.

71
00:04:41,160 --> 00:04:45,990
But you can still see there are a lot of permutations and the combination of constructors can be created,

72
00:04:46,260 --> 00:04:51,540
something like a default constructor and a constructor with just one parameter and a constructor with

73
00:04:51,720 --> 00:04:55,680
two parameters and the constructor with three parameters, as you are seeing here.

74
00:04:55,860 --> 00:04:59,400
And similarly, there are constructors that you can mix and match the.

75
00:04:59,490 --> 00:05:04,220
Accommodations on the combination, something like a constructor just with Idy and a constructor with

76
00:05:04,220 --> 00:05:09,890
ID and author and a constructor with an idea and title and then a contractor with title and other things

77
00:05:09,890 --> 00:05:10,490
of that nature.

78
00:05:10,740 --> 00:05:18,830
So you can see that for a particular given type in this case post, we can have a different kinds of

79
00:05:19,220 --> 00:05:26,330
telescopic constructors and these telescopic constructors can be complex and even more vague if our

80
00:05:26,360 --> 00:05:33,200
object is getting very, very complex and in order to resolve these kinds of situations, builder pattern

81
00:05:33,200 --> 00:05:33,980
comes in the picture.

82
00:05:34,580 --> 00:05:37,820
So as you can see, this is a static class called a builder class.

83
00:05:37,820 --> 00:05:41,180
And again, you can name it anything, but it is a standard way of calling it.

84
00:05:41,480 --> 00:05:47,630
And you can see here it tries to simplify the way we create the constructors.

85
00:05:47,990 --> 00:05:54,950
So you can see I'm still calling the Post's class, which we saw in our previous slide, and I'm parsing

86
00:05:54,950 --> 00:06:02,000
in all the properties which is required within a constructor for this particular builder class.

87
00:06:02,570 --> 00:06:07,030
And in here I'm setting all the values, something like this, which is pretty cool.

88
00:06:07,280 --> 00:06:12,920
So whichever property that you to be setting it, you only call that particular set operation so that

89
00:06:12,950 --> 00:06:15,260
these values will be set for it automatically.

90
00:06:15,680 --> 00:06:19,460
And you don't really have to worry about how these people values are being set because they're going

91
00:06:19,460 --> 00:06:25,400
to be calling only that particular properties method to just set that particular value.

92
00:06:25,610 --> 00:06:32,120
And the getter is going to be sitting within the Post's class, not within the middle class, which

93
00:06:32,120 --> 00:06:36,110
is going to oversimplify the way that we're are creating a constructor in here.

94
00:06:36,290 --> 00:06:42,380
And you can see that that is only one constructor spin car, which is something about the Post's class,

95
00:06:42,530 --> 00:06:44,690
three parameters based constructor.

96
00:06:44,900 --> 00:06:47,300
And this reduce our code dramatically.

97
00:06:47,660 --> 00:06:50,790
So how to call this particular builder class?

98
00:06:50,810 --> 00:06:53,120
Basically, it's going to be something like this.

99
00:06:53,480 --> 00:06:54,260
As you can see.

100
00:06:54,260 --> 00:06:56,840
I'm just going to call the postcard builder Duck-billed.

101
00:06:57,140 --> 00:06:57,650
That's it.

102
00:06:58,100 --> 00:07:03,530
And I can create a type of post and then I can get the value out from it.

103
00:07:03,800 --> 00:07:06,920
But if you want to set any value, then I'm going to do that.

104
00:07:06,920 --> 00:07:15,530
Builder Dot set it or set title and set order and then you can do that as well, which is going to be

105
00:07:15,530 --> 00:07:18,330
very, very easy in the builder pattern side.

106
00:07:18,620 --> 00:07:24,500
So essentially builder partners get rid of the problems with a complex object which has telescopic constructor

107
00:07:24,680 --> 00:07:30,410
in much easier way through squeakily see everything in action and understand how things work so far

108
00:07:30,410 --> 00:07:33,270
that I'm gonna flip to my intelligent idee.

109
00:07:33,650 --> 00:07:39,440
And again, for this particular video, I'm going to be using the source code, which is available below

110
00:07:39,440 --> 00:07:39,740
here.

111
00:07:40,880 --> 00:07:41,320
All right.

112
00:07:41,370 --> 00:07:46,610
Now in my intelligent idee, and you can see that this is the same project that we have already discussed

113
00:07:46,610 --> 00:07:48,980
in all our videos and our earlier videos.

114
00:07:49,250 --> 00:07:55,540
And what I'm going to do is this time and I'm going to be working with the builder pattern based class.

115
00:07:55,700 --> 00:08:00,500
So I'm just going to convert only this particular class, which is nothing but the POS class.

116
00:08:00,800 --> 00:08:03,860
And I'm going to convert that to the builder pattern in here.

117
00:08:04,130 --> 00:08:10,580
So what I'm going to do, if I remember in our earlier videos, we created this class with two constructors,

118
00:08:10,580 --> 00:08:11,420
something like this.

119
00:08:11,720 --> 00:08:16,760
And we also had a problem that without having the default constructor, the code was throwing us an

120
00:08:16,760 --> 00:08:18,650
error while we trying to execute this.

121
00:08:19,100 --> 00:08:25,280
But now, in order to resolve all these problems, that's where we are going to be calling our builder

122
00:08:25,280 --> 00:08:26,170
patterns, basically.

123
00:08:26,570 --> 00:08:32,300
So I'm going to get rid of these SEDAR at least from in here.

124
00:08:32,550 --> 00:08:34,210
So I don't really require this.

125
00:08:34,730 --> 00:08:41,120
And again, it's gone and I'm going to be calling a public static.

126
00:08:42,380 --> 00:08:50,030
Class of builder and witness builder, I'm going to set the same three properties that we created in

127
00:08:50,030 --> 00:08:57,950
our earlier videos over here, and then I'm going to create default constructors, which is going to

128
00:08:57,950 --> 00:09:03,890
be public builder, and then I need all the sitter, basically.

129
00:09:03,920 --> 00:09:10,280
So I'm going to generate once again, just get all the setters over here, which is pretty awesome.

130
00:09:10,700 --> 00:09:16,880
But the change in here for the SATs, instead of returning it to the wide, I'm going to return it as

131
00:09:16,880 --> 00:09:17,810
a builder.

132
00:09:18,080 --> 00:09:20,990
That's the creation of a design pattern, basically does.

133
00:09:21,320 --> 00:09:28,700
You're going to return all the builder type over here for each and every set operation that you're going

134
00:09:28,700 --> 00:09:29,300
to be doing.

135
00:09:30,000 --> 00:09:42,190
I just done this, not the builder knew this and that I wanted to done this and this way.

136
00:09:42,650 --> 00:09:47,990
This is going to be builder as well, and this is going to be builder.

137
00:09:47,990 --> 00:09:55,610
And I'm going to be returning this over here so you can see the builder patterns.

138
00:09:55,850 --> 00:10:02,840
I could able to create a set operation with returning all of the this type schismatic with a builder

139
00:10:02,840 --> 00:10:03,220
type.

140
00:10:03,950 --> 00:10:11,840
And this way I can also ensure that I have an isolated object for each and every properties that I'm

141
00:10:11,840 --> 00:10:12,670
actually working with.

142
00:10:13,220 --> 00:10:23,000
And finally, I'm going to be calling or post a certain type for the build method and I'm going to return

143
00:10:23,780 --> 00:10:32,280
the new posts where I'm going to pass the Idy title and author.

144
00:10:32,600 --> 00:10:34,570
So this is the builder pattern, guys.

145
00:10:34,580 --> 00:10:35,760
This is what I'm talking about.

146
00:10:35,780 --> 00:10:40,790
So this way, what will happen eventually is will produce so much, of course, that we are writing

147
00:10:40,790 --> 00:10:45,700
all these days and know how to call this particular builder pattern or code.

148
00:10:46,040 --> 00:10:49,040
So for that, I'm going to go to my get post that feature.

149
00:10:49,070 --> 00:10:56,390
And if I go all the way to the I think this one, then I should see the author name as well.

150
00:10:56,420 --> 00:10:57,020
Where here.

151
00:10:57,350 --> 00:11:02,210
This is where I have actually called the post of this one.

152
00:11:02,220 --> 00:11:05,150
So this is a common piece of code maybe.

153
00:11:06,280 --> 00:11:08,420
And I don't really have the common duplicate piece of code.

154
00:11:08,810 --> 00:11:13,220
So this code is without builder pattern.

155
00:11:15,170 --> 00:11:24,310
Right, and this time I want to call with Miller, Palin is going to be Vare of Posts, a sequel to

156
00:11:24,770 --> 00:11:27,500
New Post Dot.

157
00:11:27,830 --> 00:11:32,750
I'm going to call the builder constructor in here, and then I just call the builder.

158
00:11:33,020 --> 00:11:39,620
So basically, you can also do the starter, set it and title over here, because I don't really have

159
00:11:39,620 --> 00:11:42,400
to set any value, at least at this particular point.

160
00:11:42,680 --> 00:11:46,390
I'm just going to call the bird method over here.

161
00:11:46,850 --> 00:11:51,340
And finally, I'm going to do the post operation.

162
00:11:51,590 --> 00:11:55,940
So the post operation is going to be pretty much like how I did in here.

163
00:11:56,300 --> 00:11:59,120
So maybe I can just call this.

164
00:12:02,740 --> 00:12:03,640
Something like this.

165
00:12:04,750 --> 00:12:05,060
Right.

166
00:12:05,530 --> 00:12:17,110
So this can be a bar type and instead of the post start class, I'm just going to do the posts dot get

167
00:12:17,110 --> 00:12:23,830
class so that I can make this as a class and now I can just call the post dot get Arthur.

168
00:12:24,790 --> 00:12:30,850
Which is this one, and because this picture post actually has all the GETER operation, I get author

169
00:12:30,850 --> 00:12:36,260
title and idy, I can easily call the author or hear that's it.

170
00:12:36,280 --> 00:12:42,060
So this way it reduces dramatically a lot of ways that we can reduce the constructor.

171
00:12:42,070 --> 00:12:45,940
But now you may have a question like what difference that this particular code has made.

172
00:12:45,970 --> 00:12:51,400
Eventually this has even increased the number of lines of code here then compared to before.

173
00:12:51,460 --> 00:12:57,460
And again, guys don't think of this particular situation over here that this particular code is actually

174
00:12:57,460 --> 00:12:58,380
very, very simple.

175
00:12:58,390 --> 00:13:03,880
It has only three properties, but in real time situation with any of the other classes, you would

176
00:13:03,880 --> 00:13:09,190
see there will be a lot of different properties and you need to have a different permutations and combinations

177
00:13:09,190 --> 00:13:09,990
of constructor.

178
00:13:10,270 --> 00:13:12,970
But in here, we're not even worried about all those constructor.

179
00:13:12,980 --> 00:13:15,430
We just call in here and it just works on that only problem.

180
00:13:16,140 --> 00:13:21,140
So as I said, I'm just going to run this piece of code and see what's going to happen.

181
00:13:21,160 --> 00:13:27,880
So if I just run this particular selector scenarios, so let's see what's going to happen.

182
00:13:30,470 --> 00:13:31,020
There we go.

183
00:13:31,040 --> 00:13:34,490
The test has got failed, so let's quickly see what has gone wrong.

184
00:13:34,880 --> 00:13:41,210
Oops is because of this token, because we have removed that token in our earlier videos to be a static

185
00:13:41,210 --> 00:13:41,710
token.

186
00:13:41,720 --> 00:13:44,680
So I'm just going to include that over here.

187
00:13:45,200 --> 00:13:46,910
So that's the problem.

188
00:13:47,160 --> 00:13:48,220
I'm just gonna run this again.

189
00:13:54,360 --> 00:13:58,730
And you can see that the court has successfully completed the execution and the test has not passed,

190
00:13:59,130 --> 00:14:05,420
so this way we can see that we could be able to use the builder pattern to perform the operation, and

191
00:14:05,420 --> 00:14:09,790
it increases so much of our coding practice much, much better.

192
00:14:10,080 --> 00:14:14,430
And now you have a question like this particular piece of code has introduced are the builder pattern

193
00:14:14,430 --> 00:14:18,600
has really introduced so many different lines of code than before.

194
00:14:18,600 --> 00:14:25,860
So how to reduce this particular lines of code and how we can make our code even more neater than before,

195
00:14:25,890 --> 00:14:31,230
even though without builder patterns we can at least see the getter and setter.

196
00:14:31,440 --> 00:14:38,610
But then we also see a static class, which is something increasing some more lines of code in here.

197
00:14:38,910 --> 00:14:43,040
So be sure to have some way to reduce this particular lines of code.

198
00:14:43,380 --> 00:14:46,110
So how to get rid of all this problem you have going?

199
00:14:46,110 --> 00:14:51,870
We're talking about Leimbach plugging in our next video to see how we can reduce the number of lines

200
00:14:51,870 --> 00:14:52,320
of code.

201
00:14:52,740 --> 00:14:53,190
Thank you.

