KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > service > namespace > QNamePatternTest


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.service.namespace;
18
19
20 import junit.framework.TestCase;
21
22 /**
23  * Tests the various implementations of the
24  * {@link org.alfresco.service.namespace.QNamePattern}.
25  *
26  * @author Derek Hulley
27  */

28 public class QNamePatternTest extends TestCase
29 {
30     private static final String JavaDoc TEST_NAMESPACE = "http://www.alfresco.org/QNamePatternTest";
31     
32     QName check1;
33     QName check2;
34     QName check3;
35
36     public QNamePatternTest(String JavaDoc name)
37     {
38         super(name);
39     }
40     
41     public void setUp() throws Exception JavaDoc
42     {
43         check1 = QName.createQName(null, "ABC");
44         check2 = QName.createQName(TEST_NAMESPACE, "XYZ");
45         check3 = QName.createQName(TEST_NAMESPACE, "ABC");
46     }
47     
48     public void testSimpleQNamePattern() throws Exception JavaDoc
49     {
50         QNamePattern pattern = QName.createQName(TEST_NAMESPACE, "ABC");
51         
52         // check
53
assertFalse("Simple match failed: " + check1, pattern.isMatch(check1));
54         assertFalse("Simple match failed: " + check2, pattern.isMatch(check2));
55         assertTrue("Simple match failed: " + check3, pattern.isMatch(check3));
56     }
57     
58     public void testRegexQNamePatternMatcher() throws Exception JavaDoc
59     {
60         QNamePattern pattern = new RegexQNamePattern(".*alfresco.*", "A.?C");
61         
62         // check
63
assertFalse("Regex match failed: " + check1, pattern.isMatch(check1));
64         assertFalse("Regex match failed: " + check2, pattern.isMatch(check2));
65         assertTrue("Regex match failed: " + check3, pattern.isMatch(check3));
66         
67         assertTrue("All match failed: " + check1, RegexQNamePattern.MATCH_ALL.isMatch(check1));
68         assertTrue("All match failed: " + check2, RegexQNamePattern.MATCH_ALL.isMatch(check2));
69         assertTrue("All match failed: " + check3, RegexQNamePattern.MATCH_ALL.isMatch(check3));
70     }
71 }
72
Popular Tags