Lev,
A few things:
1) One sec... have you got things working without JUnit? If you have
NOT configured your web.xml to execute the code and have it working
without issues - end to end - with the object persisted in the DB - then
I would focus on that before getting it work w/ JUnit.
Furthermore, as you mentioned Freddy's book and even presented some
source therein you have all the tools to get the basic web app version
working. Once you have that code working then the JUnit version should
work with the code I provided (see update below) and / or by leveraging
the Rayures framework that Freddy mentioned (which simplifies a web.xml
into a mock context).
2) An IDE debugger is your friend. Just because the code is framework
code does not mean that it hurts - in fact it can help immensely - to
obtain the framework source jar (Stripes and Stripersist) and have your
IDE point to them as you step through the issues (e.g. clicking on the
exception in the stack trace OR even in learning more about how the code
works and / or potentially uncovering a bug).
Translation - when you get an exception - throwing your hands up in the
air isn't very helpful... looking at the code is the way to go :-) i.e.
the exception you provided appears to be caused by an issue somewhere in
a catch block that is 100 lines of initialization code... I have no idea
where exactly it is failing... . Also you may want to enable Stripes
debug mode to get more output.
3) Now the only thing that could possibly have been missing in the code
I provided earlier was a location to your action beans package (I didn't
think Stripes expected it but perhaps it does). So here it is once
again with the additional config line - of course put your own root
action bean package folder:
Map<String, String> filterParams = new HashMap<String, String>();
filterParams.put("ActionResolver.Packages",
"org.test.ui.web.action");
filterParams.put("Extension.Packages",
"org.stripesstuff.stripersist");
this.servletContext.addFilter(StripesFilter.class,
"StripesFilter", filterParams);
this.servletContext.setServlet(DispatcherServlet.class,
"StripesDispatcher", null);
HTH,
--Nikolaos
Lev wrote:
nikolaos,
i appear to be making progress, but now a new error.
it appears that stripes is not happy with the attempt to register
the StripesFilter. stacktrace below:
Testcase: stripesbook.dao.impl.stripersist.UserDaoImplTest:
Caused an ERROR
Exception registering new filter with name StripesFilter
java.lang.RuntimeException: Exception registering new filter with name
StripesFilter
at
net.sourceforge.stripes.mock.MockServletContext.addFilter(MockServletContext.java:215)
at
stripesbook.dao.impl.stripersist.UserDaoImplTest.setUpClass(UserDaoImplTest.java:37)
Caused by: net.sourceforge.stripes.exception.StripesRuntimeException:
Problem instantiating default configuration objects.
at
net.sourceforge.stripes.config.DefaultConfiguration.init(DefaultConfiguration.java:220)
at
net.sourceforge.stripes.config.RuntimeConfiguration.init(RuntimeConfiguration.java:272)
at
net.sourceforge.stripes.controller.StripesFilter.init(StripesFilter.java:125)
at
net.sourceforge.stripes.mock.MockServletContext.addFilter(MockServletContext.java:211)
at
net.sourceforge.stripes.controller.AnnotatedClassActionResolver.findClasses(AnnotatedClassActionResolver.java:666)
at
net.sourceforge.stripes.controller.AnnotatedClassActionResolver.init(AnnotatedClassActionResolver.java:115)
at
net.sourceforge.stripes.controller.NameBasedActionResolver.init(NameBasedActionResolver.java:125)
at
net.sourceforge.stripes.config.DefaultConfiguration.init(DefaultConfiguration.java:121)
any ideas?
thank you,
lev
On Thu, Jul 8, 2010 at 8:54 PM, Nikolaos Giannopoulos
<nikol...@brightminds.org> wrote:
Lev,
My bad. Actually it is the Stripes filter w/ appropriate arguments in
the web.xml that indirectly initializes the Stripersist module.
Your exception is occurring b/c Stripersist has not been initialized
(yes - I know - this is the understatement of the week ;-)
Unfortunately I didn't notice that my tests had code that created a
MockServletContext that setup Stripes and included in the
Extension.Packages the argument "org.stripesstuff.stripersist" that
initializes Stripersist.
I had code strewn across a heirarchy of classes to provide different
types of test frameworks... hopefully this snippet helps:
Map<String, String> filterParams = new HashMap<String, String>();
filterParams.put("Extension.Packages",
"org.stripesstuff.stripersist");
MockServletContext servletContext = new
MockServletContext("WebTest");
servletContext.addFilter(StripesFilter.class, "StripesFilter",
filterParams);
servletContext.setServlet(DispatcherServlet.class,
"StripesDispatcher", null);
Stripersist.requestInit();
BTW after the save you will explicitly need to call:
userDao.commit(userObject);
As Stripersist automatically begins a transaction for you but doesn't
automatically commit it for you (for obvious reasons... e.g. rollback).
--Nikolaos
Lev wrote:
following jocke's suggestion, i added the following:
src/test/resources/META-INF/persistence.xml
this yields:
target/test-classes/META-INF/persistence.xml
however, the same NullPointerException persists on
the call to:
Stripersist.getEntityManager()
On Thu, Jul 8, 2010 at 4:39 PM, Jocke Eriksson <jockeeriks...@msn.com> wrote:
The path should be for junit
tests target/test-classes/META-INF/persistence.xml
Date: Thu, 8 Jul 2010 01:58:28 -0500
From: d...@plektos.com
To: stripes-users@lists.sourceforge.net
Subject: Re: [Stripes-users] Stripersist.getEntityManager() -->
NullPointerException
apologies: i forgot to attach my persistence.xml file to the
previous email. please find it attached. thanks!
On Thu, Jul 8, 2010 at 1:57 AM, Lev <d...@plektos.com> wrote:
hi,
i am trying to test code from "stripes... and java web development
is fun again". specifically, i have imported the email_36 into a
netbeans maven project.
i have written a simple JUnit test for the project file:
com.dao.impl.stripersist.UserDaoImpl. i have attached the
test file.
further, i have attached my persistence.xml file. it is located in:
target/classes/META-INF/persistence.xml
the error that i receive when executing the aforementioned
JUnit test is:
javax.persistence.PersistenceException: No Persistence provider for
EntityManager named stripesbook_MavenEmail36WebApp_war_1.0-SNAPSHOTPU
the exception is thrown at line 34 of the attached Junit test
file. specifically, the call that triggers the error is:
stripersist.init(url);
i have confirmed that the URL is valid -- if i change it to something
malformed, i receive an exception complaining that the file cannot
be found.
thank you again for your help,
lev
On Wed, Jul 7, 2010 at 10:19 AM, Aaron Porter <aa...@mongus.com> wrote:
Lev,
Sounds like you're getting closer! Now it looks like you need to check
your JPA configuration - make sure your persistence.xml is correct and
you've got all the jars to support it. I use Hibernate as the JPA
provider and PostgreSQL as the database.
Aaron
On 07/06/2010 11:42 PM, Lev wrote:
hi aaron,
thank you for your help.
1) my persistence.xml ends up in the project root at:
target/classes/META-INF/persistence.xml
this appears to be correct to me. please correct me if
i am wrong.
2) i implemented the calls that you suggested in the
junit setUpClass() and tearDownClass() methods.
it appears that Stripersist is successfully instantiated.
however, the call "stirpersist.init(url)" fails with the
following exception:
javax.persistence.PersistenceException: No Persistence provider for
EntityManager named...
i believe that the URL is correctly formed. it points to
the persistence.xml file in target/classes/META-INF.
thank you again for your help,
lev
On Wed, Jul 7, 2010 at 12:56 AM, Aaron Porter<aa...@mongus.com>
wrote:
Lev,
The META-INF directory that contains persistence.xml needs to end up
at
/WEB-INF/classes/META-INF. It looks like the way you've set it up it
would be at /WEB-INF/classes/resources/META-INF. What I was proposing
was to create a new source folder called resources. In Eclipse you do
that by clicking File->New->Source Folder and enter resources as the
folder name.
I'm guessing that even if you do have the persistence.xml file in the
correct location you'll get an error about trying to use Stripersist
without the Interceptor part of it because you're trying to test with
JUnit without a servlet container. It can be done but you'll need to
call some methods in Stripersist yourself. Create a new instance of
Stripersist and call init(new URL("path/to/persistence.xml")). Call
requestInit() to initialize for the current thread then call
requestComplete() to clean up when you're done.
Aaron
On 07/06/2010 10:25 PM, Lev wrote:
hi,
i moved persistence.xml to src/resources/META-INF.
however, the original problem persists -- i receive a
NullPointerException on the call:
Stripersist.getEntityManager();
further information: i'm getting this exception when
executing a Junit test of a DAO class -- i'm not
executing web code (action beans, etc). would that
contribute to the problem?
any suggestions welcomed.
thank you,
lev
On Tue, Jul 6, 2010 at 11:59 AM, Aaron Porter<aa...@mongus.com>
wrote:
Oops! Thanks for catching that Marcus!
Aaron
On 07/06/2010 09:09 AM, M.C.S. wrote:
Hi,
Aaron Porter wrote:
If you're using Eclipse I recommend creating a source directory
named
resources and then creating a subdirectory named WEB-INF and
placing
persistence.xml in there.
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users