use of org.glassfish.hk2.api.ErrorService in project glassfish-hk2 by eclipse-ee4j.
the class NegativeConfigTest method testPerLookupDynamicConfigurationListener.
/**
* A dynamic configuration listener must be in Singleton scope
*/
@Test
public void testPerLookupDynamicConfigurationListener() {
ServiceLocator locator = LocatorHelper.create();
ServiceLocatorUtilities.addClasses(locator, DynamicConfigErrorService.class);
DynamicConfigErrorService errorService = locator.getService(DynamicConfigErrorService.class);
Assert.assertNull(errorService.getConfigException());
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration dc = dcs.createDynamicConfiguration();
dc.bind(BuilderHelper.link(BadDynamicConfigurationListener.class).to(DynamicConfigurationListener.class).build());
try {
dc.commit();
Assert.fail("Commit should have failed with PerLookup DynamicConfigurationListener");
} catch (MultiException me) {
Assert.assertTrue(me.getMessage(), me.getMessage().contains(" must be in the Singleton scope"));
Assert.assertEquals(errorService.getConfigException(), me);
}
}
use of org.glassfish.hk2.api.ErrorService in project glassfish-hk2 by eclipse-ee4j.
the class NegativeConfigTest method testPerLookupValidationService.
/**
* A validation service must be in Singleton scope
*/
@Test
public void testPerLookupValidationService() {
ServiceLocator locator = LocatorHelper.create();
ServiceLocatorUtilities.addClasses(locator, DynamicConfigErrorService.class);
DynamicConfigErrorService errorService = locator.getService(DynamicConfigErrorService.class);
Assert.assertNull(errorService.getConfigException());
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration dc = dcs.createDynamicConfiguration();
dc.bind(BuilderHelper.link(BadValidationService.class).to(ValidationService.class).in(PerLookup.class.getName()).build());
try {
dc.commit();
Assert.fail("Commit should have failed with PerLookup ValidationService");
} catch (MultiException me) {
Assert.assertTrue(me.getMessage(), me.getMessage().contains(" must be in the Singleton scope"));
Assert.assertEquals(errorService.getConfigException(), me);
}
}
use of org.glassfish.hk2.api.ErrorService in project glassfish-hk2 by eclipse-ee4j.
the class NegativeConfigTest method testPerLookupErrorService.
/**
* An error service must be in Singleton scope
*/
@Test
public void testPerLookupErrorService() {
ServiceLocator locator = LocatorHelper.create();
ServiceLocatorUtilities.addClasses(locator, DynamicConfigErrorService.class);
DynamicConfigErrorService errorService = locator.getService(DynamicConfigErrorService.class);
Assert.assertNull(errorService.getConfigException());
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration dc = dcs.createDynamicConfiguration();
dc.bind(BuilderHelper.link(BadErrorService.class).to(ErrorService.class).build());
try {
dc.commit();
Assert.fail("Commit should have failed with PerLookup ErrorService");
} catch (MultiException me) {
Assert.assertTrue(me.getMessage(), me.getMessage().contains(" must be in the Singleton scope"));
Assert.assertEquals(errorService.getConfigException(), me);
}
}
use of org.glassfish.hk2.api.ErrorService in project glassfish-hk2 by eclipse-ee4j.
the class NegativeConfigTest method testPerLookupInjectionResolver.
/**
* An injection resolver must be in Singleton scope
*/
@Test
public void testPerLookupInjectionResolver() {
ServiceLocator locator = LocatorHelper.create();
ServiceLocatorUtilities.addClasses(locator, DynamicConfigErrorService.class);
DynamicConfigErrorService errorService = locator.getService(DynamicConfigErrorService.class);
Assert.assertNull(errorService.getConfigException());
DynamicConfigurationService dcs = locator.getService(DynamicConfigurationService.class);
DynamicConfiguration dc = dcs.createDynamicConfiguration();
dc.bind(BuilderHelper.link(BadInjectionResolver.class).to(InjectionResolver.class).build());
try {
dc.commit();
Assert.fail("Commit should have failed with PerLookup InjectionResolver");
} catch (MultiException me) {
Assert.assertTrue(me.getMessage(), me.getMessage().contains(" must be in the Singleton scope"));
Assert.assertEquals(errorService.getConfigException(), me);
}
}
use of org.glassfish.hk2.api.ErrorService in project glassfish-hk2 by eclipse-ee4j.
the class Utilities method handleErrors.
/**
* Calls the list of error services for the list of errors
*
* @param results the results
* @param callThese the services to call
*/
public static void handleErrors(NarrowResults results, LinkedList<ErrorService> callThese) {
Collector collector = new Collector();
for (ErrorResults errorResult : results.getErrors()) {
for (ErrorService eService : callThese) {
try {
eService.onFailure(new ErrorInformationImpl(ErrorType.FAILURE_TO_REIFY, errorResult.getDescriptor(), errorResult.getInjectee(), errorResult.getMe()));
} catch (MultiException me) {
for (Throwable th : me.getErrors()) {
collector.addThrowable(th);
}
} catch (Throwable th) {
collector.addThrowable(th);
}
}
}
collector.throwIfErrors();
}
Aggregations