KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > xml > XmlTestCase


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 org.apache.hivemind.xml;
16
17 import java.util.Locale JavaDoc;
18
19 import hivemind.test.FrameworkTestCase;
20
21 import org.apache.hivemind.ClassResolver;
22 import org.apache.hivemind.Registry;
23 import org.apache.hivemind.Resource;
24 import org.apache.hivemind.impl.DefaultErrorHandler;
25 import org.apache.hivemind.impl.RegistryBuilder;
26 import org.apache.hivemind.parse.DependencyDescriptor;
27 import org.apache.hivemind.parse.ModuleDescriptor;
28 import org.apache.hivemind.parse.XmlResourceProcessor;
29 import org.apache.hivemind.test.HiveMindTestCase;
30
31 /**
32  * Base class for xml specific tests.
33  *
34  * @author Achim Huegen
35  */

36 public abstract class XmlTestCase extends FrameworkTestCase
37 {
38     /**
39      * Convienience method for invoking {@link #buildFrameworkRegistry(String[])} with only a single
40      * file.
41      */

42     protected Registry buildFrameworkRegistry(String JavaDoc file) throws Exception JavaDoc
43     {
44         return buildFrameworkRegistry(new String JavaDoc[]
45         { file });
46     }
47
48     /**
49      * Builds a minimal registry, containing only the specified files, plus the master module
50      * descriptor (i.e., those visible on the classpath). Files are resolved using
51      * {@link HiveMindTestCase#getResource(String)}.
52      */

53     protected Registry buildFrameworkRegistry(String JavaDoc[] files) throws Exception JavaDoc
54     {
55         ClassResolver resolver = getClassResolver();
56         
57         RegistryBuilder builder = new RegistryBuilder();
58         builder.autoDetectModules();
59
60         for (int i = 0; i < files.length; i++)
61         {
62             Resource resource = getResource(files[i]);
63
64             org.apache.hivemind.impl.XmlModuleReader reader = new org.apache.hivemind.impl.XmlModuleReader(builder.getRegistryDefinition(),
65                     resolver, builder.getErrorHandler());
66             reader.readModule(resource);
67         }
68
69         return builder.constructRegistry(Locale.getDefault());
70     }
71     
72     protected ModuleDescriptor parse(String JavaDoc file)
73         throws Exception JavaDoc
74     {
75         Resource location = getResource(file);
76         DefaultErrorHandler eh = new DefaultErrorHandler();
77
78         XmlResourceProcessor p = new XmlResourceProcessor(_resolver, eh);
79
80         ModuleDescriptor result = p.processResource(location);
81
82         return result;
83     }
84
85     /**
86      * Convenience method for creating a
87      * {@link org.apache.hivemind.parse.DependencyDescriptor}.
88      */

89     protected DependencyDescriptor createDependencyDescriptor(String JavaDoc moduleId, String JavaDoc version)
90     {
91         DependencyDescriptor result = new DependencyDescriptor();
92
93         result.setModuleId(moduleId);
94         result.setVersion(version);
95         result.setLocation(newLocation());
96
97         return result;
98     }
99
100 }
101
Popular Tags