01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.selection;
18:
19: import junit.framework.Test;
20: import junit.framework.TestSuite;
21: import junit.textui.TestRunner;
22: import org.apache.avalon.framework.parameters.Parameters;
23: import org.apache.cocoon.SitemapComponentTestCase;
24:
25: public class ResourceExistsSelectorTestCase extends
26: SitemapComponentTestCase {
27:
28: /**
29: * Run this test suite from commandline
30: *
31: * @param args commandline arguments (ignored)
32: */
33: public static void main(String[] args) {
34: TestRunner.run(suite());
35: }
36:
37: /** Create a test suite.
38: * This test suite contains all test cases of this class.
39: * @return the Test object containing all test cases.
40: */
41: public static Test suite() {
42: TestSuite suite = new TestSuite(
43: ResourceExistsSelectorTestCase.class);
44: return suite;
45: }
46:
47: /**
48: * A resource-exists parameter select test
49: */
50: public void testResourceExistsSelect() throws Exception {
51:
52: Parameters parameters = new Parameters();
53: boolean result;
54: String expression = "";
55:
56: // test selection success
57: expression = "resource://org/apache/cocoon/selection/ResourceExistsSelectorTestCase.class";
58: result = this .select("resource-exists", expression, parameters);
59: System.out.println(result);
60: assertTrue("Test if a exisitng resource is selected", result);
61:
62: // test selection failure
63: expression = "resource://org/apache/cocoon/selection/NonExistingResource.class";
64: result = this .select("resource-exists", expression, parameters);
65: System.out.println(result);
66: assertTrue("Test if a non exisitng resource is not selected",
67: !result);
68:
69: }
70:
71: /**
72: * A resource-exists parameter select test using the parameter prefix option
73: */
74: public void testResourceExistsSelectPrefix() throws Exception {
75:
76: Parameters parameters = new Parameters();
77: final String prefix = "resource://org/apache/cocoon/selection/";
78: parameters.setParameter("prefix", prefix);
79: boolean result;
80: String expression = "";
81:
82: // test selection success
83: expression = "ResourceExistsSelectorTestCase.class";
84: result = this .select("resource-exists", expression, parameters);
85: System.out.println(result);
86: assertTrue("Test if a exisitng resource is selected", result);
87:
88: // test selection failure
89: expression = "NonExistingResource.class";
90: result = this .select("resource-exists", expression, parameters);
91: System.out.println(result);
92: assertTrue("Test if a non exisitng resource is not selected",
93: !result);
94:
95: }
96: }
|