How can I pass more than one value for the same parameter to my request [soap mock service]? - web

How can I pass more than one value for the same parameter to my request [soap mock service]?
<invoices>
<!--Zero or more repetitions:-->
<invoiceData>
<id>test</id>
<MPK>test</MPK>
<RK>3</RK>
<value>100</value>
</invoiceData>
</invoices>

Related

using applyDecorators and Interceptors

I have a applyDecorators that called postCall.
This postCall built from 4 decorators Post,ApiOperation,ApiResponse,UsePipes.
And I have Interceptor that convert to me the property in the request body from camel case to snake case. When I using both of them the interceptor doesn’t work.
example :
#PostCall(...)
#UseInterceptors(...)
function(#Body()...){
...
}

How to test agains null or undefined values?

I am creating an API using typescript and as usual, i am getting values from request.body. here is the thing, those values can be undefined and i need to pass those values to my factories.
Inside a factory i have a function that validates whether the value is null or undefined. (and some other validations) In this way i make sure not passing undefined or null values to my instances. But i cannot test it because of type definitions.
The value generated from request can be or not undefined, but the constructor can get that value. When i try to test it i cannot, because the interpreter do not let me pass a null or udnefined value (because of type), example:
...
const { value } = request.body;
const result = myFactory.create(value);
// This works fine because body can be anything, literaly, even undefined.
//Althought the function is waiting for a number.
...
const nullValue = null;
const result = myFactory.create(nullValue);
// this does not work, because the function want a number and is getting a null value.
// but i need to do this in order to test that case.
...
Here is the thing: how can I test that?
I cannot generate a null value for the situation where the function receibe a null or undefined and don't create the instance because of that.
should i get out of the function the code section that validate againstNullOrUndefined?
If you expect myFactory.create factory to receive number | null | undefined then it should reflect in the type signature.
If you are receiving data from api call which is always any (or better unknown) then these factories should take any or unknown parameter.
Or you can have separate function decode(value: unknown): number which you call first and then pass decoded number to myFactory.create
There are libraries which does just that (decoding data to your domain models/types) for example io-ts

DocuSign optional parameter node js sdk

How to specify the optional parameter in update node js sdk method. Update ( account ID, envelope I'd , envelope obj )
You just add the parameter you want to the call
so, if there's an optional parameter in a method method1, you can call it like this:
method1(param1, param2, param3);
(where if param3 is optional you can also call it like this:)
method1(param1, param2);
you can also (See here - Is there a way to provide named parameters in a function call in JavaScript?) specify the names of the parameters:
method1(param1 - "param1", param2: "param2");

How to cast groovyx.net.http.HttpResponseDecorator to user defined class

I am writing a Integration Test class using Spock Framework, there my response hold inside groovyx.net.http.HttpResponseDecorator
I am trying to cast into my own class lets say TestEntity using following step
HttpResponseDecorator response = getRestClient().delete([path: "$BASE_URL"+"/96023"])
Here the Path method returns TestEntity, Now I want to get that entity and write assertions
TestEntity entity = (TestEntity)response.getData()
When I write this statement I am getting ERROR!
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object
What class is returned by getData() depends on what content type returns the REST API you are calling.
Add this line to check what class is Groovy using in your case:
println response.data.getClass()
... or use debug in your IDE to obtain the same information.
For example for content type:
application/json class org.apache.groovy.json.internal.LazyMap is used
application/xml class groovy.util.slurpersupport.NodeChild is used
text/plain class java.io.StringReader is used
If you are testing backend which uses the TestEntity class as a response (for example using #RestController and #RequestMapping in Spring) then you will not have TestEntity instance in the client (Spock test).

Spring Integration - Use SpEL in service-activator nested bean constructor-arg

I am trying to use a factory-method to initialize a service-activator as below
<int:service-activator>
<bean class="com.sample.FileWriterFactory" factory-method="createFileWriter">
<constructor-arg index="0" value="${xml.out-directory}/xml"/>
<constructor-arg index="1" value="#{ headers['file_name'] + '.xml' }"/>
</bean>
</int:service-activator>
However, the SpEL evaluation fails since the headers property is not found in the evaluation context. The exact error snippet is
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'headers' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
The purpose of doing this is that I want to reuse the same POJO by passing different parameters as needed.
What am I doing wrong?
#{...} expressions are evaluated once, during context initialization.
Expressions accessing properties (such as headers) like that need to be evaluated at runtime (against the message as the root object).
If that's what you are trying to do, use value="headers['file_name'] + '.xml'" and then, within your constructor...
private final Expression expression;
public FileWriterFactory(String directory, String expression) {
...
this.expression = new SpelExpressionParser().parseExpression(expression);
}
then, in your runtime service method
String fileName = this.expression.getValue(message, String.class);

Resources