KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > selection > ResourceExistsSelectorTestCase


1 /*
2 * Copyright 1999-2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

16 package org.apache.cocoon.selection;
17
18 import junit.framework.Test;
19 import junit.framework.TestSuite;
20 import junit.textui.TestRunner;
21 import org.apache.avalon.framework.parameters.Parameters;
22 import org.apache.cocoon.SitemapComponentTestCase;
23
24
25 public class ResourceExistsSelectorTestCase extends SitemapComponentTestCase {
26
27     /**
28      * Run this test suite from commandline
29      *
30      * @param args commandline arguments (ignored)
31      */

32     public static void main( String JavaDoc[] args ) {
33         TestRunner.run(suite());
34     }
35     
36     /** Create a test suite.
37      * This test suite contains all test cases of this class.
38      * @return the Test object containing all test cases.
39      */

40     public static Test suite() {
41         TestSuite suite = new TestSuite(ResourceExistsSelectorTestCase.class);
42         return suite;
43     }
44     
45     /**
46      * A resource-exists parameter select test
47      */

48     public void testResourceExistsSelect() throws Exception JavaDoc {
49         
50         Parameters parameters = new Parameters();
51         boolean result;
52         String JavaDoc expression = "";
53
54         // test selection success
55
expression = "resource://org/apache/cocoon/selection/ResourceExistsSelectorTestCase.class";
56         result = this.select( "resource-exists", expression, parameters );
57         System.out.println( result );
58         assertTrue( "Test if a exisitng resource is selected", result );
59         
60         // test selection failure
61
expression = "resource://org/apache/cocoon/selection/NonExistingResource.class";
62         result = this.select( "resource-exists", expression, parameters );
63         System.out.println( result );
64         assertTrue( "Test if a non exisitng resource is not selected", !result );
65         
66     }
67
68     /**
69      * A resource-exists parameter select test using the parameter prefix option
70      */

71     public void testResourceExistsSelectPrefix() throws Exception JavaDoc {
72         
73         Parameters parameters = new Parameters();
74         final String JavaDoc prefix = "resource://org/apache/cocoon/selection/";
75         parameters.setParameter( "prefix", prefix );
76         boolean result;
77         String JavaDoc expression = "";
78
79         // test selection success
80
expression = "ResourceExistsSelectorTestCase.class";
81         result = this.select( "resource-exists", expression, parameters );
82         System.out.println( result );
83         assertTrue( "Test if a exisitng resource is selected", result );
84         
85         // test selection failure
86
expression = "NonExistingResource.class";
87         result = this.select( "resource-exists", expression, parameters );
88         System.out.println( result );
89         assertTrue( "Test if a non exisitng resource is not selected", !result );
90         
91     }
92 }
93
Popular Tags