[JBoss Seam] - Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?
by pete.muirï¼ jboss.org
No, no enumerated list :( But, if you are using maven, try, for your test environment only, depending on org.jboss.embedded jboss-embedded, org.jboss.seam jboss-seam and that *should* be enough to run just JPA + EJB3. But take a look at the jboss-seam pom to see what dependencies Seam itself has (its fairly obvious what most are for). Remember that testing requires JBoss Embedded, *not* the jboss jar's we use to compile Seam (yes, this is a pita).
SeamTest now bootstraps Embedded itself - I think the init() method isn't being called from your stack trace. We will try to get more examples of using Maven into Seam, but as this is quite a drastic change in Seam, we need JBoss Tools to be able to work with a maven structure first.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099685#4099685
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099685
18Â years, 6Â months
[JBoss Seam] - Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?
by bsmithjj
Hello,
I used to be able to boot JBoss embedded from Seam tests in my app in the 1.2.1 and earlier days (was it only 6 months ago?). Anyway, now when I run my tests, I am getting null-pointer exceptions from a class called SeamBaseTest. For example:
| public class PersistenceUnitConfigurationTest extends SeamTest {
|
| private Log log = LogFactory.getLog(PersistenceUnitConfigurationTest.class);
|
| @Test
| public void test_GetManagedPersistenceContext_from_Seam() throws Exception {
|
| new FacesRequest() {
| protected void invokeApplication() throws Exception {
| EntityManager em = (EntityManager) getInstance("entityManager");
| assert em != null;
| }
| }.run();
|
| }
| }
|
yields
| -------------------------------------------------------------------------------
| Test set: SampleEJB3Test
| -------------------------------------------------------------------------------
| Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.198 sec <<< FAILURE!
| test_GetManagedPersistenceContext_from_Seam Time elapsed: 0.047 sec <<< FAILURE!
| java.lang.NullPointerException
| at org.jboss.seam.mock.BaseSeamTest$Request.run(BaseSeamTest.java:504)
| at com.javaplant.mapper.police.PersistenceUnitConfigurationTest.test_GetManagedPersistenceContext_from_Seam(PersistenceUnitConfigurationTest.java:22)
|
Ok - so it looks like there is now something called a ComponentTest, so I'll try that instead:
| public class PersistenceUnitConfigurationTest extends SeamTest {
|
| private Log log = LogFactory.getLog(PersistenceUnitConfigurationTest.class);
|
| @Test
| public void test_GetManagedPersistenceContext_from_Seam() throws Exception {
|
| new ComponentTest() {
|
| protected void testComponents() throws Exception {
| EntityManager em = (EntityManager) getInstance("entityManager");
| assert em != null;
| }
| }.run();
|
| }
| }
|
and this yields:
| -------------------------------------------------------------------------------
| Test set: SampleEJB3Test
| -------------------------------------------------------------------------------
| Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.195 sec <<< FAILURE!
| test_GetManagedPersistenceContext_from_Seam Time elapsed: 0.07 sec <<< FAILURE!
| java.lang.NullPointerException
| at org.jboss.seam.servlet.ServletSessionMap.get(ServletSessionMap.java:54)
| at org.jboss.seam.contexts.BasicContext.get(BasicContext.java:48)
| at org.jboss.seam.contexts.Contexts.lookupInStatefulContexts(Contexts.java:199)
| at org.jboss.seam.Component.getInstance(Component.java:1844)
| at org.jboss.seam.Component.getInstance(Component.java:1839)
| at org.jboss.seam.mock.BaseSeamTest.getInstance(BaseSeamTest.java:98)
| at com.javaplant.mapper.police.PersistenceUnitConfigurationTest.access$000(PersistenceUnitConfigurationTest.java:15)
| at com.javaplant.mapper.police.PersistenceUnitConfigurationTest$1.testComponents(PersistenceUnitConfigurationTest.java:25)
| at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:164)
| at com.javaplant.mapper.police.PersistenceUnitConfigurationTest.test_GetManagedPersistenceContext_from_Seam(PersistenceUnitConfigurationTest.java:22)
|
So what's going on with SeamBaseTest?
Thanks,
Brad Smith
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099682#4099682
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099682
18Â years, 6Â months
[JBoss Seam] - Re: FlushModeType not working in Seam 1.2.1 GA?
by kotlusa
If I could attach the code I would.... but since I see no way, here's some more inline code.
I modified the booking application and deployed it on both 4.2.1GA and 4.2.2GA, both of which appear to have the same FlushMode issue.
In addition to my changes to get it working with JSF 1.2 RI I did the following:
Added the following properties to persistence.xml - to create a smpc:
| <property name="jboss.entity.manager.factory.jndi.name" value="java:/entityManagerFactory"/>
| <property name="jboss.entity.manager.jndi.name" value="java:/em"/>
|
Added the following to components.xml - to create a smpc:
| <core:managed-persistence-context name="entityManager"
| auto-create="true"
| persistence-unit-jndi-name="java:/entityManagerFactory"/>
|
My new HotelBookingAction (I tried to bold the changes but that didn't work because they are in a code block):
| //$Id: HotelBookingAction.java,v 1.49 2007/03/09 01:18:21 gavin Exp $
| package org.jboss.seam.example.booking;
| import static javax.persistence.PersistenceContextType.EXTENDED;
| import java.util.Calendar;
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.End;
| import org.jboss.seam.annotations.FlushModeType;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.annotations.security.Restrict;
| import org.jboss.seam.core.Events;
| import org.jboss.seam.core.FacesMessages;
| import org.jboss.seam.log.Log;
| @Stateful
| @Name("hotelBooking")
| @Restrict("#{identity.loggedIn}")
| public class HotelBookingAction implements HotelBooking
| {
|
| @In
| private EntityManager entityManager;
|
| @In
| private User user;
|
| @In(required=false) @Out
| private Hotel hotel;
|
| @In(required=false)
| @Out(required=false)
| private Booking booking;
|
| @In
| private FacesMessages facesMessages;
|
| @In
| private Events events;
|
| @Logger
| private Log log;
|
| private boolean bookingValid;
|
| @Begin(flushMode=FlushModeType.MANUAL)
| public void selectHotel(Hotel selectedHotel)
| {
| hotel = entityManager.merge(selectedHotel);
| }
|
| public void bookHotel()
| {
| booking = new Booking(hotel, user);
| Calendar calendar = Calendar.getInstance();
| booking.setCheckinDate( calendar.getTime() );
| calendar.add(Calendar.DAY_OF_MONTH, 1);
| booking.setCheckoutDate( calendar.getTime() );
| }
| public void setBookingDetails()
| {
| Calendar calendar = Calendar.getInstance();
| calendar.add(Calendar.DAY_OF_MONTH, -1);
| if ( booking.getCheckinDate().before( calendar.getTime() ) )
| {
| facesMessages.addToControl("checkinDate", "Check in date must be a future date");
| bookingValid=false;
| }
| else if ( !booking.getCheckinDate().before( booking.getCheckoutDate() ) )
| {
| facesMessages.addToControl("checkoutDate", "Check out date must be later than check in date");
| bookingValid=false;
| }
| else
| {
| bookingValid=true;
| }
| entityManager.persist(booking);
| }
|
| public boolean isBookingValid()
| {
| return bookingValid;
| }
|
| @End
| public void confirm()
| {
| facesMessages.add("Thank you, #{user.name}, your confimation number for #{hotel.name} is #{booking.id}");
| log.info("New booking: #{booking.id} for #{user.username}");
| events.raiseTransactionSuccessEvent("bookingConfirmed");
| entityManager.flush();
| }
|
| @End
| public void cancel() {}
|
| @Destroy @Remove
| public void destroy() {}
| }
|
This causes the booking to be persisted when you set it's details. When you confirm the details, the entityManager is flushed.
To test this just create 1 booking and cancel on the confirmation page. Then create another booking and confirm it. You will see both of the bookings in your list now.
Thanks,
Austin
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4099679#4099679
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4099679
18Â years, 6Â months