Skip to content

Commit

Permalink
FORGE-1876: WeldServiceRegistry.hasService should call BeanManager.ge…
Browse files Browse the repository at this point in the history
…tBeans().isEmpty()
  • Loading branch information
gastaldi committed Jun 10, 2014
1 parent 0a32ed0 commit 84585b2
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,8 @@ public boolean hasService(String clazz)
public boolean hasService(Class<?> clazz)
{
Addons.waitUntilStarted(addon);
for (Class<?> service : serviceTypes)
{
if (clazz.isAssignableFrom(service))
{
return true;
}
}
return false;
Set<Bean<?>> beans = manager.getBeans(clazz, getQualifiersFrom(clazz));
return !beans.isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,22 @@
*/
public class PlainBean implements PlainInterface
{
private final String value;

public PlainBean()
{
this.value = null;
}

public PlainBean(String value)
{
this.value = value;
}

@Override
public String getValue()
{
return this.value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
*/
public interface PlainInterface
{

String getValue();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
@PlainQualifier
public class QualifiedPlainBean implements PlainInterface
{
@Override
public String getValue()
{
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package test.org.jboss.forge.furnace.mocks.services;

import javax.enterprise.inject.Produces;

import test.org.jboss.forge.furnace.mocks.PlainInterface;

/**
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
public class ProducesPlainInterfaceService
{
@Produces
public PlainInterface produceRawType()
{
return new PlainInterface()
{
@Override
public String getValue()
{
return "Produced";
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright 2014 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package test.org.jboss.forge.furnace.services;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.forge.arquillian.AddonDependency;
import org.jboss.forge.arquillian.Dependencies;
import org.jboss.forge.arquillian.archive.ForgeArchive;
import org.jboss.forge.furnace.addons.AddonRegistry;
import org.jboss.forge.furnace.repositories.AddonDependencyEntry;
import org.jboss.forge.furnace.services.Imported;
import org.jboss.forge.furnace.spi.ServiceRegistry;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import test.org.jboss.forge.furnace.mocks.PlainInterface;
import test.org.jboss.forge.furnace.mocks.services.ProducesPlainInterfaceService;

/**
*
* @author <a href="ggastald@redhat.com">George Gastaldi</a>
*/
@RunWith(Arquillian.class)
public class ProducerTest
{
@Deployment
@Dependencies({
@AddonDependency(name = "org.jboss.forge.furnace.container:cdi")
})
public static ForgeArchive getDeployment()
{
ForgeArchive archive = ShrinkWrap
.create(ForgeArchive.class)
.addBeansXML()
.addClasses(PlainInterface.class, ProducesPlainInterfaceService.class)
.addAsAddonDependencies(
AddonDependencyEntry.create("org.jboss.forge.furnace.container:cdi")
);
return archive;
}

@Inject
AddonRegistry addonRegistry;

@Inject
ServiceRegistry serviceRegistry;

@Test
public void testProducer()
{
Assert.assertTrue(serviceRegistry.hasService(PlainInterface.class));
Imported<PlainInterface> services = addonRegistry.getServices(PlainInterface.class);
Assert.assertFalse(services.isUnsatisfied());
Assert.assertFalse(services.isAmbiguous());
PlainInterface pi = services.get();
Assert.assertEquals("Produced", pi.getValue());
}
}

0 comments on commit 84585b2

Please sign in to comment.