struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Cook" <James.C...@wecomm.com>
Subject RE: unit test the service layer (aka data access layer)
Date Mon, 21 Jun 2010 16:31:24 GMT
You would still have you build your own EntityManager, like if you were doing it for Tomcat
eg.

http://najfiles.blogspot.com/2010/01/jpa-cat-spring.html

Then check out:

http://static.springsource.org/spring/docs/2.5.x/reference/testing.html

Particularly the bit where it talks about extending AbstractTransactionalJUnit4SpringContextTests
for your unit test and the like

Cheers

James


-----Original Message-----
From: Jake Vang [mailto:vangjake@googlemail.com] 
Sent: 21 June 2010 17:27
To: Struts Users Mailing List
Subject: Re: unit test the service layer (aka data access layer)

james,

would setting up the unit test in that way load up the service class
as if it would in in the J2EE container?

the reason why i asked is because in the tutorial, as far as i
understand, they have wired in using Spring a transaction manager.
that means in my service object, when i call update/delete/create, i
don't have to get a EntityTransaction and do .begin() and .commit()
before and after i call the EntityManager's merge/remove/persist
methods, respectively.

i tried unit testing naively, by constructing an EntityManagerFactory
from the Persistence class (defining yet another
META-INF/persistence.xml file), but my CRUD operations (minus read)
never persists changes to the database (because it is in a J2SE
environment without a transaction manager? as opposed to being in a
J2EE environment with a transaction manager? well, that's what some
sites suggests anyways).


On Mon, Jun 21, 2010 at 5:02 AM, James Cook <James.Cook@wecomm.com> wrote:
> Get involved with:
>
> Junit 4.4
> Spring-test libs
>
> And started your service test class like such:
>
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration(locations = "classpath:/testConfigXML.xml")
> public class MyServiceImplTest extends AbstractJUnit4SpringContextTests
> {
>
>    @Autowired(required = true)
>    private MyService myService = null;
>
> testConfigXML.xml will contain your *test* config..
>
> Then do the do!
>
>
> -----Original Message-----
> From: Jake Vang [mailto:vangjake@googlemail.com]
> Sent: 21 June 2010 05:54
> To: Struts Users Mailing List
> Subject: unit test the service layer (aka data access layer)
>
> hi, i've been following this code here at
> http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html.
> what i want to know is how to unit test the service layer (or data
> access object layer). in the case of the link, it would be the
> PersonServiceImpl class.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message