[webbeans-commits] Webbeans SVN: r3669 - in ri/branches/kabir-builder: tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Sep 15 11:25:54 EDT 2009
Author: kabir.khan at jboss.com
Date: 2009-09-15 11:25:53 -0400 (Tue, 15 Sep 2009)
New Revision: 3669
Added:
ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjb.java
ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjbImpl.java
ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingSimple.java
Modified:
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/DeploymentItem.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/EjbDeploymentItem.java
ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/WBClassDeploymentItem.java
ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/SorterTest.java
Log:
Check we are specializing the right thing
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/DeploymentItem.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/DeploymentItem.java 2009-09-15 13:31:15 UTC (rev 3668)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/DeploymentItem.java 2009-09-15 15:25:53 UTC (rev 3669)
@@ -86,7 +86,7 @@
if (candidate.equals(item))
return (DeploymentItem<T>)candidate;
}
- throw new IllegalStateException("Could not find item");
+ return null;
}
abstract DeploymentItem<T> getSuperClassDependency();
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/EjbDeploymentItem.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/EjbDeploymentItem.java 2009-09-15 13:31:15 UTC (rev 3668)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/EjbDeploymentItem.java 2009-09-15 15:25:53 UTC (rev 3669)
@@ -23,6 +23,7 @@
import java.util.Set;
+import org.jboss.webbeans.DefinitionException;
import org.jboss.webbeans.ejb.EjbDescriptors;
import org.jboss.webbeans.ejb.InternalEjbDescriptor;
import org.jboss.webbeans.introspector.WBClass;
@@ -58,10 +59,15 @@
if (ejb.getBeanClass().equals(superClass))
{
DeploymentItem<InternalEjbDescriptor<?>> item = new EjbDeploymentItem(null, null, getWBClass().getWBSuperclass(), ejb);
- return findDeploymentItem(item);
+ DeploymentItem<?> found = findDeploymentItem(item);
+ if (found == null || found instanceof EjbDeploymentItem == false)
+ {
+ throw new DefinitionException(toString() + " annotation defined specializing EJB must have EJB superclass " + ejbDescriptor.getEjbName() + "(" + ejbDescriptor.getBeanClass() + ")");
+ }
+ return (EjbDeploymentItem)found;
}
}
- //TODO search wbclasses too?
- throw new IllegalStateException("Could not find super class for " + ejbDescriptor);
+
+ throw new DefinitionException(toString() + " does not specialize an EJB " + ejbDescriptor.getEjbName() + "(" + ejbDescriptor.getBeanClass() + ")");
}
}
Modified: ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/WBClassDeploymentItem.java
===================================================================
--- ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/WBClassDeploymentItem.java 2009-09-15 13:31:15 UTC (rev 3668)
+++ ri/branches/kabir-builder/impl/src/main/java/org/jboss/webbeans/builder/sorter/WBClassDeploymentItem.java 2009-09-15 15:25:53 UTC (rev 3669)
@@ -23,6 +23,7 @@
import java.util.Set;
+import org.jboss.webbeans.DefinitionException;
import org.jboss.webbeans.introspector.WBClass;
/**
@@ -45,7 +46,12 @@
DeploymentItem<WBClass<?>> getSuperClassDependency()
{
DeploymentItem<WBClass<?>> item = new WBClassDeploymentItem(null, getWBClass().getWBSuperclass());
- return findDeploymentItem(item);
+ DeploymentItem<WBClass<?>> found = findDeploymentItem(item);
+ if (found == null || found instanceof WBClassDeploymentItem == false)
+ {
+ throw new DefinitionException("Simple bean must specialize a simple bean " + getWBClass());
+ }
+
+ return found;
}
-
}
Added: ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjb.java
===================================================================
--- ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjb.java (rev 0)
+++ ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjb.java 2009-09-15 15:25:53 UTC (rev 3669)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.webbeans.test.unit.builder.sorter;
+
+import javax.ejb.Local;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Local
+public interface BadSpecializingEjb
+{
+
+}
Added: ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjbImpl.java
===================================================================
--- ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjbImpl.java (rev 0)
+++ ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingEjbImpl.java 2009-09-15 15:25:53 UTC (rev 3669)
@@ -0,0 +1,38 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.webbeans.test.unit.builder.sorter;
+
+import javax.enterprise.inject.Specializes;
+
+import javax.ejb.Stateless;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Stateless
+ at Specializes
+public class BadSpecializingEjbImpl extends Employee implements BadSpecializingEjb
+{
+
+}
Added: ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingSimple.java
===================================================================
--- ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingSimple.java (rev 0)
+++ ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/BadSpecializingSimple.java 2009-09-15 15:25:53 UTC (rev 3669)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.webbeans.test.unit.builder.sorter;
+
+import javax.enterprise.inject.Specializes;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Specializes
+public class BadSpecializingSimple extends EmployeeManagerImpl
+{
+
+}
Modified: ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/SorterTest.java
===================================================================
--- ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/SorterTest.java 2009-09-15 13:31:15 UTC (rev 3668)
+++ ri/branches/kabir-builder/tests/src/test/java/org/jboss/webbeans/test/unit/builder/sorter/SorterTest.java 2009-09-15 15:25:53 UTC (rev 3669)
@@ -28,6 +28,7 @@
import java.util.Set;
import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
import org.jboss.webbeans.builder.sorter.DeploymentItem;
import org.jboss.webbeans.builder.sorter.Sorter;
import org.jboss.webbeans.introspector.WBClass;
@@ -35,6 +36,7 @@
import org.jboss.webbeans.mock.MockEELifecycle;
import org.jboss.webbeans.mock.MockEjbDescriptor;
import org.jboss.webbeans.resources.ClassTransformer;
+import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -137,6 +139,50 @@
assertArrays(sortClasses(createEjbDescriptors(SurgeonManagerImpl.class, DoctorManagerImpl.class), RedDecorator.class, BlueDecorator.class), RedDecorator.class, BlueDecorator.class, DoctorManagerImpl.class, SurgeonManagerImpl.class);
}
+ @Test
+ public void testBadSpecialisingEJB()
+ {
+ try
+ {
+ sortClasses(createEjbDescriptors(BadSpecializingEjbImpl.class), Employee.class);
+ Assert.fail("Should have picked up that superclass is not an EJB");
+ }
+ catch(DefinitionException expected)
+ {
+ }
+
+ try
+ {
+ sortClasses(createEjbDescriptors(BadSpecializingEjbImpl.class));
+ Assert.fail("Should have picked up that superclass does not exist");
+ }
+ catch(DefinitionException expected)
+ {
+ }
+ }
+
+ @Test
+ public void testBadSpecialisingSimple()
+ {
+ try
+ {
+ sortClasses(createEjbDescriptors(EmployeeManagerImpl.class), BadSpecializingSimple.class);
+ Assert.fail("Should have picked up that superclass is not a simple bean");
+ }
+ catch(DefinitionException expected)
+ {
+ }
+
+ try
+ {
+ sortClasses(BadSpecializingSimple.class);
+ Assert.fail("Should have picked up that superclass does not exist");
+ }
+ catch(DefinitionException expected)
+ {
+ }
+ }
+
private OrderedEjbDescriptors createEjbDescriptors(Class<?>...classes)
{
OrderedEjbDescriptors descriptors = new OrderedEjbDescriptors();
More information about the weld-commits
mailing list