Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
615 changes: 615 additions & 0 deletions rules-reviewed/eap6/java-ee/seam/seam-java.windup.xml

Large diffs are not rendered by default.

441 changes: 441 additions & 0 deletions rules-reviewed/eap6/java-ee/seam/tests/data/src/ConversationTest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.jboss.seam.trinidad;

import static org.jboss.seam.ScopeType.PAGE;
import static org.jboss.seam.annotations.Install.BUILT_IN;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;

import org.jboss.seam.Component;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;
import org.jboss.seam.core.AbstractMutable;
import org.jboss.seam.framework.EntityIdentifier;

/**
* EntityIdentifier manager for EntityCollectionModel
* @author pmuir
*
*/

@Name("org.jboss.seam.trinidad.entityKeyManager")
@Scope(PAGE)
@BypassInterceptors
@Install(precedence=BUILT_IN)
public class EntityKeyManager extends AbstractMutable
{

private List<EntityIdentifier> rows = new ArrayList<EntityIdentifier>();

public static EntityKeyManager instance()
{
return (EntityKeyManager) Component.getInstance(EntityKeyManager.class);
}

@Transactional
public int getIndex(Integer key, List wrappedList, EntityManager entityManager)
{
Object entity = rows.get(key).find(entityManager);
int index = wrappedList.indexOf(entity);
return index;
}


@Transactional
public Object getKey(int rowIndex, List wrappedList, EntityManager entityManager)
{
EntityIdentifier key = new EntityIdentifier(wrappedList.get(rowIndex), entityManager);
if (!rows.contains(key))
{
rows.add(key);
setDirty();
}
return rows.indexOf(key);
}

}
42 changes: 42 additions & 0 deletions rules-reviewed/eap6/java-ee/seam/tests/data/src/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.jboss.seam.example.poker;

import java.util.ArrayList;
import java.util.List;

import static org.jboss.seam.ScopeType.APPLICATION;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.Create;

/**
* The game. This is where everything happens.
*
* @author Shane Bryzak
*/
@Name("game")
@Scope(APPLICATION)
@Startup
public class Game
{
private List<String> players = new ArrayList<String>();

@Create
public void createGame()
{
players.clear();
}

public synchronized boolean login(String playerName)
{
if (!players.contains(playerName))
{
players.add(playerName);
return true;
}
else
return false;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//$Id: HotelBookingAction.java 5579 2007-06-27 00:06:49Z gavin $
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.End;
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.exception.Redirect;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.core.Events;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;

@Stateful
@Name("hotelBooking")
@Restrict("#{identity.loggedIn}")
public class HotelBookingAction implements HotelBooking
{

@PersistenceContext(type=EXTENDED)
private EntityManager em;

@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
public void selectHotel(Hotel selectedHotel)
{
hotel = em.merge(selectedHotel);
}

@Redirect(//error.xhtml")
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;
}
}

public boolean isBookingValid()
{
return bookingValid;
}

@End
public void confirm()
{
em.persist(booking);
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");
}

@End
public void cancel() {}

@Remove
public void destroy() {}
}
88 changes: 88 additions & 0 deletions rules-reviewed/eap6/java-ee/seam/tests/data/src/LoginTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//$Id$
package org.jboss.seam.example.booking.test;

import org.jboss.seam.Seam;
import org.jboss.seam.core.Manager;
import org.jboss.seam.mock.SeamTest;
import org.testng.annotations.Test;

public class LoginTest extends SeamTest
{

@Test
public void testLogin() throws Exception
{

new FacesRequest() {

@Override
protected void invokeApplication()
{
assert !isSessionInvalid();
assert getValue("#{identity.loggedIn}").equals(false);
}

}.run();

new FacesRequest() {

@Override
protected void updateModelValues() throws Exception
{
assert !isSessionInvalid();
setValue("#{identity.username}", "gavin");
setValue("#{identity.password}", "foobar");
}

@Override
protected void invokeApplication()
{
invokeMethod("#{identity.login}");
}

@Override
protected void renderResponse()
{
assert getValue("#{user.name}").equals("Gavin King");
assert getValue("#{user.username}").equals("gavin");
assert getValue("#{user.password}").equals("foobar");
assert !Manager.instance().isLongRunningConversation();
assert getValue("#{identity.loggedIn}").equals(true);
}

}.run();

new FacesRequest() {

@Override
protected void invokeApplication()
{
assert !isSessionInvalid();
assert getValue("#{identity.loggedIn}").equals(true);
}

}.run();

new FacesRequest() {

@Override
protected void invokeApplication()
{
assert !Manager.instance().isLongRunningConversation();
assert !isSessionInvalid();
invokeMethod("#{identity.logout}");
assert Seam.isSessionInvalid();
}

@Override
protected void renderResponse()
{
assert getValue("#{identity.loggedIn}").equals(false);
assert Seam.isSessionInvalid();
}

}.run();

}

}
Loading