Clover coverage report -
Coverage timestamp: Thu Jun 22 2006 14:24:50 CEST
file stats: LOC: 331   Methods: 10
NCLOC: 126   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BaseMethodInterceptor.java - 100% 100% 100%
coverage
 1    /**
 2    * EasyBeans
 3    * Copyright (C) 2006 Bull S.A.S.
 4    * Contact: easybeans@objectweb.org
 5    *
 6    * This library is free software; you can redistribute it and/or
 7    * modify it under the terms of the GNU Lesser General Public
 8    * License as published by the Free Software Foundation; either
 9    * version 2.1 of the License, or any later version.
 10    *
 11    * This library is distributed in the hope that it will be useful,
 12    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 14    * Lesser General Public License for more details.
 15    *
 16    * You should have received a copy of the GNU Lesser General Public
 17    * License along with this library; if not, write to the Free Software
 18    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 19    * USA
 20    *
 21    * --------------------------------------------------------------------------
 22    * $Id: BaseMethodInterceptor.java 191 2006-03-14 10:03:08Z studzine $
 23    * --------------------------------------------------------------------------
 24    */
 25    package org.objectweb.easybeans.tests.interceptors.business.base;
 26   
 27    import static org.objectweb.easybeans.tests.common.asserts.Assert.assertEquals;
 28   
 29    import java.util.ArrayList;
 30    import java.util.List;
 31   
 32    import org.objectweb.easybeans.tests.common.ejbs.base.ItfMethodInterceptor;
 33    import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBMethodInterceptorTest;
 34    import org.objectweb.easybeans.tests.common.interceptors.business.PackageInterceptor;
 35    import org.objectweb.easybeans.tests.common.interceptors.business.PrintOrder01Interceptor;
 36    import org.objectweb.easybeans.tests.common.interceptors.business.PrintOrder02Interceptor;
 37    import org.objectweb.easybeans.tests.common.interceptors.business.PrintOrder03Interceptor;
 38    import org.objectweb.easybeans.tests.common.interceptors.business.PrintOrder04Interceptor;
 39    import org.objectweb.easybeans.tests.common.interceptors.business.PrintOrder05Interceptor;
 40    import org.objectweb.easybeans.tests.common.interceptors.business.PrivateInterceptor;
 41    import org.objectweb.easybeans.tests.common.interceptors.business.ProtectedInterceptor;
 42    import org.testng.annotations.Test;
 43   
 44    /**
 45    * Verifies if the order to execute the method interceptors is
 46    * correct.
 47    * @author Eduardo Studzinski Estima de Castro
 48    * @author Gisele Pinheiro Souza
 49    */
 50    public class BaseMethodInterceptor {
 51   
 52    /**
 53    * Bean used to implement the test.
 54    */
 55    private ItfMethodInterceptor<Integer> mtBean;
 56   
 57    /**
 58    * Verifies if the interceptors are not executed.
 59    * @input List with no values inside
 60    * @output List with only one value, the value inserted by the method
 61    */
 62  2 @Test(groups = {"withoutInterceptor"})
 63    public void interceptorMethodTest00() {
 64    // The arrays used to know what is the interceptor order
 65  2 List<Integer> arResult = new ArrayList<Integer>();
 66  2 List<Integer> arExpected = new ArrayList<Integer>();
 67   
 68    // insert the value of the method
 69  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 70   
 71    // gets the result
 72  2 arResult = mtBean.withoutInterceptor(arResult);
 73   
 74    // compares the two values
 75  2 assertEquals(arExpected, arResult, "");
 76    }
 77   
 78    /**
 79    * Verifies if the interceptor is executed.
 80    * @input List with no values inside
 81    * @output List with two values, the value inserted by the method and the
 82    * value inserted by the interceptor
 83    */
 84  2 @Test(groups = {"withInterceptor"})
 85    public void interceptorMethodTest02() {
 86    // The arrays used to know what is the interceptor order
 87  2 List<Integer> arResult = new ArrayList<Integer>();
 88  2 List<Integer> arExpected = new ArrayList<Integer>();
 89   
 90    // insert the value of the interceptor
 91  2 arExpected.add(PrintOrder01Interceptor.ORDER);
 92    // insert the value of the method
 93  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 94   
 95    // gets the result
 96  2 arResult = mtBean.withOneMethodInterceptor(arResult);
 97   
 98    // compares the two values
 99  2 assertEquals(arExpected, arResult, "The interceptor is not running or it is running in the incorrect order.");
 100    }
 101   
 102    /**
 103    * Verifies if two interceptors are executed in order.
 104    * @input List with no values inside
 105    * @output List with three values, the value inserted by the method and the
 106    * value inserted by the interceptors.
 107    */
 108  2 @Test(groups = {"withInterceptor"})
 109    public void interceptorMethodTest03() {
 110    // The arrays used to know what is the interceptor order
 111  2 List<Integer> arResult = new ArrayList<Integer>();
 112  2 List<Integer> arExpected = new ArrayList<Integer>();
 113   
 114    // insert the value of the interceptor
 115  2 arExpected.add(PrintOrder01Interceptor.ORDER);
 116    // insert the value of the interceptor
 117  2 arExpected.add(PrintOrder02Interceptor.ORDER);
 118    // insert the value of the method
 119  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 120   
 121    // gets the result
 122  2 arResult = mtBean.withTwoMethodInterceptors(arResult);
 123   
 124    // compares the two values
 125  2 assertEquals(arExpected, arResult, "The interceptors are not called in the correct order.");
 126    }
 127   
 128    /**
 129    * Verifies if many interceptors are executed in order.
 130    * @input List with no values inside
 131    * @output List with six values, the value inserted by the method and the
 132    * value inserted by the interceptors.
 133    */
 134  2 @Test(groups = {"withInterceptor", "withInheritance"})
 135    public void interceptorMethodTest04() {
 136    // The arrays used to know what is the interceptor order
 137  2 List<Integer> arResult = new ArrayList<Integer>();
 138  2 List<Integer> arExpected = new ArrayList<Integer>();
 139   
 140    // insert the value of the interceptor
 141  2 arExpected.add(PrintOrder01Interceptor.ORDER);
 142    // insert the value of the interceptor
 143  2 arExpected.add(PrintOrder02Interceptor.ORDER);
 144    // insert the value of the method
 145  2 arExpected.add(PrintOrder03Interceptor.ORDER);
 146    // insert the value of the interceptor
 147  2 arExpected.add(PrintOrder04Interceptor.ORDER);
 148    // insert the value of the interceptor
 149  2 arExpected.add(PrintOrder05Interceptor.ORDER);
 150    // insert the value of the method
 151  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 152   
 153    // gets the result
 154  2 arResult = mtBean.withFiveMethodInterceptors(arResult);
 155   
 156    // compares the two values
 157  2 assertEquals(arExpected, arResult, "The interceptors are not running in the correct order."
 158    + " Maybe there is a problem with the interceptors inheritance.");
 159    }
 160   
 161    /**
 162    * Verifies if many interceptors are executed in order. This must repect the
 163    * declaration order.
 164    * @input List with no values inside
 165    * @output List with six values, the value inserted by the method and the
 166    * value inserted by the interceptors.
 167    */
 168  2 @Test(groups = {"withInterceptor", "withInheritance"})
 169    public void interceptorMethodTest05() {
 170    // The arrays used to know what is the interceptor order
 171  2 List<Integer> arResult = new ArrayList<Integer>();
 172  2 List<Integer> arExpected = new ArrayList<Integer>();
 173   
 174    // insert the value of the interceptor
 175  2 arExpected.add(PrintOrder05Interceptor.ORDER);
 176    // insert the value of the interceptor
 177  2 arExpected.add(PrintOrder04Interceptor.ORDER);
 178    // insert the value of the method
 179  2 arExpected.add(PrintOrder03Interceptor.ORDER);
 180    // insert the value of the interceptor
 181  2 arExpected.add(PrintOrder02Interceptor.ORDER);
 182    // insert the value of the interceptor
 183  2 arExpected.add(PrintOrder01Interceptor.ORDER);
 184    // insert the value of the method
 185  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 186   
 187    // gets the result
 188  2 arResult = mtBean.withFiveMethodInterceptorsInverse(arResult);
 189   
 190    // compares the two values
 191  2 assertEquals(arExpected, arResult, "The interceptors are not running in the correct order."
 192    + " Maybe there is a problem with the interceptors inheritance.");
 193    }
 194   
 195    /**
 196    * Verifies if interceptors are executed in order. All interceptors have a
 197    * private method that intercepts.
 198    * @input List with no values inside
 199    * @output List with 4 values, the value inserted by the method and the
 200    * value inserted by the interceptors.
 201    */
 202  2 @Test(groups = {"withInterceptor"})
 203    public void interceptorMethodTest06() {
 204    // The arrays used to know what is the interceptor order
 205  2 List<Integer> arResult = new ArrayList<Integer>();
 206  2 List<Integer> arExpected = new ArrayList<Integer>();
 207   
 208    // insert the value of the interceptor
 209  2 arExpected.add(PrivateInterceptor.ORDER);
 210    // insert the value of the interceptor
 211  2 arExpected.add(PrivateInterceptor.ORDER);
 212    // insert the value of the interceptor
 213  2 arExpected.add(PrivateInterceptor.ORDER);
 214    // insert the value of the method
 215  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 216   
 217    // gets the result
 218  2 arResult = mtBean.withPrivateInterceptors(arResult);
 219   
 220    // compares the two values
 221  2 assertEquals(arExpected, arResult, "The interceptors with private method are not running in the correct order.");
 222    }
 223   
 224    /**
 225    * Verifies if interceptors are executed in order. All interceptors have a
 226    * protected method that intercepts.
 227    * @input List with no values inside
 228    * @output List with 3 values, the value inserted by the method and the
 229    * value inserted by the interceptors.
 230    */
 231  2 @Test(groups = {"withInterceptor"})
 232    public void interceptorMethodTest07() {
 233    // The arrays used to know what is the interceptor order
 234  2 List<Integer> arResult = new ArrayList<Integer>();
 235  2 List<Integer> arExpected = new ArrayList<Integer>();
 236   
 237    // insert the value of the interceptor
 238  2 arExpected.add(ProtectedInterceptor.ORDER);
 239    // insert the value of the interceptor
 240  2 arExpected.add(ProtectedInterceptor.ORDER);
 241    // insert the value of the method
 242  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 243   
 244    // gets the result
 245  2 arResult = mtBean.withProtectedInterceptors(arResult);
 246   
 247    // compares the two values
 248  2 assertEquals(arExpected, arResult,
 249    "The interceptors with protected method are not running in the correct order.");
 250    }
 251   
 252    /**
 253    * Verifies if interceptors are executed in order. There is interceptors
 254    * with private, protected, and public method, also there is inheritance in
 255    * one interceptor(PrintOrder03Interceptor.class).
 256    * @input List with no values inside
 257    * @output List with 9 values, the value inserted by the method and the
 258    * value inserted by the interceptors.
 259    */
 260  2 @Test(groups = {"withInterceptor", "withInheritance"})
 261    public void interceptorMethodTest08() {
 262    // The arrays used to know what is the interceptor order
 263  2 List<Integer> arResult = new ArrayList<Integer>();
 264  2 List<Integer> arExpected = new ArrayList<Integer>();
 265   
 266    // insert the value of the interceptor
 267  2 arExpected.add(PrivateInterceptor.ORDER);
 268    // insert the value of the interceptor
 269  2 arExpected.add(ProtectedInterceptor.ORDER);
 270    // insert the value of the interceptor
 271  2 arExpected.add(PrintOrder01Interceptor.ORDER);
 272    // insert the value of the interceptor
 273  2 arExpected.add(PrivateInterceptor.ORDER);
 274    // insert the value of the interceptor
 275  2 arExpected.add(PrintOrder03Interceptor.ORDER);
 276    // insert the value of the interceptor
 277  2 arExpected.add(PrivateInterceptor.ORDER);
 278    // insert the value of the interceptor
 279  2 arExpected.add(ProtectedInterceptor.ORDER);
 280    // insert the value of the interceptor
 281  2 arExpected.add(ProtectedInterceptor.ORDER);
 282    // insert the value of the method
 283  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 284   
 285    // gets the result
 286  2 arResult = mtBean.withPrivateProtectedPublicInterceptors(arResult);
 287   
 288    // compares the two values
 289  2 assertEquals(arExpected, arResult, "The interceptors are not running in the correct order.");
 290    }
 291   
 292    /**
 293    * Verifies if interceptors are executed in order. There is interceptors
 294    * with package method modifier.
 295    * @input List with no values inside
 296    * @output List with 5 values, the value inserted by the method and the
 297    * value inserted by the interceptors.
 298    */
 299  2 @Test(groups = {"withInterceptor", "withInheritance"})
 300    public void interceptorMethodTest09() {
 301    // The arrays used to know what is the interceptor order
 302  2 List<Integer> arResult = new ArrayList<Integer>();
 303  2 List<Integer> arExpected = new ArrayList<Integer>();
 304   
 305    // insert the value of the interceptor
 306  2 arExpected.add(PackageInterceptor.ORDER);
 307    // insert the value of the interceptor
 308  2 arExpected.add(PackageInterceptor.ORDER);
 309    // insert the value of the interceptor
 310  2 arExpected.add(PackageInterceptor.ORDER);
 311    // insert the value of the interceptor
 312  2 arExpected.add(PackageInterceptor.ORDER);
 313   
 314    // insert the value of the method
 315  2 arExpected.add(SLSBMethodInterceptorTest.ORDER);
 316   
 317    // gets the result
 318  2 arResult = mtBean.withPackageInterceptors(arResult);
 319   
 320    // compares the two values
 321  2 assertEquals(arExpected, arResult, "The interceptors are not running in the correct order.");
 322    }
 323   
 324    /**
 325    * Sets bean used in the tests.
 326    * @param bean The bean to set.
 327    */
 328  18 public void setBean(final ItfMethodInterceptor<Integer> bean){
 329  18 this.mtBean = bean;
 330    }
 331    }