@Test(expected = CitrusRuntimeException.class) public void shouldHandleUnsupportedTypeInformation() { Map<String, String> connectionSettings = new LinkedHashMap<>(); connectionSettings.put("type", "org.unknown.Type"); connectionFactoryCreator.create(connectionSettings); }
@Override public ConnectionFactory create(Map<String, String> properties) { String className = properties.remove("type"); Assert.notNull(className, "Missing connection factory type information"); try { Class<?> type = Class.forName(className); if (!(ConnectionFactory.class.isAssignableFrom(type))) { throw new IllegalStateException(String.format("Unsupported type information %s - must be of type %s", type.getName(), ConnectionFactory.class.getName())); } Collection<String> constructorArgs = properties.values(); Constructor<? extends ConnectionFactory> constructor = Arrays.stream(type.getConstructors()) .filter(c -> c.getParameterCount() == constructorArgs.size() && Arrays.stream(c.getParameterTypes()).allMatch(paramType -> paramType.equals(String.class))) .map(c -> (Constructor<? extends ConnectionFactory>) c) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find matching constructor on connection factory")); return constructor.newInstance(constructorArgs.toArray(new Object[0])); } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { throw new CitrusRuntimeException(e); } }
DefaultConnectionFactoryCreator implements ConnectionFactoryCreator { @Override public ConnectionFactory create(Map<String, String> properties) { String className = properties.remove("type"); Assert.notNull(className, "Missing connection factory type information"); try { Class<?> type = Class.forName(className); if (!(ConnectionFactory.class.isAssignableFrom(type))) { throw new IllegalStateException(String.format("Unsupported type information %s - must be of type %s", type.getName(), ConnectionFactory.class.getName())); } Collection<String> constructorArgs = properties.values(); Constructor<? extends ConnectionFactory> constructor = Arrays.stream(type.getConstructors()) .filter(c -> c.getParameterCount() == constructorArgs.size() && Arrays.stream(c.getParameterTypes()).allMatch(paramType -> paramType.equals(String.class))) .map(c -> (Constructor<? extends ConnectionFactory>) c) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find matching constructor on connection factory")); return constructor.newInstance(constructorArgs.toArray(new Object[0])); } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { throw new CitrusRuntimeException(e); } } }
DefaultConnectionFactoryCreator implements ConnectionFactoryCreator { @Override public ConnectionFactory create(Map<String, String> properties) { String className = properties.remove("type"); Assert.notNull(className, "Missing connection factory type information"); try { Class<?> type = Class.forName(className); if (!(ConnectionFactory.class.isAssignableFrom(type))) { throw new IllegalStateException(String.format("Unsupported type information %s - must be of type %s", type.getName(), ConnectionFactory.class.getName())); } Collection<String> constructorArgs = properties.values(); Constructor<? extends ConnectionFactory> constructor = Arrays.stream(type.getConstructors()) .filter(c -> c.getParameterCount() == constructorArgs.size() && Arrays.stream(c.getParameterTypes()).allMatch(paramType -> paramType.equals(String.class))) .map(c -> (Constructor<? extends ConnectionFactory>) c) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find matching constructor on connection factory")); return constructor.newInstance(constructorArgs.toArray(new Object[0])); } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { throw new CitrusRuntimeException(e); } }  }
DefaultConnectionFactoryCreator implements ConnectionFactoryCreator { @Override public ConnectionFactory create(Map<String, String> properties) { String className = properties.remove("type"); Assert.notNull(className, "Missing connection factory type information"); try { Class<?> type = Class.forName(className); if (!(ConnectionFactory.class.isAssignableFrom(type))) { throw new IllegalStateException(String.format("Unsupported type information %s - must be of type %s", type.getName(), ConnectionFactory.class.getName())); } Collection<String> constructorArgs = properties.values(); Constructor<? extends ConnectionFactory> constructor = Arrays.stream(type.getConstructors()) .filter(c -> c.getParameterCount() == constructorArgs.size() && Arrays.stream(c.getParameterTypes()).allMatch(paramType -> paramType.equals(String.class))) .map(c -> (Constructor<? extends ConnectionFactory>) c) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find matching constructor on connection factory")); return constructor.newInstance(constructorArgs.toArray(new Object[0])); } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { throw new CitrusRuntimeException(e); } }  @Override ConnectionFactory create(Map<String, String> properties); @Override boolean supports(Class<?> type); }
DefaultConnectionFactoryCreator implements ConnectionFactoryCreator { @Override public ConnectionFactory create(Map<String, String> properties) { String className = properties.remove("type"); Assert.notNull(className, "Missing connection factory type information"); try { Class<?> type = Class.forName(className); if (!(ConnectionFactory.class.isAssignableFrom(type))) { throw new IllegalStateException(String.format("Unsupported type information %s - must be of type %s", type.getName(), ConnectionFactory.class.getName())); } Collection<String> constructorArgs = properties.values(); Constructor<? extends ConnectionFactory> constructor = Arrays.stream(type.getConstructors()) .filter(c -> c.getParameterCount() == constructorArgs.size() && Arrays.stream(c.getParameterTypes()).allMatch(paramType -> paramType.equals(String.class))) .map(c -> (Constructor<? extends ConnectionFactory>) c) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find matching constructor on connection factory")); return constructor.newInstance(constructorArgs.toArray(new Object[0])); } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { throw new CitrusRuntimeException(e); } }  @Override ConnectionFactory create(Map<String, String> properties); @Override boolean supports(Class<?> type);  }