01: package org.drools.brms.server.contenthandler;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import junit.framework.TestCase;
20:
21: import org.drools.brms.client.common.AssetFormats;
22: import org.drools.brms.client.rpc.BuilderResult;
23: import org.drools.brms.server.util.TestEnvironmentSessionHelper;
24: import org.drools.repository.AssetItem;
25: import org.drools.repository.PackageItem;
26: import org.drools.repository.RulesRepository;
27:
28: public class ContentHandlerTest extends TestCase {
29:
30: public void testContentFormat() {
31: assertTrue(ContentHandler.getHandler(AssetFormats.DRL) instanceof DRLFileContentHandler);
32: assertTrue(ContentHandler.getHandler(AssetFormats.DSL) instanceof DSLDefinitionContentHandler);
33: assertTrue(ContentHandler
34: .getHandler(AssetFormats.DSL_TEMPLATE_RULE) instanceof DSLRuleContentHandler);
35: assertTrue(ContentHandler
36: .getHandler(AssetFormats.BUSINESS_RULE) instanceof BRLContentHandler);
37: assertTrue(ContentHandler
38: .getHandler(AssetFormats.DECISION_SPREADSHEET_XLS) instanceof DecisionTableXLSHandler);
39: assertTrue(ContentHandler.getHandler(AssetFormats.ENUMERATION) instanceof EnumerationContentHandler);
40:
41: try {
42: ContentHandler.getHandler("XXX");
43: fail("should have thrown an exception");
44: } catch (IllegalArgumentException e) {
45: assertNotNull(e.getMessage());
46: }
47: }
48:
49: public void testRuleAssetType() {
50: assertTrue(ContentHandler.getHandler(AssetFormats.DRL)
51: .isRuleAsset());
52: assertTrue(ContentHandler.getHandler(
53: AssetFormats.DSL_TEMPLATE_RULE).isRuleAsset());
54: assertTrue(ContentHandler
55: .getHandler(AssetFormats.BUSINESS_RULE).isRuleAsset());
56: assertTrue(ContentHandler.getHandler(
57: AssetFormats.DECISION_SPREADSHEET_XLS).isRuleAsset());
58:
59: assertFalse(ContentHandler.getHandler(AssetFormats.DSL)
60: .isRuleAsset());
61: assertFalse(ContentHandler.getHandler(AssetFormats.MODEL)
62: .isRuleAsset());
63: assertFalse(ContentHandler.getHandler(AssetFormats.ENUMERATION)
64: .isRuleAsset());
65: }
66:
67: public void testValidating() throws Exception {
68: RulesRepository repo = new RulesRepository(
69: TestEnvironmentSessionHelper.getSession());
70: PackageItem pkg = repo.loadDefaultPackage();
71: AssetItem asset = pkg.addAsset("testValidatingEnum", "");
72: asset.updateFormat(AssetFormats.ENUMERATION);
73: asset.updateContent("'Person.age' : [1, 2, 3]");
74:
75: EnumerationContentHandler ch = new EnumerationContentHandler();
76: BuilderResult[] result = ch.validateAsset(asset);
77: assertNotNull(result);
78: assertEquals(0, result.length);
79:
80: asset.updateContent("goober boy");
81: result = ch.validateAsset(asset);
82: assertFalse(result.length == 0);
83: assertEquals(asset.getName(), result[0].assetName);
84: assertEquals(asset.getFormat(), result[0].assetFormat);
85: assertNotNull(result[0].message);
86: assertEquals(asset.getUUID(), result[0].uuid);
87:
88: }
89:
90: }
|