WEBVTT

00:00.110 --> 00:00.710
Hi everyone.

00:00.710 --> 00:01.820
Welcome back in this lecture.

00:01.820 --> 00:06.710
What we are going to do is we are going to write a JUnit test that is going to test this rust client.

00:06.740 --> 00:07.100
Okay.

00:07.130 --> 00:11.390
So the very first thing is let's go to the test folder and then check is there a test class already

00:11.390 --> 00:11.960
available.

00:11.960 --> 00:16.820
So if you go to the test folder and if you take a look at the packages, you have a package named HTTP

00:16.910 --> 00:17.600
client.

00:17.600 --> 00:20.570
And here let's open the movie's client test.

00:20.570 --> 00:26.180
So this is a test case which we are going to use in order to test the HTTP client that we had built.

00:26.180 --> 00:28.820
So I'm going to put the movies client on the right.

00:28.850 --> 00:29.630
There you go.

00:29.630 --> 00:32.840
So this is a function which we are going to create the test case for.

00:32.840 --> 00:35.720
So we have an instance of movies client already available.

00:35.720 --> 00:38.390
So now what we are going to do we are going to create a test.

00:38.390 --> 00:40.610
In this case we use our test.

00:40.610 --> 00:44.240
And then the test case name is going to be Get movies by ID.

00:44.480 --> 00:49.490
It can be any name you want, but I'm just going to keep the same name as the actual function.

00:49.490 --> 00:54.920
So in this case we use the movies client dot and then call the get movie by ID.

00:55.160 --> 00:55.490
Okay.

00:55.520 --> 00:58.340
So when you call this function what is the return type of this one.

00:58.370 --> 01:01.340
It's going to be where movie okay.

01:01.370 --> 01:04.400
And then we are going to perform some assertions on it.

01:04.400 --> 01:07.500
So in this case asserts not null.

01:07.530 --> 01:09.390
I believe there is a function like that.

01:09.390 --> 01:12.690
And then we are going to be doing an import of that.

01:12.690 --> 01:15.420
And then after that we are going to be passing the movie instance.

01:15.420 --> 01:19.590
So this is to make sure the movie that is returned by this client is not null.

01:19.590 --> 01:23.640
And after that, what we are going to do, we are going to be looking at some of the properties.

01:23.640 --> 01:26.430
So if you look at the response, what is the response that we are going to get?

01:26.460 --> 01:31.320
So we are going to get this specific response because we are going to be invoking this endpoint, which

01:31.350 --> 01:34.470
actually returns you the movie by ID dot JSON.

01:34.500 --> 01:37.950
And then I want to actually assert on this specific property which is name.

01:37.950 --> 01:42.840
So as long as this assertion succeeds, that means my client is working as expected.

01:42.840 --> 01:46.140
So in this case we can add assert equals.

01:46.140 --> 01:47.910
And then this is a movie name.

01:49.260 --> 01:52.440
And followed by that we are going to pass the movie dot name.

01:52.440 --> 01:55.440
So this is going to perform the assertion on the name.

01:55.650 --> 01:58.350
So now we are going to execute this specific test case.

01:58.350 --> 02:03.870
One thing to quickly call out is that you need to make sure your J-web server is up and running, right.

02:03.900 --> 02:06.000
So if I refresh this, I still get the response.

02:06.000 --> 02:09.060
That means my web server is still up and running.

02:09.090 --> 02:12.450
It is able to provide the response for this specific endpoint call.

02:12.450 --> 02:16.740
So now I'm going to go back to the IntelliJ and then execute this test case.

02:21.510 --> 02:21.960
There you go.

02:21.990 --> 02:23.820
I got a response as expected.

02:23.820 --> 02:26.520
And if you take a look at it we are printing this status code.

02:26.520 --> 02:27.090
Right.

02:27.090 --> 02:30.030
So the status status code value is 200.

02:30.060 --> 02:34.140
That means I was able to communicate with the J-web server that's running in my local.

02:34.170 --> 02:40.230
And then I'm able to also perform the assertion, the value or the name of that specific JSON that is

02:40.230 --> 02:42.330
returned is Batman Begins.

02:42.360 --> 02:42.870
There you go.

02:42.870 --> 02:46.920
We have our very first test case completed for the HTTP client.

02:46.920 --> 02:53.310
So what we have done so far is that we have learned how to build an HTTP client using the new HTTP client

02:53.310 --> 02:54.780
API, which is this one.

02:54.780 --> 03:00.060
And then we were able to assert that by making sure there are proper assertions in place.

03:00.060 --> 03:02.010
In this case, we are asserting the name.

03:02.010 --> 03:07.080
I hope you all were able to follow along and successfully write the HTTP client and the associated test

03:07.110 --> 03:09.570
to make sure this is working as expected.

03:09.600 --> 03:11.130
This marks the end of this lecture.

03:11.130 --> 03:12.180
Thank you for watching.
