Skip to content

Commit 9816c55

Browse files
mareknovotnyjsight
authored andcommitted
WINDUPRULE-266: new Seam API rules (#255)
* WINDUPRULE-266: new Seam API rules * WINDUPRULE-266 - clarifying EAP6/7 support in Seam API classification * WINDUPRULE-266 clarify more Seam 2.3 on EAP7 classification
1 parent cb67aa4 commit 9816c55

15 files changed

Lines changed: 2479 additions & 0 deletions

rules-reviewed/eap6/java-ee/seam/seam-java.windup.xml

Lines changed: 615 additions & 0 deletions
Large diffs are not rendered by default.

rules-reviewed/eap6/java-ee/seam/tests/data/src/ConversationTest.java

Lines changed: 441 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.jboss.seam.trinidad;
2+
3+
import static org.jboss.seam.ScopeType.PAGE;
4+
import static org.jboss.seam.annotations.Install.BUILT_IN;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import javax.persistence.EntityManager;
10+
11+
import org.jboss.seam.Component;
12+
import org.jboss.seam.annotations.Install;
13+
import org.jboss.seam.annotations.intercept.BypassInterceptors;
14+
import org.jboss.seam.annotations.Name;
15+
import org.jboss.seam.annotations.Scope;
16+
import org.jboss.seam.annotations.Transactional;
17+
import org.jboss.seam.core.AbstractMutable;
18+
import org.jboss.seam.framework.EntityIdentifier;
19+
20+
/**
21+
* EntityIdentifier manager for EntityCollectionModel
22+
* @author pmuir
23+
*
24+
*/
25+
26+
@Name("org.jboss.seam.trinidad.entityKeyManager")
27+
@Scope(PAGE)
28+
@BypassInterceptors
29+
@Install(precedence=BUILT_IN)
30+
public class EntityKeyManager extends AbstractMutable
31+
{
32+
33+
private List<EntityIdentifier> rows = new ArrayList<EntityIdentifier>();
34+
35+
public static EntityKeyManager instance()
36+
{
37+
return (EntityKeyManager) Component.getInstance(EntityKeyManager.class);
38+
}
39+
40+
@Transactional
41+
public int getIndex(Integer key, List wrappedList, EntityManager entityManager)
42+
{
43+
Object entity = rows.get(key).find(entityManager);
44+
int index = wrappedList.indexOf(entity);
45+
return index;
46+
}
47+
48+
49+
@Transactional
50+
public Object getKey(int rowIndex, List wrappedList, EntityManager entityManager)
51+
{
52+
EntityIdentifier key = new EntityIdentifier(wrappedList.get(rowIndex), entityManager);
53+
if (!rows.contains(key))
54+
{
55+
rows.add(key);
56+
setDirty();
57+
}
58+
return rows.indexOf(key);
59+
}
60+
61+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.jboss.seam.example.poker;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import static org.jboss.seam.ScopeType.APPLICATION;
7+
import org.jboss.seam.annotations.Name;
8+
import org.jboss.seam.annotations.Scope;
9+
import org.jboss.seam.annotations.Startup;
10+
import org.jboss.seam.annotations.Create;
11+
12+
/**
13+
* The game. This is where everything happens.
14+
*
15+
* @author Shane Bryzak
16+
*/
17+
@Name("game")
18+
@Scope(APPLICATION)
19+
@Startup
20+
public class Game
21+
{
22+
private List<String> players = new ArrayList<String>();
23+
24+
@Create
25+
public void createGame()
26+
{
27+
players.clear();
28+
}
29+
30+
public synchronized boolean login(String playerName)
31+
{
32+
if (!players.contains(playerName))
33+
{
34+
players.add(playerName);
35+
return true;
36+
}
37+
else
38+
return false;
39+
}
40+
41+
42+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
//$Id: HotelBookingAction.java 5579 2007-06-27 00:06:49Z gavin $
2+
package org.jboss.seam.example.booking;
3+
4+
import static javax.persistence.PersistenceContextType.EXTENDED;
5+
6+
import java.util.Calendar;
7+
8+
import javax.ejb.Remove;
9+
import javax.ejb.Stateful;
10+
import javax.persistence.EntityManager;
11+
import javax.persistence.PersistenceContext;
12+
13+
import org.jboss.seam.annotations.Begin;
14+
import org.jboss.seam.annotations.End;
15+
import org.jboss.seam.annotations.In;
16+
import org.jboss.seam.annotations.Logger;
17+
import org.jboss.seam.annotations.Name;
18+
import org.jboss.seam.annotations.Out;
19+
import org.jboss.seam.annotations.exception.Redirect;
20+
import org.jboss.seam.annotations.security.Restrict;
21+
import org.jboss.seam.core.Events;
22+
import org.jboss.seam.faces.FacesMessages;
23+
import org.jboss.seam.log.Log;
24+
25+
@Stateful
26+
@Name("hotelBooking")
27+
@Restrict("#{identity.loggedIn}")
28+
public class HotelBookingAction implements HotelBooking
29+
{
30+
31+
@PersistenceContext(type=EXTENDED)
32+
private EntityManager em;
33+
34+
@In
35+
private User user;
36+
37+
@In(required=false) @Out
38+
private Hotel hotel;
39+
40+
@In(required=false)
41+
@Out(required=false)
42+
private Booking booking;
43+
44+
@In
45+
private FacesMessages facesMessages;
46+
47+
@In
48+
private Events events;
49+
50+
@Logger
51+
private Log log;
52+
53+
private boolean bookingValid;
54+
55+
@Begin
56+
public void selectHotel(Hotel selectedHotel)
57+
{
58+
hotel = em.merge(selectedHotel);
59+
}
60+
61+
@Redirect(//error.xhtml")
62+
public void bookHotel()
63+
{
64+
booking = new Booking(hotel, user);
65+
Calendar calendar = Calendar.getInstance();
66+
booking.setCheckinDate( calendar.getTime() );
67+
calendar.add(Calendar.DAY_OF_MONTH, 1);
68+
booking.setCheckoutDate( calendar.getTime() );
69+
}
70+
71+
public void setBookingDetails()
72+
{
73+
Calendar calendar = Calendar.getInstance();
74+
calendar.add(Calendar.DAY_OF_MONTH, -1);
75+
if ( booking.getCheckinDate().before( calendar.getTime() ) )
76+
{
77+
facesMessages.addToControl("checkinDate", "Check in date must be a future date");
78+
bookingValid=false;
79+
}
80+
else if ( !booking.getCheckinDate().before( booking.getCheckoutDate() ) )
81+
{
82+
facesMessages.addToControl("checkoutDate", "Check out date must be later than check in date");
83+
bookingValid=false;
84+
}
85+
else
86+
{
87+
bookingValid=true;
88+
}
89+
}
90+
91+
public boolean isBookingValid()
92+
{
93+
return bookingValid;
94+
}
95+
96+
@End
97+
public void confirm()
98+
{
99+
em.persist(booking);
100+
facesMessages.add("Thank you, #{user.name}, your confimation number for #{hotel.name} is #{booking.id}");
101+
log.info("New booking: #{booking.id} for #{user.username}");
102+
events.raiseTransactionSuccessEvent("bookingConfirmed");
103+
}
104+
105+
@End
106+
public void cancel() {}
107+
108+
@Remove
109+
public void destroy() {}
110+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//$Id$
2+
package org.jboss.seam.example.booking.test;
3+
4+
import org.jboss.seam.Seam;
5+
import org.jboss.seam.core.Manager;
6+
import org.jboss.seam.mock.SeamTest;
7+
import org.testng.annotations.Test;
8+
9+
public class LoginTest extends SeamTest
10+
{
11+
12+
@Test
13+
public void testLogin() throws Exception
14+
{
15+
16+
new FacesRequest() {
17+
18+
@Override
19+
protected void invokeApplication()
20+
{
21+
assert !isSessionInvalid();
22+
assert getValue("#{identity.loggedIn}").equals(false);
23+
}
24+
25+
}.run();
26+
27+
new FacesRequest() {
28+
29+
@Override
30+
protected void updateModelValues() throws Exception
31+
{
32+
assert !isSessionInvalid();
33+
setValue("#{identity.username}", "gavin");
34+
setValue("#{identity.password}", "foobar");
35+
}
36+
37+
@Override
38+
protected void invokeApplication()
39+
{
40+
invokeMethod("#{identity.login}");
41+
}
42+
43+
@Override
44+
protected void renderResponse()
45+
{
46+
assert getValue("#{user.name}").equals("Gavin King");
47+
assert getValue("#{user.username}").equals("gavin");
48+
assert getValue("#{user.password}").equals("foobar");
49+
assert !Manager.instance().isLongRunningConversation();
50+
assert getValue("#{identity.loggedIn}").equals(true);
51+
}
52+
53+
}.run();
54+
55+
new FacesRequest() {
56+
57+
@Override
58+
protected void invokeApplication()
59+
{
60+
assert !isSessionInvalid();
61+
assert getValue("#{identity.loggedIn}").equals(true);
62+
}
63+
64+
}.run();
65+
66+
new FacesRequest() {
67+
68+
@Override
69+
protected void invokeApplication()
70+
{
71+
assert !Manager.instance().isLongRunningConversation();
72+
assert !isSessionInvalid();
73+
invokeMethod("#{identity.logout}");
74+
assert Seam.isSessionInvalid();
75+
}
76+
77+
@Override
78+
protected void renderResponse()
79+
{
80+
assert getValue("#{identity.loggedIn}").equals(false);
81+
assert Seam.isSessionInvalid();
82+
}
83+
84+
}.run();
85+
86+
}
87+
88+
}

0 commit comments

Comments
 (0)