Search in sources :

Example 1 with ErrorService

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);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) MultiException(org.glassfish.hk2.api.MultiException) Test(org.junit.Test)

Example 2 with ErrorService

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);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) PerLookup(org.glassfish.hk2.api.PerLookup) ValidationService(org.glassfish.hk2.api.ValidationService) MultiException(org.glassfish.hk2.api.MultiException) Test(org.junit.Test)

Example 3 with ErrorService

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);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) MultiException(org.glassfish.hk2.api.MultiException) Test(org.junit.Test)

Example 4 with ErrorService

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);
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) MultiException(org.glassfish.hk2.api.MultiException) Test(org.junit.Test)

Example 5 with ErrorService

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();
}
Also used : ErrorService(org.glassfish.hk2.api.ErrorService) MultiException(org.glassfish.hk2.api.MultiException)

Aggregations

MultiException (org.glassfish.hk2.api.MultiException)8 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)5 DynamicConfigurationService (org.glassfish.hk2.api.DynamicConfigurationService)5 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)5 Test (org.junit.Test)5 ErrorService (org.glassfish.hk2.api.ErrorService)4 RethrowErrorService (org.glassfish.hk2.utilities.RethrowErrorService)3 LinkedList (java.util.LinkedList)2 Filter (org.glassfish.hk2.api.Filter)2 IndexedFilter (org.glassfish.hk2.api.IndexedFilter)2 PerLookup (org.glassfish.hk2.api.PerLookup)2 CacheKeyFilter (org.glassfish.hk2.utilities.cache.CacheKeyFilter)2 Annotation (java.lang.annotation.Annotation)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Context (org.glassfish.hk2.api.Context)1 Injectee (org.glassfish.hk2.api.Injectee)1 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)1 TwoPhaseResource (org.glassfish.hk2.api.TwoPhaseResource)1 ValidationService (org.glassfish.hk2.api.ValidationService)1