Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: hivemind/test/FrameworkTestCase.java


1   // Copyright 2004, 2005 The Apache Software Foundation
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package hivemind.test;
16  
17  import org.apache.hivemind.ClassResolver;
18  import org.apache.hivemind.Resource;
19  import org.apache.hivemind.impl.DefaultClassResolver;
20  import org.apache.hivemind.impl.DefaultErrorHandler;
21  import org.apache.hivemind.parse.ConfigurationPointDescriptor;
22  import org.apache.hivemind.parse.DependencyDescriptor;
23  import org.apache.hivemind.parse.ModuleDescriptor;
24  import org.apache.hivemind.parse.ServicePointDescriptor;
25  import org.apache.hivemind.parse.XmlResourceProcessor;
26  import org.apache.hivemind.test.HiveMindTestCase;
27  
28  /**
29   * Base class for framework tests.
30   * 
31   * @author Howard Lewis Ship
32   */
33  public abstract class FrameworkTestCase extends HiveMindTestCase
34  {
35      protected ClassResolver _resolver = new DefaultClassResolver();
36  
37      private static final String PROJECT_ROOT = System.getProperty("PROJECT_ROOT", ".");
38  
39      protected String getFrameworkPath(String path)
40      {
41          return PROJECT_ROOT + "/framework/" + path;
42      }
43  
44      protected ModuleDescriptor parse(String file) throws Exception
45      {
46          Resource location = getResource(file);
47          DefaultErrorHandler eh = new DefaultErrorHandler();
48  
49          XmlResourceProcessor p = new XmlResourceProcessor(_resolver, eh);
50  
51          ModuleDescriptor result = p.processResource(location);
52  
53          return result;
54      }
55  
56      protected void interceptLogging()
57      {
58          interceptLogging("org.apache.hivemind");
59      }
60  
61      /**
62       * Convenience method for creating a {@link org.apache.hivemind.parse.ModuleDescriptor}.
63       */
64      protected ModuleDescriptor createModuleDescriptor(String moduleId, String version)
65      {
66          ModuleDescriptor result = new ModuleDescriptor(_resolver, new DefaultErrorHandler());
67  
68          result.setModuleId(moduleId);
69          result.setVersion(version);
70          result.setLocation(newLocation());
71  
72          return result;
73      }
74  
75      /**
76       * Convenience method for creating a {@link org.apache.hivemind.parse.DependencyDescriptor}.
77       */
78      protected DependencyDescriptor createDependencyDescriptor(String moduleId, String version)
79      {
80          DependencyDescriptor result = new DependencyDescriptor();
81  
82          result.setModuleId(moduleId);
83          result.setVersion(version);
84          result.setLocation(newLocation());
85  
86          return result;
87      }
88  
89      /**
90       * Convenience method for creating a {@link ServicePointDescriptor}.
91       */
92      protected ServicePointDescriptor createServicePointDescriptor(String pointId,
93              Class serviceInterface)
94      {
95          ServicePointDescriptor result = new ServicePointDescriptor();
96  
97          result.setId(pointId);
98          result.setInterfaceClassName(serviceInterface.getName());
99          result.setLocation(newLocation());
100 
101         return result;
102     }
103 
104     /**
105      * Convenience method for creating a {@link ConfigurationPointDescriptor}.
106      */
107     protected ConfigurationPointDescriptor createConfigurationPointDescriptor(String pointId)
108     {
109         ConfigurationPointDescriptor result = new ConfigurationPointDescriptor();
110 
111         result.setId(pointId);
112         result.setLocation(newLocation());
113 
114         return result;
115     }
116 }