KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > FrameworkTestCase


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 java.net.URL JavaDoc;
18 import java.util.ArrayList JavaDoc;
19
20 import org.apache.hivemind.ClassResolver;
21 import org.apache.hivemind.definition.ConfigurationPointDefinition;
22 import org.apache.hivemind.definition.ModuleDefinition;
23 import org.apache.hivemind.definition.Occurances;
24 import org.apache.hivemind.definition.ImplementationDefinition;
25 import org.apache.hivemind.definition.Visibility;
26 import org.apache.hivemind.definition.impl.ConfigurationPointDefinitionImpl;
27 import org.apache.hivemind.definition.impl.ModuleDefinitionImpl;
28 import org.apache.hivemind.definition.impl.ImplementationDefinitionImpl;
29 import org.apache.hivemind.definition.impl.ServicePointDefinitionImpl;
30 import org.apache.hivemind.impl.CreateClassServiceConstructor;
31 import org.apache.hivemind.impl.DefaultClassResolver;
32 import org.apache.hivemind.test.HiveMindTestCase;
33
34 /**
35  * Base class for framework tests.
36  *
37  * @author Howard Lewis Ship
38  */

39 public abstract class FrameworkTestCase extends HiveMindTestCase
40 {
41
42     protected ClassResolver _resolver = new DefaultClassResolver();
43
44     /** Returns a filesystem path to a resource within the classpath. */
45     protected String JavaDoc getFrameworkPath(String JavaDoc path)
46     {
47         URL JavaDoc url = getClass().getResource(path);
48
49         String JavaDoc protocol = url.getProtocol();
50
51         if (!protocol.equals("file"))
52             throw new RuntimeException JavaDoc("Classpath resource " + path
53                     + " is not stored on the filesystem. It is available as " + url);
54
55         return url.getPath();
56     }
57
58     protected void interceptLogging()
59     {
60         interceptLogging("org.apache.hivemind");
61     }
62
63     /**
64      * Convenience method for creating a {@link ModuleDefinitionImpl}.
65      */

66     protected ModuleDefinitionImpl createModuleDefinition(String JavaDoc moduleId)
67     {
68         ModuleDefinitionImpl result = new ModuleDefinitionImpl(moduleId, newLocation(),
69                 getClassResolver(), "");
70
71         return result;
72     }
73
74     /**
75      * Convenience method for creating a {@link ServicePointDefinitionImpl}.
76      */

77     protected ServicePointDefinitionImpl createServicePointDefinition(ModuleDefinition module, String JavaDoc pointId, Class JavaDoc serviceInterface)
78     {
79         ServicePointDefinitionImpl result = new ServicePointDefinitionImpl(module, pointId,
80                 newLocation(), Visibility.PUBLIC, serviceInterface.getName());
81
82         return result;
83     }
84     
85     /**
86      * Convenience method for creating a {@link ImplementationDefinition}.
87      */

88     protected ImplementationDefinition createServiceImplementationDefinition(ModuleDefinition module, Class JavaDoc serviceImplementationClass)
89     {
90         ImplementationDefinition result = new ImplementationDefinitionImpl(module, newLocation(),
91                 new CreateClassServiceConstructor(newLocation(), serviceImplementationClass.getName()),
92                 "singleton", true);
93
94         return result;
95     }
96
97     /**
98      * Convenience method for creating a {@link ConfigurationPointDefinition}.
99      */

100     protected ConfigurationPointDefinition createConfigurationPointDefinition(ModuleDefinition module, String JavaDoc pointId)
101     {
102         ConfigurationPointDefinitionImpl result = new ConfigurationPointDefinitionImpl(module, pointId,
103                 newLocation(), Visibility.PUBLIC, ArrayList JavaDoc.class.getName(),
104                 Occurances.UNBOUNDED);
105
106         return result;
107     }
108 }
109
Popular Tags