Using userId with Gatling DSL - gatling

I am using session.userId to parametrize my test requests like this:
exec(http("get request")
.get((s:Session) => "somebaseUrl/" + s.userId.toString ))
Is it possible to get sesion userId differently, so my request addresses are more DRY, eg I won't have to use lambda?
I tried using gatling DSL:
exec(http("get request")
.get("somebaseUrl/${userId}")
but then I get: No attribute named 'userId' is defined error
I could just calculate some random id to my tests, but why when gatling already does this.
Only solution that I came up with is saving userId to some different attribute like this:
exec((s:Session) => s.set("user_id",s.userId)),
exec(http("test").get("${user_id}"))
but that doesn't seem right, and you have to make sure to call the set before all other requests.

The userId is some internal details. Gatling Expression language only exposes Session attributes, ie the attributes Map content.
Either use the first way you described, with a function, or don't use Gatling internals and set your own UUID attribute (feeder, exec(function), etc).

To avoid using gatling internals you could use a feeder:
var userId = 0
feed(Iterator.continually(Map("userId" -> {
userId += 1
userId}.toString)))

Related

Postman passing an array as a parameter

Using a Postman to retrieve data from our project management platform that provides collections (Teamwork)
I retrieve a first list of project ID from the Get request using the following code in the Test of that first Get request :
`var jsonData = JSON.parse(responseBody);
var list = (jsonData.projects).length;
var a=[];
for (var i = 0; i < list; i++)
{
var counter = jsonData.projects[i];
IDs=counter.id
a.push(IDs)
}
postman.setEnvironmentVariable("id", a);`
That create a variable id which contains a list of id.
After that, I want to go through each of these id in the following request (replacing {id})
{{Domain}}/projects/{id}/rates.json
Domain is set in the environment variable and is working.
What code and where do i need to put it (Pre-script? Test?) so I can go through the list? That second get request would give me the employee rates in each project (identified by those id)
Thanks for your help
If you want to use the list of variables you extract from the first GET in URLs for subsequent calls, then I think you would need to use the pm.sendRequest option in the 'Test' tab of your first GET.
There is a really good example in this thread:
How to run one request from another using Pre-request Script in Postman
Note: The pre-req tab is executed before the API call is made and the test tab is executed after the API call is made.
Also, "postman." is using the old API, you would benefit from using the newer API which is "pm." so for example;
pm.environment.set("variable_key", "variable_value");
More info on this can be found here:
https://learning.postman.com/docs/sending-requests/variables/

Pass optional request query param in gatling

I am using Gatling 3.6.1.
I would like to attach gatling param to the request in order to force getting the value NOT from the cache. I would like it to be configurable, in a way to attach it when I want to force thing not to use cache and in other times I would like to use cache so I wouldn't attach the param or at least the unique value to it.
This is what I tried:
http("ProductReferencesPDP")
.get(path + "products/${product_code}/references?currentPage=1&pageSize=25&lang=de").queryParam("gatling", session => System.currentTimeMillis().toString)
.check(jsonPath("$..numberOfPages").exists)
And it attaches the gatling param always. But how can I make it optional, meaning someting like this:
http("ProductReferencesPDP")
.get(path + "products/${product_code}/references?currentPage=1&pageSize=25&lang=de").queryParam("gatling", if withCache "" else session => System.currentTimeMillis().toString)
.check(jsonPath("$..numberOfPages").exists)
But it doesn't work like this. I cannot access the session in the if clause or in u custom function for that matter.
Thanks!
.queryParam("gatling", if withCache "" else session => System.currentTimeMillis().toString)
Your if statement returns either a String or a Function. This can't possibly work. Try
.queryParam("gatling", session => if (withCache) "" else System.currentTimeMillis().toString)

Multiple get API in MEAN.IO (Express, Angular)

In traditional REST API, we should define our API like this:
GET /api/things -> get all
POST /api/things -> create
GET /api/things/:id -> get one
PUT /api/things/:id -> update
DELETE /api/things/:id -> delete
How should i define another 'get one' endpoint for querying data by any other field other than id? For example:
GET /api/things/:title -> get one by title (this sure does not work since the api isn't aware of URL parameter names)
GET /api/things/title/:title ? this does not work for me at all..
GET /api/things?title=whatever (this cannot be defined at all. When i write this in my index.js:
router.get('?title=whatever', controller.getByTitle);
I get this:
SyntaxError: Invalid regular expression: /^?title=whatever\/?$/: Nothing to repeat
at RegExp (native)
ID should be an unique identifier. Given one ID, you should return one resource at most. That's why an URI like GET /api/things/:id makes sense.
For other properties which may or may not be unique, you can have more than one result, so use the GET /api/things endpoint and pass query parameters : /api/things?title=mytitle.
app.get('/api/things', function (req, res) {
console.log(req.query.title); //mytitle
ThingModel.find({
title: req.query.title
}, function (err, things) {
res.send(things);
});
});

Make a solr query from Geotools through geoserver

I come here because I am searching (like the title mentionned) to do a query from geotools (through geoserver) to get feature from a solr index.
To be more precise :
I saw on geoserver user manual that i can do query on solr like this in http :
http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature
&typeName=mySolrLayer
&format="xxx"
&viewparams=q:"mySolrQuery"
The important part on this URL is the viewparams that I want to use directly from geotools.
I have already test this case (this is a part of my code):
url = new URL(
"http://localhost:8080/geoserver/wfs?request=GetCapabilities&VERSION=1.1.0";
);
Map<String, String> param = new HashMap();
params.put(WFSDataStoreFactory.URL.key, url);
param.put("viewparams","q:myquery");
Hints hints = new Hints();
hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, viewParams);
query.setHints(hints);
...
featureSource.getFeatures(query);
But here, it seems to doesn't work, the url send to geoserver is a normal "GET FEATURE" request without the viewparams parameter.
I tried this with geotools-12.2 ; geotools-13.2 and geotools-15-SNAPSHOT but I didn't succeed to pass the query, geoserver send me all the feature in my database and doesn't take "viewparams" as a param.
I need to do it like this because actually the query come from another program and I would easily communicate this query to another part of the project...
If someone can help me ?
There doesn't currently seem to be a way to do this in the GeoTool's WFSDatastore implementations as the GetFeature request is constructed from the URL provided by the getCapabilities document. This is as the standard requires but it may be worth making a feature enhancement request to allow clients to override this string (as QGIS does for example) which would let you specify the additional parameter in your base URL which would then be passed to the server as you need.
Unfortunately the WFS module lives in Unsupported land at present so unless you have resources to work on this issue yourself and can provide a PR to implement it there is not a great chance of it being implemented.

node.js, restify - handle a parameter of type array

I have a node.js server with restify. I want to send it a get request that has an array of names in it. I think the request should look like this (but I am not sure about it):
/users?names=bob,joe,michael,joey
Is this query correct?
How do I get the names I send on the node.js server?
The W3C recommendation is that one key can be repeated multiple times with multiple values:
GET /users?names=bob&names=joe&names=michael&names=joey
Good systems will be designed to handle this format of data and be able to recognize multiple keys to group them within an array.
You do not need to specify query variables in your route:
// perform: GET /users?names=bob&names=joe&names=michael&names=joey
server.get('/users', function (req, res) {
// All your query vars from the GET request are in req.query
res.json(req.query.names);
});

Resources