Use value from previous test - asp.net

I'm using Soap UI Free for testing my ASP.NET web API. I've made a CREATE request to the API and then a test for it and it works - the API saves my data and returns response 200 with some JSON object which also contains the ID value for the newly saved object. How can I use that ID value in the next test which will delete the object?
I found this article on the Soap UI website but it says the technique only applies to Soap UI Pro (which I don't have):
https://www.soapui.org/docs/functional-testing/properties/transferring-properties/

Apparently the method from the article also applies to the free version of SoapUI. It just doesn't say that and even though it mentions how to perform it, it doesn't really explain, how exactly.
You just have to right-click on a test case and then choose Add Step -> Property Transfer.
In the property transfer set-up window:
you have to provide a JsonPath to the value to retrieve (eg. $.data.id),
and then the parameter in the next API call to which you want the value to be copied.
So, if you call a CREATE and receive a response with a Json object:
{ "data":
{ "id": "fhiugreuuieryiuweyr893ry9yr43"
}
}
you can then set up the Property Transfer step by typing $.data.id in the Source section's text field and typing "id" in the Property field in the Target section (which could be your eg. READ, UPDATE or DELETE call).
And your tests tree will look eg. like this:

Related

Parameter transfer to URI in SOAP UI for a Rest Service

I have two REST Services: GET and PATCH.
The GET Service has a JSON Response and from which I need to trasnfer a property named tripId.
Add that property value to the URL of the PATCH Request as a resouce, i.e.,
https://patchRequest.com/api/trips/{tripId}/
Can any one tell me how to do it in SOAP UI/ READY API.
I'm not able to do it.
Thanks
Create a customer property in the test case section ( or even in the project section )
Add a Property Transfer test step and export the value to the holder that you created
Finally, Call the value in your URI

Custom Header with token in PASOE Business Class Entity with Web Service?

I have a PASOE Business Class Entity setup as a Web Service. I'm trying to determine how to create a custom header that will allow me to pass in a hashed token. Is this something that I need to upgrade to 11.7.4 for DOH(OpenEdge.Web.DataObject.DataObjectHandler)? Or is this something that I simply add into a method that's defined in the class? Apologies, for the lack of code to illustrate my situation, but I'm not sure where to begin.
If you're using a Business Entity with the web transport then you're using the DOH, and the below applies. If you're using the rest transport then you are not using the DOH, and are more limited in your choices.
There is doc available on the DOH at https://documentation.progress.com/output/oe117sp/index.html#page/gssp4/openedge-data-object-handler.html - it's for 11.7.4 but largely applies to all versions (that is, from 11.6.3+). This describes the JSON mapping file, which you'll need to create an override to the default, generated one.
If you want to use the header's value for all operations, then you may want to use one of the DOH's events. There's an example of event handlers at https://github.com/PeterJudge-PSC/http_samples/blob/master/web_handler/data_object_handler/DOHEventHandler.cls ; you will need to start that handler in a session startup procedure using new DOHEventHandler() (the way that code is written is that it makes itself a singleton).
You can now add handling code for the Invoking event which fires before the business logic is run.
If you want to pass the header value into the business logic you will need to
Copy the generated mapping file <service>.gen to a <service.map> , in the same folder. "gen" files are generated and will be overwritten by the tooling
In the .map file, add a new arg entry. This must be in the same order as the parameters to the BE's method.
The JSON should look something like the below. this will read the value of the header and pass it as an input parameter into the method.
{ "ablName": "<parameter_name>",
"ablType": "CHARACTER",
"ioMode": "INPUT",
"msgElem": {"type": "HEADER", "name": "<http-header-name>"}
}

How do I find out a field's type information for a 'record' in appmaker in Server script?

I'm trying to create a re-usable script for capturing record changes onSave with Server-side scripting. To do that, I need the model information for a given table, including what type each field is.
I have figured out how to get the model for my table and details for the fields:
var table = "Clients";
var myObject = app.models[table];
// Dump the properties of the 2nd field in the model
console.log("Field 2 properties: " + JSON.stringify(myObject["L"]["fields"]["1"]));
I see this:
{"name":"Client",
"key":"zzzkS1spSPKkRXMn",
"displayName":null,
"description":"Short name for client (must be unique)",
"type":{},
"required":false,
"uid":false,
"defaultValue":null,
"minLength":0,
"maxLength":null,
"integer":false,
"sortable":true,
"minValue":null,
"maxValue":null,
"regexp":null,
"regexpError":null,
"possibleValues":null,
"aggregationType":null
}
"type" looks like an empty property here and I can't seem to figure out how to get any reference to it to tell me what I need.
How do I get usable type information for a given field in a model?
Right now, App Maker doesn't expose an API to access the model metadata.
You snippet is actually accessing App Maker's internal state and might break in future releases (the "L" property is actually obfuscated by a JS compiler and not designed to be accessed from user land).
We know this kind of meta-programming is handy and this is something we might add in the future based on user feedback. Please feel free to submit a request feature in our issue tracker (https://developers.google.com/appmaker/support).

Application Insights Operation.Id from an HTTP header

My project uses ApplicationInsightsHttpModule which initializes Operation.Id from Microsoft.ApplicationInsights.RequestTelemetry HTTP value set by a client UI application. Now I want my API to be consumed by a third party which will provide X-Operation-Id HTTP header to correlate our activities. How do I make Application Insights to initialize Operation.Id from that header if it's present in a request?
This says that the standard context is managed automatically by AI so I need a code sample that shows how to properly initialize Operation.Id with a custom value. The following code isn't working, the header value is ignored:
var operationInitializer = TelemetryConfiguration.Active.TelemetryInitializers.OfType<Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer>().FirstOrDefault();
if (operationInitializer != null)
{
operationInitializer.RootOperationIdHeaderName = "X-Operation-Id";
}
The code that you included in your question should be working at first glance: you are looking for correct initializer and overriding correct property. However there could be multiple reasons why it is not working as expected, and debugging this is hard, because it would require you to actually step into Application Insights code (if you do decide, the sources for every release are archived on GH).
My recommendation in your case would be to take a different approach - instead of trying to override this property, create and register your own telemetry initializer to set Operation.ID from your header. If you set this property, OperationCorrelationTelemetryInitializer will ignore it and not override. This way you confirm that your headers can be read correctly, and you can easily set breakpoint in Initialize method to debug.
At the moment the question was asked AI SDK had version 2.2. Recently I've upgraded to the latest version 2.4 and it's working now as intended. So, if you pass say 'HELLO' in X-Operation-Id HTTP header (you still need that code in the question in Application_Start()) and then ask for a telemetry in Application_BeginRequest() (or wherever HttpContext is available):
RequestTelemetry telemetry = HttpContext.Current.GetRequestTelemetry();
telemetry.Id will contain something like |HELLO.d0b9d5b7_.
That hexadecimal suffix increases if you pass 'HELLO' in the next request so Id is always unique. I don't know if that can be overridden though.

Authorize request in ASP.NET Web API based on specific user

I followed this tutorial http://www.tugberkugurlu.com/archive/api-key-authorization-through-query-string-in-asp-net-web-api-authorizationfilterattribute
to create custom Authorization filter.
I have CarController with my custom Authorize Attribute:
[ApiKeyAuth("apiKey", typeof(ApiKeyAuthorizer))]
I send two parameters in the url .. host/Car/4?username=xxx&pass=xxx
It works basically fine, however I want to allow only car owners to see information about their cars.
E.g. user ABC can see only host/Car/5 and user DEF can see host/Car/6 and host/Car/10
how can I solve this scenario?
How can I access the id of the car used in query (host/Car/ID) in my ApiKeyAuthorizer.
Greetings
If you look at his code, https://github.com/tugberkugurlu/ASPNETWebAPISamples/tree/master/TugberkUg.Web.Http/src/samples and https://github.com/tugberkugurlu/ASPNETWebAPISamples/tree/master/TugberkUg.Web.Http/src/TugberkUg.Web.Http, I think you'll find that he's pulling the data directly from the query string. It should simply be a matter of extending that method to pull in the id parameter. You might also want to look at the RequestContentKeyValueModel on the HttpActionContext parameter passed into the OnAuthorization method. The documentation is sketchy and I haven't played with it yet, but that seems like a likely candidate to me. However, the route data is available indirectly through the HttpRequestMessage via an extension method, specifically:
message.GetRouteData();

Resources