Author: pete.muir(a)jboss.org
Date: 2008-09-11 10:38:32 -0400 (Thu, 11 Sep 2008)
New Revision: 106
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Orangutan.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameOrangutan.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Chimpanzee.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Gibbon.java
Removed:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentLifecycleTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentModelTest.java
ri/trunk/webbeans-ri/testng.xml
Log:
More tests for remote components
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java 2008-09-11
12:46:52 UTC (rev 105)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AbstractEnterpriseComponentModel.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -1,18 +1,11 @@
package org.jboss.webbeans.model;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
import javax.webbeans.ApplicationScoped;
import javax.webbeans.Dependent;
-import javax.webbeans.Destroys;
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.ejb.EjbMetaData;
-import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedType;
-import org.jboss.webbeans.util.Reflections;
public abstract class AbstractEnterpriseComponentModel<T> extends
AbstractClassComponentModel<T>
@@ -32,7 +25,6 @@
{
super.init(container);
ejbMetaData = container.getEjbManager().getEjbMetaData(getType());
- initRemoveMethod(container);
checkEnterpriseScopeAllowed();
}
@@ -56,52 +48,5 @@
throw new RuntimeException("Scope " + getScopeType() + " is not
allowed on singleton enterpise bean components for " + getType() + ". Only
@Dependent or @ApplicationScoped is allowed on singleton enterprise bean
components");
}
}
-
- // TODO loggigng
- protected void initRemoveMethod(ContainerImpl container)
- {
- if (getEjbMetaData().isStateful())
- {
- if (getEjbMetaData().getRemoveMethods().size() == 1)
- {
- super.removeMethod = new
InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
- }
- else if (getEjbMetaData().getRemoveMethods().size() > 1)
- {
- List<Method> possibleRemoveMethods = new ArrayList<Method>();
- for (Method removeMethod : getEjbMetaData().getRemoveMethods())
- {
- if (removeMethod.isAnnotationPresent(Destroys.class))
- {
- possibleRemoveMethods.add(removeMethod);
- }
- }
- if (possibleRemoveMethods.size() == 1)
- {
- super.removeMethod = new
InjectableMethod<Object>(possibleRemoveMethods.get(0));
- }
- else if (possibleRemoveMethods.size() > 1)
- {
- throw new RuntimeException("Multiple remove methods are annotated
@Destroys for " + getType());
- }
- else if (possibleRemoveMethods.size() == 0)
- {
- throw new RuntimeException("Multiple remove methods are declared, and
none are annotated @Destroys for " + getType());
- }
- }
- else if (getEjbMetaData().getRemoveMethods().size() == 0)
- {
- throw new RuntimeException("Stateful enterprise bean component has no
remove methods declared for " + getType());
- }
- }
- else
- {
- List<Method> destroysMethods = Reflections.getMethods(getType(),
Destroys.class);
- if (destroysMethods.size() > 0)
- {
- throw new RuntimeException("Only stateful enterprise bean components can
have methods annotated @Destroys; " + getType() + " is not a stateful enterprise
bean component");
- }
- }
- }
}
\ No newline at end of file
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-09-11
12:46:52 UTC (rev 105)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/EnterpriseComponentModel.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -1,9 +1,17 @@
package org.jboss.webbeans.model;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.webbeans.Destroys;
+
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.injectable.ComponentConstructor;
import org.jboss.webbeans.injectable.EnterpriseConstructor;
+import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedType;
+import org.jboss.webbeans.util.Reflections;
public class EnterpriseComponentModel<T> extends
AbstractEnterpriseComponentModel<T>
{
@@ -24,6 +32,7 @@
{
super.init(container);
this.constructor = new EnterpriseConstructor<T>(getEjbMetaData());
+ initRemoveMethod(container);
}
public ComponentConstructor<T> getConstructor()
@@ -46,5 +55,52 @@
}
return location;
}
+
+// TODO loggigng
+ protected void initRemoveMethod(ContainerImpl container)
+ {
+ if (getEjbMetaData().isStateful())
+ {
+ if (getEjbMetaData().getRemoveMethods().size() == 1)
+ {
+ super.removeMethod = new
InjectableMethod<Object>(getEjbMetaData().getRemoveMethods().get(0));
+ }
+ else if (getEjbMetaData().getRemoveMethods().size() > 1)
+ {
+ List<Method> possibleRemoveMethods = new ArrayList<Method>();
+ for (Method removeMethod : getEjbMetaData().getRemoveMethods())
+ {
+ if (removeMethod.isAnnotationPresent(Destroys.class))
+ {
+ possibleRemoveMethods.add(removeMethod);
+ }
+ }
+ if (possibleRemoveMethods.size() == 1)
+ {
+ super.removeMethod = new
InjectableMethod<Object>(possibleRemoveMethods.get(0));
+ }
+ else if (possibleRemoveMethods.size() > 1)
+ {
+ throw new RuntimeException("Multiple remove methods are annotated
@Destroys for " + getType());
+ }
+ else if (possibleRemoveMethods.size() == 0)
+ {
+ throw new RuntimeException("Multiple remove methods are declared, and
none are annotated @Destroys for " + getType());
+ }
+ }
+ else if (getEjbMetaData().getRemoveMethods().size() == 0)
+ {
+ throw new RuntimeException("Stateful enterprise bean component has no
remove methods declared for " + getType());
+ }
+ }
+ else
+ {
+ List<Method> destroysMethods = Reflections.getMethods(getType(),
Destroys.class);
+ if (destroysMethods.size() > 0)
+ {
+ throw new RuntimeException("Only stateful enterprise bean components can
have methods annotated @Destroys; " + getType() + " is not a stateful enterprise
bean component");
+ }
+ }
+ }
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-09-11
12:46:52 UTC (rev 105)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/RemoteComponentModel.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -1,10 +1,16 @@
package org.jboss.webbeans.model;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
import javax.webbeans.BoundTo;
+import javax.webbeans.Destroys;
import org.jboss.webbeans.ContainerImpl;
import org.jboss.webbeans.injectable.ComponentConstructor;
import org.jboss.webbeans.injectable.EnterpriseConstructor;
+import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedType;
public class RemoteComponentModel<T> extends
AbstractEnterpriseComponentModel<T>
@@ -27,8 +33,39 @@
super.init(container);
// TODO initialize constructor
initBoundTo();
+ initRemoveMethod();
}
+ protected void initRemoveMethod()
+ {
+ Set<Method> destroyMethods = new HashSet<Method>();
+ for (Method method : getAnnotatedItem().getDelegate().getMethods())
+ {
+ if (method.isAnnotationPresent(Destroys.class))
+ {
+ destroyMethods.add(method);
+ }
+ }
+ if (destroyMethods.size() == 1)
+ {
+ Method destroyMethod = destroyMethods.iterator().next();
+ if (destroyMethod.getParameterTypes().length > 0)
+ {
+ throw new RuntimeException(getLocation() + " The method annotated
@Destroys cannot take any parameters");
+ }
+ else
+ {
+ removeMethod = new InjectableMethod(destroyMethod);
+ }
+ }
+ else if (destroyMethods.size() > 1)
+ {
+ // TODO Enumerate the destroy methods
+ throw new RuntimeException(getLocation() + " There can only be a maximum of
one method declared @Destorys");
+ }
+
+ }
+
@Override
protected void checkComponentImplementation()
{
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentLifecycleTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentLifecycleTest.java 2008-09-11
12:46:52 UTC (rev 105)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentLifecycleTest.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -5,18 +5,11 @@
public class RemoteComponentLifecycleTest
{
- @Test(groups="componentLifecycle")
@SpecAssertion(section="3.2.3")
- public void testInjectonOfParametersIntoRemoveMethod()
+ @Test(groups="componentLifecycle")
@SpecAssertion(section="3.5.3")
+ public void testRemoveMethodCalledCausesContainerToRemoveInstance()
{
- // TODO Placeholder
assert false;
}
- @Test(groups="specialization") @SpecAssertion(section="3.2.3")
- public void testSpecializedComponentAlwaysUsed()
- {
- // TODO Placeholder
- assert false;
- }
}
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentModelTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentModelTest.java 2008-09-11
12:46:52 UTC (rev 105)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/RemoteComponentModelTest.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -12,7 +12,10 @@
import org.jboss.webbeans.test.annotations.Tame;
import org.jboss.webbeans.test.components.Animal;
import org.jboss.webbeans.test.components.Baboon;
-import org.jboss.webbeans.test.components.TameApe;
+import org.jboss.webbeans.test.components.Orangutan;
+import org.jboss.webbeans.test.components.TameOrangutan;
+import org.jboss.webbeans.test.components.broken.Chimpanzee;
+import org.jboss.webbeans.test.components.broken.Gibbon;
import org.jboss.webbeans.test.mock.MockContainerImpl;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -41,8 +44,8 @@
@Test @SpecAssertion(section="3.5.4")
public void testDefaultName() throws SecurityException, NoSuchMethodException
{
- RemoteComponentModel<TameApe> tameApeModel = new
RemoteComponentModel<TameApe>(new SimpleAnnotatedType<TameApe>(TameApe.class),
emptyAnnotatedItem, container);
- assert tameApeModel.getName().equals("tameApe");
+ RemoteComponentModel<TameOrangutan> tameApeModel = new
RemoteComponentModel<TameOrangutan>(new
SimpleAnnotatedType<TameOrangutan>(TameOrangutan.class), emptyAnnotatedItem,
container);
+ assert tameApeModel.getName().equals("tameOrangutan");
}
@Test @SpecAssertion(section="3.5.1")
@@ -56,9 +59,9 @@
@Test
public void testBindingType() throws SecurityException, NoSuchMethodException
{
- RemoteComponentModel<TameApe> tameApeModel = new
RemoteComponentModel<TameApe>(new SimpleAnnotatedType<TameApe>(TameApe.class),
emptyAnnotatedItem, container);
- assert tameApeModel.getBindingTypes().size() == 1;
- assert
tameApeModel.getBindingTypes().iterator().next().annotationType().equals(Tame.class);
+ RemoteComponentModel<TameOrangutan> tameOrangutanModel = new
RemoteComponentModel<TameOrangutan>(new
SimpleAnnotatedType<TameOrangutan>(TameOrangutan.class), emptyAnnotatedItem,
container);
+ assert tameOrangutanModel.getBindingTypes().size() == 1;
+ assert
tameOrangutanModel.getBindingTypes().iterator().next().annotationType().equals(Tame.class);
}
@Test(groups="remoteComponentInXml")
@SpecAssertion(section="3.5.2")
@@ -67,4 +70,31 @@
assert false;
}
+ @Test @SpecAssertion(section="3.5.3")
+ public void testSFSBMustHaveRemoveMethod()
+ {
+ // TODO How do we check this?
+ }
+
+ @Test(expectedExceptions=RuntimeException.class)
@SpecAssertion(section="3.5.3")
+ public void testRemoveMethodCannotHaveParameters()
+ {
+ RemoteComponentModel<Chimpanzee> chimpanzeeModel = new
RemoteComponentModel<Chimpanzee>(new
SimpleAnnotatedType<Chimpanzee>(Chimpanzee.class), emptyAnnotatedItem, container);
+ }
+
+ @Test(expectedExceptions=RuntimeException.class)
@SpecAssertion(section="3.5.3")
+ public void testCannotHaveMultipleRemoveMethods()
+ {
+ RemoteComponentModel<Gibbon> gibbonModel = new
RemoteComponentModel<Gibbon>(new SimpleAnnotatedType<Gibbon>(Gibbon.class),
emptyAnnotatedItem, container);
+ }
+
+ @Test @SpecAssertion(section="3.5.3")
+ public void testRemoveMethod()
+ {
+ RemoteComponentModel<TameOrangutan> tameOrangutanModel = new
RemoteComponentModel<TameOrangutan>(new
SimpleAnnotatedType<TameOrangutan>(TameOrangutan.class), emptyAnnotatedItem,
container);
+ assert
tameOrangutanModel.getRemoveMethod().getMethod().getName().equals("removeOrangutan");
+ RemoteComponentModel<Orangutan> orangutanModel = new
RemoteComponentModel<Orangutan>(new
SimpleAnnotatedType<Orangutan>(Orangutan.class), emptyAnnotatedItem, container);
+ assert
orangutanModel.getRemoveMethod().getMethod().getName().equals("removeOrangutan");
+ }
+
}
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Orangutan.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Orangutan.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Orangutan.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -0,0 +1,19 @@
+package org.jboss.webbeans.test.components;
+
+import javax.ejb.Remote;
+import javax.webbeans.BoundTo;
+import javax.webbeans.Destroys;
+import javax.webbeans.Named;
+import javax.webbeans.Production;
+
+@Remote
+@Production
+@BoundTo("/beans/orangutan")
+@Named
+public interface Orangutan extends Animal
+{
+
+ @Destroys
+ public void removeOrangutan();
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/Orangutan.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java 2008-09-11
12:46:52 UTC (rev 105)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -1,18 +0,0 @@
-package org.jboss.webbeans.test.components;
-
-import javax.ejb.Remote;
-import javax.webbeans.BoundTo;
-import javax.webbeans.Named;
-import javax.webbeans.Production;
-
-import org.jboss.webbeans.test.annotations.Tame;
-
-@Remote
-@Production
-@BoundTo("/beans/ape")
-@Tame
-@Named
-public interface TameApe extends Animal
-{
-
-}
Copied:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameOrangutan.java
(from rev 99,
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameApe.java)
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameOrangutan.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameOrangutan.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -0,0 +1,18 @@
+package org.jboss.webbeans.test.components;
+
+import javax.ejb.Remote;
+import javax.webbeans.BoundTo;
+import javax.webbeans.Named;
+import javax.webbeans.Production;
+
+import org.jboss.webbeans.test.annotations.Tame;
+
+@Remote
+@Production
+@BoundTo("/beans/tame/orangutan")
+@Tame
+@Named
+public interface TameOrangutan extends Orangutan
+{
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/TameOrangutan.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Chimpanzee.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Chimpanzee.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Chimpanzee.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.components.broken;
+
+import javax.ejb.Remote;
+import javax.webbeans.BoundTo;
+import javax.webbeans.Destroys;
+import javax.webbeans.Production;
+
+@Remote
+@BoundTo("/beans/Chimpanzee")
+@Production
+public interface Chimpanzee
+{
+
+ @Destroys
+ public void remove(String foo);
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Chimpanzee.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Gibbon.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Gibbon.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Gibbon.java 2008-09-11
14:38:32 UTC (rev 106)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.test.components.broken;
+
+import javax.ejb.Remote;
+import javax.webbeans.BoundTo;
+import javax.webbeans.Destroys;
+import javax.webbeans.Production;
+
+@Remote
+@BoundTo("/beans/Chimpanzee")
+@Production
+public interface Gibbon
+{
+
+ @Destroys
+ public void remove();
+
+ @Destroys
+ public void removeAgain();
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/components/broken/Gibbon.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/testng.xml
===================================================================
--- ri/trunk/webbeans-ri/testng.xml 2008-09-11 12:46:52 UTC (rev 105)
+++ ri/trunk/webbeans-ri/testng.xml 2008-09-11 14:38:32 UTC (rev 106)
@@ -54,6 +54,7 @@
<class
name="org.jboss.webbeans.test.EnterpriseComponentLifecycleTest" />
<class
name="org.jboss.webbeans.test.ProducerMethodComponentLifecycleTest" />
<class
name="org.jboss.webbeans.test.ProducerExpressionComponentLifecycleTest" />
+ <class name="org.jboss.webbeans.test.RemoteComponentLifecycleTest"
/>
</classes>
</test>