Clover Coverage Report - Commons BeanUtils 1.8.3-kuali-SNAPSHOT
Coverage timestamp: Thu Jun 9 2011 11:19:33 MST
83   267   22   11.86
30   146   0.27   7
7     3.14  
1    
 
  PropertyUtilsBenchCase       Line # 34 83 0% 22 120 0% 0.0
 
No Tests
 
1    /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10    *
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   
18   
19    package org.apache.commons.beanutils;
20   
21   
22    import java.util.HashMap;
23    import java.util.Iterator;
24    import java.util.Map;
25    import junit.framework.TestCase;
26    import junit.framework.Test;
27    import junit.framework.TestSuite;
28   
29   
30    /**
31    * JUnit Test Case containing microbenchmarks for PropertyUtils.
32    */
33   
 
34    public class PropertyUtilsBenchCase extends TestCase {
35   
36   
37    // ------------------------------------------------------------ Constructors
38   
39   
40    /**
41    * Construct a new instance of this test case.
42    *
43    * @param name Name of the test case
44    */
 
45  0 toggle public PropertyUtilsBenchCase(String name) {
46   
47  0 super(name);
48   
49    }
50   
51   
52    // ------------------------------------------------------ Instance Variables
53   
54   
55    // Basic loop counter
56    private long counter = 100000;
57   
58    // DynaClass for inDyna and outDyna
59    private DynaClass dynaClass = null;
60   
61    // Input objects that have identical sets of properties and values.
62    private BenchBean inBean = null;
63    private DynaBean inDyna = null;
64    private Map inMap = null;
65   
66    // Output objects that have identical sets of properties.
67    private BenchBean outBean = null;
68    private DynaBean outDyna = null;
69   
70    // PropertyUtilsBean instance to be used
71    private PropertyUtilsBean pu = null;
72   
73   
74    // ---------------------------------------------------- Overall Test Methods
75   
76   
77    /**
78    * Set up instance variables required by this test case.
79    */
 
80  0 toggle public void setUp() throws Exception {
81   
82    // Set up loop counter (if property specified)
83  0 String prop = System.getProperty("counter");
84  0 if (prop != null) {
85  0 counter = Long.parseLong(prop);
86    }
87   
88    // Set up DynaClass for our DynaBean instances
89  0 dynaClass = new BasicDynaClass
90    ("BenchDynaClass", null,
91    new DynaProperty[]{
92    new DynaProperty("booleanProperty", Boolean.TYPE),
93    new DynaProperty("byteProperty", Byte.TYPE),
94    new DynaProperty("doubleProperty", Double.TYPE),
95    new DynaProperty("floatProperty", Float.TYPE),
96    new DynaProperty("intProperty", Integer.TYPE),
97    new DynaProperty("longProperty", Long.TYPE),
98    new DynaProperty("shortProperty", Short.TYPE),
99    new DynaProperty("stringProperty", String.class),
100    });
101   
102    // Create input instances
103  0 inBean = new BenchBean();
104  0 inMap = new HashMap();
105  0 inMap.put("booleanProperty", new Boolean(inBean.getBooleanProperty()));
106  0 inMap.put("byteProperty", new Byte(inBean.getByteProperty()));
107  0 inMap.put("doubleProperty", new Double(inBean.getDoubleProperty()));
108  0 inMap.put("floatProperty", new Float(inBean.getFloatProperty()));
109  0 inMap.put("intProperty", new Integer(inBean.getIntProperty()));
110  0 inMap.put("longProperty", new Long(inBean.getLongProperty()));
111  0 inMap.put("shortProperty", new Short(inBean.getShortProperty()));
112  0 inMap.put("stringProperty", inBean.getStringProperty());
113  0 inDyna = dynaClass.newInstance();
114  0 Iterator inKeys = inMap.keySet().iterator();
115  0 while (inKeys.hasNext()) {
116  0 String inKey = (String) inKeys.next();
117  0 inDyna.set(inKey, inMap.get(inKey));
118    }
119   
120    // Create output instances
121  0 outBean = new BenchBean();
122  0 outDyna = dynaClass.newInstance();
123  0 Iterator outKeys = inMap.keySet().iterator();
124  0 while (outKeys.hasNext()) {
125  0 String outKey = (String) outKeys.next();
126  0 outDyna.set(outKey, inMap.get(outKey));
127    }
128   
129    // Set up PropertyUtilsBean instance we will use
130  0 pu = PropertyUtilsBean.getInstance();
131   
132    }
133   
134   
135    /**
136    * Return the tests included in this test suite.
137    */
 
138  0 toggle public static Test suite() {
139   
140  0 return (new TestSuite(PropertyUtilsBenchCase.class));
141   
142    }
143   
144   
145    /**
146    * Tear down instance variables required by this test case.
147    */
 
148  0 toggle public void tearDown() {
149   
150  0 dynaClass = null;
151  0 inBean = null;
152  0 inDyna = null;
153  0 inMap = null;
154  0 outBean = null;
155  0 outDyna = null;
156  0 pu = null;
157   
158    }
159   
160   
161   
162    // ------------------------------------------------- Individual Test Methods
163   
164   
165    // Time copyProperties() from a bean
 
166  0 toggle public void testCopyPropertiesBean() throws Exception {
167   
168  0 long start;
169  0 long stop;
170   
171    // Bean->Bean
172  0 for (long i = 0; i < counter; i++) {
173  0 pu.copyProperties(outBean, inBean);
174    }
175  0 start = System.currentTimeMillis();
176  0 for (long i = 0; i < counter; i++) {
177  0 pu.copyProperties(outBean, inBean);
178    }
179  0 stop = System.currentTimeMillis();
180  0 System.err.println("PU.copyProperties(bean,bean), count=" + counter +
181    ", time=" + (stop - start));
182   
183    // Bean->Dyna
184  0 for (long i = 0; i < counter; i++) {
185  0 pu.copyProperties(outDyna, inBean);
186    }
187  0 start = System.currentTimeMillis();
188  0 for (long i = 0; i < counter; i++) {
189  0 pu.copyProperties(outDyna, inBean);
190    }
191  0 stop = System.currentTimeMillis();
192  0 System.err.println("PU.copyProperties(dyna,bean), count=" + counter +
193    ", time=" + (stop - start));
194   
195    }
196   
197   
198    // Time copyProperties() from a DynaBean
 
199  0 toggle public void testCopyPropertiesDyna() throws Exception {
200   
201  0 long start;
202  0 long stop;
203   
204    // Dyna->Bean
205  0 for (long i = 0; i < counter; i++) {
206  0 pu.copyProperties(outBean, inDyna);
207    }
208  0 start = System.currentTimeMillis();
209  0 for (long i = 0; i < counter; i++) {
210  0 pu.copyProperties(outBean, inDyna);
211    }
212  0 stop = System.currentTimeMillis();
213  0 System.err.println("PU.copyProperties(bean,dyna), count=" + counter +
214    ", time=" + (stop - start));
215   
216    // Dyna->Dyna
217  0 for (long i = 0; i < counter; i++) {
218  0 pu.copyProperties(outDyna, inDyna);
219    }
220  0 start = System.currentTimeMillis();
221  0 for (long i = 0; i < counter; i++) {
222  0 pu.copyProperties(outDyna, inDyna);
223    }
224  0 stop = System.currentTimeMillis();
225  0 System.err.println("PU.copyProperties(dyna,dyna), count=" + counter +
226    ", time=" + (stop - start));
227   
228    }
229   
230   
231    // Time copyProperties() from a Map
 
232  0 toggle public void testCopyPropertiesMap() throws Exception {
233   
234  0 long start;
235  0 long stop;
236   
237    // Dyna->Bean
238  0 for (long i = 0; i < counter; i++) {
239  0 pu.copyProperties(outBean, inMap);
240    }
241  0 start = System.currentTimeMillis();
242  0 for (long i = 0; i < counter; i++) {
243  0 pu.copyProperties(outBean, inMap);
244    }
245  0 stop = System.currentTimeMillis();
246  0 System.err.println("PU.copyProperties(bean, map), count=" + counter +
247    ", time=" + (stop - start));
248   
249    // Dyna->Dyna
250  0 for (long i = 0; i < counter; i++) {
251  0 pu.copyProperties(outDyna, inMap);
252    }
253  0 start = System.currentTimeMillis();
254  0 for (long i = 0; i < counter; i++) {
255  0 pu.copyProperties(outDyna, inMap);
256    }
257  0 stop = System.currentTimeMillis();
258  0 System.err.println("PU.copyProperties(dyna, map), count=" + counter +
259    ", time=" + (stop - start));
260   
261    }
262   
263   
264    // --------------------------------------------------------- Support Methods
265   
266   
267    }