/*
* 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@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);
}
}