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;
}
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
}
}
}
}
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);
}
}
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);
}
}
}
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;
}
Aggregations