KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > components > util > verifier > VerifierTestCase


1 /*
2  * Copyright (C) The Loom Group. All rights reserved.
3  *
4  * This software is published under the terms of the Loom
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.loom.components.util.verifier;
9
10 import junit.framework.TestCase;
11 import org.codehaus.dna.impl.ConsoleLogger;
12 import org.codehaus.loom.components.assembler.data.Component1;
13 import org.codehaus.loom.components.assembler.data.Component2;
14 import org.codehaus.loom.components.assembler.data.Component3;
15 import org.codehaus.loom.components.assembler.data.Service1;
16 import org.codehaus.loom.components.util.info.ComponentInfo;
17 import org.codehaus.loom.components.util.info.DependencyDescriptor;
18 import org.codehaus.loom.components.util.info.ServiceDescriptor;
19 import org.codehaus.loom.components.util.metadata.ComponentTemplate;
20 import org.codehaus.loom.components.util.metadata.DependencyDirective;
21 import org.codehaus.loom.components.util.metadata.PartitionTemplate;
22 import org.codehaus.loom.components.util.profile.ComponentProfile;
23 import org.codehaus.loom.components.util.profile.PartitionProfile;
24 import org.codehaus.loom.components.util.verifier.SarVerifier;
25 import org.codehaus.loom.interfaces.ContainerConstants;
26
27 /**
28  * An basic test case for the LogManager.
29  *
30  * @author Peter Donald
31  * @version $Revision: 1.2 $ $Date: 2004/05/01 12:48:35 $
32  */

33 public class VerifierTestCase
34     extends TestCase
35 {
36     public void testBasic()
37         throws Exception JavaDoc
38     {
39         final DependencyDirective dependency =
40             new DependencyDirective( Service1.class.getName(),
41                                      "c2",
42                                      Service1.class.getName() );
43         final ComponentTemplate c1MetaData =
44             new ComponentTemplate( "c1",
45                                    Component1.class.getName(),
46                                    new DependencyDirective[]{dependency},
47                                    null,
48                                    null,
49                                    false );
50         final ComponentTemplate c2MetaData =
51             new ComponentTemplate( "c2",
52                                    Component2.class.getName(),
53                                    DependencyDirective.EMPTY_SET,
54                                    null,
55                                    null,
56                                    false );
57         final PartitionTemplate listenerMetaData =
58             new PartitionTemplate( ContainerConstants.LISTENER_PARTITION,
59                                    new String JavaDoc[ 0 ],
60                                    PartitionTemplate.EMPTY_SET,
61                                    ComponentTemplate.EMPTY_SET );
62         final PartitionTemplate blockMetaData =
63             new PartitionTemplate( ContainerConstants.BLOCK_PARTITION,
64                                    new String JavaDoc[]{
65                                        ContainerConstants.LISTENER_PARTITION},
66                                    PartitionTemplate.EMPTY_SET,
67                                    new ComponentTemplate[]{c1MetaData,
68                                                            c2MetaData} );
69         final PartitionTemplate metaData =
70             new PartitionTemplate( "assembly1",
71                                    new String JavaDoc[ 0 ],
72                                    new PartitionTemplate[]{blockMetaData,
73                                                            listenerMetaData},
74                                    ComponentTemplate.EMPTY_SET );
75         final ComponentInfo c1Info =
76             new ComponentInfo( Component1.class,
77                                ServiceDescriptor.EMPTY_SET,
78                                new DependencyDescriptor[]{
79                                    new DependencyDescriptor(
80                                        Service1.class.getName(),
81                                        Service1.class.getName(),
82                                        false )},
83                                null );
84         final ComponentInfo c2Info =
85             new ComponentInfo( Component2.class,
86                                new ServiceDescriptor[]{
87                                    new ServiceDescriptor(
88                                        Service1.class.getName() )},
89                                DependencyDescriptor.EMPTY_SET,
90                                null );
91         final ComponentProfile c1Profile =
92             new ComponentProfile( c1Info, c1MetaData );
93         final ComponentProfile c2Profile =
94             new ComponentProfile( c2Info, c2MetaData );
95         final PartitionProfile blockProfile =
96             new PartitionProfile( blockMetaData,
97                                   PartitionProfile.EMPTY_SET,
98                                   new ComponentProfile[]{c1Profile, c2Profile} );
99         final PartitionProfile listenerProfile =
100             new PartitionProfile( listenerMetaData,
101                                   PartitionProfile.EMPTY_SET,
102                                   ComponentProfile.EMPTY_SET );
103         final PartitionProfile profile =
104             new PartitionProfile( metaData,
105                                   new PartitionProfile[]{blockProfile,
106                                                          listenerProfile},
107                                   ComponentProfile.EMPTY_SET );
108         verify( profile );
109     }
110
111     public void testComplex()
112         throws Exception JavaDoc
113     {
114         final DependencyDirective dependency1 =
115             new DependencyDirective(
116                 Service1.class.getName() + DependencyDescriptor.ARRAY_POSTFIX,
117                 "c2a",
118                 Service1.class.getName() );
119         final DependencyDirective dependency2 =
120             new DependencyDirective(
121                 Service1.class.getName() + DependencyDescriptor.ARRAY_POSTFIX,
122                 "c2b",
123                 Service1.class.getName() );
124         final DependencyDirective dependency3 =
125             new DependencyDirective(
126                 Service1.class.getName() + DependencyDescriptor.ARRAY_POSTFIX,
127                 "c2c",
128                 Service1.class.getName() );
129         final ComponentTemplate c3MetaData =
130             new ComponentTemplate( "c3",
131                                    Component3.class.getName(),
132                                    new DependencyDirective[]{dependency1,
133                                                              dependency2,
134                                                              dependency3},
135                                    null,
136                                    null,
137                                    false );
138         final ComponentTemplate c2aMetaData =
139             new ComponentTemplate( "c2a",
140                                    Component2.class.getName(),
141                                    DependencyDirective.EMPTY_SET,
142                                    null,
143                                    null,
144                                    false );
145         final ComponentTemplate c2bMetaData =
146             new ComponentTemplate( "c2b",
147                                    Component2.class.getName(),
148                                    DependencyDirective.EMPTY_SET,
149                                    null,
150                                    null,
151                                    false );
152         final ComponentTemplate c2cMetaData =
153             new ComponentTemplate( "c2c",
154                                    Component2.class.getName(),
155                                    DependencyDirective.EMPTY_SET,
156                                    null,
157                                    null,
158                                    false );
159         final PartitionTemplate listenerMetaData =
160             new PartitionTemplate( ContainerConstants.LISTENER_PARTITION,
161                                    new String JavaDoc[ 0 ],
162                                    PartitionTemplate.EMPTY_SET,
163                                    ComponentTemplate.EMPTY_SET );
164         final PartitionTemplate blockMetaData =
165             new PartitionTemplate( ContainerConstants.BLOCK_PARTITION,
166                                    new String JavaDoc[]{
167                                        ContainerConstants.LISTENER_PARTITION},
168                                    PartitionTemplate.EMPTY_SET,
169                                    new ComponentTemplate[]{c2aMetaData,
170                                                            c2bMetaData,
171                                                            c2cMetaData,
172                                                            c3MetaData} );
173         final PartitionTemplate metaData =
174             new PartitionTemplate( "assembly1",
175                                    new String JavaDoc[ 0 ],
176                                    new PartitionTemplate[]{blockMetaData,
177                                                            listenerMetaData},
178                                    ComponentTemplate.EMPTY_SET );
179
180         final ComponentInfo c3Info =
181             new ComponentInfo( Component3.class,
182                                ServiceDescriptor.EMPTY_SET,
183                                new DependencyDescriptor[]{
184                                    new DependencyDescriptor(
185                                        Service1.class.getName() +
186                                        DependencyDescriptor.ARRAY_POSTFIX,
187                                        Service1.class.getName() +
188                                        DependencyDescriptor.ARRAY_POSTFIX,
189                                        false )},
190                                null );
191         final ComponentInfo c2Info =
192             new ComponentInfo( Component2.class,
193                                new ServiceDescriptor[]{
194                                    new ServiceDescriptor(
195                                        Service1.class.getName() )},
196                                DependencyDescriptor.EMPTY_SET,
197                                null );
198         final ComponentProfile c3Profile =
199             new ComponentProfile( c3Info, c3MetaData );
200         final ComponentProfile c2aProfile =
201             new ComponentProfile( c2Info, c2aMetaData );
202         final ComponentProfile c2bProfile =
203             new ComponentProfile( c2Info, c2bMetaData );
204         final ComponentProfile c2cProfile =
205             new ComponentProfile( c2Info, c2cMetaData );
206         final PartitionProfile blockProfile =
207             new PartitionProfile( blockMetaData,
208                                   PartitionProfile.EMPTY_SET,
209                                   new ComponentProfile[]{c3Profile,
210                                                          c2aProfile,
211                                                          c2bProfile,
212                                                          c2cProfile} );
213         final PartitionProfile listenerProfile =
214             new PartitionProfile( listenerMetaData,
215                                   PartitionProfile.EMPTY_SET,
216                                   ComponentProfile.EMPTY_SET );
217         final PartitionProfile profile =
218             new PartitionProfile( metaData,
219                                   new PartitionProfile[]{blockProfile,
220                                                          listenerProfile},
221                                   ComponentProfile.EMPTY_SET );
222         verify( profile );
223     }
224
225     private void verify( final PartitionProfile profile )
226         throws Exception JavaDoc
227     {
228         final ClassLoader JavaDoc classLoader = getClass().getClassLoader();
229         final SarVerifier verifier = new SarVerifier();
230         verifier.enableLogging( new ConsoleLogger() );
231         verifier.verifySar( profile, classLoader );
232     }
233 }
234
Popular Tags