1   package org.apache.fulcrum.pool;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.fulcrum.testcontainer.BaseUnitTest;
23  
24  /**
25   * @author Eric Pugh
26   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
27   *
28   * To change the template for this generated type comment go to
29   * Window>Preferences>Java>Code Generation>Code and Comments
30   */
31  public class PoolServiceTest extends BaseUnitTest
32  {
33      private PoolService poolService = null;
34      /**
35      	* Defines the testcase name for JUnit.
36      	*
37      	* @param name the testcase's name.
38      	*/
39      public PoolServiceTest(String name)
40      {
41          super(name);
42      }
43  
44      public void setUp() throws Exception
45      {
46          super.setUp();
47  
48          poolService = (PoolService) this.resolve( PoolService.class.getName() );
49      }
50  
51      /*
52       * Class to test for Object getInstance(Class)
53       */
54      public void testGetInstanceClass() throws PoolException
55      {
56          Object object = poolService.getInstance(StringBuffer.class);
57          assertTrue(object instanceof StringBuffer);
58  
59      }
60  
61      public void testPutInstance()
62      {
63          String s = "I am a string";
64          assertEquals(0, poolService.getSize("java.lang.String"));
65          poolService.putInstance(s);
66          assertEquals(1, poolService.getSize("java.lang.String"));
67  
68      }
69      public void testGetSetCapacity()
70      {
71          assertEquals(128, poolService.getCapacity("java.lang.String"));
72          poolService.setCapacity("java.lang.String", 278);
73          assertEquals(278, poolService.getCapacity("java.lang.String"));
74  
75      }
76      public void testGetSize()
77      {
78          String s = "I am a string";
79          assertEquals(0, poolService.getSize("java.lang.String"));
80          poolService.putInstance(s);
81          assertEquals(1, poolService.getSize("java.lang.String"));
82  
83      }
84      /*
85       * Class to test for void clearPool(String)
86       */
87      public void testClearPoolString()
88      {
89          String s = "I am a string";
90          assertEquals(0, poolService.getSize("java.lang.String"));
91          poolService.putInstance(s);
92          assertEquals(1, poolService.getSize("java.lang.String"));
93          poolService.clearPool("java.lang.String");
94          assertEquals(0, poolService.getSize("java.lang.String"));
95  
96      }
97      /*
98       * Class to test for void clearPool()
99       */
100     public void testClearPool()
101     {
102         String s = "I am a string";
103         assertEquals(0, poolService.getSize("java.lang.String"));
104         poolService.putInstance(s);
105         poolService.putInstance(new Double(32));
106         assertEquals(1, poolService.getSize("java.lang.String"));
107         poolService.clearPool();
108         assertEquals(0, poolService.getSize("java.lang.String"));
109         assertEquals(0, poolService.getSize("java.lang.Double"));
110 
111     }
112 }