KickJava   Java API By Example, From Geeks To Geeks.

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


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.config;
20
21 import org.apache.beehive.netui.tools.testrecorder.shared.util.StringHelper;
22
23 import java.util.Map JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collections JavaDoc;
28
29 /**
30  * User: ozzy
31  * Date: Apr 9, 2004
32  * Time: 2:36:12 PM
33  */

34 public class TestDefinitions {
35
36     private List JavaDoc testDefinitions;
37     private Categories categories;
38     private Webapps webapps;
39     // test name -> TestDefinition
40
private Map JavaDoc testsByNameMap;
41     // webapp name -> List of TestDefinition objects
42
private Map JavaDoc testsByWebappMap;
43
44     public TestDefinitions( List JavaDoc testDefinitions, Categories categories, Webapps webapps ) {
45         this.testDefinitions = testDefinitions;
46         this.categories = categories;
47         this.webapps = webapps;
48         testsByNameMap = new HashMap JavaDoc();
49         testsByWebappMap = new HashMap JavaDoc();
50         init();
51     }
52
53     private void init() {
54         TestDefinition testDefinition = null;
55         for ( int i = 0; i < testDefinitions.size(); i++ ) {
56             testDefinition = (TestDefinition) testDefinitions.get(i);
57             addToMap( testDefinition );
58         }
59     }
60
61     private void addToMap( TestDefinition test ) {
62         getTestsByNameMap().put( test.getName(), test );
63         List JavaDoc list = (List JavaDoc) getTestsByWebappMap().get( test.getWebapp().getName() );
64         if ( list == null ) {
65             list = new ArrayList JavaDoc();
66             getTestsByWebappMap().put( test.getWebapp().getName(), list );
67         }
68         list.add( test );
69     }
70
71     public void add( TestDefinition test ) {
72         WebappConfig webapp = test.getWebapp();
73         WebappConfig temp = webapps.getWebapp( webapp.getName() );
74         if ( temp == null || temp != webapp ) {
75             throw new RuntimeConfigException( "ERROR: webapp does not exist in this set of definitions, webapp( " +
76                     webapp + " ), found match( " + temp + " )");
77         }
78         testDefinitions.add( test );
79         addToMap( test );
80     }
81
82     public List JavaDoc getTestDefinitions() {
83         return Collections.unmodifiableList( testDefinitions );
84     }
85
86     public Categories getCategories() {
87         return categories;
88     }
89
90     public Webapps getWebapps() {
91         return webapps;
92     }
93
94     public TestDefinition getTest( String JavaDoc name ) {
95         return (TestDefinition) getTestsByNameMap().get( name );
96     }
97
98     public List JavaDoc getTestList( String JavaDoc webappName ) {
99         return (List JavaDoc) getTestsByWebappMap().get( webappName );
100     }
101
102     private Map JavaDoc getTestsByWebappMap() {
103         return testsByWebappMap;
104     }
105
106     private Map JavaDoc getTestsByNameMap() {
107         return testsByNameMap;
108     }
109
110     public String JavaDoc toString() {
111         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( 64 );
112         sb.append( "[ " );
113         sb.append( "tests( " + StringHelper.toString( getTestDefinitions(), "\n", "\n" ) + " )" );
114         sb.append( ",\ncategories( " + categories + " )" );
115         sb.append( " ]" );
116         return sb.toString();
117     }
118
119 }
120
Popular Tags