Package org.jboss.ejb3.interceptors.test.ejbthree2080.unit

Source Code of org.jboss.ejb3.interceptors.test.ejbthree2080.unit.AOPWeirdnessTestCase

/*
* 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.interceptors.test.ejbthree2080.unit;

import org.apache.log4j.Appender;
import org.apache.log4j.spi.LoggingEvent;
import org.jboss.aspects.common.AOPDeployer;
import org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory;
import org.jboss.ejb3.interceptors.proxy.ProxyContainer;
import org.jboss.ejb3.interceptors.test.ejbthree2080.MyStateMachine;
import org.jboss.ejb3.interceptors.test.ejbthree2080.StateMachineLocal;
import org.jboss.logging.Logger;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentMatcher;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

/**
* @author <a href="cdewolf@redhat.com">Carlo de Wolf</a>
*/
public class AOPWeirdnessTestCase
{
   private static final Logger log = Logger.getLogger(AOPWeirdnessTestCase.class);
   private static AOPDeployer deployer = new AOPDeployer("proxy/jboss-aop.xml");

   @AfterClass
   public static void afterClass()
   {
      log.info(deployer.undeploy());
   }

   @BeforeClass
   public static void beforeClass() throws Exception
   {
      log.info(deployer.deploy());
   }

   @Test
   public void test1() throws Throwable
   {
      Appender appender = mock(Appender.class);
      doThrow(new AssertionError("logging WEIRDNESS IN AOP")).when(appender).doAppend(weirdnessInAOP());
      org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(InjectInterceptorsFactory.class);
      logger.addAppender(appender);
      try
      {
         ProxyContainer<MyStateMachine> container = new ProxyContainer<MyStateMachine>("AOPWeirdnessTestCase", "InterceptorContainer", MyStateMachine.class);

         Class<?> interfaces[] = { StateMachineLocal.class };
         StateMachineLocal proxy = container.constructProxy(interfaces);

         proxy.start();

         assertEquals(1, MyStateMachine.invocations());
      }
      finally
      {
         logger.removeAppender(appender);
      }
   }

   private static LoggingEvent weirdnessInAOP()
   {
      return argThat(new ArgumentMatcher<LoggingEvent>() {
         @Override
         public boolean matches(Object argument)
         {
            return ((LoggingEvent) argument).getRenderedMessage().contains("WEIRDNESS IN AOP");
         }
      });
   }
}
TOP

Related Classes of org.jboss.ejb3.interceptors.test.ejbthree2080.unit.AOPWeirdnessTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.