Testing #RooJavaBean class in Eclipse IDE with JUnit - eclipse

I use Spring Roo to generate getters/setters.
When I update my class under test and then run JUnit tests from Eclipse IDE (STS), it does't see changes I have made.
For example:
java.lang.NoSuchMethodError: com.example.web.forms.UserRegistrationForm_Roo_JavaBean.ajc$interMethodDispatch1$com_datefitting_web_forms_UserRegistrationForm_Roo_JavaBean$com_example_web_forms_UserRegistrationForm$setName(Lcom/datefitting/web/forms/UserRegistrationForm;Ljava/lang/String;)V`
After running roo>perform tests everything runs fine even in IDE. In project settings there is AspectJ builder.
How to run JUnit tests of #RooJavaBean annotated class in IDE, without invoking mvn test or roo>perform tests?

Is the Roo shell open in STS while you are running? In order for your aspects to be recreated based on changes to the target types, the Roo shell must be running in the IDE. If it is running on the command line (from outside the IDE), STS will not be made aware that changes have been made to aspects and it will not be picked up in your project.

Related

is it possible to run geb-spock test on eclipse IDE

Using the junit runner, is it possible to run geb-spock test like a normal spock tests?
It seems that a stock eclipse installation can't do it and couldn't find any eclipse plugin to add the functionality.
I'm trying this using eclipse-oxygen latest.
To run Geb-Spock tests like a normal Spock test. (I am thinking you mean without initializing a browser.) Just extends Specification instead of extends GebSpec. Spock uses jUnit as the default test runner. So a Eclipse plugin for jUnit should work with Spock.

Automate JUnit tests for functionality on the server in Eclipse?

I would have added some JUnit tests to an Eclipse project that test functionality on the server to an Eclipse web project.
I can run the web application from inside Eclipse on an external Tomcat server (Run As | Run on Server) and then run the JUnit tests also from inside Eclipse while the first is still up.
I understand that is should be possible to fully automate both steps as one by making use of a Jetty (instead of Tomcat) server that runs inside Eclipse and that could be booted e.g. in #BeforeClass (or earlier).
Does Eclipse support this kind of unit testing out-of-the-box. I am currently using Eclipse Java EE IDE for Web Developers (Version: Kepler Service Release 2).
Eclipse (and any other IDE for that matter) doesn't stop you from doing anything in unit tests. It doesn't really support much, either, which is the core of your problem: Eclipse won't start a server for your unit tests. The same is true for all other IDEs that I know of.
Instead, you need to read up on how to embed Jetty in a Java application (= your unit tests) so the first test can start the server. Use a lazy init pattern for this:
private static JettyManager jetty;
#Before public void startServer() {
if( null == jetty ) {
jetty = new JettyManager();
jetty.start();
}
}
You can use a JVM shutdown hook to cleanly stop the server.
I use the same pattern to create the database which should be used during the tests to make sure it's clean. For this, I embed an H2 database.
If you want more automation, look at Maven. It can run integration tests (including deploying the WAR before starting the tests). See http://www.benoitschweblin.com/2013/03/run-jetty-in-maven-life-cycle.html
With the Maven Cargo plugin, you can deploy to almost every J2EE container.
Or use Jenkins: http://programmaticponderings.wordpress.com/2013/11/13/building-a-deployment-pipeline-using-git-maven-jenkins-and-glassfish-part-2-of-2/

Maven build runs when I run a Unit test in eclipse

I have a maven project. I am trying to run a single test in maven command line and that works fine. I am trying to debug that test in eclipse and using -Dmaven.surefire.debug option and starting a debug on port 5005 as "Remote Application" in maven - ref http://maven.apache.org/surefire/maven-surefire-plugin/examples/debugging.html
Now when I do so - as part of my maven command in command line all classes/test-classes, spring config get compiled and put in right places. However when I am Run Debug from eclipse when the test pauses to listen on port 5005 - I see eclipse is running a maven build all over again and all classes are recompiled. And while doing this it is not picking up all the profiles required for the test as not all profiles are active by default. I could fix that by Project->Properties->Maven and set the active Maven profiles there.
What I am looking for if why is eclipse trying to do a maven build when I am trying to run my test for which a compiled class is already present? Is that a default behaviour of eclipse maven plugin m2e? And can this be turned off - so that it only executes the class instead of trying a maven build?

JUnit test fails with java.lang.ClassNotFoundException: com.mysql.jdbc.Driver on Tycho environment

I have a very strange situation. I have a set of eclipse plugin projects which I am using tycho and maven for building them. I used JDBC driver in one of the projects and I have a test plugin to test this project. Since the com.mysql.jdbc plugin was not available in the eclipse p2 repository ( and we don't have our own p2), I imported the jdbc plugin and created an OSGi plugin and add the dependency to my local plugin.
I have multiple eclipse workspaces sat up. Only in the very first workspace that created the test and jdbc plugin, junit tests are working when I run them using eclipse run as -> Junit test command. When others or even me checkout the source codes and try to run the test in different workspaces, this exception is thrown:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I also tried using tycho integration test (runing mvn integration-test) but that doesn't work neither and I still get the same exception. I tried searching for this a lot but I couldn't find the answer.
UPDATE:I think it is not a tycho problem. I just tried to create the eclipse plug in based on com.jdbc.mysql jar. The workspace I created this on is working fine. But as soon as I commit the code and import the project in another workspace the tests stop working. All of the settings are same among two workspaces, one is working the other gets the ClassNotFound exception!
Tycho computes the OSGi runtime based on the transitive dependencies of your test bundle.
You probably have no design-time dependency on the mysql driver bundle (but rather only on the JDBC interfaces it implements)
Try adding a test runtime dependency on the mysql jdbc driver bundle.
See http://wiki.eclipse.org/Tycho/FAQ#How_to_add_a_undeclared_dependency.3F__.28e.g..2C_OSGi_declarative_service.29 on how to do this.
ClassNotFoundExceptions in an OSGi runtime indicate that there is something wrong in the imports and/or export declarations in the OSGi manifests. The most frequent case is that a bundle claims to export a certain package, but doesn't actually have the binaries/class files of that package.
In a Tycho build, this can easily happen if you don't have the entry . in the bin.includes property in the build.properties.

JUnit uses wrong Base64

I wanna use the class Base64 from commons-codec 1.5 and when I run the code on Server this works fine. My application runs on Websphere 7.0.
But when I run my JUnit tests the wrong Base64 Class is choosen, when i ask the Class with:
System.out.println(Base64.class.getProtectionDomain().getCodeSource().getLocation());
the output is: file:/C:/EProg/IBM/SDP80/runtimes/base_v7/plugins/com.ibm.ws.prereq.soap.jar
Thats definitly the wrong Version.
And an error occurs because of the wrong Version:
java.lang.NoSuchMethodError:
org/apache/commons/codec/binary/Base64.decodeBase64(Ljava/lang/String;)
The crazy thing is, that happens only it i choose one Test and run it with Run As: JUnit Test in Eclipse, if I run the whole thing with Maven everthing works fine.
I use JUnit 4.8.1 and Eclipse Indigo Service Release 2 with some Plugins for Websphere, GWT and Maven.``
com.ibm.ws.prereq.soap.jar is an OSGi bundle, and in WebSphere (which is built on an OSGi container), the classes in org.apache.commons.codec.binary are not visible to applications because that package is not exported by the OSGi bundle (you can examine the list of exported packages by looking at the META-INF/MANIFEST.MF file in com.ibm.ws.prereq.soap.jar). That explains why you don't encounter any issue when running your application in WebSphere.
On the other hand, when you add that JAR to a Java project in Eclipse, it will be treated like a simple JAR, not an OSGi bundle, and all packages will be visible. In your case this creates a conflict with another commons-codec dependency.
I guess that the reason why you don't encounter that issue in Maven is that com.ibm.ws.prereq.soap.jar is only a dependency of your Eclipse project, but not of your Maven project.
Unfortunately there are not many (simple) ways to solve that issue. One is to remove com.ibm.ws.prereq.soap.jar from your Java project (I doubt that you are actually using Apache SOAP). The other is to change the order, so that your other commons-codec dependency comes before com.ibm.ws.prereq.soap.jar.
It looks like a class path issue. More precisely, Eclipse integration with Maven. I would investigate Eclipse dependencies and make sure that it uses Maven for dependency management.
You can do it in two ways, either you can run mvn eclipse:eclipse command or use M2Eclipse plugin. If you use the later, then there is a update dependency option, in the project context menu.