Skip to content

Commit

Permalink
implicit add -> fail when getting instance of bean not registered in …
Browse files Browse the repository at this point in the history
…manager

git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@391 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Dec 3, 2008
1 parent f79f07c commit 7a972d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Expand Up @@ -27,6 +27,7 @@
import javassist.util.proxy.ProxyFactory;
import javassist.util.proxy.ProxyObject;

import javax.webbeans.DefinitionException;
import javax.webbeans.UnproxyableDependencyException;
import javax.webbeans.manager.Bean;

Expand Down Expand Up @@ -174,15 +175,16 @@ public Object getClientProxy(Bean<?> bean)
try
{
int beanIndex = manager.getBeans().indexOf(bean);
// Implicit add required since it is looked up on activation with
// then index
if (beanIndex < 0)
{
manager.addBean(bean);
beanIndex = manager.getBeans().size() - 1;
throw new DefinitionException(bean + " is not known to the manager");
}
clientProxy = createClientProxy(bean, beanIndex);
}
catch (DefinitionException e)
{
throw e;
}
catch (Exception e)
{
// TODO: What to *really* do here?
Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import javax.webbeans.DefinitionException;
import javax.webbeans.UnproxyableDependencyException;
import javax.webbeans.manager.Bean;

Expand Down Expand Up @@ -85,11 +86,11 @@ public void testReflectionsInvocation()
assert tuna.getState().equals("tuned");
}

@Test(groups = "Reflections")
public void testProxyCreationDoesImplicitAddBean() {
@Test(groups = "Reflections", expectedExceptions=DefinitionException.class)
public void testGettingUnknownBeanFails() {
Bean<Tuna> tunaBean = BeanFactory.createSimpleBean(Tuna.class, manager);
Tuna tuna = manager.getInstance(tunaBean);
assert manager.getBeans().size() == 2;
assert false;
}

}

0 comments on commit 7a972d1

Please sign in to comment.