aslak

Arquillian - Byteman integration

Dec 31st, 2010
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. /*
  2.  * JBoss, Home of Professional Open Source
  3.  * Copyright 2010, Red Hat Middleware LLC, and individual contributors
  4.  * by the @authors tag. See the copyright.txt in the distribution for a
  5.  * full listing of individual contributors.
  6.  *
  7.  * Licensed under the Apache License, Version 2.0 (the "License");
  8.  * you may not use this file except in compliance with the License.
  9.  * You may obtain a copy of the License at
  10.  * http://www.apache.org/licenses/LICENSE-2.0
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jboss.arquillian.framework.byteman.test;
  18.  
  19. import javax.ejb.EJB;
  20.  
  21. import org.jboss.arquillian.api.Deployment;
  22. import org.jboss.arquillian.framework.byteman.api.BMRule;
  23. import org.jboss.arquillian.framework.byteman.api.BMRules;
  24. import org.jboss.arquillian.junit.Arquillian;
  25. import org.jboss.shrinkwrap.api.Archive;
  26. import org.jboss.shrinkwrap.api.ShrinkWrap;
  27. import org.jboss.shrinkwrap.api.spec.JavaArchive;
  28. import org.junit.Assert;
  29. import org.junit.Test;
  30. import org.junit.runner.RunWith;
  31.  
  32. /**
  33.  * BytemanIntegrationTestCase
  34.  *
  35.  * @author <a href="mailto:[email protected]">Aslak Knutsen</a>
  36.  * @version $Revision: $
  37.  */
  38. @BMRules(
  39.       @BMRule(
  40.             name = "Throw exception on success",
  41.             targetClass = "StatelessTestBean",
  42.             targetMethod = "success",
  43.             action = "throw new java.lang.RuntimeException()")
  44. )
  45. @RunWith(Arquillian.class)
  46. public class BytemanIntegrationTestCase
  47. {
  48.    @Deployment
  49.    public static Archive<?> createDeployment()
  50.    {
  51.       return ShrinkWrap.create(JavaArchive.class, "test.jar")
  52.                .addClass(StatelessTestBean.class);
  53.    }
  54.    
  55.    @EJB
  56.    private StatelessTestBean bean;
  57.    
  58.    @Test
  59.    public void shouldBeAbleToInjectThrowRule()
  60.    {
  61.       Assert.assertNotNull("Verify bean was injected", bean);
  62.      
  63.       try
  64.       {
  65.          bean.success();
  66.          Assert.fail("A Exception should have been injected into target class");
  67.       }
  68.       catch (Exception e)
  69.       {
  70.          // verify my exception?
  71.       }
  72.    }
  73. }
Add Comment
Please, Sign In to add comment