| 
  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TestServiceLocator | Line # 34 | 12 | 0% | 2 | 1 | 92.3% | 
0.9230769
 | 
                
                                    ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (1) | |||
| Result | |||
| 
            0.9230769
                         | 
        
            org.perfectjpattern.jee.business.servicelocator.TestServiceLocator.testServiceLocator
             
            org.perfectjpattern.jee.business.servicelocator.TestServiceLocator.testServiceLocator
         | 
        1 PASS | |
| 1 | //---------------------------------------------------------------------- | |
| 2 | // | |
| 3 | // PerfectJPattern: "Design patterns are good but components are better!" | |
| 4 | // TestServiceLocator.java Copyright (c) 2009 Giovanni Azua Garcia | |
| 5 | // bravegag@hotmail.com | |
| 6 | // | |
| 7 | // This program is free software; you can redistribute it and/or | |
| 8 | // modify it under the terms of the GNU General Public License | |
| 9 | // as published by the Free Software Foundation; either version 3 | |
| 10 | // of the License, or (at your option) any later version. | |
| 11 | // | |
| 12 | // This program is distributed in the hope that it will be useful, | |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | // GNU General Public License for more details. | |
| 16 | // | |
| 17 | // You should have received a copy of the GNU General Public License | |
| 18 | // along with this program; if not, see <http://www.gnu.org/licenses/>. | |
| 19 | // | |
| 20 | //---------------------------------------------------------------------- | |
| 21 | package org.perfectjpattern.jee.business.servicelocator; | |
| 22 | ||
| 23 | import junit.framework.*; | |
| 24 | ||
| 25 | import org.perfectjpattern.jee.api.business.servicelocator.*; | |
| 26 | ||
| 27 | /** | |
| 28 | * Test suite for the {@link ServiceLocator} implementation | |
| 29 | * | |
| 30 | * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a> | |
| 31 | * @version $Revision: 1.0 $Date: Feb 9, 2009 8:20:48 PM $ | |
| 32 | */ | |
| 33 | public | |
| 34 | class TestServiceLocator | |
| 35 | extends TestCase | |
| 36 | { | |
| 37 | //------------------------------------------------------------------------ | |
| 38 | // public | |
| 39 | //------------------------------------------------------------------------ | |
| 40 | 1 | 
         public void | 
| 41 | testServiceLocator() | |
| 42 | { | |
| 43 | 1 | System.setProperty("log4j.category.OpenEJB", "debug"); | 
| 44 | ||
| 45 | 1 | IServiceLocator myLocator = ServiceLocator.getInstance(); | 
| 46 | ||
| 47 | 1 | ICalculatorRemote myCalculator = myLocator.locate("CalculatorRemote"); | 
| 48 | 1 | assertNotNull("EJB lookup was unsuccessful", myCalculator); | 
| 49 | ||
| 50 | 1 | int myResult = myCalculator.sum(2, 3); | 
| 51 | 1 | assertEquals("EJB calculator call was unsuccessful", 5, myResult); | 
| 52 | ||
| 53 | // test the Service caching | |
| 54 | 1 | ICalculatorRemote myCached = myLocator.locate("CalculatorRemote"); | 
| 55 | 1 | assertSame("Service was not cached", myCalculator, myCached); | 
| 56 | ||
| 57 | // test trying to lookup a misspelled Service | |
| 58 | 1 | try | 
| 59 | { | |
| 60 | 1 | myCalculator = myLocator.locate("CalculatorRimote"); | 
| 61 | 0 | fail("ServiceLocatorException must be thrown requesting " + | 
| 62 | "unmatching services"); | |
| 63 | } | |
| 64 | catch (ServiceLocatorException anException) | |
| 65 | { | |
| 66 | // ok | |
| 67 | } | |
| 68 | ||
| 69 | 1 | myLocator.shutdown(); | 
| 70 | } | |
| 71 | } | |
  | 
||||||||||||