@Override public ServletContext getContext() { if (!initialised) { throw new TestException("Staging server have not been initialised"); } return contextProxy; }
private void checkNotInitialized() { if (initialized) { throw new TestException("JSF test environment has already been initialized"); } }
@Override public ServletContext getContext() { if (!initialised) { throw new TestException("Staging server have not been initialised"); } return contextProxy; }
private void checkInitialized() { if (!initialized) { throw new TestException("JSF test environment has not been initialized"); } }
private void checkNotInitialized() { if (initialized) { throw new TestException("JSF test environment has already been initialized"); } }
private void checkInitialized() { if (!initialized) { throw new TestException("JSF test environment has not been initialized"); } }
@Override public URL getURL() { //necessary to avoid NPE for temp directories try { return new URL("jetty_virtual_resource", null, -1, path, VirtualResourceURLStreamHandler.INSTANCE); } catch (MalformedURLException e) { throw new TestException(e.getMessage(), e); } }
@Override public String getContentAsString() { try { return httpClientMethod.getResponseBodyAsString(); } catch (IOException e) { throw new TestException(e); } }
public Resource getResource(Resource resource, ServerResourcePath path) { try { return resource.addPath(path.toString()); } catch (MalformedURLException e) { throw new TestException(e.getMessage(), e); } catch (IOException e) { throw new TestException(e.getMessage(), e); } }
@Override public byte[] getResponseBody() { try { return httpClientMethod.getResponseBody(); } catch (IOException e) { throw new TestException(e); } }
/** * Internal method used by the {@link #addResourcesFromDirectory(String, URL)} to process 'file' protocol. * * @param resource * source directory. * @param baseDirectory * target virtual directory. */ protected void addResourcesFromFile(String resourcePath, URL resource) { File file = new File(resource.getPath()); if (!file.isDirectory()) { file = file.getParentFile(); } try { addFiles(resourcePath, file); } catch (MalformedURLException e) { throw new TestException(e); } }
/** * Get virtual connection to the given URL. Even thought for an http request * to the external servers, only local connection to the virtual server will * be created. * * @param url * request url. * @return local connection to the appropriate servlet in the virtual * server. * @throws {@link TestException} if no servlet found to process given URL. */ @Override public StagingConnection getConnection(URL url) { if (!initialised) { throw new TestException("Staging server have not been initialised"); } return new StagingConnection(this, url); }
@Override public void addResource(String path, URL resource) { try { serverRoot.addResource(path, Resource.newResource(resource)); } catch (IOException e) { throw new TestException(e.getMessage(), e); } }
@Override public void execute() { if (isStarted() || isFinished()) { throw new TestException( "request have already been executed"); } start(); try { this.servlet.execute(request, response); } catch (ServletException e) { throw new TestException("Error execute request ",e); } catch (IOException e) { throw new TestException("IO Error during request execution",e); } finally { finish(); } }
@Override public void execute() { if (isStarted() || isFinished()) { throw new TestException( "request have already been executed"); } start(); try { this.servlet.execute(request, response); } catch (ServletException e) { throw new TestException("Error execute request ",e); } catch (IOException e) { throw new TestException("IO Error during request execution",e); } finally { finish(); } }
@Override public void destroy() { try { server.stop(); server.setStopAtShutdown(false); server.destroy(); } catch (Exception e) { throw new TestException(e.getMessage(), e); } finally { session = null; server = null; } }
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 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 FacesEnvironment withSeam() { checkNotInitialized(); try { Filter ajaxFilter = createInstance("org.jboss.seam.servlet.SeamFilter"); withFilter("ajax4jsf", ajaxFilter); EventListener seamListener = createInstance("org.jboss.seam.servlet.SeamListener"); facesServer.addWebListener(seamListener); webXmlDefault = "org/jboss/test/faces/ajax-web.xml"; return this; } catch (ClassNotFoundException e) { throw new TestException(e); } }
public FacesEnvironment withSeam() { checkNotInitialized(); try { Filter ajaxFilter = createInstance("org.jboss.seam.servlet.SeamFilter"); withFilter("ajax4jsf", ajaxFilter); EventListener seamListener = createInstance("org.jboss.seam.servlet.SeamListener"); facesServer.addWebListener(seamListener); webXmlDefault = "org/jboss/test/faces/ajax-web.xml"; return this; } catch (ClassNotFoundException e) { throw new TestException(e); } }