Runnig junit4 tests in junit5 environment, all test cases are failing - junit4

I am trying to use JUnit4 in JUnit5 tests environment. actuallty i have upgraded my pom to use higher version of MOckito and POwerMock.Until now, all tests were based on JUnit4. I added the platform and vintage dependencies to my pom.xml. Noow, my any test case for JUnit4 is not running.
Earlier pom.xml dependencies
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
Latest pom.xml dependencies
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.7.4</version>
<scope>test</scope>
</dependency>
i m getting below errors
Errors:
[ERROR] IntegratorAccessUpdateTest.testBeanProperties:13 » NullPointer
[ERROR] ActionHistoryTest.testBeanProperties » StackOverflow
[ERROR] ApplicationPreferenceManagerTest.testGetBoolean » NoClassDefFound org/powermoc...
[ERROR] ApplicationPreferenceManagerTest.testGetString » NoClassDefFound org/powermock...
[ERROR] CommonValidatorsDispatcherTest.setUp:25 » IllegalState Could not initialize pl...
[ERROR] CommonValidatorsDispatcherTest.setUp:25 » IllegalState Could not initialize pl...
How can i remove these errors, I am not sure that changing each and every class is feasible.is there is any compatibility issue with the versions? why is it showing stackoverflow error?

Junit provides guidance on how to upgrade from Junit4 to Junit5.
https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4

Related

Jersery #FormDataParam and FormDataContentDisposition is not working even after adding maven dependencies

I have added these 3 maven dependency. But when i try to use #FormDataParam and FormDataContentDisposition its showing red mark as it is not found. But I can see that in the multipart lib I am attaching image for reference.
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.27</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.27</version>
</dependency>
</dependencies>
Even after adding dependency in maven it was not working .. Then it showed me suggestion to fix project on the error statement,on clicking that suggestion it asked to add org.glassfish.jersey.media.multipart library to build . Then i simply selected it and ok....It started working

Adding rampart.mar to classpath via Maven

I have been trying to find a solution for this for several days, but with no avail.
I'm currently in the process of introducing Maven to some of my Java projects. One of them requires Axis2 and Rampart for WS Security.
I added all Axis2 and Rampart dependencies in pom.xml:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-core</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-policy</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart-trust</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.rampart</groupId>
<artifactId>rampart</artifactId>
<version>1.5.2</version>
<type>mar</type>
</dependency>
When I import the project in Eclipse, rampart.mar is not there, and attempting to engage the rampart module on runtime causes a failure.
However, when I use maven-dependency-plugin to copy all dependencies to a specific repository, I see that the rampart mar file is there!
This makes me believe that this is a limitation in the Eclipse m2e plugin. Anyone stumbled upon this one before? I saw several similar questions on Stackoverflow that were left unanswered.

Eclipse STS Hibernate error: "Fetching children of Database". org.slf4j.spi.LocationAwareLogger.log

I have looked and tried various solutions dealing with the SLF4J related issue but nothing has worked. All I am trying to do is use the Hibernate plug in inside STS. I Simply click on the Hibernate perspective, Then the down arrow on my project and down arrow on the Database and this exception occurs.
I saw in the properties of the Hibernate console that there is an Eclipse log file dir to a logback. Do I have to setup logback in my pom somewhere?
I used my setup from eclipse tutorials I found online. The only difference is that I'm using the specific STS version and a more recent version of Spring and Hibernate. I have setup the hibernate conifig and the console config.
Any help to get this Hibernate plugin working correctly with Logging using Maven would be really appreciated. Thanks in advance!!
The following is my setup:
STS v3.2, MySQL DB, vFabric Server (comes with STS), Using Maven
POM versions:
<java-version>1.6</java-version>
<spring.version>3.2.2.RELEASE</spring.version>
<spring.security.version>3.1.3.RELEASE</spring.security.version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.7.2</org.slf4j-version>
<org.apache.tiles>2.2.2</org.apache.tiles>
<mysql>5.1.24</mysql>
<hibernate.version>4.1.5.Final</hibernate.version>
<junit.version>4.11</junit.version>
Spring, Hibernate & Logging sections:
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Saw this fix online and was trying - doesn't work, temp commented out
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.1.Final</version>
<exclusions>
Exclude SLF4j to avoid version conflicts (we have 1.6.2, this drags in 1.6.1)
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.1.Final</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
END Saw this fix online and was trying - doesn't work, temp commented out -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.1.0.CR2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
Below is the stack trace:
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getTables(JDBCMetaDataDialect.java:26)
at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:476)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:74)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter$2.execute(LazyDatabaseSchemaWorkbenchAdapter.java:126)
at org.hibernate.console.execution.DefaultExecutionContext.execute(DefaultExecutionContext.java:63)
at org.hibernate.console.ConsoleConfiguration.execute(ConsoleConfiguration.java:107)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.readDatabaseSchema(LazyDatabaseSchemaWorkbenchAdapter.java:115)
at org.hibernate.eclipse.console.workbench.LazyDatabaseSchemaWorkbenchAdapter.getChildren(LazyDatabaseSchemaWorkbenchAdapter.java:65)
at org.hibernate.eclipse.console.workbench.BasicWorkbenchAdapter.fetchDeferredChildren(BasicWorkbenchAdapter.java:106)
at org.eclipse.ui.progress.DeferredTreeContentManager$1.run(DeferredTreeContentManager.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Thanks! I actually ended up just commenting out logging for a couple minutes while I let the Hibernate reveng tool do its thing. Per this post forum.hibernate.org/viewtopic.php?p=2441023 I then readded them after and all is well! :D –
The NoSuchMethodError on LocationAwareLogger.log() method with 6 arguments is symptomatic of a slf4j binding with version prior to 1.6 on the class path. The 'mvn dependency:tree' should indicate as much, i.e that you have an older binding, say slf4j-log4j-1.5.jar.

RequestFactory javax.validation.ValidationException NoClassDefFoundError

I use Guice along with GWT 2.4 but I get a javax.validation.ValidationException NoClassDefFoundError when I run the server. In the pom.xml file I referenced the correct dependency:
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<classifier>sources</classifier>
<scope>provided</scope>
</dependency>
but in Eclipse I can't see the validation-api-1.0.0.GA.jar in the Maven Dependencies tree. The behavior is pretty strange:
I can find validation-api-1.0.0.GA-sources.jar and javax.validation-validation-api-1.0.0.GA-sources.jar under the target directory. I don't understand why it's there.
In the Maven Dependencies tree of eclipse, I can see a reference to javax.validation-validation-api-1.0.0.GA-sources.jar which contains 5 packages but no classes.
Running the app outside eclipse works. I run it using mvn gwt:run.
Any ideas?
The problem came from the dependency gwt-user, I managed to fix it by excluding the dependency on validation-api:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
</exclusions>
</dependency>

Problem with #Indexed annotations in hibernate search

I'm actually trying to deploy HibernateSearch in a J2EE application. I have imported some dependencies I've seen on tuto's :
<!-- HIBERNATE DEPENDENCIES -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>${commons-dbcp.version}</version>
</dependency>
<!-- Hibernate Search -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.3.0.ga</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-analyzers</artifactId>
<version>3.0.3</version>
</dependency>
My problem is, in order to continue, I need to put the #Indexed annotation in my entity classes but I don't have access to this annotation(Eclipse doesn't know it and of course,that doesn't pass the compilation)
Could you give me some advice or lead ? Maybe I don't have the good dependencies ?
I don't use Eclipse or Maven but I can confirm that in my project that uses Hibernate Search 3.3.0 that the Indexed annotation does definitely exist in the hibernate-search-3.3.0.Final JAR. Try update your dependencies to use the latest JAR. There is definitely nothing else that you need to use this annotation though.