[jboss-cvs] JBossAS SVN: r105001 - in projects/ejb3/trunk/deployers: src/main/java/org/jboss/ejb3/deployers and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 19 17:17:00 EDT 2010
Author: wolfc
Date: 2010-05-19 17:16:59 -0400 (Wed, 19 May 2010)
New Revision: 105001
Added:
projects/ejb3/trunk/deployers/src/test/java/org/
projects/ejb3/trunk/deployers/src/test/java/org/jboss/
projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/
projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/deployers/
projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/deployers/test/
projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/deployers/test/ejbthree2095/
projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/deployers/test/ejbthree2095/NoEnterpriseBeansTestCase.java
Modified:
projects/ejb3/trunk/deployers/pom.xml
projects/ejb3/trunk/deployers/src/main/java/org/jboss/ejb3/deployers/EJBsDeployer.java
Log:
EJBTHREE-2095: only use processed metadata and validate it before deploy
Modified: projects/ejb3/trunk/deployers/pom.xml
===================================================================
--- projects/ejb3/trunk/deployers/pom.xml 2010-05-19 20:49:25 UTC (rev 105000)
+++ projects/ejb3/trunk/deployers/pom.xml 2010-05-19 21:16:59 UTC (rev 105001)
@@ -72,7 +72,11 @@
</exclusions>
</dependency>
-
-
- </dependencies>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.4</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
Modified: projects/ejb3/trunk/deployers/src/main/java/org/jboss/ejb3/deployers/EJBsDeployer.java
===================================================================
--- projects/ejb3/trunk/deployers/src/main/java/org/jboss/ejb3/deployers/EJBsDeployer.java 2010-05-19 20:49:25 UTC (rev 105000)
+++ projects/ejb3/trunk/deployers/src/main/java/org/jboss/ejb3/deployers/EJBsDeployer.java 2010-05-19 21:16:59 UTC (rev 105001)
@@ -21,9 +21,6 @@
*/
package org.jboss.ejb3.deployers;
-import java.util.ArrayList;
-import java.util.List;
-
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.helpers.AbstractComponentDeployer;
import org.jboss.deployers.spi.deployer.helpers.AbstractDeploymentVisitor;
@@ -32,8 +29,12 @@
import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
import org.jboss.logging.Logger;
import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Create components out of EJB 3 JBossMetaData.
*
@@ -45,6 +46,8 @@
private static final Logger log = Logger.getLogger(EJBsDeployer.class);
private static final JBossDeploymentVisitor deploymentVisitor = new JBossDeploymentVisitor();
+
+ private String attachmentName = AttachmentNames.PROCESSED_METADATA;
/**
*
@@ -52,12 +55,9 @@
public EJBsDeployer()
{
// Since we don't set component visitor
- addInput(deploymentVisitor.getVisitorType());
+ addInput(attachmentName);
setOutput(deploymentVisitor.getComponentType());
- // for ordering
- addInput(AttachmentNames.PROCESSED_METADATA);
-
setDeploymentVisitor(deploymentVisitor);
}
@@ -72,7 +72,15 @@
@Override
protected List<? extends JBossEnterpriseBeanMetaData> getComponents(JBossMetaData deployment)
{
- return new ArrayList<JBossEnterpriseBeanMetaData>(deployment.getEnterpriseBeans());
+ if(deployment == null || !deployment.isEJB3x())
+ return null;
+ JBossEnterpriseBeansMetaData enterpriseBeans = deployment.getEnterpriseBeans();
+ if(enterpriseBeans == null)
+ {
+ log.warn("EJBTHREE-2095: did not find any beans in " + deployment + " which is a violation of the xsd");
+ return null;
+ }
+ return new ArrayList<JBossEnterpriseBeanMetaData>(enterpriseBeans);
}
@Override
@@ -92,7 +100,7 @@
{
// I only want a single attachment deployed
- U deployment = unit.getAttachment(visitor.getVisitorType());
+ U deployment = unit.getAttachment(attachmentName, visitor.getVisitorType());
try
{
visitor.deploy(unit, deployment);
@@ -104,32 +112,14 @@
}
@Override
- public void internalDeploy(DeploymentUnit unit) throws DeploymentException
+ protected <U> void undeploy(DeploymentUnit unit, DeploymentVisitor<U> visitor)
{
- if(!isValid(unit))
+ if(visitor == null)
return;
- log.debug("Processing " + unit);
-
- super.internalDeploy(unit);
+ // I only want a single attachment undeployed
+
+ U deployment = unit.getAttachment(attachmentName, visitor.getVisitorType());
+ visitor.undeploy(unit, deployment);
}
-
- @Override
- public void internalUndeploy(DeploymentUnit unit)
- {
- // if we don't check then undeploy will be done for stuff that was never deployed.
- if(!isValid(unit))
- return;
-
- super.internalUndeploy(unit);
- }
-
- protected boolean isValid(DeploymentUnit unit)
- {
- // for good measure, we only do this for EJB 3 deployments
- JBossMetaData md = unit.getAttachment(JBossMetaData.class);
- if(md == null || !md.isEJB3x())
- return false;
- return true;
- }
}
Added: projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/deployers/test/ejbthree2095/NoEnterpriseBeansTestCase.java
===================================================================
--- projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/deployers/test/ejbthree2095/NoEnterpriseBeansTestCase.java (rev 0)
+++ projects/ejb3/trunk/deployers/src/test/java/org/jboss/ejb3/deployers/test/ejbthree2095/NoEnterpriseBeansTestCase.java 2010-05-19 21:16:59 UTC (rev 105001)
@@ -0,0 +1,97 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.ejb3.deployers.test.ejbthree2095;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.common.deployers.spi.AttachmentNames;
+import org.jboss.ejb3.deployers.EJBsDeployer;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
+import org.junit.Test;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * @author <a href="cdewolf at redhat.com">Carlo de Wolf</a>
+ */
+public class NoEnterpriseBeansTestCase
+{
+ @Test
+ public void testNoEJBsDeploy() throws Exception
+ {
+ EJBsDeployer deployer = new EJBsDeployer();
+
+ DeploymentUnit unit = mock(DeploymentUnit.class);
+ JBossMetaData metaData = new JBossMetaData();
+ metaData.setEjbVersion("3.0");
+ when(unit.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class)).thenReturn(metaData);
+ deployer.deploy(unit);
+
+ // make sure the deployer actually looked at the metadata
+ verify(unit).getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class);
+ verifyNoMoreInteractions(unit);
+ }
+
+ @Test
+ public void testNoEJBsUndeploy() throws Exception
+ {
+ EJBsDeployer deployer = new EJBsDeployer();
+
+ DeploymentUnit unit = mock(DeploymentUnit.class);
+ JBossMetaData metaData = new JBossMetaData();
+ metaData.setEjbVersion("3.0");
+ when(unit.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class)).thenReturn(metaData);
+ deployer.undeploy(unit);
+
+ // make sure the deployer actually looked at the metadata
+ verify(unit).getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class);
+ verifyNoMoreInteractions(unit);
+ }
+
+ @Test
+ public void testOneEJBDeploy() throws Exception
+ {
+ EJBsDeployer deployer = new EJBsDeployer();
+
+ DeploymentUnit unit = mock(DeploymentUnit.class);
+ JBossMetaData metaData = new JBossMetaData();
+ metaData.setEjbVersion("3.0");
+ JBossEnterpriseBeansMetaData enterpriseBeans = new JBossEnterpriseBeansMetaData();
+ JBossSessionBeanMetaData sessionBean = new JBossSessionBeanMetaData();
+ sessionBean.setEjbName("Test");
+ enterpriseBeans.add(sessionBean);
+ metaData.setEnterpriseBeans(enterpriseBeans);
+ when(unit.getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class)).thenReturn(metaData);
+ DeploymentUnit component = mock(DeploymentUnit.class);
+ when(unit.addComponent(JBossEnterpriseBeanMetaData.class.getName() + ".Test")).thenReturn(component);
+ deployer.deploy(unit);
+
+ // make sure the deployer actually looked at the metadata
+ verify(unit).getAttachment(AttachmentNames.PROCESSED_METADATA, JBossMetaData.class);
+ // make sure the component got created
+ verify(unit).addComponent(JBossEnterpriseBeanMetaData.class.getName() + ".Test");
+ verify(component).addAttachment(eq(JBossEnterpriseBeanMetaData.class.getName()), eq(sessionBean));
+ verifyNoMoreInteractions(unit);
+ }
+}
More information about the jboss-cvs-commits
mailing list