use of com.google.inject.ConfigurationException in project cucumber-jvm by cucumber.
the class GuiceFactoryTest method factoryStartFailsIfScenarioScopeIsNotBound.
@Test
void factoryStartFailsIfScenarioScopeIsNotBound() {
initFactory(Guice.createInjector());
Executable testMethod = () -> factory.start();
ConfigurationException actualThrown = assertThrows(ConfigurationException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), startsWith("Guice configuration errors:\n" + "\n" + "1) [Guice/MissingImplementation]: No implementation for ScenarioScope was bound."));
}
use of com.google.inject.ConfigurationException in project shiro by apache.
the class BeanTypeListener method hear.
public <I> void hear(TypeLiteral<I> type, final TypeEncounter<I> encounter) {
PropertyDescriptor[] propertyDescriptors = beanUtilsBean.getPropertyUtils().getPropertyDescriptors(type.getRawType());
final Map<PropertyDescriptor, Key<?>> propertyDependencies = new HashMap<PropertyDescriptor, Key<?>>(propertyDescriptors.length);
final Provider<Injector> injectorProvider = encounter.getProvider(Injector.class);
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
if (propertyDescriptor.getWriteMethod() != null && Modifier.isPublic(propertyDescriptor.getWriteMethod().getModifiers())) {
Type propertyType = propertyDescriptor.getWriteMethod().getGenericParameterTypes()[0];
propertyDependencies.put(propertyDescriptor, createDependencyKey(propertyDescriptor, propertyType));
}
}
encounter.register(new MembersInjector<I>() {
public void injectMembers(I instance) {
for (Map.Entry<PropertyDescriptor, Key<?>> dependency : propertyDependencies.entrySet()) {
try {
final Injector injector = injectorProvider.get();
Object value = injector.getInstance(getMappedKey(injector, dependency.getValue()));
dependency.getKey().getWriteMethod().invoke(instance, value);
} catch (ConfigurationException e) {
// This is ok, it simply means that we can't fulfill this dependency.
// Is there a better way to do this?
} catch (InvocationTargetException e) {
throw new RuntimeException("Couldn't set property " + dependency.getKey().getDisplayName(), e);
} catch (IllegalAccessException e) {
throw new RuntimeException("We shouldn't have ever reached this point, we don't try to inject to non-accessible methods.", e);
}
}
}
});
}
use of com.google.inject.ConfigurationException in project gora by apache.
the class ElasticsearchMappingBuilder method readMappingFile.
/**
* Reads Elasticsearch mappings from file.
*
* @param inputStream Mapping input stream
* @param xsdValidation Parameter for enabling XSD validation
*/
public void readMappingFile(InputStream inputStream, boolean xsdValidation) {
try {
SAXBuilder saxBuilder = new SAXBuilder();
if (inputStream == null) {
LOG.error("The mapping input stream is null!");
throw new GoraException("The mapping input stream is null!");
}
// Convert input stream to a string to use it a few times
String mappingStream = IOUtils.toString(inputStream, Charset.defaultCharset());
// XSD validation for XML file
if (xsdValidation) {
Source xmlSource = new StreamSource(IOUtils.toInputStream(mappingStream, Charset.defaultCharset()));
Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new StreamSource(getClass().getClassLoader().getResourceAsStream(XSD_MAPPING_FILE)));
schema.newValidator().validate(xmlSource);
LOG.info("Mapping file is valid.");
}
Document document = saxBuilder.build(IOUtils.toInputStream(mappingStream, Charset.defaultCharset()));
if (document == null) {
LOG.error("The mapping document is null!");
throw new GoraException("The mapping document is null!");
}
Element root = document.getRootElement();
// Extract class descriptions
@SuppressWarnings("unchecked") List<Element> classElements = root.getChildren(TAG_CLASS);
for (Element classElement : classElements) {
final Class<T> persistentClass = dataStore.getPersistentClass();
final Class<K> keyClass = dataStore.getKeyClass();
if (haveKeyClass(keyClass, classElement) && havePersistentClass(persistentClass, classElement)) {
loadPersistentClass(classElement, persistentClass);
break;
}
}
} catch (IOException | JDOMException | ConfigurationException | SAXException ex) {
throw new RuntimeException(ex);
}
LOG.info("Gora Elasticsearch mapping file was read successfully.");
}
use of com.google.inject.ConfigurationException in project gora by apache.
the class IgniteMappingBuilder method readMappingFile.
/**
* Reads Ignite mappings from file
*
* @param inputStream Input stream of the mapping
*/
public void readMappingFile(InputStream inputStream) {
try {
SAXBuilder saxBuilder = new SAXBuilder();
if (inputStream == null) {
LOG.error("The mapping input stream is null!");
throw new IOException("The mapping input stream is null!");
}
Document document = saxBuilder.build(inputStream);
if (document == null) {
LOG.error("The mapping document is null!");
throw new IOException("The mapping document is null!");
}
@SuppressWarnings("unchecked") List<Element> classes = document.getRootElement().getChildren("class");
for (Element classElement : classes) {
if (classElement.getAttributeValue("keyClass").equals(dataStore.getKeyClass().getCanonicalName()) && classElement.getAttributeValue("name").equals(dataStore.getPersistentClass().getCanonicalName())) {
final String tableNameFromMapping = classElement.getAttributeValue("table");
String tableName = dataStore.getSchemaName(tableNameFromMapping, dataStore.getPersistentClass());
igniteMapping.setTableName(tableName);
@SuppressWarnings("unchecked") List<Element> prColumns = classElement.getChildren("primarykey");
List<Column> prFields = new ArrayList<>();
for (Element aPrimaryKey : prColumns) {
String name = aPrimaryKey.getAttributeValue("column");
String type = aPrimaryKey.getAttributeValue("type");
prFields.add(new Column(name, Column.FieldType.valueOf(type)));
}
igniteMapping.setPrimaryKey(prFields);
@SuppressWarnings("unchecked") List<Element> fields = classElement.getChildren("field");
Map<String, Column> mp = new HashMap<>();
for (Element field : fields) {
String fieldName = field.getAttributeValue("name");
String columnName = field.getAttributeValue("column");
String columnType = field.getAttributeValue("type");
mp.put(fieldName, new Column(columnName, Column.FieldType.valueOf(columnType)));
}
igniteMapping.setFields(mp);
break;
}
}
} catch (IOException | JDOMException | ConfigurationException e) {
throw new RuntimeException(e);
}
LOG.info("Gora Ignite mapping file was read successfully.");
}
use of com.google.inject.ConfigurationException in project google-gin by gwtplus.
the class FactoryBindingTest method testDuplicateNamedAssistedAnnotations.
public void testDuplicateNamedAssistedAnnotations() {
try {
new FactoryBinding(Collections.<Key<?>, TypeLiteral<?>>emptyMap(), Key.get(TwoAssistedFooStringsFactory.class), CONTEXT, new GuiceUtil(createInjectableCollector()), null);
fail("Expected ConfigurationException.");
} catch (ConfigurationException e) {
assertTrue(e.getMessage().contains("has more than one parameter of type " + "java.lang.String annotated with @Assisted(\"foo\")."));
}
}
Aggregations