KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > policy > PolicyComponentTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.policy;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.List JavaDoc;
22
23 import junit.framework.TestCase;
24
25 import org.alfresco.repo.dictionary.DictionaryBootstrap;
26 import org.alfresco.repo.dictionary.DictionaryComponent;
27 import org.alfresco.repo.dictionary.DictionaryDAOImpl;
28 import org.alfresco.repo.dictionary.NamespaceDAO;
29 import org.alfresco.repo.dictionary.NamespaceDAOImpl;
30 import org.alfresco.service.namespace.QName;
31
32
33 public class PolicyComponentTest extends TestCase
34 {
35     private static final String JavaDoc TEST_MODEL = "org/alfresco/repo/policy/policycomponenttest_model.xml";
36     private static final String JavaDoc TEST_NAMESPACE = "http://www.alfresco.org/test/policycomponenttest/1.0";
37     private static QName BASE_TYPE = QName.createQName(TEST_NAMESPACE, "base");
38     private static QName BASE_PROP_A = QName.createQName(TEST_NAMESPACE, "base_a");
39     private static QName BASE_ASSOC_A = QName.createQName(TEST_NAMESPACE, "base_assoc_a");
40     private static QName FILE_TYPE = QName.createQName(TEST_NAMESPACE, "file");
41     private static QName FILE_PROP_B = QName.createQName(TEST_NAMESPACE, "file_b");
42     private static QName FOLDER_TYPE = QName.createQName(TEST_NAMESPACE, "folder");
43     private static QName FOLDER_PROP_D = QName.createQName(TEST_NAMESPACE, "folder_d");
44     private static QName TEST_ASPECT = QName.createQName(TEST_NAMESPACE, "aspect");
45     private static QName ASPECT_PROP_A = QName.createQName(TEST_NAMESPACE, "aspect_a");
46     private static QName INVALID_TYPE = QName.createQName(TEST_NAMESPACE, "classdoesnotexist");
47
48     private PolicyComponent policyComponent = null;
49
50
51     @Override JavaDoc
52     protected void setUp() throws Exception JavaDoc
53     {
54         // Instantiate Dictionary Service
55
NamespaceDAO namespaceDAO = new NamespaceDAOImpl();
56         DictionaryDAOImpl dictionaryDAO = new DictionaryDAOImpl(namespaceDAO);
57         
58         DictionaryBootstrap bootstrap = new DictionaryBootstrap();
59         List JavaDoc<String JavaDoc> bootstrapModels = new ArrayList JavaDoc<String JavaDoc>();
60         bootstrapModels.add("alfresco/model/dictionaryModel.xml");
61         bootstrapModels.add("org/alfresco/repo/policy/policycomponenttest_model.xml");
62         bootstrapModels.add(TEST_MODEL);
63         bootstrap.setModels(bootstrapModels);
64         bootstrap.setDictionaryDAO(dictionaryDAO);
65         bootstrap.bootstrap();
66
67         DictionaryComponent dictionary = new DictionaryComponent();
68         dictionary.setDictionaryDAO(dictionaryDAO);
69
70         // Instantiate Policy Component
71
policyComponent = new PolicyComponentImpl(dictionary);
72     }
73
74
75     public void testJavaBehaviour()
76     {
77         Behaviour validBehaviour = new JavaBehaviour(this, "validTest");
78         TestClassPolicy policy = validBehaviour.getInterface(TestClassPolicy.class);
79         assertNotNull(policy);
80         String JavaDoc result = policy.test("argument");
81         assertEquals("ValidTest: argument", result);
82     }
83     
84     
85     @SuppressWarnings JavaDoc("unchecked")
86     public void testRegisterDefinitions()
87     {
88         try
89         {
90             @SuppressWarnings JavaDoc("unused") ClassPolicyDelegate<InvalidMetaDataPolicy> delegate = policyComponent.registerClassPolicy(InvalidMetaDataPolicy.class);
91             fail("Failed to catch hidden metadata");
92         }
93         catch(PolicyException e)
94         {
95         }
96     
97         try
98         {
99             @SuppressWarnings JavaDoc("unused") ClassPolicyDelegate<NoMethodPolicy> delegate = policyComponent.registerClassPolicy(NoMethodPolicy.class);
100             fail("Failed to catch no methods defined in policy");
101         }
102         catch(PolicyException e)
103         {
104         }
105
106         try
107         {
108             @SuppressWarnings JavaDoc("unused") ClassPolicyDelegate<MultiMethodPolicy> delegate = policyComponent.registerClassPolicy(MultiMethodPolicy.class);
109             fail("Failed to catch multiple methods defined in policy");
110         }
111         catch(PolicyException e)
112         {
113         }
114         
115         QName policyName = QName.createQName(TEST_NAMESPACE, "test");
116         boolean isRegistered = policyComponent.isRegisteredPolicy(PolicyType.Class, policyName);
117         assertFalse(isRegistered);
118         ClassPolicyDelegate<TestClassPolicy> delegate = policyComponent.registerClassPolicy(TestClassPolicy.class);
119         assertNotNull(delegate);
120         isRegistered = policyComponent.isRegisteredPolicy(PolicyType.Class, policyName);
121         assertTrue(isRegistered);
122         PolicyDefinition definition = policyComponent.getRegisteredPolicy(PolicyType.Class, policyName);
123         assertNotNull(definition);
124         assertEquals(policyName, definition.getName());
125         assertEquals(PolicyType.Class, definition.getType());
126         assertEquals(TestClassPolicy.class, definition.getPolicyInterface());
127     }
128     
129     
130     public void testBindBehaviour()
131     {
132         QName policyName = QName.createQName(TEST_NAMESPACE, "test");
133         Behaviour validBehaviour = new JavaBehaviour(this, "validTest");
134         
135         // Test null policy
136
try
137         {
138             policyComponent.bindClassBehaviour(null, FILE_TYPE, validBehaviour);
139             fail("Failed to catch null policy whilst binding behaviour");
140         }
141         catch(IllegalArgumentException JavaDoc e) {}
142
143         // Test null Class Reference
144
try
145         {
146             policyComponent.bindClassBehaviour(policyName, null, validBehaviour);
147             fail("Failed to catch null class reference whilst binding behaviour");
148         }
149         catch(IllegalArgumentException JavaDoc e) {}
150
151         // Test invalid Class Reference
152
try
153         {
154             policyComponent.bindClassBehaviour(policyName, INVALID_TYPE, validBehaviour);
155             fail("Failed to catch invalid class reference whilst binding behaviour");
156         }
157         catch(IllegalArgumentException JavaDoc e) {}
158         
159         // Test null Behaviour
160
try
161         {
162             policyComponent.bindClassBehaviour(policyName, FILE_TYPE, null);
163             fail("Failed to catch null behaviour whilst binding behaviour");
164         }
165         catch(IllegalArgumentException JavaDoc e) {}
166
167         // Test invalid behaviour (for registered policy)
168
Behaviour invalidBehaviour = new JavaBehaviour(this, "methoddoesnotexist");
169         policyComponent.registerClassPolicy(TestClassPolicy.class);
170         try
171         {
172             policyComponent.bindClassBehaviour(policyName, FILE_TYPE, invalidBehaviour);
173             fail("Failed to catch invalid behaviour whilst binding behaviour");
174         }
175         catch(PolicyException e) {}
176         
177         // Test valid behaviour (for registered policy)
178
try
179         {
180             BehaviourDefinition<ClassBehaviourBinding> definition = policyComponent.bindClassBehaviour(policyName, FILE_TYPE, validBehaviour);
181             assertNotNull(definition);
182             assertEquals(policyName, definition.getPolicy());
183             assertEquals(FILE_TYPE, definition.getBinding().getClassQName());
184         }
185         catch(PolicyException e)
186         {
187             fail("Policy exception thrown for valid behaviour");
188         }
189     }
190
191
192     public void testClassDelegate()
193     {
194         // Register Policy
195
ClassPolicyDelegate<TestClassPolicy> delegate = policyComponent.registerClassPolicy(TestClassPolicy.class);
196         
197         // Bind Class Behaviour
198
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
199         Behaviour fileBehaviour = new JavaBehaviour(this, "fileTest");
200         policyComponent.bindClassBehaviour(policyName, FILE_TYPE, fileBehaviour);
201
202         // Test NOOP Policy delegate
203
Collection JavaDoc<TestClassPolicy> basePolicies = delegate.getList(BASE_TYPE);
204         assertNotNull(basePolicies);
205         assertTrue(basePolicies.size() == 0);
206         TestClassPolicy basePolicy = delegate.get(BASE_TYPE);
207         assertNotNull(basePolicy);
208         
209         // Test single Policy delegate
210
Collection JavaDoc<TestClassPolicy> filePolicies = delegate.getList(FILE_TYPE);
211         assertNotNull(filePolicies);
212         assertTrue(filePolicies.size() == 1);
213         TestClassPolicy filePolicy = delegate.get(FILE_TYPE);
214         assertNotNull(filePolicy);
215         assertEquals(filePolicies.iterator().next(), filePolicy);
216
217         // Bind Service Behaviour
218
Behaviour serviceBehaviour = new JavaBehaviour(this, "serviceTest");
219         policyComponent.bindClassBehaviour(policyName, this, serviceBehaviour);
220
221         // Test multi Policy delegate
222
Collection JavaDoc<TestClassPolicy> file2Policies = delegate.getList(FILE_TYPE);
223         assertNotNull(file2Policies);
224         assertTrue(file2Policies.size() == 2);
225         TestClassPolicy filePolicy2 = delegate.get(FILE_TYPE);
226         assertNotNull(filePolicy2);
227     }
228
229     
230     public void testClassOverride()
231     {
232         // Register Policy
233
ClassPolicyDelegate<TestClassPolicy> delegate = policyComponent.registerClassPolicy(TestClassPolicy.class);
234         
235         // Bind Behaviour
236
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
237         Behaviour baseBehaviour = new JavaBehaviour(this, "baseTest");
238         policyComponent.bindClassBehaviour(policyName, BASE_TYPE, baseBehaviour);
239         Behaviour folderBehaviour = new JavaBehaviour(this, "folderTest");
240         policyComponent.bindClassBehaviour(policyName, FOLDER_TYPE, folderBehaviour);
241
242         // Invoke Policies
243
TestClassPolicy basePolicy = delegate.get(BASE_TYPE);
244         String JavaDoc baseResult = basePolicy.test("base");
245         assertEquals("Base: base", baseResult);
246         TestClassPolicy filePolicy = delegate.get(FILE_TYPE);
247         String JavaDoc fileResult = filePolicy.test("file");
248         assertEquals("Base: file", fileResult);
249         TestClassPolicy folderPolicy = delegate.get(FOLDER_TYPE);
250         String JavaDoc folderResult = folderPolicy.test("folder");
251         assertEquals("Folder: folder", folderResult);
252     }
253     
254     
255     public void testClassCache()
256     {
257         // Register Policy
258
ClassPolicyDelegate<TestClassPolicy> delegate = policyComponent.registerClassPolicy(TestClassPolicy.class);
259         
260         // Bind Behaviour
261
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
262         Behaviour baseBehaviour = new JavaBehaviour(this, "baseTest");
263         policyComponent.bindClassBehaviour(policyName, BASE_TYPE, baseBehaviour);
264         Behaviour folderBehaviour = new JavaBehaviour(this, "folderTest");
265         policyComponent.bindClassBehaviour(policyName, FOLDER_TYPE, folderBehaviour);
266
267         // Invoke Policies
268
TestClassPolicy basePolicy = delegate.get(BASE_TYPE);
269         String JavaDoc baseResult = basePolicy.test("base");
270         assertEquals("Base: base", baseResult);
271         TestClassPolicy filePolicy = delegate.get(FILE_TYPE);
272         String JavaDoc fileResult = filePolicy.test("file");
273         assertEquals("Base: file", fileResult);
274         TestClassPolicy folderPolicy = delegate.get(FOLDER_TYPE);
275         String JavaDoc folderResult = folderPolicy.test("folder");
276         assertEquals("Folder: folder", folderResult);
277         
278         // Retrieve delegates again
279
TestClassPolicy basePolicy2 = delegate.get(BASE_TYPE);
280         assertTrue(basePolicy == basePolicy2);
281         TestClassPolicy filePolicy2 = delegate.get(FILE_TYPE);
282         assertTrue(filePolicy == filePolicy2);
283         TestClassPolicy folderPolicy2 = delegate.get(FOLDER_TYPE);
284         assertTrue(folderPolicy == folderPolicy2);
285         
286         // Bind new behaviour (forcing base & file cache resets)
287
Behaviour newBaseBehaviour = new JavaBehaviour(this, "newBaseTest");
288         policyComponent.bindClassBehaviour(policyName, BASE_TYPE, newBaseBehaviour);
289
290         // Invoke Policies
291
TestClassPolicy basePolicy3 = delegate.get(BASE_TYPE);
292         assertTrue(basePolicy3 != basePolicy2);
293         String JavaDoc baseResult3 = basePolicy3.test("base");
294         assertEquals("NewBase: base", baseResult3);
295         TestClassPolicy filePolicy3 = delegate.get(FILE_TYPE);
296         assertTrue(filePolicy3 != filePolicy2);
297         String JavaDoc fileResult3 = filePolicy3.test("file");
298         assertEquals("NewBase: file", fileResult3);
299         TestClassPolicy folderPolicy3 = delegate.get(FOLDER_TYPE);
300         assertTrue(folderPolicy3 == folderPolicy2);
301         String JavaDoc folderResult3 = folderPolicy3.test("folder");
302         assertEquals("Folder: folder", folderResult3);
303         
304         // Bind new behaviour (forcing file cache reset)
305
Behaviour fileBehaviour = new JavaBehaviour(this, "fileTest");
306         policyComponent.bindClassBehaviour(policyName, FILE_TYPE, fileBehaviour);
307
308         // Invoke Policies
309
TestClassPolicy basePolicy4 = delegate.get(BASE_TYPE);
310         assertTrue(basePolicy4 == basePolicy3);
311         String JavaDoc baseResult4 = basePolicy4.test("base");
312         assertEquals("NewBase: base", baseResult4);
313         TestClassPolicy filePolicy4 = delegate.get(FILE_TYPE);
314         assertTrue(filePolicy4 != filePolicy3);
315         String JavaDoc fileResult4 = filePolicy4.test("file");
316         assertEquals("File: file", fileResult4);
317         TestClassPolicy folderPolicy4 = delegate.get(FOLDER_TYPE);
318         assertTrue(folderPolicy4 == folderPolicy4);
319         String JavaDoc folderResult4 = folderPolicy4.test("folder");
320         assertEquals("Folder: folder", folderResult4);
321     }
322
323
324     public void testPropertyDelegate()
325     {
326         // Register Policy
327
PropertyPolicyDelegate<TestPropertyPolicy> delegate = policyComponent.registerPropertyPolicy(TestPropertyPolicy.class);
328         
329         // Bind Property Behaviour
330
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
331         Behaviour fileBehaviour = new JavaBehaviour(this, "fileTest");
332         policyComponent.bindPropertyBehaviour(policyName, FILE_TYPE, FILE_PROP_B, fileBehaviour);
333
334         // Test NOOP Policy delegate
335
Collection JavaDoc<TestPropertyPolicy> basePolicies = delegate.getList(BASE_TYPE, BASE_PROP_A);
336         assertNotNull(basePolicies);
337         assertTrue(basePolicies.size() == 0);
338         TestPropertyPolicy basePolicy = delegate.get(BASE_TYPE, BASE_PROP_A);
339         assertNotNull(basePolicy);
340         
341         // Test single Policy delegate
342
Collection JavaDoc<TestPropertyPolicy> filePolicies = delegate.getList(FILE_TYPE, FILE_PROP_B);
343         assertNotNull(filePolicies);
344         assertTrue(filePolicies.size() == 1);
345         TestPropertyPolicy filePolicy = delegate.get(FILE_TYPE, FILE_PROP_B);
346         assertNotNull(filePolicy);
347         assertEquals(filePolicies.iterator().next(), filePolicy);
348
349         // Bind Service Behaviour
350
Behaviour serviceBehaviour = new JavaBehaviour(this, "serviceTest");
351         policyComponent.bindPropertyBehaviour(policyName, this, serviceBehaviour);
352
353         // Test multi Policy delegate
354
Collection JavaDoc<TestPropertyPolicy> file2Policies = delegate.getList(FILE_TYPE, FILE_PROP_B);
355         assertNotNull(file2Policies);
356         assertTrue(file2Policies.size() == 2);
357         TestPropertyPolicy filePolicy2 = delegate.get(FILE_TYPE, FILE_PROP_B);
358         assertNotNull(filePolicy2);
359     }
360
361     
362     public void testPropertyOverride()
363     {
364         // Register Policy
365
PropertyPolicyDelegate<TestPropertyPolicy> delegate = policyComponent.registerPropertyPolicy(TestPropertyPolicy.class);
366         
367         // Bind Behaviour
368
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
369         Behaviour baseBehaviour = new JavaBehaviour(this, "baseTest");
370         policyComponent.bindPropertyBehaviour(policyName, BASE_TYPE, BASE_PROP_A, baseBehaviour);
371         Behaviour folderBehaviour = new JavaBehaviour(this, "folderTest");
372         policyComponent.bindPropertyBehaviour(policyName, FOLDER_TYPE, BASE_PROP_A, folderBehaviour);
373         Behaviour folderBehaviourD = new JavaBehaviour(this, "folderTest");
374         policyComponent.bindPropertyBehaviour(policyName, FOLDER_TYPE, FOLDER_PROP_D, folderBehaviourD);
375
376         // Invoke Policies
377
TestPropertyPolicy basePolicy = delegate.get(BASE_TYPE, BASE_PROP_A);
378         String JavaDoc baseResult = basePolicy.test("base");
379         assertEquals("Base: base", baseResult);
380         TestPropertyPolicy filePolicy = delegate.get(FILE_TYPE, BASE_PROP_A);
381         String JavaDoc fileResult = filePolicy.test("file");
382         assertEquals("Base: file", fileResult);
383         TestPropertyPolicy folderPolicy = delegate.get(FOLDER_TYPE, BASE_PROP_A);
384         String JavaDoc folderResult = folderPolicy.test("folder");
385         assertEquals("Folder: folder", folderResult);
386         TestPropertyPolicy folderPolicy2 = delegate.get(FOLDER_TYPE, FOLDER_PROP_D);
387         String JavaDoc folderResult2 = folderPolicy2.test("folder");
388         assertEquals("Folder: folder", folderResult2);
389     }
390
391     
392     public void testPropertyWildcard()
393     {
394         // Register Policy
395
PropertyPolicyDelegate<TestPropertyPolicy> delegate = policyComponent.registerPropertyPolicy(TestPropertyPolicy.class);
396         
397         // Bind Behaviour
398
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
399         Behaviour baseBehaviour = new JavaBehaviour(this, "baseTest");
400         policyComponent.bindPropertyBehaviour(policyName, BASE_TYPE, baseBehaviour);
401         Behaviour folderBehaviour = new JavaBehaviour(this, "folderTest");
402         policyComponent.bindPropertyBehaviour(policyName, FOLDER_TYPE, folderBehaviour);
403         Behaviour aspectBehaviour = new JavaBehaviour(this, "aspectTest");
404         policyComponent.bindPropertyBehaviour(policyName, TEST_ASPECT, aspectBehaviour);
405         
406         // Invoke Policies
407
TestPropertyPolicy basePolicy = delegate.get(BASE_TYPE, BASE_PROP_A);
408         String JavaDoc baseResult = basePolicy.test("base");
409         assertEquals("Base: base", baseResult);
410         TestPropertyPolicy filePolicy = delegate.get(FILE_TYPE, BASE_PROP_A);
411         String JavaDoc fileResult = filePolicy.test("file");
412         assertEquals("Base: file", fileResult);
413         TestPropertyPolicy folderPolicy = delegate.get(FOLDER_TYPE, BASE_PROP_A);
414         String JavaDoc folderResult = folderPolicy.test("folder");
415         assertEquals("Folder: folder", folderResult);
416         TestPropertyPolicy folderPolicy2 = delegate.get(FOLDER_TYPE, FOLDER_PROP_D);
417         String JavaDoc folderResult2 = folderPolicy2.test("folder");
418         assertEquals("Folder: folder", folderResult2);
419         TestPropertyPolicy aspectPolicy = delegate.get(TEST_ASPECT, ASPECT_PROP_A);
420         String JavaDoc aspectResult = aspectPolicy.test("aspect_prop_a");
421         assertEquals("Aspect: aspect_prop_a", aspectResult);
422         TestPropertyPolicy aspectPolicy2 = delegate.get(TEST_ASPECT, FOLDER_PROP_D);
423         String JavaDoc aspectResult2 = aspectPolicy2.test("aspect_folder_d");
424         assertEquals("Aspect: aspect_folder_d", aspectResult2);
425
426         // Override wild-card with specific property binding
427
Behaviour folderDBehaviour = new JavaBehaviour(this, "folderDTest");
428         policyComponent.bindPropertyBehaviour(policyName, FOLDER_TYPE, FOLDER_PROP_D, folderDBehaviour);
429         TestPropertyPolicy folderPolicy3 = delegate.get(FOLDER_TYPE, FOLDER_PROP_D);
430         String JavaDoc folderResult3 = folderPolicy3.test("folder");
431         assertEquals("FolderD: folder", folderResult3);
432     }
433     
434
435     public void testPropertyCache()
436     {
437         // Register Policy
438
PropertyPolicyDelegate<TestPropertyPolicy> delegate = policyComponent.registerPropertyPolicy(TestPropertyPolicy.class);
439         
440         // Bind Behaviour
441
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
442         Behaviour baseBehaviour = new JavaBehaviour(this, "baseTest");
443         policyComponent.bindPropertyBehaviour(policyName, BASE_TYPE, baseBehaviour);
444         Behaviour folderBehaviour = new JavaBehaviour(this, "folderTest");
445         policyComponent.bindPropertyBehaviour(policyName, FOLDER_TYPE, folderBehaviour);
446         Behaviour folderDBehaviour = new JavaBehaviour(this, "folderDTest");
447         policyComponent.bindPropertyBehaviour(policyName, FOLDER_TYPE, FOLDER_PROP_D, folderDBehaviour);
448         Behaviour aspectBehaviour = new JavaBehaviour(this, "aspectTest");
449         policyComponent.bindPropertyBehaviour(policyName, TEST_ASPECT, aspectBehaviour);
450         
451         // Invoke Policies
452
TestPropertyPolicy filePolicy = delegate.get(FILE_TYPE, BASE_PROP_A);
453         String JavaDoc fileResult = filePolicy.test("file");
454         assertEquals("Base: file", fileResult);
455         TestPropertyPolicy folderPolicy = delegate.get(FOLDER_TYPE, FOLDER_PROP_D);
456         String JavaDoc folderResult = folderPolicy.test("folder");
457         assertEquals("FolderD: folder", folderResult);
458
459         // Re-bind Behaviour
460
Behaviour newBaseBehaviour = new JavaBehaviour(this, "newBaseTest");
461         policyComponent.bindPropertyBehaviour(policyName, BASE_TYPE, newBaseBehaviour);
462
463         // Re-invoke Policies
464
TestPropertyPolicy filePolicy2 = delegate.get(FILE_TYPE, BASE_PROP_A);
465         String JavaDoc fileResult2 = filePolicy2.test("file");
466         assertEquals("NewBase: file", fileResult2);
467         TestPropertyPolicy folderPolicy2 = delegate.get(FOLDER_TYPE, FOLDER_PROP_D);
468         String JavaDoc folderResult2 = folderPolicy2.test("folder");
469         assertEquals("FolderD: folder", folderResult2);
470     }
471     
472     
473     public void testAssociationDelegate()
474     {
475         // Register Policy
476
AssociationPolicyDelegate<TestAssociationPolicy> delegate = policyComponent.registerAssociationPolicy(TestAssociationPolicy.class);
477         
478         // Bind Association Behaviour
479
QName policyName = QName.createQName(TEST_NAMESPACE, "test");
480         Behaviour baseBehaviour = new JavaBehaviour(this, "baseTest");
481         policyComponent.bindAssociationBehaviour(policyName, BASE_TYPE, BASE_ASSOC_A, baseBehaviour);
482
483         // Test single Policy delegate
484
Collection JavaDoc<TestAssociationPolicy> filePolicies = delegate.getList(FILE_TYPE, BASE_ASSOC_A);
485         assertNotNull(filePolicies);
486         assertTrue(filePolicies.size() == 1);
487         TestAssociationPolicy filePolicy = delegate.get(FILE_TYPE, BASE_ASSOC_A);
488         assertNotNull(filePolicy);
489         String JavaDoc fileResult = filePolicy.test("file");
490         assertEquals("Base: file", fileResult);
491         
492         // Bind Service Behaviour
493
Behaviour serviceBehaviour = new JavaBehaviour(this, "serviceTest");
494         policyComponent.bindAssociationBehaviour(policyName, this, serviceBehaviour);
495
496         // Test multi Policy delegate
497
Collection JavaDoc<TestAssociationPolicy> file2Policies = delegate.getList(FILE_TYPE, BASE_ASSOC_A);
498         assertNotNull(file2Policies);
499         assertTrue(file2Policies.size() == 2);
500         TestAssociationPolicy filePolicy2 = delegate.get(FILE_TYPE, BASE_ASSOC_A);
501         assertNotNull(filePolicy2);
502     }
503
504     
505     //
506
// The following interfaces represents policies
507
//
508

509     public interface TestClassPolicy extends ClassPolicy
510     {
511         static String JavaDoc NAMESPACE = TEST_NAMESPACE;
512         public String JavaDoc test(String JavaDoc argument);
513     }
514
515     public interface TestPropertyPolicy extends PropertyPolicy
516     {
517         static String JavaDoc NAMESPACE = TEST_NAMESPACE;
518         public String JavaDoc test(String JavaDoc argument);
519     }
520
521     public interface TestAssociationPolicy extends AssociationPolicy
522     {
523         static String JavaDoc NAMESPACE = TEST_NAMESPACE;
524         public String JavaDoc test(String JavaDoc argument);
525     }
526
527     public interface InvalidMetaDataPolicy extends ClassPolicy
528     {
529         static int NAMESPACE = 0;
530         public String JavaDoc test(String JavaDoc nodeRef);
531     }
532
533     public interface NoMethodPolicy extends ClassPolicy
534     {
535     }
536     
537     public interface MultiMethodPolicy extends ClassPolicy
538     {
539         public void a();
540         public void b();
541     }
542     
543     
544     //
545
// The following methods represent Java Behaviours
546
//
547

548     public String JavaDoc validTest(String JavaDoc argument)
549     {
550         return "ValidTest: " + argument;
551     }
552     
553     public String JavaDoc baseTest(String JavaDoc argument)
554     {
555         return "Base: " + argument;
556     }
557
558     public String JavaDoc newBaseTest(String JavaDoc argument)
559     {
560         return "NewBase: " + argument;
561     }
562     
563     public String JavaDoc fileTest(String JavaDoc argument)
564     {
565         return "File: " + argument;
566     }
567     
568     public String JavaDoc folderTest(String JavaDoc argument)
569     {
570         return "Folder: " + argument;
571     }
572
573     public String JavaDoc aspectTest(String JavaDoc argument)
574     {
575         return "Aspect: " + argument;
576     }
577     
578     public String JavaDoc folderDTest(String JavaDoc argument)
579     {
580         return "FolderD: " + argument;
581     }
582
583     public String JavaDoc serviceTest(String JavaDoc argument)
584     {
585         return "Service: " + argument;
586     }
587     
588 }
589
Popular Tags