Java Code Examples for org.jboss.forge.furnace.addons.AddonRegistry#getServices()

The following examples show how to use org.jboss.forge.furnace.addons.AddonRegistry#getServices() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyMethodHandlerDispatchTest.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@Ignore
public void testProxyCallsDelegateAppropriately() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();

   Imported<ConcreteC> imported = registry.getServices(ConcreteC.class);
   ConcreteC c = imported.get();
   Assert.assertNotNull(c);

   String payload = "PAYLOAD";
   c.setPayload(payload);

   Assert.assertEquals(payload, c.getPayload());
   Assert.assertEquals(payload.toString(), c.toString());
}
 
Example 2
Source File: CommandsResource.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected ResourceFactory getResourceFactory() {
    AddonRegistry addonRegistry = furnace.getAddonRegistry();
    Imported<ResourceFactory> resourceFactoryImport = addonRegistry.getServices(ResourceFactory.class);
    ResourceFactory resourceFactory = null;
    try {
        resourceFactory = resourceFactoryImport.get();
    } catch (Exception e) {
        LOG.warn("Failed to get ResourceFactory injected: " + e, e);
    }
    if (resourceFactory == null) {
        // lets try one more time - might work this time?
        resourceFactory = resourceFactoryImport.get();
    }
    return resourceFactory;
}
 
Example 3
Source File: CommandsResource.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
public ConverterFactory getConverterFactory() {
    if (converterFactory == null) {
        AddonRegistry addonRegistry = furnace.getAddonRegistry();
        Imported<ConverterFactory> converterFactoryImport = addonRegistry.getServices(ConverterFactory.class);
        converterFactory = converterFactoryImport.get();
    }
    return converterFactory;
}
 
Example 4
Source File: ClassLoaderAdapterWhitelistLoaderLookupTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testWhitelistLookupConvertsClassTypes() throws Exception
{
   ClassLoader thisLoader = ClassLoaderAdapterWhitelistLoaderLookupTest.class.getClassLoader();

   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();

   ClassLoader loader1 = registry.getAddon(AddonId.from("dep1", "1")).getClassLoader();
   ClassLoader loader2 = registry.getAddon(AddonId.from("dep2", "1")).getClassLoader();
   ClassLoader loader3 = registry.getAddon(AddonId.from("dep3", "1")).getClassLoader();

   AddonRegistry enhancedRegistry = ClassLoaderAdapterBuilder.callingLoader(thisLoader)
            .delegateLoader(loader2)
            .whitelist(new HashSet<>(Arrays.asList(loader1, loader3))).enhance(registry);

   Assert.assertNotSame(MockContextConsumer.class, registry.getServices(MockContextConsumer.class.getName()).get()
            .getClass());

   Imported<MockContextConsumer> importedByName = enhancedRegistry.getServices(MockContextConsumer.class.getName());
   Assert.assertFalse(importedByName.isUnsatisfied());
   MockContextConsumer consumerByName = importedByName.get();
   Assert.assertSame(MockContextConsumer.class, consumerByName.getClass().getSuperclass());

   Imported<MockContextConsumer> importedByClass = enhancedRegistry.getServices(MockContextConsumer.class);
   Assert.assertFalse(importedByClass.isUnsatisfied());
   MockContextConsumer consumerByClass = importedByClass.get();
   Assert.assertNotSame(MockContextConsumer.class, consumerByClass.getClass());
}
 
Example 5
Source File: ImportedLookupTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test(expected = ContainerException.class)
public void testDoesNotResolveNonService() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();

   Imported<MockServiceConsumer> importedByName = registry.getServices(MockServiceConsumer.class.getName());
   Assert.assertTrue(importedByName.isUnsatisfied());
   importedByName.get();
}
 
Example 6
Source File: ServiceLookupTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void shouldResolveImpls() throws Exception
{
   AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader())
            .getAddonRegistry();
   Imported<MockInterface> imported = registry.getServices(MockInterface.class);
   Assert.assertTrue(imported.isAmbiguous());
   Assert.assertEquals(3, Iterators.asList(imported).size());
   Assert.assertThat(registry.getExportedTypes(MockInterface.class).size(), equalTo(3));
   Assert.assertThat(imported, CoreMatchers.<MockInterface> hasItems(
            instanceOf(MockImpl1.class),
            instanceOf(MockImpl2.class),
            instanceOf(SubMockImpl1.class)));
}
 
Example 7
Source File: ImportedTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIsAmbiguous() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   AddonRegistry registry = furnace.getAddonRegistry();
   Imported<MockInterface> services = registry.getServices(MockInterface.class);
   Assert.assertFalse(services.isUnsatisfied());
   Assert.assertTrue(services.isAmbiguous());
}
 
Example 8
Source File: ImportedTest.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testIsAmbiguousUsingClassName() throws Exception
{
   Furnace furnace = LocalServices.getFurnace(getClass().getClassLoader());
   AddonRegistry registry = furnace.getAddonRegistry();
   Imported<MockInterface> services = registry.getServices(MockInterface.class.getName());
   Assert.assertFalse(services.isUnsatisfied());
   Assert.assertTrue(services.isAmbiguous());
}