Hello, and welcome back to the Virtualize Free Edition.

In this video, we will talk about Extending a Virtual Service.

So, one of the more powerful aspects of a responder is correlation or the ability to map certain requests to a certain virtual response. This functionality allows you to use your virtual service in more dynamic scenarios. In this video, we will use the Hello World virtual asset we created earlier to cover the following topics: Configuring responder correlation, Configuring unique responses, Deploying Virtual Services, and Adding a catch-all responder.

So let's go ahead and get started by going back into Parasoft Virtualize. And if you remember, in the last video we created a JSON message responder where to go ahead and use that same responder again for these exercises.

So, the first thing you want to do is double-click on that message responder. We're going to go over to responder correlation. And here, what you can see is that there are a number of different ways to configure my responder correlation, including the request body URL parameters or URL paths and so forth. For this, we're going to actually use the URL parameters.

So we're going to click on that, we're going to Enable correlation, and we're going to go ahead and add a parameter here, and we're going to call this parameter ID, and we're going to give it a value of one. Click Okay. And we want to make sure to click Save after we create this. Now what we want to do is we want to create a few other message responders so that we can respond to different kinds of requests, not only when your ID is equal to one.

So, the way we're going to do that is going to go ahead, and we're going to copy this. We're going to right-click on Responder Suite and paste it, and we're going to go ahead and create two different ones. Two additional ones here. Now that I've created those. What I want to do is I want to go into the second responder here and open that up. And I actually want to change this value to two. Click Okay. Save. Now going to the third one here. And we're going to change this value to three. And we will save it one more time.

Now, the last thing we want to do is configure a unique response for each responder so that we know the correlation is working correctly a little bit later.

So let's go back to the first responder here. And go to the Response tab. And change the message to FOO. We're also going to change the name to FOO.

So, we know what chat, what this one relates to. Click Save. We're going to the second one here. Again, go to the Response tab. Change this to BAR. Changed the name up here as well to BAR. Click Save.

Go to the third one, hit the responder, change this to FOOBAR, and change the name one more time. And click Save.

And the last thing we have to do is make sure we deploy the virtual service by just starting the Virtualize Server here on the right. Click on the Server. Click on the green arrow here, and that'll start the server.

You can see that getting set up here in the console. By default, my hello-world.pva will be deployed on port 9080. I'm actually using port 9081 since my port 9080 is being used elsewhere. I showed how to change this in a previous video, so I can go back and take a look at that if you need to. So just to validate that my virtual services working as expected.

Let's go ahead and open my browser here.

And we're going to go localhost:9081/HelloWorld. And we're going to look for the first id. And as you can see here, responded Hello World with FOO. And if we change this two, that comes back with BAR. And if we change this to three. We get FOOBAR. So, the next question is, what about requests that have no correlation?

So, let's say my id was five, six, or seven. Let's put five in here. And you can see that this brings back an error. With this error message from the Virtualize Server tells us that we don't have a valid message responder that can handle that kind of request. What we can do so you don't get this error is set up a catch-all inside my virtual service. This catch-all is going to respond to any request, no matter what it is.

So, let's go back to Virtualize and add a catch-all responder. The way we do this is very simple. We can just go in and add a responder in the responder suite, and we're just going to right-click there Add. Add a new responder. Again, we're going to use a JSON message responder. Click Finish. And in the response, we are just going to add an element, and this is going to be called Message. Click Okay. Catch-all. And go ahead and rename it here as Catch-all. And Click Save. And now, if we go back to our message, instead of getting the error message, we will get now the new message says, catch-all now for catch-all responders. The correlation is very simple. We don't set up any response correlations at all. That way, it will handle every request that comes along. So that's how easy it is to extend a virtual service in the Virtualize Free Edition.

Coming up next, we're going to be looking at Data Source Parameterization and Correlation.

Comments are closed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}