Seam SVN: r12400 - modules/security/trunk/examples/seamspace/src/main/webapp.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-04-06 09:12:13 -0400 (Tue, 06 Apr 2010)
New Revision: 12400
Modified:
modules/security/trunk/examples/seamspace/src/main/webapp/userdetail.xhtml
modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml
Log:
minor
Modified: modules/security/trunk/examples/seamspace/src/main/webapp/userdetail.xhtml
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/webapp/userdetail.xhtml 2010-04-06 13:11:46 UTC (rev 12399)
+++ modules/security/trunk/examples/seamspace/src/main/webapp/userdetail.xhtml 2010-04-06 13:12:13 UTC (rev 12400)
@@ -1,10 +1,9 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
- xmlns:f="http://java.sun.com/jsf/core"
- xmlns:rich="http://richfaces.org/rich"
- xmlns:s="http://jboss.com/products/seam/taglib">
+ xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="template.xhtml">
@@ -24,19 +23,19 @@
<div class="formRow">
<h:outputLabel for="firstname" value="First name" styleClass="formLabel"/>
- <h:inputText id="firstname" value="#{userAction.firstname}" readonly="#{identityManager.userExists(userAction.username)}"/>
+ <h:inputText id="firstname" value="#{userAction.firstname}"/>
<div class="validationError"><h:message for="firstname"/></div>
</div>
<div class="formRow">
<h:outputLabel for="lastname" value="Last name" styleClass="formLabel"/>
- <h:inputText id="lastname" value="#{userAction.lastname}" readonly="#{identityManager.userExists(userAction.username)}"/>
+ <h:inputText id="lastname" value="#{userAction.lastname}"/>
<div class="validationError"><h:message for="lastname"/></div>
</div>
<div class="formRow">
<h:outputLabel for="username" value="Username" styleClass="formLabel"/>
- <h:inputText id="username" value="#{userAction.username}" readonly="#{identityManager.userExists(userAction.username)}"/>
+ <h:inputText id="username" value="#{userAction.username}"/>
<div class="validationError"><h:message for="username"/></div>
</div>
@@ -55,7 +54,7 @@
<h:outputLabel for="roles" value="Member of" styleClass="formLabel"/>
<div class="selectMany">
<h:selectManyCheckbox id="roles" value="#{userAction.roles}" layout="pageDirection" styleClass="roles">
- <s:selectItems value="#{identityManager.listGrantableRoles()}" var="role" label="#{role}"/>
+ <!--s:selectItems value="#{identityManager.grantableRoles}" var="role" label="#{role}"/-->
</h:selectManyCheckbox>
</div>
<div class="validationError"><h:message for="roles"/></div>
@@ -68,7 +67,7 @@
<div class="formButtons">
<h:commandButton id="save" value="Save" action="#{userAction.save}" styleClass="formButton"/>
- <s:button id="cancel" view="/usermanager.xhtml" value="Cancel" propagation="end" styleClass="formButton"/>
+ <h:button id="cancel" outcome="/usermanager.xhtml" action="#{conversation.end}" value="Cancel" styleClass="formButton"/>
</div>
<br class="clear"/>
Modified: modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml
===================================================================
--- modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml 2010-04-06 13:11:46 UTC (rev 12399)
+++ modules/security/trunk/examples/seamspace/src/main/webapp/usermanager.xhtml 2010-04-06 13:12:13 UTC (rev 12400)
@@ -24,7 +24,7 @@
<h2>User Manager</h2>
- <h:button id="newUser" action="#{userAction.createUser}" styleClass="newuser" rendered="#{identity.hasPermission('seam.account', 'create')}"/>
+ <h:button id="newUser" outcome="userdetail.xhtml" action="#{userAction.createUser}" styleClass="newuser" rendered="#{identity.hasPermission('seam.account', 'create')}"/>
<h:dataTable
id="threads"
14 years, 2 months
Seam SVN: r12399 - in modules/security/trunk/core/src/main/java/org/jboss/seam/security/management: action and 1 other directory.
by seam-commits@lists.jboss.org
Author: shane.bryzak(a)jboss.com
Date: 2010-04-06 09:11:46 -0400 (Tue, 06 Apr 2010)
New Revision: 12399
Modified:
modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/IdentityManager.java
modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/RoleAction.java
modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserAction.java
modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
Log:
rename list* methods in IdentityManager with get* to make more EL friendly
Modified: modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/IdentityManager.java
===================================================================
--- modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/IdentityManager.java 2010-04-05 21:45:25 UTC (rev 12398)
+++ modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/IdentityManager.java 2010-04-06 13:11:46 UTC (rev 12399)
@@ -152,7 +152,7 @@
return roleIdentityStore.roleExists(name);
}
- public List<String> listUsers()
+ public List<String> getUsers()
{
identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
List<String> users = identityStore.listUsers();
@@ -166,7 +166,7 @@
return users;
}
- public List<String> listUsers(String filter)
+ public List<String> getUsers(String filter)
{
identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
List<String> users = identityStore.listUsers(filter);
@@ -180,7 +180,7 @@
return users;
}
- public List<String> listRoles()
+ public List<String> getRoles()
{
identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_READ);
List<String> roles = roleIdentityStore.listRoles();
@@ -194,7 +194,7 @@
return roles;
}
- public List<String> listGrantableRoles()
+ public List<String> getGrantableRoles()
{
List<String> roles = roleIdentityStore.listGrantableRoles();
Modified: modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/RoleAction.java
===================================================================
--- modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/RoleAction.java 2010-04-05 21:45:25 UTC (rev 12398)
+++ modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/RoleAction.java 2010-04-06 13:11:46 UTC (rev 12399)
@@ -101,7 +101,7 @@
public List<String> getAssignableRoles()
{
- List<String> roles = identityManager.listGrantableRoles();
+ List<String> roles = identityManager.getGrantableRoles();
roles.remove(role);
return roles;
}
Modified: modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserAction.java
===================================================================
--- modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-04-05 21:45:25 UTC (rev 12398)
+++ modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-04-06 13:11:46 UTC (rev 12399)
@@ -20,6 +20,8 @@
@ConversationScoped
public class UserAction implements Serializable
{
+ private static final long serialVersionUID = 5820385095080724087L;
+
private String firstname;
private String lastname;
private String username;
Modified: modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java
===================================================================
--- modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java 2010-04-05 21:45:25 UTC (rev 12398)
+++ modules/security/trunk/core/src/main/java/org/jboss/seam/security/management/action/UserSearch.java 2010-04-06 13:11:46 UTC (rev 12399)
@@ -24,7 +24,7 @@
public void loadUsers()
{
- users = identityManager.listUsers();
+ users = identityManager.getUsers();
}
public String getUserRoles(String username)
14 years, 2 months
Seam SVN: r12398 - in modules/faces/trunk: impl/src/main/java/org/jboss/seam/faces/event and 1 other directories.
by seam-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-05 17:45:25 -0400 (Mon, 05 Apr 2010)
New Revision: 12398
Removed:
modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/qualifier/AnyPhase.java
Modified:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java
Log:
Drop @AnyPhase, some more tests
Deleted: modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/qualifier/AnyPhase.java
===================================================================
--- modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/qualifier/AnyPhase.java 2010-04-05 21:35:24 UTC (rev 12397)
+++ modules/faces/trunk/api/src/main/java/org/jboss/seam/faces/event/qualifier/AnyPhase.java 2010-04-05 21:45:25 UTC (rev 12398)
@@ -1,23 +0,0 @@
-package org.jboss.seam.faces.event.qualifier;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
-/**
- * Qualifies observer method parameters to select events that occur in a any
- * phase in the JSF lifecycle
- *
- * @author <a href="mailto:lincolnbaxter@gmail.com>Lincoln Baxter, III</a>
- */
-@Qualifier
-@Target( { FIELD, PARAMETER })
-@Retention(RUNTIME)
-public @interface AnyPhase
-{
-}
\ No newline at end of file
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java 2010-04-05 21:35:24 UTC (rev 12397)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/event/PhaseEventBridge.java 2010-04-05 21:45:25 UTC (rev 12398)
@@ -12,7 +12,6 @@
import org.jboss.seam.faces.cdi.BeanManagerAware;
import org.jboss.seam.faces.event.qualifier.After;
-import org.jboss.seam.faces.event.qualifier.AnyPhase;
import org.jboss.seam.faces.event.qualifier.ApplyRequestValues;
import org.jboss.seam.faces.event.qualifier.Before;
import org.jboss.seam.faces.event.qualifier.InvokeApplication;
@@ -96,7 +95,6 @@
Annotation[] qualifiers = new Annotation[] { whenQualifier, phaseQualifier };
log.debug("Fired event #0 with qualifiers #1", event, qualifiers);
getBeanManager().fireEvent(event, qualifiers);
- getBeanManager().fireEvent(event, new Annotation[] { whenQualifier, ANY_PHASE });
}
public void afterPhase(final PhaseEvent e)
@@ -127,11 +125,6 @@
private static final long serialVersionUID = 5121252401235504952L;
};
- private static final AnnotationLiteral<AnyPhase> ANY_PHASE = new AnnotationLiteral<AnyPhase>()
- {
- private static final long serialVersionUID = 6334015723435615561L;
- };
-
private static final AnnotationLiteral<RestoreView> RESTORE_VIEW = new AnnotationLiteral<RestoreView>()
{
private static final long serialVersionUID = 8812020629644833820L;
Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java 2010-04-05 21:35:24 UTC (rev 12397)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventBridgeTest.java 2010-04-05 21:45:25 UTC (rev 12398)
@@ -1,18 +1,5 @@
package org.jboss.seam.faces.event;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_APPLY_VALUES;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_INVOKE_APPLICATION;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_PROCESS_VALIDATION;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_RENDER_RESPONSE;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_RESTORE_VIEW;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.AFTER_UPDATE_MODEL_VALUES;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_APPLY_VALUES;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_INVOKE_APPLICATION;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_PROCESS_VALIDATION;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_RENDER_RESPONSE;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_RESTORE_VIEW;
-import static org.jboss.seam.faces.event.PhaseEventObserver.Observation.BEFORE_UPDATE_MODEL_VALUES;
-
import java.util.ArrayList;
import java.util.List;
@@ -64,12 +51,10 @@
private final MockFacesContext facesContext = new MockFacesContext();
private final MockLifecycle lifecycle = new MockLifecycle();
- @Test
- public void testBeforeAnyPhaseObserver()
+ private void fireAllPhases()
{
- observer.reset();
fireAllBeforePhases();
- observer.assertAllBeforePhasesObserved();
+ fireAllAfterPhases();
}
private void fireAllBeforePhases()
@@ -90,14 +75,6 @@
phaseEventBridge.beforePhase(new PhaseEvent(facesContext, phaseId, lifecycle));
}
- @Test
- public void testAfterAnyPhaseObserver()
- {
- observer.reset();
- fireAllAfterPhases();
- observer.assertAllAfterPhasesObserved();
- }
-
private void fireAllAfterPhases()
{
fireAfterPhases(ALL_PHASES);
@@ -120,96 +97,168 @@
public void testBeforeRenderResponseObserver()
{
observer.reset();
- fireBeforePhase(PhaseId.RENDER_RESPONSE);
- observer.assertSingleObservation(BEFORE_RENDER_RESPONSE);
+ fireAllPhases();
+ observer.assertObservations("1", PhaseId.RENDER_RESPONSE);
}
@Test
public void testAfterRenderResponseObserver()
{
observer.reset();
- fireAfterPhase(PhaseId.RENDER_RESPONSE);
- observer.assertSingleObservation(AFTER_RENDER_RESPONSE);
+ fireAllPhases();
+ observer.assertObservations("2", PhaseId.RENDER_RESPONSE);
}
@Test
public void testBeforeApplyRequestValuesObserver()
{
observer.reset();
- fireBeforePhase(PhaseId.APPLY_REQUEST_VALUES);
- observer.assertSingleObservation(BEFORE_APPLY_VALUES);
+ fireAllPhases();
+ observer.assertObservations("3", PhaseId.APPLY_REQUEST_VALUES);
}
@Test
public void testAfterApplyRequestValuesObserver()
{
observer.reset();
- fireAfterPhase(PhaseId.APPLY_REQUEST_VALUES);
- observer.assertSingleObservation(AFTER_APPLY_VALUES);
+ fireAllPhases();
+ observer.assertObservations("4", PhaseId.APPLY_REQUEST_VALUES);
}
@Test
public void testBeforeInvokeApplicationObserver()
{
observer.reset();
- fireBeforePhase(PhaseId.INVOKE_APPLICATION);
- observer.assertSingleObservation(BEFORE_INVOKE_APPLICATION);
+ fireAllPhases();
+ observer.assertObservations("5", PhaseId.INVOKE_APPLICATION);
}
@Test
public void testAfterInvokeApplicationObserver()
{
observer.reset();
- fireAfterPhase(PhaseId.INVOKE_APPLICATION);
- observer.assertSingleObservation(AFTER_INVOKE_APPLICATION);
+ fireAllPhases();
+ observer.assertObservations("6", PhaseId.INVOKE_APPLICATION);
}
@Test
public void testBeforeProcessValidationsObserver()
{
observer.reset();
- fireBeforePhase(PhaseId.PROCESS_VALIDATIONS);
- observer.assertSingleObservation(BEFORE_PROCESS_VALIDATION);
+ fireAllPhases();
+ observer.assertObservations("7", PhaseId.PROCESS_VALIDATIONS);
}
@Test
public void testAfterProcessValidationsObserver()
{
observer.reset();
- fireAfterPhase(PhaseId.PROCESS_VALIDATIONS);
- observer.assertSingleObservation(AFTER_PROCESS_VALIDATION);
+ fireAllPhases();
+ observer.assertObservations("8", PhaseId.PROCESS_VALIDATIONS);
}
@Test
public void testBeforeRestoreViewObserver()
{
observer.reset();
- fireBeforePhase(PhaseId.RESTORE_VIEW);
- observer.assertSingleObservation(BEFORE_RESTORE_VIEW);
+ fireAllPhases();
+ observer.assertObservations("9", PhaseId.RESTORE_VIEW);
}
@Test
public void testAfterRestoreViewObserver()
{
observer.reset();
- fireAfterPhase(PhaseId.RESTORE_VIEW);
- observer.assertSingleObservation(AFTER_RESTORE_VIEW);
+ fireAllPhases();
+ observer.assertObservations("10", PhaseId.RESTORE_VIEW);
}
@Test
public void testBeforeUpdateModelValuesObserver()
{
observer.reset();
- fireBeforePhase(PhaseId.UPDATE_MODEL_VALUES);
- observer.assertSingleObservation(BEFORE_UPDATE_MODEL_VALUES);
+ fireAllPhases();
+ observer.assertObservations("11", PhaseId.UPDATE_MODEL_VALUES);
}
@Test
public void testAfterUpdateModelValuesObserver()
{
observer.reset();
- fireAfterPhase(PhaseId.UPDATE_MODEL_VALUES);
- observer.assertSingleObservation(AFTER_UPDATE_MODEL_VALUES);
+ fireAllPhases();
+ observer.assertObservations("11", PhaseId.UPDATE_MODEL_VALUES);
}
+ @Test
+ public void testAllRenderResponseObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("13", PhaseId.RENDER_RESPONSE, PhaseId.RENDER_RESPONSE);
+ }
+
+ @Test
+ public void testAllApplyRequestValuesObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("14", PhaseId.APPLY_REQUEST_VALUES, PhaseId.APPLY_REQUEST_VALUES);
+ }
+
+ @Test
+ public void testAllInvokeApplicationObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("15", PhaseId.INVOKE_APPLICATION, PhaseId.INVOKE_APPLICATION);
+ }
+
+ @Test
+ public void testAllProcessValidationsObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("16", PhaseId.PROCESS_VALIDATIONS, PhaseId.PROCESS_VALIDATIONS);
+ }
+
+ @Test
+ public void testAllRestoreViewObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("17", PhaseId.RESTORE_VIEW, PhaseId.RESTORE_VIEW);
+ }
+
+ @Test
+ public void testAllUpdateModelValuesObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("18", PhaseId.UPDATE_MODEL_VALUES, PhaseId.UPDATE_MODEL_VALUES);
+ }
+
+ @Test
+ public void testAllBeforeEventsObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("19", PhaseId.APPLY_REQUEST_VALUES, PhaseId.INVOKE_APPLICATION, PhaseId.PROCESS_VALIDATIONS, PhaseId.RENDER_RESPONSE, PhaseId.RESTORE_VIEW, PhaseId.UPDATE_MODEL_VALUES);
+ }
+
+ @Test
+ public void testAllAfterEventsObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("20", PhaseId.APPLY_REQUEST_VALUES, PhaseId.INVOKE_APPLICATION, PhaseId.PROCESS_VALIDATIONS, PhaseId.RENDER_RESPONSE, PhaseId.RESTORE_VIEW, PhaseId.UPDATE_MODEL_VALUES);
+ }
+
+ @Test
+ public void testAllEventsObserver()
+ {
+ observer.reset();
+ fireAllPhases();
+ observer.assertObservations("21", PhaseId.APPLY_REQUEST_VALUES, PhaseId.INVOKE_APPLICATION, PhaseId.PROCESS_VALIDATIONS, PhaseId.RENDER_RESPONSE, PhaseId.RESTORE_VIEW, PhaseId.UPDATE_MODEL_VALUES, PhaseId.APPLY_REQUEST_VALUES, PhaseId.INVOKE_APPLICATION, PhaseId.PROCESS_VALIDATIONS, PhaseId.RENDER_RESPONSE, PhaseId.RESTORE_VIEW, PhaseId.UPDATE_MODEL_VALUES);
+ }
+
}
Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java 2010-04-05 21:35:24 UTC (rev 12397)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/event/PhaseEventObserver.java 2010-04-05 21:45:25 UTC (rev 12398)
@@ -1,14 +1,17 @@
package org.jboss.seam.faces.event;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
import org.jboss.seam.faces.event.qualifier.After;
-import org.jboss.seam.faces.event.qualifier.AnyPhase;
import org.jboss.seam.faces.event.qualifier.ApplyRequestValues;
import org.jboss.seam.faces.event.qualifier.Before;
import org.jboss.seam.faces.event.qualifier.InvokeApplication;
@@ -20,169 +23,135 @@
@ApplicationScoped
public class PhaseEventObserver
{
- public static enum Observation
- {
- BEFORE_RENDER_RESPONSE, AFTER_RENDER_RESPONSE, BEFORE_APPLY_VALUES, AFTER_APPLY_VALUES, BEFORE_INVOKE_APPLICATION, AFTER_INVOKE_APPLICATION, BEFORE_PROCESS_VALIDATION, BEFORE_RESTORE_VIEW, AFTER_RESTORE_VIEW, AFTER_UPDATE_MODEL_VALUES, AFTER_PROCESS_VALIDATION, BEFORE_UPDATE_MODEL_VALUES
- }
+ private Map<String, List<PhaseId>> observations = new HashMap<String, List<PhaseId>>();
- private static final List<Observation> ALL_BEFORE_OBSERVATIONS = new ArrayList<Observation>()
+ private void recordObservation(String id, PhaseId observation)
{
- private static final long serialVersionUID = 1L;
+ List<PhaseId> observed = observations.get(id);
+ if (observed == null)
{
- add(Observation.BEFORE_APPLY_VALUES);
- add(Observation.BEFORE_INVOKE_APPLICATION);
- add(Observation.BEFORE_PROCESS_VALIDATION);
- add(Observation.BEFORE_RENDER_RESPONSE);
- add(Observation.BEFORE_RESTORE_VIEW);
- add(Observation.BEFORE_UPDATE_MODEL_VALUES);
+ observed = new ArrayList<PhaseId>();
+ observations.put(id, observed);
}
- };
+ observed.add(observation);
+ }
- private static final List<Observation> ALL_AFTER_OBSERVATIONS = new ArrayList<Observation>()
- {
- private static final long serialVersionUID = 1L;
- {
- add(Observation.AFTER_APPLY_VALUES);
- add(Observation.AFTER_INVOKE_APPLICATION);
- add(Observation.AFTER_PROCESS_VALIDATION);
- add(Observation.AFTER_RENDER_RESPONSE);
- add(Observation.AFTER_RESTORE_VIEW);
- add(Observation.AFTER_UPDATE_MODEL_VALUES);
- }
- };
-
- private List<Observation> observations = new ArrayList<Observation>();
- private List<Observation> beforeAnyObservations = new ArrayList<Observation>();
- private List<Observation> afterAnyObservations = new ArrayList<Observation>();
-
public void reset()
{
observations.clear();
- beforeAnyObservations.clear();
- afterAnyObservations.clear();
}
- public void assertSingleObservation(Observation observation)
+ public void assertObservations(String id, PhaseId... observations)
{
- assert observations.size() == 1;
- assert observation.equals(observations.iterator().next());
+ List<PhaseId> observed = this.observations.get(id);
+ assert observed != null && observed.size() == observations.length;
+ assert observed.containsAll(Arrays.asList(observations));
}
- private void recordObservation(Observation observation)
+ public void observeBeforeRenderResponse(@Observes @Before @RenderResponse final PhaseEvent e)
{
- observations.add(observation);
+ recordObservation("1", e.getPhaseId());
}
- public void observeBeforeAnyPhase(@Observes @Before @AnyPhase final PhaseEvent e)
+ public void observeAfterRenderResponse(@Observes @After @RenderResponse final PhaseEvent e)
{
- recordBeforeAnyObservations();
+ recordObservation("2", e.getPhaseId());
}
- private void recordBeforeAnyObservations()
+ public void observeBeforeApplyRequestValues(@Observes @Before @ApplyRequestValues final PhaseEvent e)
{
- recordBeforeAnyObservation(Observation.BEFORE_APPLY_VALUES);
- recordBeforeAnyObservation(Observation.BEFORE_INVOKE_APPLICATION);
- recordBeforeAnyObservation(Observation.BEFORE_PROCESS_VALIDATION);
- recordBeforeAnyObservation(Observation.BEFORE_RENDER_RESPONSE);
- recordBeforeAnyObservation(Observation.BEFORE_RESTORE_VIEW);
- recordBeforeAnyObservation(Observation.BEFORE_UPDATE_MODEL_VALUES);
+ recordObservation("3", e.getPhaseId());
}
- private void recordBeforeAnyObservation(Observation observation)
+ public void observeAfterApplyRequestValues(@Observes @After @ApplyRequestValues final PhaseEvent e)
{
- beforeAnyObservations.add(observation);
+ recordObservation("4", e.getPhaseId());
}
- public void observeAfterAnyPhase(@Observes @After @AnyPhase final PhaseEvent e)
+ public void observeBeforeInvokeApplication(@Observes @Before @InvokeApplication final PhaseEvent e)
{
- recordAfterAnyObservations();
+ recordObservation("5", e.getPhaseId());
}
- private void recordAfterAnyObservations()
+ public void observeAfterInvokeApplication(@Observes @After @InvokeApplication final PhaseEvent e)
{
- recordAfterAnyObservation(Observation.AFTER_APPLY_VALUES);
- recordAfterAnyObservation(Observation.AFTER_INVOKE_APPLICATION);
- recordAfterAnyObservation(Observation.AFTER_PROCESS_VALIDATION);
- recordAfterAnyObservation(Observation.AFTER_RENDER_RESPONSE);
- recordAfterAnyObservation(Observation.AFTER_RESTORE_VIEW);
- recordAfterAnyObservation(Observation.AFTER_UPDATE_MODEL_VALUES);
+ recordObservation("6", e.getPhaseId());
}
- private void recordAfterAnyObservation(Observation observation)
+ public void observeBeforeProcessValidations(@Observes @Before @ProcessValidations final PhaseEvent e)
{
- afterAnyObservations.add(observation);
+ recordObservation("7", e.getPhaseId());
}
- public void observeBeforeRenderResponse(@Observes @Before @RenderResponse final PhaseEvent e)
+ public void observeAfterProcessValidations(@Observes @After @ProcessValidations final PhaseEvent e)
{
- recordObservation(Observation.BEFORE_RENDER_RESPONSE);
+ recordObservation("8", e.getPhaseId());
}
- public void observeAfterRenderResponse(@Observes @After @RenderResponse final PhaseEvent e)
+ public void observeBeforeRestoreView(@Observes @Before @RestoreView final PhaseEvent e)
{
- recordObservation(Observation.AFTER_RENDER_RESPONSE);
+ recordObservation("9", e.getPhaseId());
}
- public void observeBeforeApplyRequestValues(@Observes @Before @ApplyRequestValues final PhaseEvent e)
+ public void observeAfterRestoreView(@Observes @After @RestoreView final PhaseEvent e)
{
- recordObservation(Observation.BEFORE_APPLY_VALUES);
+ recordObservation("10", e.getPhaseId());
}
- public void observeAfterApplyRequestValues(@Observes @After @ApplyRequestValues final PhaseEvent e)
+ public void observeBeforeUpdateModelValues(@Observes @Before @UpdateModelValues final PhaseEvent e)
{
- recordObservation(Observation.AFTER_APPLY_VALUES);
+ recordObservation("11", e.getPhaseId());
}
- public void observeBeforeInvokeApplication(@Observes @Before @InvokeApplication final PhaseEvent e)
+ public void observeAfterUpdateModelValues(@Observes @After @UpdateModelValues final PhaseEvent e)
{
- recordObservation(Observation.BEFORE_INVOKE_APPLICATION);
+ recordObservation("12", e.getPhaseId());
}
- public void observeAfterInvokeApplication(@Observes @After @InvokeApplication final PhaseEvent e)
+ public void observeAllRenderResponse(@Observes @RenderResponse final PhaseEvent e)
{
- recordObservation(Observation.AFTER_INVOKE_APPLICATION);
+ recordObservation("13", e.getPhaseId());
}
- public void observeBeforeProcessValidations(@Observes @Before @ProcessValidations final PhaseEvent e)
+ public void observeAllApplyRequestValues(@Observes @ApplyRequestValues final PhaseEvent e)
{
- recordObservation(Observation.BEFORE_PROCESS_VALIDATION);
+ recordObservation("14", e.getPhaseId());
}
- public void observeAfterProcessValidations(@Observes @After @ProcessValidations final PhaseEvent e)
+ public void observeAllInvokeApplication(@Observes @InvokeApplication final PhaseEvent e)
{
- recordObservation(Observation.AFTER_PROCESS_VALIDATION);
+ recordObservation("15", e.getPhaseId());
}
- public void observeBeforeRestoreView(@Observes @Before @RestoreView final PhaseEvent e)
+ public void observeAllProcessValidations(@Observes @ProcessValidations final PhaseEvent e)
{
- recordObservation(Observation.BEFORE_RESTORE_VIEW);
+ recordObservation("16", e.getPhaseId());
}
- public void observeAfterRestoreView(@Observes @After @RestoreView final PhaseEvent e)
+ public void observeAllRestoreView(@Observes @RestoreView final PhaseEvent e)
{
- recordObservation(Observation.AFTER_RESTORE_VIEW);
+ recordObservation("17", e.getPhaseId());
}
- public void observeBeforeUpdateModelValues(@Observes @Before @UpdateModelValues final PhaseEvent e)
+ public void observeAllUpdateModelValues(@Observes @UpdateModelValues final PhaseEvent e)
{
- recordObservation(Observation.BEFORE_UPDATE_MODEL_VALUES);
+ recordObservation("18", e.getPhaseId());
}
- public void observeAfterUpdateModelValues(@Observes @After @UpdateModelValues final PhaseEvent e)
+ public void observeAllBeforeEvents(@Observes @Before final PhaseEvent e)
{
- recordObservation(Observation.AFTER_UPDATE_MODEL_VALUES);
+ recordObservation("19", e.getPhaseId());
}
-
- public void assertAllAfterPhasesObserved()
+
+ public void observeAllAfterEvents(@Observes @Before final PhaseEvent e)
{
-// assert afterAnyObservations.size() == ALL_AFTER_OBSERVATIONS.size();
- assert afterAnyObservations.containsAll(ALL_AFTER_OBSERVATIONS);
+ recordObservation("20", e.getPhaseId());
}
-
- public void assertAllBeforePhasesObserved()
+
+ public void observeAllEvents(@Observes final PhaseEvent e)
{
-// assert beforeAnyObservations.size() == ALL_BEFORE_OBSERVATIONS.size();
- assert beforeAnyObservations.containsAll(ALL_BEFORE_OBSERVATIONS);
+ recordObservation("21", e.getPhaseId());
}
+
}
14 years, 2 months
Seam SVN: r12397 - in modules/xml/trunk: core/src/main/java/org/jboss/seam/xml/core and 7 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-04-05 17:35:24 -0400 (Mon, 05 Apr 2010)
New Revision: 12397
Added:
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/Interface1.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceBean.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceQualifier.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceTest.java
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/iface/
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/iface/interface-beans.xml
Modified:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
modules/xml/trunk/docs/
Log:
added interface config to XML extensions
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-04-05 20:25:12 UTC (rev 12396)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -33,6 +33,7 @@
import org.jboss.seam.xml.parser.SaxNode;
import org.jboss.seam.xml.util.FileDataReader;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,8 +48,6 @@
Set<Class<?>> veto = new HashSet<Class<?>>();
- Map<Class<?>, AnnotatedType<?>> types = new HashMap<Class<?>, AnnotatedType<?>>();
-
int count = 0;
private static final Logger log = LoggerFactory.getLogger(XmlExtension.class);
@@ -130,7 +129,6 @@
AnnotatedType<?> tp = bb.getBuilder().create();
log.info("Adding XML definied bean: " + tp.getJavaClass().getName());
event.addAnnotatedType(tp);
- types.put(tp.getJavaClass(), tp);
}
veto.addAll(r.getVeto());
@@ -146,6 +144,23 @@
log.info("Preventing installation of default bean: " + event.getAnnotatedType().getJavaClass().getName());
event.veto();
}
+ boolean found = false;
+ NewAnnotatedTypeBuilder builder = new NewAnnotatedTypeBuilder(event.getAnnotatedType());
+ for (XmlResult r : results)
+ {
+ for (BeanResult<?> i : r.getInterfaces())
+ {
+ if (i.getType().isAssignableFrom(event.getAnnotatedType().getJavaClass()))
+ {
+ found = true;
+ builder.mergeAnnotations(i.getBuilder().create(), true);
+ }
+ }
+ }
+ if (found)
+ {
+ event.setAnnotatedType(builder.create());
+ }
}
@@ -160,7 +175,18 @@
List<FieldValueObject> fvs = fieldValues.get(xid.value());
event.setInjectionTarget(new InjectionTargetWrapper<T>(event.getInjectionTarget(), fvs));
}
-
+ for (XmlResult r : results)
+ {
+ for (Entry<Class<?>, List<FieldValueObject>> e : r.getInterfaceFieldValues().entrySet())
+ {
+ if (e.getKey().isAssignableFrom(event.getAnnotatedType().getJavaClass()))
+ {
+ log.info("Wrapping InjectionTarget to set field values based on interface " + e.getKey().getName() + ": " + event.getAnnotatedType().getJavaClass().getName());
+ List<FieldValueObject> fvs = e.getValue();
+ event.setInjectionTarget(new InjectionTargetWrapper<T>(event.getInjectionTarget(), fvs));
+ }
+ }
+ }
}
public void processAfterBeanDeployment(@Observes AfterBeanDiscovery event)
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-04-05 20:25:12 UTC (rev 12396)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -33,8 +33,12 @@
List<BeanResult<?>> beans = new ArrayList<BeanResult<?>>();
+ List<BeanResult<?>> interfaces = new ArrayList<BeanResult<?>>();
+
Map<BeanResult<?>, List<FieldValueObject>> fieldValues = new HashMap<BeanResult<?>, List<FieldValueObject>>();
+ Map<Class<?>, List<FieldValueObject>> interfaceFieldValues = new HashMap<Class<?>, List<FieldValueObject>>();
+
public Map<Class<? extends Annotation>, Annotation[]> getStereotypes()
{
return stereotypes;
@@ -80,4 +84,14 @@
return veto;
}
+ public List<BeanResult<?>> getInterfaces()
+ {
+ return interfaces;
+ }
+
+ public Map<Class<?>, List<FieldValueObject>> getInterfaceFieldValues()
+ {
+ return interfaceFieldValues;
+ }
+
}
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-04-05 20:25:12 UTC (rev 12396)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -7,10 +7,8 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -107,7 +105,14 @@
if (type == ResultType.BEAN)
{
BeanResult<?> tp = buildAnnotatedType((ClassXmlItem) rb);
- ret.getBeans().add(tp);
+ if (rb.getJavaClass().isInterface())
+ {
+ ret.getInterfaces().add(tp);
+ }
+ else
+ {
+ ret.getBeans().add(tp);
+ }
if (tp.isOverride() || tp.isExtend())
{
ret.addVeto(tp.getType());
@@ -131,7 +136,14 @@
}
if (!fields.isEmpty())
{
- ret.getFieldValues().put(tp, fields);
+ if (rb.getJavaClass().isInterface())
+ {
+ ret.getInterfaceFieldValues().put(tp.getType(), fields);
+ }
+ else
+ {
+ ret.getFieldValues().put(tp, fields);
+ }
}
}
else if (type == ResultType.QUALIFIER)
@@ -294,7 +306,6 @@
}
if (!types.isEmpty())
{
- Set<Type> fieldTypes = new HashSet<Type>();
List<ClassXmlItem> overridenTypes = types.get(0).getChildrenOfType(ClassXmlItem.class);
if (overridenTypes.size() != 1)
{
@@ -336,7 +347,6 @@
}
if (!types.isEmpty())
{
- Set<Type> fieldTypes = new HashSet<Type>();
List<ClassXmlItem> overridenTypes = types.get(0).getChildrenOfType(ClassXmlItem.class);
if (overridenTypes.size() != 1)
{
@@ -373,7 +383,6 @@
}
if (!types.isEmpty())
{
- Set<Type> fieldTypes = new HashSet<Type>();
List<ClassXmlItem> overridenTypes = types.get(0).getChildrenOfType(ClassXmlItem.class);
if (overridenTypes.size() != 1)
{
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-04-05 20:25:12 UTC (rev 12396)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -76,7 +76,7 @@
// now deal with primitive types
- Class primType = null;
+ Class<?> primType = null;
if (item.equals("int"))
{
primType = int.class;
Added: modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/Interface1.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/Interface1.java (rev 0)
+++ modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/Interface1.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -0,0 +1,9 @@
+package org.jboss.seam.xml.test.iface;
+
+public interface Interface1
+{
+ public String value();
+
+ public void setMessage(String value);
+
+}
Added: modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceBean.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceBean.java (rev 0)
+++ modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceBean.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -0,0 +1,18 @@
+package org.jboss.seam.xml.test.iface;
+
+public class InterfaceBean implements Interface1
+{
+
+ String message;
+
+ public void setMessage(String value)
+ {
+ this.message = value;
+ }
+
+ public String value()
+ {
+ return "hi world";
+ }
+
+}
Added: modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceQualifier.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceQualifier.java (rev 0)
+++ modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceQualifier.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -0,0 +1,13 @@
+package org.jboss.seam.xml.test.iface;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface InterfaceQualifier
+{
+
+}
Added: modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceTest.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceTest.java (rev 0)
+++ modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/iface/InterfaceTest.java 2010-04-05 21:35:24 UTC (rev 12397)
@@ -0,0 +1,30 @@
+package org.jboss.seam.xml.test.iface;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.testng.annotations.Test;
+
+public class InterfaceTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "interface-beans.xml";
+ }
+
+ @Test
+ public void testInterfaceConfig()
+ {
+ InterfaceBean x = getReference(InterfaceBean.class, new AnnotationLiteral<InterfaceQualifier>()
+ {
+ });
+ assert x.message.equals("hello world");
+ String s = getReference(String.class, new AnnotationLiteral<InterfaceQualifier>()
+ {
+ });
+ assert s.equals("hi world");
+ }
+
+}
\ No newline at end of file
Added: modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/iface/interface-beans.xml
===================================================================
--- modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/iface/interface-beans.xml (rev 0)
+++ modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/iface/interface-beans.xml 2010-04-05 21:35:24 UTC (rev 12397)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="urn:java:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.iface">
+
+
+ <test:Interface1>
+ <test:InterfaceQualifier/>
+ <test:message>hello world</test:message>
+ <test:value><Produces/><test:InterfaceQualifier/></test:value>
+ </test:Interface1>
+
+
+</beans>
\ No newline at end of file
Property changes on: modules/xml/trunk/docs
___________________________________________________________________
Name: svn:ignore
- target
.classpath
.project
.settings
+ target
.classpath
.project
.settings
xml-reference.pdf
14 years, 2 months
Seam SVN: r12396 - in modules/faces/trunk/impl/src: main/java/org/jboss/seam/faces/environment and 1 other directories.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-04-05 16:25:12 -0400 (Mon, 05 Apr 2010)
New Revision: 12396
Removed:
modules/faces/trunk/impl/src/main/java/javax/
Modified:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java
Log:
Fixed import errors.
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java 2010-04-05 20:21:36 UTC (rev 12395)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java 2010-04-05 20:25:12 UTC (rev 12396)
@@ -1,5 +1,5 @@
//$Id: FacesContext.java 5350 2007-06-20 17:53:19Z gavin $
-package org.jboss.seam.faces.producer;
+package org.jboss.seam.faces.environment;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
@@ -8,17 +8,19 @@
/**
* <p>
- * A producer which retrieves the {@link ExternalContext} for the current request
- * of the JavaServer Faces application by calling {@link FacesContext#getExternalContext()}
- * and stores the result as a request-scoped bean instance.
+ * A producer which retrieves the {@link ExternalContext} for the current
+ * request of the JavaServer Faces application by calling
+ * {@link FacesContext#getExternalContext()} and stores the result as a
+ * request-scoped bean instance.
* </p>
- *
+ *
* <p>
* This producer allows the {@link ExternalContext} to be injected:
* </p>
- *
+ *
* <pre>
- * @Inject ExternalContext ctx;
+ * @Inject
+ * ExternalContext ctx;
* </pre>
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
@@ -26,7 +28,9 @@
*/
public class ExternalContextProducer
{
- public @Produces @RequestScoped ExternalContext getExternalContext(FacesContext context)
+ public @Produces
+ @RequestScoped
+ ExternalContext getExternalContext(final FacesContext context)
{
return context.getExternalContext();
}
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java 2010-04-05 20:21:36 UTC (rev 12395)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java 2010-04-05 20:25:12 UTC (rev 12396)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.jboss.seam.faces.producer;
+package org.jboss.seam.faces.environment;
import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.context.RequestScoped;
@@ -24,14 +24,18 @@
/**
* <p>
* A producer which retrieves the {@link FacesContext} for the current request
- * of the JavaServer Faces application by calling {@link FacesContext#getCurrentInstance()}
- * and stores the result as a request-scoped bean instance.
+ * of the JavaServer Faces application by calling
+ * {@link FacesContext#getCurrentInstance()} and stores the result as a
+ * request-scoped bean instance.
* </p>
- *
- * <p>This producer allows the {@link FacesContext} to be injected:</p>
- *
+ *
+ * <p>
+ * This producer allows the {@link FacesContext} to be injected:
+ * </p>
+ *
* <pre>
- * @Inject FacesContext ctx;
+ * @Inject
+ * FacesContext ctx;
* </pre>
*
* <p>
@@ -44,7 +48,9 @@
*/
public class FacesContextProducer
{
- public @Produces @RequestScoped FacesContext getFacesContext()
+ public @Produces
+ @RequestScoped
+ FacesContext getFacesContext()
{
FacesContext ctx = FacesContext.getCurrentInstance();
if (ctx == null)
Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java 2010-04-05 20:21:36 UTC (rev 12395)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java 2010-04-05 20:25:12 UTC (rev 12396)
@@ -3,15 +3,13 @@
import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.inject.Instance;
import javax.faces.context.ExternalContext;
-
import javax.faces.context.FacesContext;
import javax.inject.Inject;
+
import junit.framework.Assert;
+
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.faces.producer.ExternalContextProducer;
-import org.jboss.seam.faces.producer.FacesContextProducer;
-
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.Archives;
@@ -21,9 +19,9 @@
import org.junit.runner.RunWith;
/**
- * Verify that the ExternalContextProducer produces the same ExternalContext
- * as returned by FacesContext#getExternalContext().
- *
+ * Verify that the ExternalContextProducer produces the same ExternalContext as
+ * returned by FacesContext#getExternalContext().
+ *
* @author Dan Allen
*/
@RunWith(Arquillian.class)
@@ -32,12 +30,11 @@
@Deployment
public static Archive<?> createTestArchive()
{
- return Archives.create("test.jar", JavaArchive.class)
- .addClass(FacesContextProducer.class).addClass(ExternalContextProducer.class)
- .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ return Archives.create("test.jar", JavaArchive.class).addClass(FacesContextProducer.class).addClass(ExternalContextProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
}
- @Inject Instance<ExternalContext> externalContextInstance;
+ @Inject
+ Instance<ExternalContext> externalContextInstance;
@Test
public void testReturnsCurrentExternalContext()
@@ -59,7 +56,7 @@
Assert.assertFalse(actualExternalContext == producedExternalContext);
// verify we have same object through proxy by comparing hash codes
Assert.assertEquals(actualExternalContext.hashCode(), producedExternalContext.hashCode());
- //Assert.assertEquals(actualExternalContext, producedExternalContext);
+ // Assert.assertEquals(actualExternalContext, producedExternalContext);
Assert.assertEquals("/app", producedExternalContext.getRequestContextPath());
}
Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java 2010-04-05 20:21:36 UTC (rev 12395)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java 2010-04-05 20:25:12 UTC (rev 12396)
@@ -2,15 +2,14 @@
import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.inject.Instance;
-
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
import javax.inject.Inject;
+
import junit.framework.Assert;
+
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.faces.producer.FacesContextProducer;
-
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.Archives;
@@ -20,9 +19,9 @@
import org.junit.runner.RunWith;
/**
- * Verify that the FacesContextProducer produces the same FacesContext
- * as returned by FacesContext#getCurrentInstance().
- *
+ * Verify that the FacesContextProducer produces the same FacesContext as
+ * returned by FacesContext#getCurrentInstance().
+ *
* @author Dan Allen
*/
@RunWith(Arquillian.class)
@@ -31,12 +30,11 @@
@Deployment
public static Archive<?> createTestArchive()
{
- return Archives.create("test.jar", JavaArchive.class)
- .addClass(FacesContextProducer.class)
- .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ return Archives.create("test.jar", JavaArchive.class).addClass(FacesContextProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
}
- @Inject Instance<FacesContext> facesContextInstance;
+ @Inject
+ Instance<FacesContext> facesContextInstance;
@Test
public void testReturnsCurrentFacesContext()
@@ -57,7 +55,7 @@
Assert.assertFalse(actualFacesContext == producedFacesContext);
// verify we have same object through proxy by comparing hash codes
Assert.assertEquals(actualFacesContext.hashCode(), producedFacesContext.hashCode());
- //Assert.assertEquals(actualFacesContext, producedFacesContext);
+ // Assert.assertEquals(actualFacesContext, producedFacesContext);
Assert.assertSame(PhaseId.RENDER_RESPONSE, producedFacesContext.getCurrentPhaseId());
}
14 years, 2 months
Seam SVN: r12395 - in modules/faces/trunk/examples/tiny-url: src and 11 other directories.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-04-05 16:21:36 -0400 (Mon, 05 Apr 2010)
New Revision: 12395
Added:
modules/faces/trunk/examples/tiny-url/pom.xml
modules/faces/trunk/examples/tiny-url/src/
modules/faces/trunk/examples/tiny-url/src/main/
modules/faces/trunk/examples/tiny-url/src/main/java/
modules/faces/trunk/examples/tiny-url/src/main/java/org/
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java
modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java
modules/faces/trunk/examples/tiny-url/src/main/resources/
modules/faces/trunk/examples/tiny-url/src/main/webapp/
modules/faces/trunk/examples/tiny-url/src/main/webapp/META-INF/
modules/faces/trunk/examples/tiny-url/src/main/webapp/META-INF/MANIFEST.MF
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/beans.xml
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/faces-config.xml
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/lib/
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml
modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml
modules/faces/trunk/examples/tiny-url/src/main/webapp/editLink.xhtml
modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml
modules/faces/trunk/examples/tiny-url/src/test/
modules/faces/trunk/examples/tiny-url/src/test/java/
modules/faces/trunk/examples/tiny-url/src/test/resources/
Modified:
modules/faces/trunk/examples/tiny-url/
Log:
Initial import.
Property changes on: modules/faces/trunk/examples/tiny-url
___________________________________________________________________
Name: svn:ignore
+ .settings
target
.classpath
.project
Added: modules/faces/trunk/examples/tiny-url/pom.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/pom.xml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/pom.xml 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,112 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jboss.seam.faces</groupId>
+ <artifactId>faces-examples-tiny-url</artifactId>
+
+ <packaging>war</packaging>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>tiny.url with Seam & PrettyFaces</name>
+
+ <url>http://go.jboss.org/</url>
+
+ <repositories>
+ <repository>
+ <id>java.net2</id>
+ <name>Repository hosting the jee6 artifacts</name>
+ <url>http://download.java.net/maven/2</url>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-faces</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.5.9.RC1</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax</groupId>
+ <artifactId>javaee-web-api</artifactId>
+ <version>6.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.ocpsoft</groupId>
+ <artifactId>ocpsoft-pretty-faces</artifactId>
+ <version>2.0.5-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.ocpsoft</groupId>
+ <artifactId>ocpsoft-pretty-time</artifactId>
+ <version>1.0.5</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>Glassfish</id>
+ <url>http://download.java.net/maven/glassfish/</url>
+ </pluginRepository>
+ </pluginRepositories>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.glassfish</groupId>
+ <artifactId>maven-embedded-glassfish-plugin</artifactId>
+ <version>3.0</version>
+ <configuration>
+ <goalPrefix>glassfish</goalPrefix>
+ <app>test.war</app>
+ <port>8080</port>
+ <contextRoot>test</contextRoot>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>install</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.1-beta-1</version>
+ <configuration>
+ <failOnMissingWebXml>false</failOnMissingWebXml>
+ </configuration>
+ </plugin>
+ </plugins>
+ <finalName>tiny.url</finalName>
+ </build>
+
+</project>
Added: modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/LinkBean.java 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,54 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.examples;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.ConversationScoped;
+import javax.inject.Named;
+
+import org.jboss.seam.faces.context.conversation.Begin;
+import org.jboss.seam.faces.context.conversation.End;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+@Named
+@ConversationScoped
+public class LinkBean implements Serializable
+{
+ private static final long serialVersionUID = -2209547152337410725L;
+
+ private String key;
+ private String url;
+
+ @Begin
+ @End
+ public String createLink()
+ {
+ System.out.println("Created link: [ " + key + " => " + url + " ]");
+ return "pretty:edit";
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public void setKey(final String key)
+ {
+ this.key = key;
+ }
+
+ public String getUrl()
+ {
+ return url;
+ }
+
+ public void setUrl(final String url)
+ {
+ this.url = url;
+ }
+}
Added: modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/java/org/jboss/seam/faces/examples/RedirectBean.java 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,45 @@
+/**
+ *
+ */
+package org.jboss.seam.faces.examples;
+
+import java.io.IOException;
+
+import javax.enterprise.context.RequestScoped;
+import javax.faces.context.FacesContext;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+@Named
+@RequestScoped
+public class RedirectBean
+{
+ @Inject
+ FacesContext context;
+
+ private String key;
+
+ public void send() throws IOException
+ {
+ String url = "http://ocpsoft.com";
+ System.out.println("Sent redirect for key: " + key);
+ HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
+ response.sendRedirect(url);
+ context.responseComplete();
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public void setKey(final String key)
+ {
+ this.key = key;
+ }
+}
Added: modules/faces/trunk/examples/tiny-url/src/main/webapp/META-INF/MANIFEST.MF
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/META-INF/MANIFEST.MF (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/META-INF/MANIFEST.MF 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
Added: modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/beans.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/beans.xml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/beans.xml 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans/>
\ No newline at end of file
Added: modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/faces-config.xml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/faces-config.xml 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+ version="2.0">
+
+</faces-config>
Added: modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/pretty-config.xml 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,25 @@
+<pretty-config xmlns="http://ocpsoft.com/prettyfaces/2.0.4"
+xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+xsi:schemaLocation="http://ocpsoft.com/prettyfaces/2.0.4
+http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-2.0.4.xsd">
+
+ <rewrite trailingSlash="remove" toCase="lowercase" />
+
+ <url-mapping id="create">
+ <pattern value="/" />
+ <view-id>/faces/index.xhtml</view-id>
+ </url-mapping>
+
+ <url-mapping id="redirect">
+ <pattern value="/#{key}" />
+ <view-id>/faces/index.xhtml</view-id>
+ <action phaseId="RENDER_RESPONSE">#{redirectBean.send}</action>
+ </url-mapping>
+
+ <url-mapping id="edit">
+ <pattern value="/#{key}/edit" />
+ <view-id>/faces/editLink.xhtml</view-id>
+ <action phaseId="INVOKE_APPLICATION">#{linkBean.send}</action>
+ </url-mapping>
+
+</pretty-config>
Added: modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/WEB-INF/web.xml 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+ <context-param>
+ <param-name>javax.faces.PROJECT_STAGE</param-name>
+ <param-value>Development</param-value>
+ </context-param>
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/faces/*</url-pattern>
+ </servlet-mapping>
+ <session-config>
+ <session-timeout>
+ 30
+ </session-timeout>
+ </session-config>
+ <welcome-file-list>
+ <welcome-file>faces/index.xhtml</welcome-file>
+ </welcome-file-list>
+</web-app>
Added: modules/faces/trunk/examples/tiny-url/src/main/webapp/editLink.xhtml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/editLink.xhtml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/editLink.xhtml 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,27 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets">
+
+ <f:metadata>
+ <f:viewParam name="key" value="#{redirectBean.key}" />
+ </f:metadata>
+
+ <h:head>
+ </h:head>
+
+ <h:body>
+ <h:form>
+ <h3>View a new link:</h3>
+ <label for="key">Key: <h:messages for="key"/><br/></label>
+ <h:inputText id="key" value="#{createLinkBean.key}" /><br/>
+ <label for="url">Link URL: <h:messages for="url"/><br/></label>
+ <h:inputText id="url" value="#{createLinkBean.url}" /><br/>
+ <h:commandButton action ="#{createLinkBean.done}" value="Create" />
+ </h:form>
+ </h:body>
+
+</html>
+
Added: modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml
===================================================================
--- modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml (rev 0)
+++ modules/faces/trunk/examples/tiny-url/src/main/webapp/index.xhtml 2010-04-05 20:21:36 UTC (rev 12395)
@@ -0,0 +1,27 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:h="http://java.sun.com/jsf/html"
+ xmlns:f="http://java.sun.com/jsf/core"
+ xmlns:ui="http://java.sun.com/jsf/facelets">
+
+ <f:metadata>
+ <f:viewParam name="key" value="#{redirectBean.key}" />
+ </f:metadata>
+
+ <h:head>
+ </h:head>
+
+ <h:body>
+ <h:form>
+ <h3>Create a new link:</h3>
+ <label for="key">Key: <h:messages for="key"/><br/></label>
+ <h:inputText id="key" value="#{createLinkBean.key}" /><br/>
+ <label for="url">Link URL: <h:messages for="url"/><br/></label>
+ <h:inputText id="url" value="#{createLinkBean.url}" /><br/>
+ <h:commandButton action ="#{createLinkBean.createLink}" value="Create" />
+ </h:form>
+ </h:body>
+
+</html>
+
14 years, 2 months
Seam SVN: r12393 - modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-05 16:04:50 -0400 (Mon, 05 Apr 2010)
New Revision: 12393
Added:
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockExternalContext.java
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockFacesContext.java
Modified:
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java
Log:
test for ExternalContextProducer
refactor out mocks
cleanup FacesContextProducerTest
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/ExternalContextProducerTest.java 2010-04-05 20:04:50 UTC (rev 12393)
@@ -0,0 +1,73 @@
+package org.jboss.seam.faces.environment;
+
+import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.inject.Instance;
+import javax.faces.context.ExternalContext;
+
+import javax.faces.context.FacesContext;
+import javax.inject.Inject;
+import junit.framework.Assert;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.faces.producer.ExternalContextProducer;
+import org.jboss.seam.faces.producer.FacesContextProducer;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Verify that the ExternalContextProducer produces the same ExternalContext
+ * as returned by FacesContext#getExternalContext().
+ *
+ * @author Dan Allen
+ */
+(a)RunWith(Arquillian.class)
+public class ExternalContextProducerTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ return Archives.create("test.jar", JavaArchive.class)
+ .addClass(FacesContextProducer.class).addClass(ExternalContextProducer.class)
+ .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject Instance<ExternalContext> externalContextInstance;
+
+ @Test
+ public void testReturnsCurrentExternalContext()
+ {
+ new MockFacesContext().set();
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ Assert.assertSame(new ExternalContextProducer().getExternalContext(ctx), ctx.getExternalContext());
+ }
+
+ @Test
+ public void testProducesContextualCurrentFacesContext()
+ {
+ new MockFacesContext().set();
+
+ ExternalContext actualExternalContext = FacesContext.getCurrentInstance().getExternalContext();
+ ExternalContext producedExternalContext = externalContextInstance.get();
+
+ // not equal since the produced ExternalContext is a proxy
+ Assert.assertFalse(actualExternalContext == producedExternalContext);
+ // verify we have same object through proxy by comparing hash codes
+ Assert.assertEquals(actualExternalContext.hashCode(), producedExternalContext.hashCode());
+ //Assert.assertEquals(actualExternalContext, producedExternalContext);
+ Assert.assertEquals("/app", producedExternalContext.getRequestContextPath());
+ }
+
+ @Test(expected = ContextNotActiveException.class)
+ public void testProducerThrowsExceptionWhenFacesContextNotActive()
+ {
+ new MockFacesContext().release();
+ // NOTE the return value must be invoked to carry out the lookup
+ externalContextInstance.get().toString();
+ }
+}
Modified: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java 2010-04-05 19:37:40 UTC (rev 12392)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java 2010-04-05 20:04:50 UTC (rev 12393)
@@ -1,16 +1,7 @@
package org.jboss.seam.faces.environment;
-import java.util.Iterator;
import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.inject.Instance;
-import javax.faces.application.Application;
-import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.ExternalContext;
-import javax.faces.context.ResponseStream;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.RenderKit;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseId;
@@ -40,7 +31,9 @@
@Deployment
public static Archive<?> createTestArchive()
{
- return Archives.create("test.jar", JavaArchive.class).addClass(FacesContextProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ return Archives.create("test.jar", JavaArchive.class)
+ .addClass(FacesContextProducer.class)
+ .addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
}
@Inject Instance<FacesContext> facesContextInstance;
@@ -48,7 +41,7 @@
@Test
public void testReturnsCurrentFacesContext()
{
- new MockFacesContext().set().setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
+ new MockFacesContext().set();
Assert.assertSame(new FacesContextProducer().getFacesContext(), FacesContext.getCurrentInstance());
}
@@ -65,7 +58,7 @@
// verify we have same object through proxy by comparing hash codes
Assert.assertEquals(actualFacesContext.hashCode(), producedFacesContext.hashCode());
//Assert.assertEquals(actualFacesContext, producedFacesContext);
- Assert.assertSame(producedFacesContext.getCurrentPhaseId(), PhaseId.RENDER_RESPONSE);
+ Assert.assertSame(PhaseId.RENDER_RESPONSE, producedFacesContext.getCurrentPhaseId());
}
@Test(expected = ContextNotActiveException.class)
@@ -75,141 +68,4 @@
// NOTE the return value must be invoked to carry out the lookup
facesContextInstance.get().toString();
}
-
- private class MockFacesContext extends FacesContext
- {
- private PhaseId currentPhaseId;
-
- public FacesContext set()
- {
- setCurrentInstance(this);
- return this;
- }
-
- @Override
- public void release()
- {
- setCurrentInstance(null);
- }
-
- @Override
- public PhaseId getCurrentPhaseId()
- {
- return currentPhaseId;
- }
-
- @Override
- public void setCurrentPhaseId(PhaseId currentPhaseId)
- {
- this.currentPhaseId = currentPhaseId;
- }
-
- @Override
- public Application getApplication()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public Iterator<String> getClientIdsWithMessages()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public ExternalContext getExternalContext()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public Severity getMaximumSeverity()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public Iterator<FacesMessage> getMessages()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public Iterator<FacesMessage> getMessages(String clientId)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public RenderKit getRenderKit()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public boolean getRenderResponse()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public boolean getResponseComplete()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public ResponseStream getResponseStream()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public void setResponseStream(ResponseStream stream)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public ResponseWriter getResponseWriter()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public void setResponseWriter(ResponseWriter writer)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public UIViewRoot getViewRoot()
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public void setViewRoot(UIViewRoot uivr)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public void addMessage(String clientId, FacesMessage message)
- {
- throw new UnsupportedOperationException("Not supported");
- }
-
- @Override
- public void renderResponse()
- {
- throw new UnsupportedOperationException("Not supported.");
- }
-
- @Override
- public void responseComplete()
- {
- throw new UnsupportedOperationException("Not supported.");
- }
- }
}
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockExternalContext.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockExternalContext.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockExternalContext.java 2010-04-05 20:04:50 UTC (rev 12393)
@@ -0,0 +1,22 @@
+package org.jboss.seam.faces.environment;
+
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ExternalContextWrapper;
+
+/**
+ * @author Dan Allen
+ */
+public class MockExternalContext extends ExternalContextWrapper
+{
+ @Override
+ public String getRequestContextPath()
+ {
+ return "/app";
+ }
+
+ @Override
+ public ExternalContext getWrapped()
+ {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+}
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockFacesContext.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockFacesContext.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/MockFacesContext.java 2010-04-05 20:04:50 UTC (rev 12393)
@@ -0,0 +1,154 @@
+package org.jboss.seam.faces.environment;
+
+import java.util.Iterator;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.event.PhaseId;
+import javax.faces.render.RenderKit;
+
+/**
+ * @author Dan Allen
+ */
+public class MockFacesContext extends FacesContext
+{
+ private PhaseId currentPhaseId;
+ private ExternalContext externalContext = new MockExternalContext();
+
+ public FacesContext set()
+ {
+ setCurrentInstance(this);
+ return this;
+ }
+
+ @Override
+ public void release()
+ {
+ setCurrentInstance(null);
+ }
+
+ @Override
+ public PhaseId getCurrentPhaseId()
+ {
+ return currentPhaseId;
+ }
+
+ @Override
+ public void setCurrentPhaseId(PhaseId currentPhaseId)
+ {
+ this.currentPhaseId = currentPhaseId;
+ }
+
+ @Override
+ public Application getApplication()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public Iterator<String> getClientIdsWithMessages()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public ExternalContext getExternalContext()
+ {
+ return externalContext;
+ }
+
+ @Override
+ public Severity getMaximumSeverity()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public Iterator<FacesMessage> getMessages()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public Iterator<FacesMessage> getMessages(String clientId)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public RenderKit getRenderKit()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public boolean getRenderResponse()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public boolean getResponseComplete()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public ResponseStream getResponseStream()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void setResponseStream(ResponseStream stream)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public ResponseWriter getResponseWriter()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void setResponseWriter(ResponseWriter writer)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public UIViewRoot getViewRoot()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void setViewRoot(UIViewRoot uivr)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void addMessage(String clientId, FacesMessage message)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void renderResponse()
+ {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void responseComplete()
+ {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+}
14 years, 2 months
Seam SVN: r12392 - in modules/faces/trunk/impl/src: test/java/org/jboss/seam/faces and 1 other directories.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-04-05 15:37:40 -0400 (Mon, 05 Apr 2010)
New Revision: 12392
Added:
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/
modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java
Modified:
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java
modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java
Log:
throw exception if retrieving FacesContext outside an active JSF lifecycle
test for FacesContextProducer
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java 2010-04-05 19:22:20 UTC (rev 12391)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/ExternalContextProducer.java 2010-04-05 19:37:40 UTC (rev 12392)
@@ -1,34 +1,33 @@
//$Id: FacesContext.java 5350 2007-06-20 17:53:19Z gavin $
-package org.jboss.seam.faces.environment;
+package org.jboss.seam.faces.producer;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import javax.inject.Inject;
/**
* <p>
- * A producer which retrieves the current JSF ExternalContext by calling
- * {@link FacesContext#getCurrentInstance#getExternalContext()}, thus allowing
- * it to be injected.
+ * A producer which retrieves the {@link ExternalContext} for the current request
+ * of the JavaServer Faces application by calling {@link FacesContext#getExternalContext()}
+ * and stores the result as a request-scoped bean instance.
* </p>
+ *
+ * <p>
+ * This producer allows the {@link ExternalContext} to be injected:
+ * </p>
+ *
+ * <pre>
+ * @Inject ExternalContext ctx;
+ * </pre>
*
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ * @author Dan Allen
*/
public class ExternalContextProducer
{
- @Inject
- FacesContext context;
-
- public @Produces
- @RequestScoped
- ExternalContext getExternalContext()
+ public @Produces @RequestScoped ExternalContext getExternalContext(FacesContext context)
{
- if (context != null)
- {
- return context.getExternalContext();
- }
- return null;
+ return context.getExternalContext();
}
}
Modified: modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java
===================================================================
--- modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java 2010-04-05 19:22:20 UTC (rev 12391)
+++ modules/faces/trunk/impl/src/main/java/org/jboss/seam/faces/environment/FacesContextProducer.java 2010-04-05 19:37:40 UTC (rev 12392)
@@ -1,21 +1,40 @@
-//$Id: FacesContext.java 5350 2007-06-20 17:53:19Z gavin $
-package org.jboss.seam.faces.environment;
+/*
+ * JBoss, Community-driven Open Source Middleware
+ * Copyright 2010, JBoss by Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.seam.faces.producer;
+import javax.enterprise.context.ContextNotActiveException;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.faces.context.FacesContext;
/**
* <p>
- * A producer which retrieves the current JSF FacesContext by calling
- * {@link FacesContext#getCurrentInstance}, thus allowing it to be injected.
+ * A producer which retrieves the {@link FacesContext} for the current request
+ * of the JavaServer Faces application by calling {@link FacesContext#getCurrentInstance()}
+ * and stores the result as a request-scoped bean instance.
* </p>
+ *
+ * <p>This producer allows the {@link FacesContext} to be injected:</p>
+ *
+ * <pre>
+ * @Inject FacesContext ctx;
+ * </pre>
*
* <p>
- * QUESTION should we return null if there is no current phase id? (seems to be
- * a common check)
- * </p>
- * <p>
* QUESTION is it correct to use a @RequestScoped producer? If it is @Dependent,
* then a developer could unknowingly bind it to a wider-scoped bean
* </p>
@@ -25,10 +44,13 @@
*/
public class FacesContextProducer
{
- public @Produces
- @RequestScoped
- FacesContext getFacesContext()
+ public @Produces @RequestScoped FacesContext getFacesContext()
{
- return FacesContext.getCurrentInstance();
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ if (ctx == null)
+ {
+ throw new ContextNotActiveException("FacesContext is not active");
+ }
+ return ctx;
}
}
Added: modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java
===================================================================
--- modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java (rev 0)
+++ modules/faces/trunk/impl/src/test/java/org/jboss/seam/faces/environment/FacesContextProducerTest.java 2010-04-05 19:37:40 UTC (rev 12392)
@@ -0,0 +1,215 @@
+package org.jboss.seam.faces.environment;
+
+import java.util.Iterator;
+import javax.enterprise.context.ContextNotActiveException;
+import javax.enterprise.inject.Instance;
+import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
+import javax.faces.application.FacesMessage.Severity;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.ResponseStream;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
+import javax.inject.Inject;
+import junit.framework.Assert;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.faces.producer.FacesContextProducer;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Verify that the FacesContextProducer produces the same FacesContext
+ * as returned by FacesContext#getCurrentInstance().
+ *
+ * @author Dan Allen
+ */
+(a)RunWith(Arquillian.class)
+public class FacesContextProducerTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive()
+ {
+ return Archives.create("test.jar", JavaArchive.class).addClass(FacesContextProducer.class).addManifestResource(new ByteArrayAsset(new byte[0]), ArchivePaths.create("beans.xml"));
+ }
+
+ @Inject Instance<FacesContext> facesContextInstance;
+
+ @Test
+ public void testReturnsCurrentFacesContext()
+ {
+ new MockFacesContext().set().setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
+ Assert.assertSame(new FacesContextProducer().getFacesContext(), FacesContext.getCurrentInstance());
+ }
+
+ @Test
+ public void testProducesContextualCurrentFacesContext()
+ {
+ new MockFacesContext().set().setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
+
+ FacesContext actualFacesContext = FacesContext.getCurrentInstance();
+ FacesContext producedFacesContext = facesContextInstance.get();
+
+ // not equal since the produced FacesContext is a proxy
+ Assert.assertFalse(actualFacesContext == producedFacesContext);
+ // verify we have same object through proxy by comparing hash codes
+ Assert.assertEquals(actualFacesContext.hashCode(), producedFacesContext.hashCode());
+ //Assert.assertEquals(actualFacesContext, producedFacesContext);
+ Assert.assertSame(producedFacesContext.getCurrentPhaseId(), PhaseId.RENDER_RESPONSE);
+ }
+
+ @Test(expected = ContextNotActiveException.class)
+ public void testProducerThrowsExceptionWhenFacesContextNotActive()
+ {
+ new MockFacesContext().release();
+ // NOTE the return value must be invoked to carry out the lookup
+ facesContextInstance.get().toString();
+ }
+
+ private class MockFacesContext extends FacesContext
+ {
+ private PhaseId currentPhaseId;
+
+ public FacesContext set()
+ {
+ setCurrentInstance(this);
+ return this;
+ }
+
+ @Override
+ public void release()
+ {
+ setCurrentInstance(null);
+ }
+
+ @Override
+ public PhaseId getCurrentPhaseId()
+ {
+ return currentPhaseId;
+ }
+
+ @Override
+ public void setCurrentPhaseId(PhaseId currentPhaseId)
+ {
+ this.currentPhaseId = currentPhaseId;
+ }
+
+ @Override
+ public Application getApplication()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public Iterator<String> getClientIdsWithMessages()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public ExternalContext getExternalContext()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public Severity getMaximumSeverity()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public Iterator<FacesMessage> getMessages()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public Iterator<FacesMessage> getMessages(String clientId)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public RenderKit getRenderKit()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public boolean getRenderResponse()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public boolean getResponseComplete()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public ResponseStream getResponseStream()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void setResponseStream(ResponseStream stream)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public ResponseWriter getResponseWriter()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void setResponseWriter(ResponseWriter writer)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public UIViewRoot getViewRoot()
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void setViewRoot(UIViewRoot uivr)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void addMessage(String clientId, FacesMessage message)
+ {
+ throw new UnsupportedOperationException("Not supported");
+ }
+
+ @Override
+ public void renderResponse()
+ {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+
+ @Override
+ public void responseComplete()
+ {
+ throw new UnsupportedOperationException("Not supported.");
+ }
+ }
+}
14 years, 2 months