/** * Tests test() with configuration that should NOT be correct. Expects a RuntimeException to be * thrown. */ @Test public void testTestFail() { final String testPropertyName = "testsuite." + TEST_NAME + "." + PROPERTY_NAME_INVALID_CONFIG; // run test only in case operation is supported if (ConnectorHelper.operationsSupported(getConnectorFacade(), getAPIOperations())) { // READ THE TEST PROPERTY WITH WRONG CONFIGURATIONS THAT OVERRIDE THE DEFAULT CONFIGURATION Object o = null; try { o = getDataProvider().getTestSuiteAttribute(PROPERTY_NAME_INVALID_CONFIG, TEST_NAME); } catch (ObjectNotFoundException ex) { fail(String.format("Missing test property: '%s'", testPropertyName)); } if (!(o instanceof List<?>)) { fail(String.format("Test property '%s' should be of type List", testPropertyName)); } final List<?> wrongConfigList = (List<?>) o; for (Object currentWrongConfigMap : wrongConfigList) { if (!(currentWrongConfigMap instanceof Map<?, ?>)) { fail( String.format( "Test property '%s' contains other than Map properties.", testPropertyName)); } Map<?, ?> currentWrongMapConfig = (Map<?, ?>) currentWrongConfigMap; _connFacade = ConnectorHelper.createConnectorFacadeWithWrongConfiguration( getDataProvider(), currentWrongMapConfig); try { // should throw RuntimeException getConnectorFacade().test(); String msg = String.format( "test() should throw RuntimeException because configuration should be invalid. Wrong properties used: \n%s", currentWrongMapConfig.toString()); fail(msg); } catch (RuntimeException ex) { // expected } } } else { LOG.info("--------------------------------"); LOG.info("Skipping test ''testTestFail''."); LOG.info("--------------------------------"); } }
/** * Creates a new helper for a given client connector. * * @param client The client to help. * @param helperClass Optional helper class name. * @return The new helper. */ @SuppressWarnings("unchecked") public ConnectorHelper<Client> createHelper(Client client, String helperClass) { ConnectorHelper<Client> result = null; if (client.getProtocols().size() > 0) { ConnectorHelper<Client> connector = null; for (final Iterator<ConnectorHelper<Client>> iter = getRegisteredClients().iterator(); (result == null) && iter.hasNext(); ) { connector = iter.next(); if (connector.getProtocols().containsAll(client.getProtocols())) { if ((helperClass == null) || connector.getClass().getCanonicalName().equals(helperClass)) { try { result = connector.getClass().getConstructor(Client.class).newInstance(client); } catch (Exception e) { Context.getCurrentLogger() .log( Level.SEVERE, "Exception during the instantiation of the client connector.", e); } } } } if (result == null) { // Couldn't find a matching connector StringBuilder sb = new StringBuilder(); sb.append("No available client connector supports the required protocols: "); for (Protocol p : client.getProtocols()) { sb.append("'").append(p.getName()).append("' "); } sb.append(". Please add the JAR of a matching connector to your classpath."); if (Edition.CURRENT == Edition.ANDROID) { sb.append(" Then, register this connector helper manually."); } Context.getCurrentLogger().log(Level.WARNING, sb.toString()); } } return result; }