Jenkins Gradle test fails on Commons Configuration - java

I have a project that uses Apache Commons Configuration. The project is built using gradle. I have some unit test cases written on this project and gradle test works fine when run locally.
However when the unit tests are run in Jenkins it fails.
Please see the screenshot of the error. The error seems to be to do something with Commons Configuration that I am using. Please help.
org.apache.commons.configuration.ConfigurationRuntimeException: No ConfigurationProvider registered for tag disabledAdministrativeMonitors
org.apache.commons.configuration.ConfigurationException: org.apache.commons.configuration.ConfigurationRuntimeException: org.apache.commons.configuration.ConfigurationRuntimeException: No ConfigurationProvider registered for tag disabledAdministrativeMonitors
at org.apache.commons.configuration.DefaultConfigurationBuilder.createConfigurationAt(DefaultConfigurationBuilder.java:752) ~[commons-configuration-1.6.jar:1.6]
at org.apache.commons.configuration.DefaultConfigurationBuilder.initCombinedConfiguration(DefaultConfigurationBuilder.java:628) ~[commons-configuration-1.6.jar:1.6]
at org.apache.commons.configuration.DefaultConfigurationBuilder.getConfiguration(DefaultConfigurationBuilder.java:560) ~[commons-configuration-1.6.jar:1.6]

The ConfigurationProvider try to load a configuration xml file which is default the config.xml.
In my case the project is build using Jenkins. Jenkins provides a config.xml in Jenkins home dir. This is loaded first instead of my desired one. Maybe that applies for you too?
Example Jenkins config.xml
<?xml version=’1.1' encoding=’UTF-8'?>
<hudson>
<disabledAdministrativeMonitors>
...
</disabledAdministrativeMonitors>
...

Related

Using SpringExtension with Tomcat and Hibernate web app

We are trying to use spring-test's SpringExtension to write integration tests for our Spring and Hibernate-based Tomcat web application. Our sessionFactory bean configuration has the property configured mappingJarLocations with a sample value as /WEB-INF/lib/company-common*.jar which contains hibernate mapping files. In both actual deployment and Eclipse dev deployment, this works fine as the docBasePath (in Servlet environment) is appended to this pattern and the files are getting resolved. But this is not the case while running JUnit test cases either in a local or a CI environment.
We tried our best to use the provided support by having few overridden implementations of WebTestContextBootstraper, GenricXmlWebContextLoader, XmlWebApplicationContext, and WebDelegatingSmartContextLoader but had to finally give up as we cannot override the final method org.springframework.test.context.web.AbstractGenericWebContextLoader.loadContext(MergedContextConfiguration) to provide the custom implementation of XmlWebApplicationContext. Our current approach is to manually create the application context and use it in the tests.
Here is the project structure:
Project_WebApp
|--src/**
|--WebContent/**
|--pom.xml
When the app is packaged as Project_WebApp.war, the dependencies are inside WEB-INF/lib from the root of extracted war. When deployed as a webapp in Tomcat using Eclipse, the dependencies are copied to <Eclipse_Workspace_Dir>/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/Project_WebApp/WEB-INF/lib. In both cases, the dependencies are available at <Resource_Base_Path>/WEB-INF/lib and Resource_Base_Path has no relation to Project_WebApp base directory.
Questions:
Did any one use SpringExtension in a scenario similar to above? If so can you suggest any alternative approaches?
Instead of /WEB-INF/lib/company-common*.jar, we tried a classpath-based pattern but didn't work as the obtained class path resources don't match the pattern. Is there anything else to try here?

Junit test run in Eclipse but fails with `gradle test`

I'm using Spring Boot 2 and I'm trying to do an integration test.
I configured a custom application.properties this way:
#TestPropertySource(
locations = "classpath:###/$$$/application-integrationtest.properties"
)
#ComponentScan(basePackages = { "###.$$$" })
File is under src/test/java/###/$$$/application-integrationtest.properties
Running Junit under Eclipse works fine, but if I try gradle test, I get:
java.io.FileNotFoundException: class path resource
[###/$$$/application-integrationtest.properties] cannot be opened
because it does not exist
What's the deal?
Ok, I put my property file under src/test/resources and added the folder to the build path in Eclipse.
PS: my previous answer was wrong. If I name the file application.properties, the default one has the precedence and it's loaded instead of the test one.

Overriding web.xml context params

I have a maven project that I am migrating to gradle. In the maven project I use the jetty plugin and provide an overrideDescriptor like this:
<webAppConfig>
<overrideDescriptor>override.xml</overrideDescriptor>
</webAppConfig>
Using this, I can override some context parameters from my web.xml with parameters from the override.xml, but any parameters not in the override.xml will revert to the value in the web.xml. This all works as expected.
Now that I am moving to gradle, I am trying to replicate this using the gradle jetty plugin. I tried providing a webXml value, but it replaces the entire web.xml file:
jettyRun {
webXml file('override.xml')
}
Is there any way I can provide the same override functionality via gradle, or am I stuck reworking my override file to be a complete replacement for my default web.xml.
Try overrideWebXml, e.g.:
jettyRun {
overrideWebXml file('override.xml')
}
This is a property on AbstractJettyRunTask, and worked for me.
This would be entirely within the gradle plugin so best to check the documentation for the plugin to see if there is an override option. If not it ought to be relatively easy to add it and contribute back to that project.

How do I configure arquillian suite extension

How do I configure Arquillian Suite extesion?
https://github.com/it-crowd/arquillian-suite-extension
I would like to use it for single deployment tests, in order not to have to deploy for every single class that have #Test methods in my project.
By the way, I'm using TESTNG with arquillian..
I pushed extension bit further, it can be found on maven central and there is part of help written + tests to look how it should be done.
I also created "generic" deployer builder that should work with javaee6.
https://github.com/ingwarsw/arquillian-suite-extension

How to test JPA in Arquillian

I am trying to use Arquillian to test my JPA repository classes. However I only get nullpointer exception telling me that it doesn't find the persistence.xml. How do you configure it in a standard Maven project?
Have you looked # the official documentation here. The project structure suggests that its built using Maven.
If you still run into issues do post the exception messages.
Good luck!
It looks like your ShrinkWrap deployment does not contain the persistence.xml in the right path. The persistence.xml file should be located in the META-INF directory of a JAR, or in WEB-INF/META-INF directory of a WAR. You could verify this in two ways:
Through the verbosity flag of the Archive.toString(...) method:
In your #Deployment method, you can print out the contents of the archive, using the toString method, like
#Deployment
public static Archive<?> createDeployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class).addClasses(Foo.class);
System.out.println(war.toString(true));
return war;
}
Configuring Arquillian to write the generated deployment to disk:
You can add the engine configuration element to your arquillian.xml with the deploymentdeploymentExportPath property, like
<engine>
<property name="deploymentExportPath">target/deployment</property>
</engine>
This would instruct Arquillian to write the deployments it generates into a subdirectory under the target directory generated by Maven.
There is also bunch of examples in the showcase project on github, including JPA testing (also using Arquillian Persistence Extension).
Hopefully this will lead to you to the right path :)

Categories

Resources