KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > context > support > PerformanceMonitorListenerTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.context.support;
18
19 import java.io.FileNotFoundException JavaDoc;
20
21 import junit.framework.TestCase;
22
23 import org.springframework.context.event.ContextRefreshedEvent;
24 import org.springframework.context.support.StaticApplicationContext;
25
26 /**
27  * @author Alef Arendsen
28  */

29 public class PerformanceMonitorListenerTests extends TestCase {
30
31     public void testPerformanceMonitorListener() {
32         // well, constructing it...
33
PerformanceMonitorListener l = new PerformanceMonitorListener();
34         // ...done ;-)
35
}
36
37     public void testOnApplicationEvent() throws FileNotFoundException JavaDoc {
38         PerformanceMonitorListener l = new PerformanceMonitorListener();
39         l.onApplicationEvent(new ContextRefreshedEvent(new StaticApplicationContext()));
40         assertEquals(0, l.responseTimeMonitor.getAccessCount());
41         
42         RequestHandledEvent evt = new RequestHandledEvent(new Object JavaDoc(),
43             "http://www.springframework.org", 200, "192.168.1.122", "GET", "servlet");
44         l.onApplicationEvent(evt);
45         assertEquals(1, l.responseTimeMonitor.getAccessCount());
46         assertEquals(200, l.responseTimeMonitor.getAverageResponseTimeMillis());
47         assertEquals(200, l.responseTimeMonitor.getBestResponseTimeMillis());
48         assertEquals(200, l.responseTimeMonitor.getWorstResponseTimeMillis());
49     }
50
51 }
52
Popular Tags