@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); } }
/** * <p class="changed_added_4_0"> * </p> * * @param <T> * @param className * @return * @throws TestException * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") private <T> T createInstance(String className) throws TestException, ClassNotFoundException { try { Class<?> clazz = FacesEnvironment.class.getClassLoader().loadClass(className); return (T) clazz.newInstance(); } catch (ClassNotFoundException e) { throw e; } catch (Exception e) { throw new TestException(e); } }
@Override public byte[] getResponseBody() { try { return httpClientMethod.getResponseBody(); } catch (IOException e) { throw new TestException(e); } }
/** * <p class="changed_added_4_0"> * </p> * * @param <T> * @param className * @return * @throws TestException * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") private <T> T createInstance(String className) throws TestException, ClassNotFoundException { try { Class<?> clazz = FacesEnvironment.class.getClassLoader().loadClass(className); return (T) clazz.newInstance(); } catch (ClassNotFoundException e) { throw e; } catch (Exception e) { throw new TestException(e); } }
/** * Add all files from the directory to the virtual web application content. * * @param path * name of the target directory in the virtual web application. If no such directory exists, it will be * created, as well as all parent directories as needed. * @param resource * {@code File} of the source directory or any file in the source directory. If this parameter points to * a file, it will be converted to a enclosing directory. */ public void addResourcesFromDirectory(String path, File directory) { if (!directory.exists()) { throw new TestException("directory does not exist:" + directory.getAbsolutePath()); } try { addFiles(path, directory); } catch (MalformedURLException e) { throw new TestException(e); } }
/** * Add all files from the directory to the virtual web application content. * * @param path * name of the target directory in the virtual web application. If no such directory exists, it will be * created, as well as all parent directories as needed. * @param resource * {@code File} of the source directory or any file in the source directory. If this parameter points to * a file, it will be converted to a enclosing directory. */ public void addResourcesFromDirectory(String path, File directory) { if (!directory.exists()) { throw new TestException("directory does not exist:" + directory.getAbsolutePath()); } try { addFiles(path, directory); } catch (MalformedURLException e) { throw new TestException(e); } }
public URL getURL() { if (url == null) { // JDK-5 singleton-like synchronization. // @see http://jeremymanson.blogspot.com/2008/05/double-checked-locking.html synchronized (this) { if(log.isLoggable(Level.FINEST)){ log.finest("get classpath resource from "+this.classpath); } ClassLoader classLoader = Thread.currentThread() .getContextClassLoader(); if (null == classLoader) { classLoader = this.getClass().getClassLoader(); } url = classLoader.getResource(classpath); if(null == url){ throw new TestException("Virtual server resource can't be loaded from "+classpath); } } } return url; }
/** * <p class="changed_added_4_0"></p> * @param applicationServerClassName * @return */ private static ApplicationServer createApplicationServer(String applicationServerClassName) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = ApplicationServer.class.getClassLoader(); } Class<?> applicationServer; try { applicationServer = Class.forName(applicationServerClassName, true, classLoader); Class<? extends ApplicationServer> applicationServerClass = applicationServer.asSubclass(ApplicationServer.class); return applicationServerClass.newInstance(); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); throw new TestException(e); } } }
public URL getURL() { if (url == null) { // JDK-5 singleton-like synchronization. // @see http://jeremymanson.blogspot.com/2008/05/double-checked-locking.html synchronized (this) { if(log.isLoggable(Level.FINEST)){ log.finest("get classpath resource from "+this.classpath); } ClassLoader classLoader = Thread.currentThread() .getContextClassLoader(); if (null == classLoader) { classLoader = this.getClass().getClassLoader(); } url = classLoader.getResource(classpath); if(null == url){ throw new TestException("Virtual server resource can't be loaded from "+classpath); } } } return url; }
/** * 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); }
/** * <p class="changed_added_4_0"></p> * @param applicationServerClassName * @return */ private static ApplicationServer createApplicationServer(String applicationServerClassName) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = ApplicationServer.class.getClassLoader(); } Class<?> applicationServer; try { applicationServer = Class.forName(applicationServerClassName, true, classLoader); Class<? extends ApplicationServer> applicationServerClass = applicationServer.asSubclass(ApplicationServer.class); return applicationServerClass.newInstance(); } catch (Exception e) { log.log(Level.SEVERE, e.getMessage(), e); throw new TestException(e); } } }