Hi everyone.
Welcome back in this lecture.
What we are going to do is we are going to write a JUnit test that is going to test this rust client.
Okay.
So the very first thing is let's go to the test folder and then check is there a test class already
available.
So if you go to the test folder and if you take a look at the packages, you have a package named HTTP
client.
And here let's open the movie's client test.
So this is a test case which we are going to use in order to test the HTTP client that we had built.
So I'm going to put the movies client on the right.
There you go.
So this is a function which we are going to create the test case for.
So we have an instance of movies client already available.
So now what we are going to do we are going to create a test.
In this case we use our test.
And then the test case name is going to be Get movies by ID.
It can be any name you want, but I'm just going to keep the same name as the actual function.
So in this case we use the movies client dot and then call the get movie by ID.
Okay.
So when you call this function what is the return type of this one.
It's going to be where movie okay.
And then we are going to perform some assertions on it.
So in this case asserts not null.
I believe there is a function like that.
And then we are going to be doing an import of that.
And then after that we are going to be passing the movie instance.
So this is to make sure the movie that is returned by this client is not null.
And after that, what we are going to do, we are going to be looking at some of the properties.
So if you look at the response, what is the response that we are going to get?
So we are going to get this specific response because we are going to be invoking this endpoint, which
actually returns you the movie by ID dot JSON.
And then I want to actually assert on this specific property which is name.
So as long as this assertion succeeds, that means my client is working as expected.
So in this case we can add assert equals.
And then this is a movie name.
And followed by that we are going to pass the movie dot name.
So this is going to perform the assertion on the name.
So now we are going to execute this specific test case.
One thing to quickly call out is that you need to make sure your J-web server is up and running, right.
So if I refresh this, I still get the response.
That means my web server is still up and running.
It is able to provide the response for this specific endpoint call.
So now I'm going to go back to the IntelliJ and then execute this test case.
There you go.
I got a response as expected.
And if you take a look at it we are printing this status code.
Right.
So the status status code value is 200.
That means I was able to communicate with the J-web server that's running in my local.
And then I'm able to also perform the assertion, the value or the name of that specific JSON that is
returned is Batman Begins.
There you go.
We have our very first test case completed for the HTTP client.
So what we have done so far is that we have learned how to build an HTTP client using the new HTTP client
API, which is this one.
And then we were able to assert that by making sure there are proper assertions in place.
In this case, we are asserting the name.
I hope you all were able to follow along and successfully write the HTTP client and the associated test
to make sure this is working as expected.
This marks the end of this lecture.
Thank you for watching.