1 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 ; 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 import java.util.Collections ; 28 29 34 public class TestDefinitions { 35 36 private List testDefinitions; 37 private Categories categories; 38 private Webapps webapps; 39 private Map testsByNameMap; 41 private Map testsByWebappMap; 43 44 public TestDefinitions( List testDefinitions, Categories categories, Webapps webapps ) { 45 this.testDefinitions = testDefinitions; 46 this.categories = categories; 47 this.webapps = webapps; 48 testsByNameMap = new HashMap (); 49 testsByWebappMap = new HashMap (); 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 list = (List ) getTestsByWebappMap().get( test.getWebapp().getName() ); 64 if ( list == null ) { 65 list = new ArrayList (); 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 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 name ) { 95 return (TestDefinition) getTestsByNameMap().get( name ); 96 } 97 98 public List getTestList( String webappName ) { 99 return (List ) getTestsByWebappMap().get( webappName ); 100 } 101 102 private Map getTestsByWebappMap() { 103 return testsByWebappMap; 104 } 105 106 private Map getTestsByNameMap() { 107 return testsByNameMap; 108 } 109 110 public String toString() { 111 StringBuffer sb = new StringBuffer ( 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 |