Is there a way to configure 2 property system in same #Value ins spring boot? - spring

I trying to use 2 different property files with the same parameters which every parameter is describing the same property for example:
NewsPaperConsumer.properties, MarketConsumer.properties when every file have the same parameters.
My aim is to use the separated way to make the configuration files more readable but at the progromatic side union them to one hash map for example:
NewPaperConsumer and MarketConsumer have the parameter serverAddress so I'll get it by:
#Value("${serverAddress}")
private HashMap<String,String> serverAdresses;
how I change the way the system property save the parameter (instead of assign the value to string that It will assign it to hash map - {"key" : "value }

Related

Fetch value from XML using dynamic tag in ESQL

I have an xml
<family>
<child_one>ROY</child_one>
<child_two>VIC</child_two>
</family>
I want to fetch the value from the XML based on the dynamic tag in ESQL. I have tried like this
SET dynamicTag = 'child_'||num;
SET value = InputRoot.XMLNSC.parent.(XML.Element)dynamicTag;
Here num is the value received from the input it can be one or two. The result should be value = ROY if num is one and value is VIC if num is two.
The chapter ESQL field reference overview describes this use case:
Because the names of the fields appear in the ESQL program, they must be known when the program is written. This limitation can be avoided by using the alternative syntax that uses braces ( { ... } ).
So can change your code like this:
SET value = InputRoot.XMLNSC.parent.(XMLNSC.Element){dynamicTag};
Notice the change of the element type as well, see comment of #kimbert.

0 xsd:anyURI using esql.IBM Integration Bus

<payload xsi:type="ns787:SomeRequest" xmlns:ns787="http://ws.abc.efg.com"/>
I'm working with IIB v10.0.0.7. I'd like to define one of the XML elements to be of type xsd:anyURI using esql. output should be like given above:
I assume that you are asking about the xsi:type attribute. The XMLNSC parser does not automatically populate the namespace prefix in the value of the xsi:type attribute - you must set the entire value (prefix:localName) as a literal text string.
DECLARE namespace787 NAMESPACE 'http://ws.abc.efg.com';
DECLARE namespaceXSI NAMESPACE 'http://www.w3.org/2001/XMLSchema-instance';
CREATE LASTCHILD OF OutputRoot.XMLNSC.payload TYPE XMLNSC.Attribute NAMESPACE namespaceXSI NAME 'type' VALUE 'ns787:SomeRequest';
CREATE LASTCHILD OF OutputRoot.XMLNSC.payload TYPE XMLNSC.NamespaceDecl NAME 'xmlns:ns787' VALUE namespace787;
or, if you prefer using SET instead of CREATE:
...
SET OutputRoot.XMLNSC.payload.(XMLNSC.Attribute)namespaceXSI:type = namespaceXSI;
SET OutputRoot.XMLNSC.payload.(XMLNSC.NamespaceDecl)xmlns:ns787 = namespace787;
If you are still stuck then you may find this technique useful: How to create a complex object in ESQL

Generate and store random variables

I am trying to create some dynamic user defined variables, use them within http requests in JMETER and also save them to file. Basically I'm testing the creation of accounts and would like to save the accounts I've created.
The problem is when I use User Defined Variables and then set the values as below, it only generated the random strings once and in subsequent loops it uses the same data and fails as email already exists:
FIRSTNAME1 Bob${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}
LASTNAME1 Surname${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}
EMAIL1 Bob${__RandomString(10,abcdefghijklmnopqrstuvwxyz,)}#emailaddres.com
To save this to file I use:
name1 = vars.get("EMAIL1");
name2 = vars.get("FIRSTNAME1");
name3 = vars.get("LASTNAME1");
f = new FileOutputStream("C://test/Register_new_user_Jmeter.csv", true);
p = new PrintStream(f);
this.interpreter.setOut(p);
p.println(name1 + "," + name2 + "," + name3);
f.close(
How do I set this up so I can generate random strings, use them to create new accounts and also save the info to file? Thanks
Yes, User Defined Variables are used for defining once (static) variables, use other component, especially User Parameters for dynamic values.
If a runtime element such as a User Parameters Pre-Processor or Regular Expression Extractor defines a variable with the same name as one of the UDV variables, then this will replace the initial value, and all other test elements in the thread will see the updated value.
User Parameters are creating variables same as User Defined Variable, but can override pervious values
If there are more threads than values, the values get re-used. For example, this can be used to assign a distinct user id to be used by each thread. User variables can be referenced in any field of any JMeter Component.

Spring propery placeholder not working as expected if defined twice

I have defined 2 property placeholder conf with same order .Behaviour what i was found is that if i define a property in the 2nd file with default value it is not picking from the file.if i didnot specify the default value it is taking from the file.can anybody help.``
1)
config.properties
userName=Jithin
2)
configtext.properties
charlength=256
Program:
#Value("${charlength:128}")
private String charLenght;
If i specify the default values as 128, charLenth field is assigned with 128
If i am not specifying the default value. ie:
#Value("${charlength}")
private String charLenght; In this case, it is reading from the property file and assigned with 256

How to use "Result Variable Name" in JDBC Request object of Jmeter

In JMeter I added the configuration for oracle server. Then I added a JDBC request object and put the ResultSet variable name to status.
The test executes fine and result is displayed in treeview listener.
I want to use the variable status and compare it with string but jmeter is throwing error about casting arraylist to string.
How to retrieve this variable and compare with string in While Controller?
Just used some time to figure this out and think the accepted answer is slightly incorrect as the JDBC request sampler has two types of result variables.
The ones you specify in the Variable names box map to individual columns returned by your query and these you can access by saying columnVariable_{index}.
The one you specify in the Result variable name contains the entire result set and in practice this is a list of maps to values. The above syntax will obviously not work in this case.
The ResultSet variable returned with JDBC request in JMeter are in the for of array. So if you want to use variable status, you will have to use it with index. If you want to use the first(or only) record user status_1. So you need to use it like status_{index}.
String host = vars.getObject("status").get(0).get("option_value");
print(host);
log.info("----- " + host);
Form complete infromation read the "yellow box" in this link:
http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
Other util example:
http://jmeter.apache.org/usermanual/build-db-test-plan.html
You can use Beanshell/Groovy (same code works) in JSR233 PostProcessor to work with “Result Variable Name” from JDBC Request like this:
ArrayList results = vars.getObject("status");
for (HashMap row: results){
Iterator it = row.entrySet().iterator();
while (it.hasNext()){
Map.Entry pair = (Map.Entry)it.next();
log.info(pair.getKey() + "=" + pair.getValue());
}
}
Instead of output to log replace with adding to string with delimiters of your choice.

Resources