1 16 package org.jmanage.core.util; 17 18 import junit.framework.TestCase; 19 20 26 public class ExpressionTest extends TestCase { 27 28 private static final String appName = "testApp"; 29 private static final String mbeanName = "jmanage:name=AppMBean"; 30 private static final String quotedMBeanName = "jmanage:name=\"AppMBean\""; 31 private static final String attrName = "AppName"; 32 private static final String exprString = appName + 33 Expression.DELIMITER + quotedMBeanName + 34 Expression.DELIMITER + attrName; 35 36 37 public ExpressionTest(String 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 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 mbeanWithDelimiter = "myNew/mbean"; 84 final String attr = "attr2"; 85 final String 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 appName2 = "testApp2"; 96 final String mbeanWithDelimiter = "myNew/mbean"; 97 final String attr = "attr2"; 98 final String 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 |