public static FacesEnvironment createEnvironment() { return new FacesEnvironment(); }
public FacesEnvironment withRichFaces() { checkNotInitialized(); try { Filter ajaxFilter = createInstance("org.ajax4jsf.Filter"); withFilter("ajax4jsf", ajaxFilter); webXmlDefault = "org/jboss/test/faces/ajax-web.xml"; return this; } catch (ClassNotFoundException e) { throw new TestException(e); } }
public FacesRequest createFacesRequest(String url) throws MalformedURLException, FacesException { return environment.createFacesRequest(url); }
/** * <p class="changed_added_4_0"> * </p> * * @param root * @return */ public FacesEnvironment withWebRoot(String root) { checkNotInitialized(); return withWebRoot(FacesEnvironment.class.getClassLoader().getResource(root)); }
/** * This hook method called from the {@link #setUp()} should append JSF implementation listener to the test server. * Default version applends "com.sun.faces.config.ConfigureListener" or * "org.apache.myfaces.webapp.StartupServletContextListener" for the existed SUN RI or MyFaces implementation. This * metod also calls appropriate {@link #setupSunFaces()} or {@link #setupMyFaces()} methods. */ protected void setupFacesListener() { EventListener listener = null; try { // Check Sun RI configuration listener class. listener = createInstance("com.sun.faces.config.ConfigureListener"); setupSunFaces(); } catch (ClassNotFoundException e) { // No JSF RI listener, check MyFaces. try { listener = createInstance("org.apache.myfaces.webapp.StartupServletContextListener"); setupMyFaces(); } catch (ClassNotFoundException e1) { throw new TestException("No JSF listeners have been found", e1); } } facesServer.addWebListener(listener); }
public ApplicationServer getServer() { return environment.getServer(); }
public FacesEnvironment withWebRoot(File root) { checkNotInitialized(); webRoot = root; return this; }
public FacesRequest submit() throws MalformedURLException, FacesException { if (!connection.isFinished()) { throw new IllegalStateException(); } // Extract VIEW_STATE value. Map<String, String> fields = getHiddenFields(connection.getContentAsString()); if (!fields.containsKey(ResponseStateManager.VIEW_STATE_PARAM)) { throw new FacesException("No view state field in response"); } FacesRequest facesRequest = createFacesRequest(connection.getRequest().getRequestURL().toString()) .withViewId(viewId); facesRequest.connection.setRequestMethod(HttpMethod.POST); for (Map.Entry<String, String> entry : fields.entrySet()) { facesRequest.withParameter(entry.getKey(), entry.getValue()); } return facesRequest; }
public Application getApplication() { return environment.getApplication(); }
public Lifecycle getLifecycle() { return environment.getLifecycle(); }
/** * JSF and Virtual server instance cleanup. * * @throws java.lang.Exception */ public void release() { checkInitialized(); for (FacesRequest request : this.requests) { request.release(); } facesServer.destroy(); Thread.currentThread().setContextClassLoader(contextClassLoader); facesServer = null; application = null; lifecycle = null; initialized = false; }
public static Map<String, String> getHiddenFields(String content){ Collection<String> inputFields = getInputFields(content); HashMap<String, String> parameters = new HashMap<String, String>(inputFields.size()); for (String string : inputFields) { if(string.contains("type='hidden'")||string.contains("type=\"hidden\"")){ Matcher matcher = NAME_PATTERN.matcher(string); if(matcher.find()){ String name = matcher.group(1); Matcher valueMatcher = VALUE_PATTERN.matcher(string); if(valueMatcher.find()){ parameters.put(name, valueMatcher.group(1)); } else { parameters.put(name, ""); } } } } return parameters; }
/** * This hook method called from the {@link #setUp()} should append JSF implementation listener to the test server. * Default version applends "com.sun.faces.config.ConfigureListener" or * "org.apache.myfaces.webapp.StartupServletContextListener" for the existed SUN RI or MyFaces implementation. This * metod also calls appropriate {@link #setupSunFaces()} or {@link #setupMyFaces()} methods. */ protected void setupFacesListener() { EventListener listener = null; try { // Check Sun RI configuration listener class. listener = createInstance("com.sun.faces.config.ConfigureListener"); setupSunFaces(); } catch (ClassNotFoundException e) { // No JSF RI listener, check MyFaces. try { listener = createInstance("org.apache.myfaces.webapp.StartupServletContextListener"); setupMyFaces(); } catch (ClassNotFoundException e1) { throw new TestException("No JSF listeners have been found", e1); } } facesServer.addWebListener(listener); }
public ApplicationServer getServer() { return environment.getServer(); }
public FacesEnvironment withWebRoot(File root) { checkNotInitialized(); webRoot = root; return this; }
/** * <p class="changed_added_4_0"> * </p> * * @param root * @return */ public FacesEnvironment withWebRoot(String root) { checkNotInitialized(); return withWebRoot(FacesEnvironment.class.getClassLoader().getResource(root)); }
public FacesRequest submit() throws MalformedURLException, FacesException { if (!connection.isFinished()) { throw new IllegalStateException(); } // Extract VIEW_STATE value. Map<String, String> fields = getHiddenFields(connection.getContentAsString()); if (!fields.containsKey(ResponseStateManager.VIEW_STATE_PARAM)) { throw new FacesException("No view state field in response"); } FacesRequest facesRequest = createFacesRequest(connection.getRequest().getRequestURL().toString()) .withViewId(viewId); facesRequest.connection.setRequestMethod(HttpMethod.POST); for (Map.Entry<String, String> entry : fields.entrySet()) { facesRequest.withParameter(entry.getKey(), entry.getValue()); } return facesRequest; }
public Application getApplication() { return environment.getApplication(); }
public Lifecycle getLifecycle() { return environment.getLifecycle(); }
/** * JSF and Virtual server instance cleanup. * * @throws java.lang.Exception */ public void release() { checkInitialized(); for (FacesRequest request : this.requests) { request.release(); } facesServer.destroy(); Thread.currentThread().setContextClassLoader(contextClassLoader); facesServer = null; application = null; lifecycle = null; initialized = false; }