And welcome back.
In our last video, we discussed correlation, which allows us to make our virtual services dynamic. In this video, we will discuss a different strategy called Data Source Correlation.
This will allow a single virtual service to support a large number of regression tests. I will be showing you how to do this by creating a new virtual asset, adding a data source, creating a responder that uses that data source, and adding a catch-all inside of that data source. This is where data source correlation comes into the picture.
So if I go back to my responder, you'll notice that one of the tabs I have is Data Source Correlation.
So if I click on that, you'll see that we can specify what property or attribute to pull the incoming request in order to do the lookup of my data source. To do that, we're going to add the URL parameter name ID, and we are going to make sure we map that to the column ID. Once we do that, we're going to click Okay, and again, we're going to click Save.
Everything's now configured in my responder.
Just to confirm that we understand exactly what is happening. Let me talk through a scenario. Let's say that an ID request comes in with the URL parameter of ID 2. What the responder will do is take that ID value. It knows the ID maps to ID and the data source, and it will do a lookup until it finds the matching ID 2. Then it will know that the message response is BAR, and it will take that and put it into the message element of the response.
Now that everything is set up let me open my browser and test it out.
In my browser, we're going to invoke the virtual service. So to get to it, it's going to be a localhost:9081/HelloWorldDS with the URL parameter. So you can see ID as returning FOO to that here. And if we change this to 2. We're going to get BAR, and if we change this to 3, we're going to get FOOBAR. So, it looks like everything is working. But just like in my last video, if we had a situation where the id is, let's say, 5. There is no responder that can handle that correlation. We have a very similar situation here. My data source only has 1, 2, or 3.
So if I put a 5 in, what's going to happen? Well, you can see, like before, it's giving us an error. It's telling us that there is no value in the data source that can respond to 5. Similar to 4 we're going to fix this by creating a catch-all. Except this time it will be with one of the rows in my data source. To do that, I'm going to go to Virtualize again.
I'm going to open up my data source. And in the final row here, we are going to add some syntax. It's going to be bracket asterisk in the center and closing bracket. Telling Virtualize, no matter what the value is to correlate on this row. And then we are going to get the message, and we're going to call it catch-all. Just as a side note, there's other syntax we can use, like the less than and greater than operators. These allow us to handle a bit more complex logic. And now we can go test it out in the browser again.
So, make sure it's saved. Jump in the browser. Click Refresh. And you can see here, it brings up the message Catch-all.
This is how easy it is to set up Data Source Parameterization and Correlation.
Next up, I'll be showing you how to set up your demo environment.