REST API - SOAPUI - POST script generates key ID at the end of the query - api

I have a bit of a problem here. I was making some API tests using the POST Method in SOAP UI. I put this script to generate a new entry
{
"title":"Mark",
"author":"Hampton",
"text":"TestRest",
"created":"${#Project#Timestamp}" - can be a fixed value
}
I got a proper response and an entry is created as following
{
"title":"Mark",
"author":"Hampton",
"text":"TestRest",
"created":"12/05/2022-15:40",
"id":6
}
The "id" property is generated automatically. I was wondering if there is a way to force the "id" property to be on top. When I did a PATCH method and added a new parameter. The "id" property was above the new parameter
{
"title":"Johan",
"author":"Dudes",
"text":"Dyke",
"created":"12/05/2022-15:40",
"id":6,
"updated":"12/06/2022-17:07"
}
So, how can I do a POST method where the ID is generated automatically at the top, and in the response script, the ID parameter is not at the bottom of a response

Related

How can I make a Jira REST API call to get a specific value?

I am making a Jira REST API call using this example url:
http://example.com/rest/api/2/search/?jql=project=example%20and%20type=test&fields=customfield_14600
Here is an example of the returned JSON
{
"expand":"names",
"startAt":0,
"maxResults":50,
"total":2,
"issues":[
{
"expand":"examples",
"id":"1111",
"self":"https://example.com/rest/api/2/issue/111111",
"key":"EX-1111",
"fields":{
"customfield_14600":{
"self":"https://example.com/rest/api/2/customFieldOption/1111",
"value":"Common",
"id":"11111",
"disabled":false
}
}
},
{
"expand":"examples",
"id":"1111",
"self":"https://example.com/rest/api/2/issue/111111",
"key":"EX-1111",
"fields":{
"customfield_14600":{
"self":"https://example.com/rest/api/2/customFieldOption/1111",
"value":"Uncommon",
"id":"11111",
"disabled":false
}
}
}
]
}
Here is an image of the returned JSON with better formatting
What URL would I use to only return the issues with the value "Common" for the customfield_14600? Basically I am trying to return the number of issues with the "Common" value.
Thank you.
Hello Yousuf and welcome to StackOverflow.
Since you are using a JQL query, you could add another filter to check that the custom field you need has the value you require, as such:
project = example AND type = test AND cf[14600] = "Common"
Or, if you know the name of the custom field and/or prefer it to be readable:
project = example AND type = test AND "Field name" = "Common"
You can check the manual for more operators/keywords.
On another topic, I would recommend using the POST endpoint instead of the GET one for searches that include complex queries. Check the REST API documentation for instructions.

Customize aspnet core routing attribute so that Url.Action() returns a different url?

This is an example of what I want to achieve, however I want to do my own custom attribute that also feeds itself from something other than the request url. In the case of HttpGet/HttpPost these built-in attributes obviously have to look at the http request method, but is there truly no way to make Url.Action() resolve the correct url then?
[HttpGet("mygeturl")]
[HttpPost("myposturl")]
public ActionResult IndexAsync()
{
// correct result: I get '/mygeturl' back
var getUrl = Url.Action("Index");
// wrong result: It adds a ?method=POST query param instead of returning '/myposturl'
var postUrl = Url.Action("Index", new { method = "POST" });
return View();
}
I've looked at the aspnet core source code and I truly can't find a feature that would work here. All the LinkGenerator source code seems to require routedata values but routedata always seems to require to be in the url somewhere, either in the path or in the query string. But even if I add the routedata value programmatically, it won't be in time for the action selection or the linkgenerator doesn't care.
In theory what I need is to pass something to the UrlHelper/LinkGenerator and have it understand that I want the url back out that I defined in my custom attribute, in this case the HttpPost (but I'll make my own attribute).

how to evaluate java function using __groovy and assign it as part of Http Request

I have a http request with the following structure.
Http Request :-
"Accounts": [
{
"accountType": "SAVINGS",
"RefNumber": "${RefNumber}",
"accountNo": "${AccNumber}"
}
],
"encryptionKey": "${__groovy(new com.util.EncryptUtil().encrypt(), encryptedValue)}"
The value of encryptionKey is calculated using the mentioned groovy function. The encrypt function takes the Accounts object and calculates the encryptedValue based on the value of RefNumber and accountNo. The value of accountNo comes from the first Http Response API. The value of the RefNumber comes from the second Http Response API. How do I accept the dynamic Accounts object json and calculate the encrypted value in jmeter and how do I check if the function result is being assigned to encryptionKey using jmeter?
First of all you can check your function output using The Function Helper Dialog
Example class I use for demo looks like:
package com.util;
public class EncryptUtil {
public String encrypt() {
return "some encrypted value";
}
}
Second, you can check your request payload using View Results Tree listener
And finally you can check generated ${encryptedValue} variable using Debug Sampler

Auto-increment Custom Properties for SOAPUI testSuite

I am looking to auto-increment a Custom Property as my SOAPUI test is running. Currently my tests require that there be a unique portion, referred to as UniqueUserPortion, that get incremented as I test for uniqueness in usernames/emails. Is there a way for me to increment this custom property (#Project#UniqueUserPortion), as I will need it to be unique for the next step which is the check for unique username?
Check for unique email:
{
"UpdateIdentityRequest":{
"guid":"${#Project#UserGUID}",
"emailAddress": "tomTestUser11#testit.com",
"screenName": "UpdateUser${#Project#UniqueUserPortion}",
"inputSystem":"${#Project#UserInputSystem}"
}
}
Check for unique username:
{
"UpdateIdentityRequest":{
"guid":"${#Project#UserGUID}",
"emailAddress": "UpdateUser${#Project#UniqueUserPortion}#test.com",
"screenName": "testUser2011",
"inputSystem":"${#Project#UserInputSystem}"
}
}
Remember that internally SoapUI keeps everything in XML, and so all properties are just strings. Further, every Groovy Script step get instantiated as a new class, so it cannot "remember" any previous state.
You will have to do something like:
// read the property as a string
def uniqueUserPortion = testRunner.testCase.testSuite.project.getPropertyValue("UniqueUserPortion")
// convert it to an Integer, and increment
def uniqueUserPortionInc = uniqueUserPortion.toInteger() + 1
// set the property back as string
testRunner.testCase.testSuite.project.setPropertyValue("UniqueUserPortion", uniqueUserPortionInc.toString())
// check
log.info testRunner.testCase.testSuite.project.getPropertyValue("UniqueUserPortion")

Why does storing a Nancy.DynamicDictionary in RavenDB only save the property-names and not the property-values?

I am trying to save (RavenDB build 960) the names and values of form data items passed into a Nancy Module via its built in Request.Form.
If I save a straightforward instance of a dynamic object (with test properties and values) then everything works and both the property names and values are saved. However, if I use Nancy's Request.Form then only the dynamic property names are saved.
I understand that I will have to deal with further issues to do with restoring the correct types when retrieving the dynamic data (RavenJObjects etc) but for now, I want to solve the problem of saving the dynamic names / values in the first place.
Here is the entire test request and code:
Fiddler Request (PUT)
Nancy Module
Put["/report/{name}/add"] = parameters =>
{
reportService.AddTestDynamic(Db, parameters.name, Request.Form);
return HttpStatusCode.Created;
};
Service
public void AddTestDynamic(IDocumentSession db, string name, dynamic data)
{
var testDynamic = new TestDynamic
{
Name = name,
Data = data
};
db.Store(testDynamic);
db.SaveChanges();
}
TestDynamic Class
public class TestDynamic
{
public string Name;
public dynamic Data;
}
Dynamic contents of Request.Form at runtime
Resulting RavenDB Document
{
"Name": "test",
"Data": [
"username",
"age"
]
}
Note: The type of the Request.Form is Nancy.DynamicDictionary. I think this may be the problem since it inherits from IEnumerable<string> and not the expected IEnumerable<string, object>. I think that RavenDB is enumerating the DynamicDictionary and only getting back the dynamic member-names rather than the member name / value pairs.
Can anybody tell me how or whether I can treat the Request.Form as a dynamic object with respect to saving it to RavenDB? If possible I want to avoid any hand-crafted enumeration of DynamicDictionary to build a dynamic instance so that RavenDB can serialise correctly.
Thank You
Edit 1 #Ayende
The DynamicDictionary appears to implement the GetDynamicMemberNames() method:
Taking a look at the code on GitHub reveals the following implementation:
public override IEnumerable<string> GetDynamicMemberNames()
{
return dictionary.Keys;
}
Is this what you would expect to see here?
Edit 2 #TheCodeJunkie
Thanks for the code update. To test this I have:
Created a local clone of the NancyFx/Nancy master branch from
GitHub
Added the Nancy.csproj to my solution and referenced the project
Run the same test as above
RavenDB Document from new DynamicDictionary
{
"Name": "test",
"Data": {
"$type": "Nancy.DynamicDictionary, Nancy",
"username": {},
"age": {}
}
}
You can see that the resulting document is an improvement. The DynamicDictionary type information is now being correctly picked up by RavenDB and whilst the dynamic property-names are correctly serialized, unfortunately the dynamic property-values are not.
The image below shows the new look DynamicDictionary in action. It all looks fine to me, the new Dictionary interface is clearly visible. The only thing I noticed was that the dynamic 'Results view' (as opposed to the 'Dynamic view') in the debugger, shows just the property-names and not their values. The 'Dynamic view' shows both as before (see image above).
Contents of DynamicDictionary at run time
biofractal,
The problem is the DynamicDictionary, in JSON, types can be either objects or lists ,they can't be both.
And for dynamic object serialization, we rely on the implementation of GetDynamicMemberNames() to get the properties, and I assume that is isn't there.