001: package org.drools.decisiontable.parser;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.List;
020:
021: import junit.framework.TestCase;
022:
023: import org.drools.decisiontable.model.Global;
024: import org.drools.decisiontable.model.Import;
025:
026: /**
027: * @author <a href="mailto:michael.neale@gmail.com"> Michael Neale</a>
028: *
029: * Nuff said...
030: */
031: public class RuleSheetParserUtilTest extends TestCase {
032:
033: public void testRuleName() {
034: final String row = " RuleTable This is my rule name";
035: final String result = RuleSheetParserUtil.getRuleName(row);
036: assertEquals("This is my rule name", result);
037: }
038:
039: /**
040: * This is hear as the old way was to do this.
041: */
042: public void testInvalidRuleName() {
043: final String row = "RuleTable This is my rule name (type class)";
044: try {
045: final String result = RuleSheetParserUtil.getRuleName(row);
046: fail("should have failed, but get result: " + result);
047: } catch (final IllegalArgumentException e) {
048: assertNotNull(e.getMessage());
049: }
050: }
051:
052: public void testIsStringMeaningTrue() {
053: assertTrue(RuleSheetParserUtil.isStringMeaningTrue("true"));
054: assertTrue(RuleSheetParserUtil.isStringMeaningTrue("TRUE"));
055: assertTrue(RuleSheetParserUtil.isStringMeaningTrue("yes"));
056: assertTrue(RuleSheetParserUtil.isStringMeaningTrue("oN"));
057:
058: assertFalse(RuleSheetParserUtil.isStringMeaningTrue("no"));
059: assertFalse(RuleSheetParserUtil.isStringMeaningTrue("false"));
060: assertFalse(RuleSheetParserUtil.isStringMeaningTrue(null));
061: }
062:
063: public void testListImports() {
064: String cellVal = null;
065: List list = RuleSheetParserUtil.getImportList(cellVal);
066: assertNotNull(list);
067: assertEquals(0, list.size());
068:
069: assertEquals(0, RuleSheetParserUtil.getImportList("").size());
070:
071: cellVal = "com.something.Yeah, com.something.No,com.something.yeah.*";
072: list = RuleSheetParserUtil.getImportList(cellVal);
073: assertEquals(3, list.size());
074: assertEquals("com.something.Yeah", ((Import) list.get(0))
075: .getClassName());
076: assertEquals("com.something.No", ((Import) list.get(1))
077: .getClassName());
078: assertEquals("com.something.yeah.*", ((Import) list.get(2))
079: .getClassName());
080: }
081:
082: public void testListVariables() {
083: final List varList = RuleSheetParserUtil
084: .getVariableList("Var1 var1, Var2 var2,Var3 var3");
085: assertNotNull(varList);
086: assertEquals(3, varList.size());
087: Global var = (Global) varList.get(0);
088: assertEquals("Var1", var.getClassName());
089: var = (Global) varList.get(2);
090: assertEquals("Var3", var.getClassName());
091: assertEquals("var3", var.getIdentifier());
092: }
093:
094: public void testBadVariableFormat() {
095: final String bad = "class1, object2";
096: try {
097: RuleSheetParserUtil.getVariableList(bad);
098: fail("should not work");
099: } catch (final DecisionTableParseException e) {
100: assertNotNull(e.getMessage());
101: }
102: }
103: }
|