KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tools > testrecorder > shared > PlaybackSessionBean


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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  * $Header:$
17  */

18
19 package org.apache.beehive.netui.tools.testrecorder.shared;
20
21 import java.util.List JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24
25 /**
26  * User: ozzy
27  * Date: Jun 15, 2004
28  * Time: 9:19:12 AM
29  */

30 public class PlaybackSessionBean extends RecordSessionBean {
31
32     private static final Logger log = Logger.getInstance( PlaybackSessionBean.class );
33
34     private int recordedTestCount = -1;
35     private int passedCount = 0;
36     private int failedCount = 0;
37     private List JavaDoc testResults;
38
39     public PlaybackSessionBean( String JavaDoc sessionName ) {
40         this( sessionName, false );
41     }
42
43     public PlaybackSessionBean( String JavaDoc sessionName, boolean error ) {
44         super( sessionName );
45         setError( error );
46         testResults = new ArrayList JavaDoc();
47     }
48
49     public int getRecordedTestCount() {
50         return recordedTestCount;
51     }
52
53     public void setRecordedTestCount( int recordedTestCount ) {
54         this.recordedTestCount = recordedTestCount;
55     }
56
57     public int getTestCount() {
58         return testResults.size();
59     }
60
61     public TestResults getTestResults( int index ) {
62         return (TestResults) testResults.get( index );
63     }
64
65     public List JavaDoc getTestResults() {
66         return Collections.unmodifiableList( testResults );
67     }
68
69     public void addTestResults( TestResults results ) {
70         if ( results.isTestPassed() ) {
71             incrementPassedCount();
72         }
73         else {
74             incrementFailedCount();
75         }
76         testResults.add( results );
77     }
78
79     public boolean isError() {
80         if ( error ) {
81             return error;
82         }
83         return isErrorInternal();
84     }
85
86     private boolean isErrorInternal() {
87         boolean rtnVal = false;
88         if ( getRecordedTestCount() < 1 ) {
89             if ( log.isDebugEnabled() ) {
90                 log.debug( "Invalid recorded test count(" + getRecordedTestCount() + ")" );
91             }
92             rtnVal = true;
93         }
94         else if ( ( getTestCount() ) != getRecordedTestCount() ) {
95             if ( log.isDebugEnabled() ) {
96                 log.debug( "executed count(" + getTestCount() + ") does not equal recorded test count(" +
97                         getRecordedTestCount() + ")" );
98             }
99             rtnVal = true;
100         }
101         return rtnVal;
102     }
103
104     public String JavaDoc getStatus() {
105         if ( isError() ) {
106             return Constants.ERROR;
107         }
108         if ( isSessionPassed() ) {
109             return Constants.PASS;
110         }
111         return Constants.FAIL;
112     }
113
114     public boolean isSessionPassed() {
115         if ( isError() ) {
116             return false;
117         }
118         if ( passedCount != getRecordedTestCount() ) {
119             return false;
120         }
121         return true;
122     }
123
124     public int incrementPassedCount() {
125         return ++passedCount;
126     }
127
128     public int getPassedCount() {
129         return passedCount;
130     }
131
132     public int incrementFailedCount() {
133         return ++failedCount;
134     }
135
136     public int getFailedCount() {
137         return failedCount;
138     }
139
140 }
141
Popular Tags