Alternative to splitter in mule - foreach

I have a payload that is repeating which is like below:-
<FinalTest xmlns:ser="com.test://http">
<Test>
</Test>
<Test>
</Test>
..
..
</FinalTest>
I have a sequence of steps that I to execute for each Test object.
Please let me know on how to use mule for each.
Note that is not limited to twice like above it can be any number of times

You can use Mule's ForEach routing processor.
You can make a collection of your objects and then use Foreach to Execute the sequesnce of steps for each of the Test objects.
More help at the following Mule documentation links.
http://www.mulesoft.org/documentation/display/current/Foreach
http://www.mulesoft.org/documentation/display/current/Foreach+Processing+and+Choice+Routing+Example
Hope this helps.

You first need to add Mule namespace manger in your flow since your XML have namespace
reference :- https://developer.mulesoft.com/docs/display/current/XML+Namespaces
Then you can use for each :- https://developer.mulesoft.com/docs/display/current/Foreach
and XPATH
reference :- http://blogs.mulesoft.com/mule-3-6-xml-xpath-xslt-xquery3/

Related

Get list of jobs which created via job-dsl and list of manual jobs

Part of the job was generated through job-dsl, but there is still part of the job that was created by manual. If Jenkins has a mechanism or api to get a list of all manual jobs.
I see that all jobs through job-dsl have a mark which job created them(seed job). Perhaps having received a list of all generated ones, you can take a list of all jobs and weed out manual ...
JobDSL saves information about generated jobs in the javaposse.jobdsl.plugin.ExecuteDslScripts.xml file, example:
<?xml version='1.1' encoding='UTF-8'?>
<javaposse.jobdsl.plugin.DescriptorImpl plugin="job-dsl#1.77">
<templateJobMap class="com.google.common.collect.HashMultimap" serialization="custom">
<com.google.common.collect.HashMultimap>
<default/>
<int>8</int>
<int>0</int>
</com.google.common.collect.HashMultimap>
</templateJobMap>
<generatedJobMap class="concurrent-hash-map">
<entry>
<string>generated-job-name1</string>
<javaposse.jobdsl.plugin.SeedReference>
<seedJobName>job-which-created-it</seedJobName>
<digest>hash1</digest>
</javaposse.jobdsl.plugin.SeedReference>
</entry>
<entry>
<string>generated-job-name2</string>
<javaposse.jobdsl.plugin.SeedReference>
<seedJobName>job-which-created-it</seedJobName>
<digest>hash2</digest>
</javaposse.jobdsl.plugin.SeedReference>
</entry>
...
</generatedJobMap>
</javaposse.jobdsl.plugin.DescriptorImpl>
If you parse the file and collect all javaposse.jobdsl.plugin.DescriptorImpl/generatedJobMap/entry/string values then you get a list of all generated jobs.
You can next get all jobs by using Jenkins.get().getItems(), collect all names and at the end remove those which were found in the javaposse.jobdsl.plugin.ExecuteDslScripts.xml file.
EDIT:
The file keeps an XML representation of the javaposse.jobdsl.plugin.DescriptorImpl class. You can also get it programmatically: Jenkins.get().getDescriptorByType(Class<?> type).
def jenkins = Jenkins.get()
def clazz = Class.forName('javaposse.jobdsl.plugin.DescriptorImpl', true, jenkins.pluginManager.uberClassLoader)
def descriptor = jenkins.getDescriptorByType(clazz)
descriptor.generatedJobMap // map with listed previously entries
I found a way using the script console!
TL;DR:
Jenkins.instance.jobNames.findAll {
job = Jenkins.instance.getItemByFullName(it)
a = job.getAction(javaposse.jobdsl.plugin.actions.SeedJobAction.class)
return a?.isConfigChanged()
}.each {
println it
}
Explanation
It took some digging (and I've no idea what I'm doing; maybe there's an easy way). I noticed that all the information I was looking for was readily available on the "front page" of jobs. Information here can be added via plugins. After searching the JobDsl code for the string "Seed job:" I came across this file, which is a Jelly file. After some guesswork I came up with the code above.
The a object has getters for the information you see accessed via the it object in the Jelly file, e.g. getSeedJob(). For checking whether the config changed you prefix it with is instead of get, presumably because it returns a boolean. If a is null then it was not generated by a seed job.
If you want to automate: Jenkins has a detailed rest api where you can fetch information about jobs etc. You will get JSON objects back which then need to be interpreted.
https://www.jenkins.io/doc/book/using/remote-access-api/
To check if the Api provides the information you need, you can use http://jenkins:8080/job/yourjob/api/json?pretty=true

Ant task to get value of repeating XML element

I have the following requirement.
from Ant xmlproperty task. What happens when there is more than one tag with the same name?
it's clear how to repeat for each file.
My requirement is to iterate for each file and I would like to get the value of 'machine' element for corresponding file
eg:
<echo>${PREFIX.main.tagList.tag.file[file1]}</echo> // should return machine1
<echo>${PREFIX.main.tagList.tag.file[file2]}</echo> // should return machine2
An example would help, but I think I discovered this limitation in the xmlproperty task before. For performing complex processing of external files I would use an embedded groovy task, which just loves XML :-)
You haven't specified a sample input, so here's a similar example:
Parse HTML using with an Ant Script

Add multiple exclusion filters to OpenCover

I know how I can add 1 exclusion filter but, what if I want to exclude multiple projects at one? Do I repeat the "-" statement? or is it comma separated? Particularly, I'm trying to exclude Tests and Installer from the coverage calculation:
<property name="coverage.report.filter" value="+[${product}*]* -[${product}*Installer.Designer*]* -[${product}*Tests]* " />
Sorry, newbie to OpenCover :)
Thanks in advance!
If you type OpenCover.Console.exe on the command line I think you will see that it is accepts space separated filters. This is also detailed on the supplied documentation that should be installed with OpenCover - assuming you are using the download from GitHub.
The information is also available on the WIKI

Canoo and Groovy - how to use storeRegEx

We would like to test the following flow using Canoo. The tests are written in Groovy, and not as Ant tasks.
Send a request to a specific URL (we use "invoke")
Extract specific information from the response (we use "storeRegEx" with property:"ans")
Print the extracted value (for debug purposes). println "${ans}" - does not work
Use the extracted value in the next action (e.g. invoke "new/url/id=#{ans}")
We saw some references to using an AntBuilder, it fails as well.
Is there some example for that flow?
Thanks
remember that it depends on the ant property type (dynamic or ant) whether you have to use #{ans} or ${ans}
println will not work in webtests. Use the description property of webtest steps instead:
group(description:"#{ans}") {
...
}
this will show you the value of your property in the test result.

Dynamic property names in ant

I am reading a file in ant and loading the properties through loadproperties. I am interested in using the value of a specific property, whose name is not known. I know that it follows a pattern because that is how I load the property.
I can echoproperties and see that it is being loaded.
But I dont know how to access its value, given that its name is actually a pattern rather that hardcoded.
How can I access this property's value to do some processing.
I hope this is clear. Please ask if I need to clarify some more.
Take a look at ant-contrib package. Its propertycopy task will do what you need. If you need to resolve an arbitrary number of properties following an established pattern, you would use ant-contrib's propertycopy in conjunction with ant-contribs "for" task.
http://ant-contrib.sourceforge.net/tasks/tasks/index.html
You should use Ant's script task.
I suggest using the beanshell script since it is pure java.
For example, to print all properties for your project, use the following:
<target name="echoprops">
<script language="beanshell">
System.out.println("All Properties: " + project.getProperties().keySet());
</script>
</target>
It should be easy to modify the above script to get the property you want.
To use this task, you will need to run the following in $ANT_HOME first:
ant -f fetch.xml script -Ddest=user
That will download all required optional jars to ~/.ant/lib .

Resources