Monday, 9 April 2018

Changes to Automating a REST API code base for Java 1.9 RestAssured 3.0.7

TLDR: For Java 1.9 upgrade Rest Assured to version 3.0.6 0r 3.0.7. I also had to add some JAXB Maven Dependencies

I my book Automating and Testing a REST API I used Java 1.8 and Rest Assured version 3.0.1. This was in the days prior to Java 1.9 becoming the default.

I recently checked the code against Java 1.9 and had to make some changes to update Rest Assured.




The move to Java 1.9 from Java 1.8 was the least backwards compatible Java version I have seen. I suspect due to the modules and the reflection.

Both of which seem to have impacted RestAssured.

RestAssured, on its website, reports version 3.0.6 as being the version compatible with Java 1.9

When I used version 3.0.6 in my case study source it did work, but I found some issues with XML parsing.

In RestASsuredXMLExamplesTest the following tests failed:

  • anXmlAPISerializationExample
  • aSetOfXmlPathExamples
  • anXmlAPIDeserializationExample
  • anXmlDeserializationExample
  • anXmlDeserializationExampleFromUrl

I upgraded to version 3.0.7 and the issues were still there.

A variety of stack overflow searches for the exact error messages led me to add three new dependencies into my project.

To remove the error

java.lang.RuntimeException: javax.xml.bind.JAXBException
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]

I added

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>

To remove the error

java.lang.NoClassDefFoundError: com/sun/xml/bind/v2/model/annotation/AnnotationReader

I added

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>

And to remove the error:

java.lang.NoClassDefFoundError: javax/activation/DataSource

I added:


<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

In total I added the following dependencies:

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.3.0</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.3.0</version>
</dependency>

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

I did not need to add the dependencies to run Rest Assured 3.0.7 against Java 1.8, but adding them did not impact Java 1.8 so I left the in the pom without any java version config.

Hopefully this will help anyone else experiencing the same issues.

No comments:

Post a Comment