use of com.sun.faces.mock.MockFacesContext in project mojarra by eclipse-ee4j.
the class JUnitFacesTestCaseBase method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Set up Servlet API Objects
servletContext = new MockServletContext();
servletContext.addInitParameter("appParamName", "appParamValue");
servletContext.setAttribute("appScopeName", "appScopeValue");
config = new MockServletConfig(servletContext);
session = new MockHttpSession();
session.setAttribute("sesScopeName", "sesScopeValue");
request = new MockHttpServletRequest(session);
request.setAttribute("reqScopeName", "reqScopeValue");
response = new MockHttpServletResponse();
// Set up Faces API Objects
FactoryFinder.releaseFactories();
Method reInitializeFactoryManager = FactoryFinder.class.getDeclaredMethod("reInitializeFactoryManager", (Class<?>[]) null);
reInitializeFactoryManager.setAccessible(true);
reInitializeFactoryManager.invoke(null, (Object[]) null);
// Create something to stand-in as the InitFacesContext
new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle());
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, "com.sun.faces.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY, "com.sun.faces.mock.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, "com.sun.faces.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY, "com.sun.faces.mock.MockRenderKitFactory");
FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
lifecycle = (MockLifecycle) lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext = (MockFacesContext) fcFactory.getFacesContext(servletContext, request, response, lifecycle);
externalContext = (MockExternalContext) facesContext.getExternalContext();
Map map = new HashMap();
externalContext.setRequestParameterMap(map);
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
use of com.sun.faces.mock.MockFacesContext in project mojarra by eclipse-ee4j.
the class UIComponentBaseAttachedStateTestCase method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
component = new UIOutput();
facesContext = new MockFacesContext();
servletContext = new MockServletContext();
servletContext.addInitParameter("appParamName", "appParamValue");
servletContext.setAttribute("appScopeName", "appScopeValue");
request = new MockHttpServletRequest(null);
request.setAttribute("reqScopeName", "reqScopeValue");
response = new MockHttpServletResponse();
// Create something to stand-in as the InitFacesContext
new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle());
}
use of com.sun.faces.mock.MockFacesContext in project mojarra by eclipse-ee4j.
the class UIOutputAttachedObjectStateTestCase method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
facesContext = new MockFacesContext();
facesContext = new MockFacesContext();
servletContext = new MockServletContext();
servletContext.addInitParameter("appParamName", "appParamValue");
servletContext.setAttribute("appScopeName", "appScopeValue");
request = new MockHttpServletRequest(null);
request.setAttribute("reqScopeName", "reqScopeValue");
response = new MockHttpServletResponse();
// Create something to stand-in as the InitFacesContext
new MockFacesContext(new MockExternalContext(servletContext, request, response), new MockLifecycle());
}
use of com.sun.faces.mock.MockFacesContext in project newrelic-java-agent by newrelic.
the class JSFTest method testPhase.
@Test
public void testPhase() {
final List<Tracer> tracers = new ArrayList<>();
final MockFacesContext mockFacesContext = new MockFacesContext();
final Phase phase = new Phase() {
@Override
public void execute(FacesContext arg0) throws FacesException {
Tracer lastTracer = Transaction.getTransaction().getTransactionActivity().getLastTracer();
tracers.add(lastTracer);
}
@Override
protected void handleAfterPhase(FacesContext arg0, ListIterator<PhaseListener> arg1, PhaseEvent arg2) {
}
@Override
protected void handleBeforePhase(FacesContext arg0, ListIterator<PhaseListener> arg1, PhaseEvent arg2) {
}
@Override
protected void queueException(FacesContext ctx, Throwable t, String booleanKey) {
super.queueException(ctx, t, booleanKey);
}
@Override
protected void queueException(FacesContext ctx, Throwable t) {
super.queueException(ctx, t);
}
@Override
public PhaseId getId() {
return PhaseId.ANY_PHASE;
}
};
new Runnable() {
@Override
@Trace(dispatcher = true)
public void run() {
phase.doPhase(mockFacesContext, new MockLifecycle(), new ArrayList<PhaseListener>().listIterator());
}
}.run();
Assert.assertEquals(1, tracers.size());
Tracer tracer = tracers.get(0);
ClassMethodSignature sig = new ClassMethodSignature(phase.getClass().getName(), "doPhase", "(Ljavax/faces/context/FacesContext;Ljavax/faces/lifecycle/Lifecycle;Ljava/util/ListIterator;)V");
Assert.assertEquals(ClassMethodMetricNameFormat.getMetricName(sig, phase, MetricNames.CUSTOM), tracer.getMetricName());
}
use of com.sun.faces.mock.MockFacesContext in project mojarra by eclipse-ee4j.
the class FacesLoggerTest method unresolvedNavigationGermany.
@Test
public void unresolvedNavigationGermany() {
MockFacesContext facesContext = new MockFacesContext();
facesContext.setApplication(new MockApplication());
facesContext.setELContext(EasyMock.createMock(ELContext.class));
UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null);
root.setLocale(Locale.GERMANY);
facesContext.setViewRoot(root);
final Object[] params = { "componentId1", "outcome.xhtml", "viewId.xhtml" };
Locale.setDefault(new Locale("de", "DE"));
final String result = FacesLogger.RENDERKIT.interpolateMessage(facesContext, "faces.outcometarget.navigation.case.not.resolved", params);
Assert.assertEquals("JSF1090: Navigations-Fall wurde für Komponente componentId1 nicht aufgelöst.", result);
}
Aggregations