Search in sources :

Example 6 with GwtTestConfigurationException

use of com.googlecode.gwt.test.exceptions.GwtTestConfigurationException in project gwt-test-utils by gwt-test-utils.

the class WebXmlRemoteServiceCreateHandler method findService.

/*
     * (non-Javadoc)
     *
     * @see com.googlecode.gwt.test.server.RemoteServiceCreateHandler#findService(java .lang .Class,
     * java.lang.String)
     */
@Override
protected Object findService(Class<?> remoteServiceClass, String remoteServiceRelativePath) {
    String servletPath = "/" + GWT.getModuleName() + "/" + remoteServiceRelativePath;
    Object serviceImpl = servicesImplMap.get(servletPath);
    if (serviceImpl != null) {
        return serviceImpl;
    }
    String className = WebXmlUtils.get().getServletClass(servletPath);
    if (className == null) {
        return null;
    }
    try {
        serviceImpl = GwtReflectionUtils.instantiateClass(GwtReflectionUtils.getClass(className.trim()));
    } catch (ClassNotFoundException e) {
        // should not happen..
        throw new GwtTestConfigurationException(e);
    }
    // cache the implementation
    servicesImplMap.put(servletPath, serviceImpl);
    return serviceImpl;
}
Also used : GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)

Example 7 with GwtTestConfigurationException

use of com.googlecode.gwt.test.exceptions.GwtTestConfigurationException in project gwt-test-utils by gwt-test-utils.

the class DocumentPatcher method getHostPageHTML.

private static String getHostPageHTML(String hostPagePath) {
    // try classpath relative path
    InputStream is = JavaScriptObjects.class.getClassLoader().getResourceAsStream(hostPagePath);
    if (is == null) {
        try {
            // try project relative or absolute path
            is = new FileInputStream(hostPagePath);
        } catch (FileNotFoundException e) {
        // handle just after
        }
    }
    if (is == null) {
        LOGGER.warn("Cannot find the host HTML file '" + hostPagePath + "', fallback to an empty HTML document instead. You may want to override " + GwtConfig.get().getModuleRunner().getClass().getSimpleName() + ".getHostPagePath(String moduleFullQualifiedName) method to specify the relative path of the your HTML file from the root directory of your java project");
        return EMPTY_HTML;
    }
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
        return sb.toString();
    } catch (IOException e) {
        throw new GwtTestConfigurationException("Error while reading module HTML host page '" + hostPagePath + "'", e);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
            // don't care
            }
        }
    }
}
Also used : JavaScriptObjects(com.googlecode.gwt.test.utils.JavaScriptObjects) GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)

Example 8 with GwtTestConfigurationException

use of com.googlecode.gwt.test.exceptions.GwtTestConfigurationException in project gwt-test-utils by gwt-test-utils.

the class XmlUtils method newXMLReader.

public static XMLReader newXMLReader() {
    try {
        XMLReader saxReader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
        saxReader.setFeature("http://xml.org/sax/features/validation", false);
        saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        saxReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        return saxReader;
    } catch (Exception e) {
        // should never happen..
        throw new GwtTestConfigurationException("Error while creating a XMLReader", e);
    }
}
Also used : GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException) XMLReader(org.xml.sax.XMLReader) GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)

Example 9 with GwtTestConfigurationException

use of com.googlecode.gwt.test.exceptions.GwtTestConfigurationException in project gwt-test-utils by gwt-test-utils.

the class TestRemoteServiceCreateHandler method instanciateRemoteServiceInstance.

@SuppressWarnings("unchecked")
private <T> T instanciateRemoteServiceInstance(Class<T> remoteServiceClass, String remoteServiceRelativePath) {
    String moduleName = GwtConfig.get().getTestedModuleName();
    Class<?> remoteServiceImplClass = ModuleData.get(moduleName).getRemoteServiceImplClass(remoteServiceRelativePath);
    if (remoteServiceImplClass == null) {
        return null;
    } else if (!remoteServiceClass.isAssignableFrom(remoteServiceImplClass)) {
        throw new GwtTestConfigurationException("The servlet class '" + remoteServiceImplClass.getName() + "' setup for path '" + remoteServiceRelativePath + "' does not implement RemoteService interface '" + remoteServiceClass.getName());
    } else {
        try {
            return (T) GwtReflectionUtils.instantiateClass(remoteServiceImplClass);
        } catch (Exception e) {
            throw new GwtTestConfigurationException("Error during the instanciation of " + RemoteService.class.getSimpleName() + " implementation for servlet path '" + remoteServiceRelativePath + "'", e);
        }
    }
}
Also used : RemoteService(com.google.gwt.user.client.rpc.RemoteService) GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException) GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)

Example 10 with GwtTestConfigurationException

use of com.googlecode.gwt.test.exceptions.GwtTestConfigurationException in project gwt-test-utils by gwt-test-utils.

the class GwtConfig method setupGwtModule.

public void setupGwtModule(Class<?> testClass) {
    GwtModule gwtModule = testClass.getAnnotation(GwtModule.class);
    if (gwtModule == null) {
        throw new GwtTestConfigurationException("The test class " + testClass.getName() + " must be annotated with @" + GwtModule.class.getSimpleName() + " to specify the fully qualified name of the GWT module to test");
    }
    String moduleName = gwtModule.value();
    if (moduleName == null || "".equals(moduleName.trim())) {
        throw new GwtTestConfigurationException("Incorrect value for @" + GwtModule.class.getSimpleName() + " on " + testClass.getName() + ": " + moduleName);
    }
    if (!GwtFactory.get().getConfigurationLoader().getGwtModules().contains(moduleName)) {
        throw new GwtTestConfigurationException("The tested @GwtModule '" + moduleName + "' configured in " + testClass.getName() + " has not been found. Did you forget to declare a 'gwt-module' property in your 'META-INF/gwt-test-utils.properties' configuration file ?");
    }
    this.testedModuleName = moduleName;
}
Also used : GwtModule(com.googlecode.gwt.test.GwtModule) GwtTestConfigurationException(com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)

Aggregations

GwtTestConfigurationException (com.googlecode.gwt.test.exceptions.GwtTestConfigurationException)11 UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)1 RemoteService (com.google.gwt.user.client.rpc.RemoteService)1 GwtModule (com.googlecode.gwt.test.GwtModule)1 GwtTestException (com.googlecode.gwt.test.exceptions.GwtTestException)1 JavaScriptObjects (com.googlecode.gwt.test.utils.JavaScriptObjects)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 XPath (javax.xml.xpath.XPath)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 Document (org.w3c.dom.Document)1 XMLReader (org.xml.sax.XMLReader)1