OT: Maven2 Junit4 JPA problem

I have a JUnit4 test class that tests my JPA bean that uses annotations. It runs correctly if I run it via right-clicking on it and running it in IntelliJ, but does not run via mvn test. The basis for this project is the Practical Apache Struts2 Web 2.0 Projects book. The difference is that I am using JUnit4 and Oracle. I closed the project, then opened it via the pom.xml to ensure that all of the modules, etc are in sync with what Maven expects.

Here is the maven output:
Scanning for projects...
-


Building Struts 2 Starter
task-segment:
-


Attempting to resolve a version for plugin: org.apache.maven.plugins:maven-resources-plugin using meta-version: LATEST
Using version: 2.2 of plugin: org.apache.maven.plugins:maven-resources-plugin
Attempting to resolve a version for plugin: org.apache.maven.plugins:maven-compiler-plugin using meta-version: LATEST
Using version: 2.0.2 of plugin: org.apache.maven.plugins:maven-compiler-plugin
Attempting to resolve a version for plugin: org.apache.maven.plugins:maven-surefire-plugin using meta-version: LATEST
Using version: 2.4.2 of plugin: org.apache.maven.plugins:maven-surefire-plugin
Attempting to resolve a version for plugin: org.apache.maven.plugins:maven-war-plugin using meta-version: LATEST
artifact org.apache.maven.plugins:maven-war-plugin: checking for updates from central
Using version: 2.1-alpha-1 of plugin: org.apache.maven.plugins:maven-war-plugin

Using default encoding to copy filtered resources.

Compiling 4 source files to C:\Documents and Settings\SheltonN\IdeaProjects\struts2-book\target\classes

Using default encoding to copy filtered resources.

Compiling 3 source files to C:\Documents and Settings\SheltonN\IdeaProjects\struts2-book\target\test-classes
In mojo: test, parameter: skipExec is deprecated:




Surefire report directory: C:\Documents and Settings\SheltonN\IdeaProjects\struts2-book\target\surefire-reports

-


T E S T S
-


Running com.fdar.apress.s2.UserLoginTestCase
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 1.002 sec <<< FAILURE!
Running com.fdar.apress.s2.HelloWorldActionTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.32 sec
Running com.fdar.apress.s2.IndexActionTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.05 sec

Results :

Tests in error:
testCreateFindUserLogin(com.fdar.apress.s2.UserLoginTestCase)
testCreateFindUserLogin(com.fdar.apress.s2.UserLoginTestCase)

Tests run: 4, Failures: 0, Errors: 2, Skipped: 0

Maven Embedder execution error: There are test failures.

Please refer to C:\Documents and Settings\SheltonN\IdeaProjects\struts2-book\target\surefire-reports for the individual test results.
org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:530)
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:636)
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:498)
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:320)
org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:148)
org.apache.maven.DefaultMaven.execute_aroundBody0(DefaultMaven.java:223)
org.apache.maven.DefaultMaven.execute_aroundBody1$advice(DefaultMaven.java:304)
org.apache.maven.DefaultMaven.execute(DefaultMaven.java:1)
org.apache.maven.embedder.MavenEmbedder.execute_aroundBody4(MavenEmbedder.java:827)
org.apache.maven.embedder.MavenEmbedder.execute_aroundBody5$advice(MavenEmbedder.java:304)
org.apache.maven.embedder.MavenEmbedder.execute(MavenEmbedder.java:1)
org.jetbrains.idea.maven.runner.executor.MavenEmbeddedExecutor.execute(MavenEmbeddedExecutor.java:94)
org.jetbrains.idea.maven.runner.MavenRunnerImpl$2.run(MavenRunnerImpl.java:112)
com.intellij.openapi.progress.impl.ProgressManagerImpl$5.run(ProgressManagerImpl.java:2)
com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:8)
com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:50)
com.intellij.openapi.progress.impl.ProgressManagerImpl$6.run(ProgressManagerImpl.java:5)
com.intellij.openapi.application.impl.ApplicationImpl$5.run(ApplicationImpl.java:9)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
java.util.concurrent.FutureTask.run(FutureTask.java:138)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
java.lang.Thread.run(Thread.java:619)
com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:1)



Attachment(s):
com.fdar.apress.s2.UserLoginTestCase.txt
0

Do the tests pass with 'mvn test' command?

0

No they do not. They work correctly when I have IntelliJ run the tests, but mvn test produces the results that I posted. Attached is the pom.xml



Attachment(s):
pom.xml
0

Accoring to the logs and the stacktrace I reckon it is a configration problem.
You should consult with the jpa and toplink documentation.
The cause of the failed tests is this:

javax.persistence.PersistenceException: No Persistence provider for EntityManager named goarmy: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory:
java.lang.AssertionError
java.lang.AssertionError
at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:263)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:148)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:110)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
at com.fdar.apress.s2.UserLoginTestCase.setUp(UserLoginTestCase.java:28)

0

Correct. That is what I see. The persistence.xml does exist in the META-INF directory like it is supposed to. It runs via the IntelliJ test correctly, but does not via the mvn test. I verified that this is being moved to the test-classes for maven.

oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider com.fdar.apress.s2.entity.UserLogin ]]>
<!TopLink Essentials specific properties>
]]>

0

Not quite understand - What is correct? 8) Have you found the cause of the problem?
If you haven't - check if the resources directory (with META-INF) is in the right place (look at the maven-war-plugin documentation)

0

The problem is that mvn test does not work. It acts like it cannot find the persistence context. If I run the JUnit test directly from IntelliJ by right-clicking on the class and running it, it works fine. There appears to be something in the IntelliJ configuration that is missing/incorrect in the Maven only configuration. I was thinking that there was something that was missing from the pom.xml that IntelliJ was assuming was there (like jee.jar), but when I have the project rebuilt from the pom.xml, it still has the same problem.

0

There is your descriptor localed? In accordance with http://maven.apache.org/plugins/maven-war-plugin/usage.html, it must be found in src/main/webapp directory. Please check your project layout and run 'mvn validate'

0

请先登录再写评论。