KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > util > ExpressionTest


1 /**
2  * Copyright 2004-2005 jManage.org
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.jmanage.core.util;
17
18 import junit.framework.TestCase;
19
20 /**
21  * Defines unit tests for Expression
22  *
23  * Date: Jul 1, 2005
24  * @author Rakesh Kalra
25  */

26 public class ExpressionTest extends TestCase {
27
28     private static final String JavaDoc appName = "testApp";
29     private static final String JavaDoc mbeanName = "jmanage:name=AppMBean";
30     private static final String JavaDoc quotedMBeanName = "jmanage:name=\"AppMBean\"";
31     private static final String JavaDoc attrName = "AppName";
32     private static final String JavaDoc exprString = appName +
33             Expression.DELIMITER + quotedMBeanName +
34             Expression.DELIMITER + attrName;
35
36
37     public ExpressionTest(String JavaDoc name){
38         super(name);
39     }
40
41     public void testNormalCase(){
42         Expression expression =
43                 new Expression(appName, mbeanName, attrName);
44         assertEquals(expression.getAppName(), appName);
45         assertEquals(expression.getMBeanName(), mbeanName);
46         assertEquals(expression.getTargetName(), attrName);
47     }
48
49     public void testAllWildCard(){
50         Expression expression = new Expression(null, null, null);
51         assertEquals(expression.getAppName(), Expression.WILDCARD);
52         assertEquals(expression.getMBeanName(), Expression.WILDCARD);
53         assertEquals(expression.getTargetName(), Expression.WILDCARD);
54     }
55
56     public void testWildCardApplication(){
57         Expression expression =
58                 new Expression("", mbeanName, attrName);
59         assertEquals(expression.getAppName(), Expression.WILDCARD);
60         assertEquals(expression.getMBeanName(), mbeanName);
61         assertEquals(expression.getTargetName(), attrName);
62     }
63
64     public void testExprString(){
65         Expression expression = new Expression(exprString);
66         assertEquals(expression.getAppName(), appName);
67         assertEquals(expression.getMBeanName(), quotedMBeanName);
68         assertEquals(expression.getTargetName(), attrName);
69     }
70
71     ////////////////////////////////////////////////////////////////////////////
72
// Expression Context Tests
73

74     public void testSimpleExpressionContext(){
75         Expression context = new Expression(exprString);
76         Expression expression = new Expression("attr2", context);
77         assertEquals(expression.getAppName(), appName);
78         assertEquals(expression.getMBeanName(), quotedMBeanName);
79         assertEquals(expression.getTargetName(), "attr2");
80     }
81
82     public void testSimpleExpressionContext2(){
83         final String JavaDoc mbeanWithDelimiter = "myNew/mbean";
84         final String JavaDoc attr = "attr2";
85         final String JavaDoc expr2 = "\"" + mbeanWithDelimiter + "\"" +
86                 Expression.DELIMITER + attr;
87         Expression context = new Expression(exprString);
88         Expression expression = new Expression(expr2, context);
89         assertEquals(expression.getAppName(), appName);
90         assertEquals(expression.getMBeanName(), mbeanWithDelimiter);
91         assertEquals(expression.getTargetName(), attr);
92     }
93
94     public void testSimpleExpressionContext3(){
95         final String JavaDoc appName2 = "testApp2";
96         final String JavaDoc mbeanWithDelimiter = "myNew/mbean";
97         final String JavaDoc attr = "attr2";
98         final String JavaDoc expr2 = appName2 +
99                 Expression.DELIMITER + "\"" + mbeanWithDelimiter + "\"" +
100                 Expression.DELIMITER + attr;
101         Expression context = new Expression(exprString);
102         Expression expression = new Expression(expr2, context);
103         assertEquals(expression.getAppName(), appName2);
104         assertEquals(expression.getMBeanName(), mbeanWithDelimiter);
105         assertEquals(expression.getTargetName(), attr);
106     }
107 }
108
Popular Tags