private URL getRemoteWebDriverURL(String url) { try { return new URL(url); } catch (MalformedURLException e) { throw new ChorusException("Invalid URL for Selenium RemoteWebDriver [" + url + "]", e); } }
private Tuple2<Connection, SqlConfig> getConnectionDetails(String configName) { Tuple2<Connection, SqlConfig> connectionDetails = configNameToConnectionDetails.get(configName); if ( connectionDetails == null) { throw new ChorusException("Could not find a database connection for database " + configName); } return connectionDetails; }
protected boolean parseBooleanProperty(String value, String propertyKey) { try { return Boolean.parseBoolean(value); } catch (Exception e) { throw new ChorusException("Failed to parse property " + propertyKey + " with value '" + value + "' as boolean"); } }
@Override protected void validate() throws Exception { if ( ! alignedClients.contains(clientName)) { boolean connected = connectedClients.contains(clientName); String message = connected ? "connect" : "finish publishing steps (send steps aligned)"; throw new ChorusException("Client " + clientName + " did not " + message); } } };
private void checkValidHandlerType(Object handler) { Class<?> handlerClass = handler.getClass(); if (handlerClass.getAnnotation(Handler.class) != null) { return; } if (handler instanceof StepInvokerProvider) { return; } throw new ChorusException(String.format("Cannot export object of type (%s) it does not declare the @Handler annotation or implement type (StepInvokerProvider)", handlerClass.getName())); }
/** * Add a step to be published */ private void addStepInvoker(StepInvoker stepInvoker) { if ( connected.get() ) { throw new ChorusException("You cannot add more steps once the WebSocketStepPublisher is connected"); } stepInvokers.put(stepInvoker.getId(), stepInvoker); }
private void checkConnection(String processNameList, Function<String, Boolean> checkToPerform) throws ClientConnectionException { List<String> componentNames = HandlerPatterns.getNames(processNameList); componentNames.forEach(componentName -> { boolean success = checkToPerform.apply(componentName); if ( ! success) { throw new ChorusException("Client " + componentName + " is not connected"); } }); }
private static String[] findClassNames(ChorusLog log) { String[] classNames; try { long startTime = System.currentTimeMillis(); classNames = getClasspathClassNames(); long timeTaken = System.currentTimeMillis() - startTime; log.trace("ClasspathScanner class scanning took " + timeTaken + " millis and found " + classNames.length + " class names"); } catch (Throwable t) { throw new ChorusException("Failed during classpath scanning", t); } return classNames; }
public synchronized void waitForProcessToTerminate(String processName) { NamedProcess p = processes.get(processName); if ( p == null ) { throw new ChorusException("There is no process named '" + processName + "' to wait to terminate"); } int waitTime = p.getTerminateWaitTime(); waitForProcessToTerminate(processName, waitTime); }
public JmxStepResult(Map chorusContext, Object result) { put(CHORUS_CONTEXT_FIELD, chorusContext); put(STEP_RESULT_FIELD, result); if ( result != null && ! (result instanceof Serializable)) { throw new ChorusException( "The returned type of a remotely called step implementation must be Serializable, " + "class type was " + result.getClass() ); } }
@Step(".*execute the script (.*) in the " + HandlerPatterns.namePattern + " browser") public void executeScriptInNamedBrowser(String scriptPath, String configName) { Object o = seleniumManager.executeScriptFile(configName, scriptPath); if ( o instanceof Boolean && !((Boolean)o)) { throw new ChorusException("Execution of script failed (script returned false)"); } }
public synchronized void checkProcessIsRunning(String processName) { NamedProcess p = processes.get(processName); if ( p == null ) { throw new ChorusException("There is no process named '" + processName + "' to check is running"); } ChorusAssert.assertTrue("Check the process " + processName + " is running", ! p.getProcess().isStopped()); }
public synchronized void checkProcessHasStopped(String processName) { NamedProcess p = processes.get(processName); if ( p == null ) { throw new ChorusException("There is no process named '" + processName + "' to check is stopped"); } ChorusAssert.assertTrue("The process " + processName + " was not stopped", p.getProcess().isStopped()); }
@Override public void sendMessage(String clientId, AbstractTypedMessage message) { WebSocket webSocket = clientIdToSocket.get(clientId); if ( webSocket == null) { throw new ChorusException("Cannot send a message to client " + clientId + " no websocket connection"); } String messageAsString = JsonUtils.prettyFormat(message); if ( log.isDebugEnabled()) { log.debug(String.format("Sending message to web socket client %s [%s]", clientId, messageAsString)); } webSocket.send(messageAsString); }
@Step(value = ".* call a step with a step retry and the step is polled until it passes", retryDuration = 1, retryIntervalMillis = 100) public int stepWhichFailsAtFirst() throws InterruptedException { tryCount ++; if ( tryCount < 10) { throw new ChorusException("Simulate Failure"); } return tryCount; }
private ProcessConfig buildProcessesConfig(String configName, Properties processProperties) { ProcessConfig config; try { config = new ConfigBuilder().buildConfig(ProcessConfig.class, processProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
private SqlConfig getSqlConfig(String configName, Properties processProperties) { SqlConfigBean config; try { config = new ConfigBuilder().buildConfig(SqlConfigBean.class, processProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
private WebSocketsConfig getWebSocketsConfig(String configName, Properties webSocketsProperties) { WebSocketsConfigBean config; try { config = new ConfigBuilder().buildConfig(WebSocketsConfigBean.class, webSocketsProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
private SeleniumConfig getSeleniumConfig(String configName, Properties remotingProperties) { SeleniumConfigBean config; try { config = new ConfigBuilder().buildConfig(SeleniumConfigBean.class, remotingProperties); } catch (ConfigBuilderException e) { throw new ChorusException(String.format("Invalid config '%s'. %s", configName, e.getMessage())); } config.setConfigName(configName); return config; }
@Step(".*the value of the injected (.*) is '(.*)'") public void checkInjectedValue(String type, String value) { if ("Integer".equalsIgnoreCase(type)) { assertEquals(Integer.parseInt(value), injectedInteger.intValue()); } else if ("String".equalsIgnoreCase(type)) { assertEquals(value, injectedString); } else { throw new ChorusException("Did not recognise value for type parameter: " + type); } }