How to validate "multi header"? - rest-assured

I have a JAX-RS service that returns multiple "Link" headers:
Expires=Thu, 01 Jan 1970 01:00:00 CET
Link=http://localhost:7080/rest/resource?ps=2&category=service&page=2; rel='next'
Link=http://localhost:7080/rest/resource?page=1&ps=2&category=service; rel='current'
Content-Encoding=gzip
Now I want to validate that there is a link with rel=next and another with rel=current, but none with rel=prev
When I write
expect()
.header("Link", containsString("page=2"))
.header("Link", containsString("current"))
.header("Link", not(containsString("prev")))
Then rest-assured fails on the 2nd line, as the 1st Link header line from above does not contain 'current'
What is the right way to run those checks?

I don't think you can do it in that way unfortunately (because REST Assured returns only the first header value). A workaround would be:
List<Header> listHeaders = get("/your_resource").headers().getList("Link");
Now you can assert each header value using using normal JUnit asserts (or something similar).

Related

configure Saxon in eXist-db 5+ for xinclude

As of version 5.0 eXist-db no longer supports dynamically passing the option expand-xincludes=no to the Saxon processor during serialization. As such, I have to configure this in a Saxon config file. However this configuration does not seem to work - the xincludes are still being expanded in output.
Steps:
Following this comment and Saxon docs I created a configuration file called saxon-config.xml with the #xInclude="false" parameter:
<configuration xmlns="http://saxon.sf.net/ns/configuration" edition="HE">
<global xInclude="false"/>
</configuration>
I saved this in eXist's /etc/ directory and pointed to this file in the attribute in eXist's conf.xml:
<transformer class="net.sf.saxon.TransformerFactoryImpl" caching="no">
<attribute name="http://saxon.sf.net/feature/version-warning" value="false" type="boolean"/>
<attribute name="http://saxon.sf.net/feature/configuration-file" value="/Applications/eXist-db-5.2/etc/saxon-config.xml" type="string"/>
</transformer>
Yet the serializer still expands all the xincludes on output.
As a test to see if Saxon is reading the config, I put a deliberate error in the Saxon config file and Saxon objected.
Have I configured this for xInclude correctly?
--- adding more about workflow ---
Serialization in eXist 5.0 is performed in Xquery with the function fn:serialize().
I obtain a node (testing shows that this action does not expand xi:includes automatically in eXist) = $mydoc
I pass the node to the function with certain parameters, for example
fn:serialize($mydoc, map {"indent":true(),"method":"xml", "omit-xml-declaration":false()})
Output has expanded xinclude
I noticed this message on a recent mailing list, perhaps it's relevant.
My reading of this is that it's eXist doing the serialization with XInclude expansion, and this has nothing to do with Saxon. This doesn't solve your problem but hopefully it means you will be able to look in the right place for a solution; nothing you do with Saxon configuration options is going to make any difference.
Hi Ihe,
See the eXist documentation on XInclude, particularly the section on error handling:
https://exist-db.org/exist/apps/doc/xinclude
Joe
On Thu, Jun 18, 2020 at 7:50 AM Ihe Onwuka <ihe.onwuka#gmail.com> wrote:
5.2.0
On Thu, Jun 18, 2020 at 6:31 AM Jean-Paul Rehr <rehrjb#gmail.com> wrote:
Which version of eXist? Prior to 5.0 you can use
declare option exist:serialize "expand-xincludes=no";
in your Xquery declarations to allow/disallow Xinclude expansion (assuming you are using Xquery to execute the transformation). After 5.0...this no longer has an effect. Hopefully it will be reintroduced or another method discovered (see https://github.com/eXist-db/exist/issues/3446).
On Thu, Jun 18, 2020 at 11:12 AM Ihe Onwuka <ihe.onwuka#gmail.com> wrote:
A short while ago I wrote a transform that was supposed to transform a certain input element to an Xinclude element.
eXist blew up because it tried to resolve Xinclude call as soon as I attempted to store the transformation in the database.
Is that supposed to happen? Including the xsl list because am wondering whether this was a use case for namespace aliasing.
I have since solved the problem another way so the question is of academic interest only.
_______________________________________________
Exist-open mailing list
Exist-open#lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/exist-open

Add field to JSON api to retrieve date of build job

At the moment, in Jenkins 2.204.1, using JSON API it is not possible to retrieve date of build job. How can I add that field to build info?
On the bottom right of the build page there is an API link. There I found this URL for querying the build timestamp:
https://JENKINSROOT/job/JOBNAME/BUILDNUM/buildTimestamp
Example output: 2/28/20 10:23 PM
This could be local-dependent.
You can also specify a date format:
https://JENKINSROOT/job/JOBNAME/BUILDNUM/buildTimestamp?format=yyyy/MM/dd+HH:mm
Example output: 2020/02/28 22:23
To get latest build you can use literal "lastBuild" in place of BUILDNUM, e. g.:
https://JENKINSROOT/job/JOBNAME/lastBuild/buildTimestamp

XDoclet Ant Tasks Not Respecting force="true" Attribute

I've been running into some issues with the ejbdoclet Ant task, specifically, it is giving me output such as the following:
[ejbdoclet] XJavaDoc Ignoring class myClass in
/path/myClass.java. It was generated (Wed Mar 28 16:59:12 EDT 2012) after XJavaDoc's timestamp was reset (Wed Mar 28 16:58:52 EDT
2012)
You will note that the file is being ignored because it was generated after the timestamp on the file. The source files are currently sitting on an NFS share connected to the build cluster and for various resasons, generating the files on the local machines will not be posible. As such, I have used the force="true" tag as documented as follows:
<ejbdoclet ejbSpec="2.0" destdir="${common.generated}" force="true">
However, it is not being respected by XDoclet, any thoughts as to what might be going on?
Oddly enough, this appears to be an error where the message that was provided didn't accurately reflect what was expected. The error message indicates that the file is being ignored due to the fact that it's date stamp is in the future when compared to the one that ejbdoclet is using to determine if the files should be generated. This actually bypasses the force attribute so the error is actually with regards to the system clocks not being synchronized as opposed to with ejbdoclet itself per se.

URLTrigger plugin. Need examples for TXT-RegEx or XML-XPath

So, I try to use plugin https://wiki.jenkins-ci.org/display/JENKINS/URLTrigger+Plugin.
I want to trigger my Jenkins job when the text "Last build (#40), 17 hr ago" in the response of provided URL is changed (build number will be different after each build).
So I made following configurations:
1. Build trigger: Set [URLTrigger] - Poll with a URL.
2. Specified URL to another Jenkins: http://mydomain:8080/job/MasterJobDoNothing/
3. Set Inspect URL content option
4. Set Monitor the contents of a TEXT response
5. Set following regular expression: ^Last build[.]*
6. Set Schedule every minute: * * * * *
7. Trigger the job on another Jenkins
Actual result: My job wasn't triggered.
Then I tried to deal with XML/XPath and specify
8. Set Monitor the contents of an XML response
9. Set XPath: //*[#id="side-panel"] (also tried with one "/")
Actual result: the same.
Tell me please what I'm doing wrong? Please provide examples of RegEx or XPath if possible.
Thanks, Dima
I managed to trigger reliably with regex setting.
The regex pattern matches each line of the input.
No need to use ^ or $. it always match line start to line end.
This plugin compares the contents of the matched lines. It triggers if different.
This plugin compares the count of the matched lines. It triggers if the count is different.
This plugin uses matches() method of java.util.regex.Matcher. So the regex pattern should conform to it. (it's fairly normal regex)
As for your example,
Last build.*
may work.
Refs:
Reference of regex patten:
http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
Reference of Matcher: http://docs.oracle.com/javase/7/docs/api/java/util/regex/Matcher.html#matches()
The regex trigger source code:
github.com/jenkinsci/urltrigger-plugin/blame/master/src/main/java/org/jenkinsci/plugins/urltrigger/content/TEXTContentType.java
I'd recommend to use the "RSS for all" link as a trigger URL instead, and /feed/entry[1] as the XPath expression for the XML response content nature.
PS: I was using PathEnq to debug the XPath expression.

Feed Parsing In Rails

I am working on Ubuntu 10.04 and I am using feed-zirra to parse RSS feeds and I have MySQL database.
I am trying to parse RSS feeds from Times of India Top Stories. There seems to be problem with the first link, I am sure TOI guys will correct it soon. But anyway, I dont want to face similar error later so thats why I want to ask you guys how to solve this problem.
Just look at this and especially look for link
<item>
<title>CWG: Abhinav Bindra, Gagan Narang win first Gold for India</title
<description>Abhinav Bindra and Gagan Narang on Tuesday bagged Gold for the men's 10 m air rifle pair's event, getting India its first gold in the 19th Commonwealth Games.</description>
<link>/cwgarticleshow/6688747.cms</link>
<guid>/cwgarticleshow/6688747.cms</guid>
<pubDate>Tue, 05 Oct 2010 04:57:46 GMT</pubDate>
</item>
The link is <link>/cwgarticleshow/6688747.cms</link>
Now, when I click the link, in the view.. its getting routed to http://localhost:3000/cwgarticleshow/6688747.cms instead of http://timesofindia.indiatimes.com/cwgarticleshow/6688747.cms
And the error I am getting is
**Routing Error**
No route matches "/cwgarticleshow/6688747.cms" with {:method=>:get}
How do I correct this type of Error?
Looking forward for your help and support
Thanks
You just need to prepend http://timesofindia.indiatimes.com to the link tag value and you'll be ok.
You can use URI class. You can, for example, define following method
require "uri"
def repair_link(feed_link)
uri = URI.parse(feed_link)
uri.scheme ||= "http"
uri.host ||= "timesofindia.indiatimes.com"
uri.to_s
end
It will set the scheme and host part of the URL if they are not already filled. So if you call it for normal link (like http://foo/bar.cms) then nothing will be changed.
And last thing - you probably should catch exception somewhere as the #parse method raises exception InvalidURIError in case of invalid URI. But it's up to you how you will deal with it.

Resources