Skip to content

Commit

Permalink
AS7-4905 @remove on base class of the bean should be taken into account
Browse files Browse the repository at this point in the history
  • Loading branch information
jaikiran authored and kabir committed Jun 12, 2012
1 parent 07dd8d1 commit dd670f8
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@
*/
package org.jboss.as.ejb3.deployment.processors.merging;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.ejb.Remove;

import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleClassDescription;
import org.jboss.as.ee.metadata.ClassAnnotationInformation;
import org.jboss.as.ee.metadata.MethodAnnotationAggregator;
import org.jboss.as.ee.metadata.RuntimeAnnotationInformation;
import org.jboss.as.ejb3.component.stateful.StatefulComponentDescription;
import org.jboss.as.ejb3.deployment.processors.dd.MethodResolutionUtils;
import org.jboss.as.server.deployment.DeploymentUnit;
Expand All @@ -43,6 +34,14 @@
import org.jboss.metadata.ejb.spec.RemoveMethodMetaData;
import org.jboss.metadata.ejb.spec.SessionBeanMetaData;

import javax.ejb.Remove;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Class that can merge {@link javax.ejb.Remove}
*
Expand All @@ -56,17 +55,14 @@ public RemoveMethodMergingProcessor() {
}

protected void handleAnnotations(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
EEModuleClassDescription clazz = applicationClasses.getClassByName(componentClass.getName());
if (clazz != null) {
ClassAnnotationInformation<Remove, Boolean> annotations = clazz.getAnnotationInformation(Remove.class);
if (annotations != null) {
for(Map.Entry<MethodIdentifier, List<Boolean>> entry : annotations.getMethodLevelAnnotations().entrySet()) {
final Boolean retainIfException = entry.getValue().get(0);
componentConfiguration.addRemoveMethod(entry.getKey(), retainIfException);
}
final RuntimeAnnotationInformation<Boolean> removeMethods = MethodAnnotationAggregator.runtimeAnnotationInformation(componentClass, applicationClasses, deploymentReflectionIndex, Remove.class);
for (Map.Entry<Method, List<Boolean>> entry : removeMethods.getMethodAnnotations().entrySet()) {
if (!entry.getValue().isEmpty()) {
final Boolean retainIfException = entry.getValue().get(0);
final MethodIdentifier removeMethodIdentifier = MethodIdentifier.getIdentifierForMethod(entry.getKey());
componentConfiguration.addRemoveMethod(removeMethodIdentifier, retainIfException);
}
}

}

protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final StatefulComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., 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.as.test.integration.ejb.stateful.remove;

import javax.ejb.Remove;

/**
* @author Jaikiran Pai
*/
public class BaseSFSB {

@Remove(retainIfException = true)
public void baseRetainIfAppException() {
throw new SimpleAppException();
}

@Remove
public void baseRemoveEvenIfAppException() {
throw new SimpleAppException();
}

@Remove
public void baseJustRemove() {
// do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
* User: Jaikiran Pai
*/
@RunWith(Arquillian.class)
@Ignore("[AS7-734] Migrate to ARQ Beta1")
public class RemoveMethodOnSFSBTestCase {

private static final Logger log = Logger.getLogger(RemoveMethodOnSFSBTestCase.class.getName());
Expand All @@ -56,7 +55,7 @@ public static JavaArchive createDeployment() {
return jar;
}

@EJB
@EJB (mappedName = "java:module/SFSBWithRemoveMethods!org.jboss.as.test.integration.ejb.stateful.remove.SFSBWithRemoveMethods")
private SFSBWithRemoveMethods sfsbWithRemoveMethods;

/**
Expand Down Expand Up @@ -136,4 +135,69 @@ public void testSimpleNonRemoveMethodOnSFSB() {
sfsbWithRemoveMethods.doNothing();
sfsbWithRemoveMethods.doNothing();
}

/**
* Tests that a invocation on SFSB base class method annotated with @Remove (and without the retainIfException set to true) results in
* removal of the bean even in case of application exception.
*/
@Test
public void testRemoveEvenIfAppExceptionOnSFSBBaseClass() {
// invoke the remove method which throws a app exception
try {
sfsbWithRemoveMethods.baseRemoveEvenIfAppException();
Assert.fail("Did not get the expected app exception");
} catch (SimpleAppException sae) {
// expected
}

// invoke again and it *must* throw NoSuchEJBException
try {
sfsbWithRemoveMethods.doNothing();
Assert.fail("Did not get the expected NoSuchEJBException on second invocation on SFSB");
} catch (NoSuchEJBException nsee) {
// expected
log.info("Got the expected NoSuchEJBException on second invocation on SFSB");
}
}

/**
* Tests that a invocation on a SFSB base class method annotated with @Remove results in the removal of the bean instance
*/
@Test
public void testSimpleRemoveOnSFSBBaseClass() {
// remove the SFSB
sfsbWithRemoveMethods.baseJustRemove();
// try invoking again. we should expect a NoSuchEJBException
try {
sfsbWithRemoveMethods.doNothing();
Assert.fail("SFSB was expected to be removed after a call to the @Remove method");
} catch (NoSuchEJBException nsee) {
// expected
log.info("Got the expected NoSuchEJBException after invoking remove on the SFSB");
}
}

/**
* Tests that a invocation on SFSB base class method annotated with @Remove and with "retainIfException = true" *doesn't* result
* in removal of the bean when a application exception is thrown.
*/
@Test
public void testRemoveWithRetainIfExceptionOnSFSBBaseClass() {
// invoke the remove method which throws a app exception
try {
sfsbWithRemoveMethods.baseRetainIfAppException();
Assert.fail("Did not get the expected app exception");
} catch (SimpleAppException sae) {
// expected
}

// invoke again and it should *not* throw NoSuchEJBException
try {
sfsbWithRemoveMethods.baseRetainIfAppException();
Assert.fail("Did not get the expected app exception on second invocation on SFSB");
} catch (SimpleAppException sae) {
// expected
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* User: jpai
*/
@Stateful
public class SFSBWithRemoveMethods {
public class SFSBWithRemoveMethods extends BaseSFSB {

@Remove
public void remove() {
Expand Down

0 comments on commit dd670f8

Please sign in to comment.