001: /*
002: * Bossa Workflow System
003: *
004: * $Id: ExpressionTest.java,v 1.9 2004/01/29 21:24:37 gdvieira Exp $
005: *
006: * Copyright (C) 2003,2004 OpenBR Sistemas S/C Ltda.
007: *
008: * This file is part of Bossa.
009: *
010: * Bossa is free software; you can redistribute it and/or modify it
011: * under the terms of version 2 of the GNU General Public License as
012: * published by the Free Software Foundation.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public
020: * License along with this program; if not, write to the
021: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
022: * Boston, MA 02111-1307, USA.
023: */
024:
025: package com.bigbross.bossa.resource;
026:
027: import junit.framework.TestCase;
028:
029: public class ExpressionTest extends TestCase {
030:
031: ResourceRegistry registry;
032:
033: Resource a, b, c, x, A, B, C;
034:
035: public ExpressionTest(String name) {
036: super (name);
037: }
038:
039: protected void setUp() {
040: registry = new ResourceRegistry("null");
041: A = registry.createResourceImpl("A", false);
042: B = registry.createResourceImpl("B", false);
043: C = registry.createResourceImpl("C", false);
044: a = registry.createResourceImpl("a", false);
045: b = registry.createResourceImpl("b", false);
046: c = registry.createResourceImpl("c", false);
047: x = registry.createResourceImpl("x", false);
048: A.includeImpl(a, false);
049: A.includeImpl(x, false);
050: B.includeImpl(b, false);
051: B.includeImpl(x, false);
052: C.includeImpl(c, false);
053: }
054:
055: public void testReference() {
056: Expression resource = registry.compile("C");
057: assertTrue(resource.contains(C));
058:
059: ResourceRegistry context = new ResourceRegistry("null");
060: Resource newC = context.createResourceImpl("C", false);
061: newC.includeImpl(x, false);
062:
063: assertTrue(resource.contains(c));
064: assertTrue(resource.contains(context, c));
065:
066: assertFalse(resource.contains(x));
067: assertFalse(resource.contains(context, x));
068: }
069:
070: public void testReferenceCreation() {
071: Expression resource = registry.compile("new");
072: Resource r = registry.getResource("new");
073: assertNotNull(r);
074: assertTrue(resource.contains(r));
075: }
076:
077: public void testLazyReference() {
078: Expression resource = registry.compile("$C");
079: assertTrue(resource.contains(C));
080:
081: ResourceRegistry context = new ResourceRegistry("null");
082: Resource newC = context.createResourceImpl("C", false);
083: newC.includeImpl(x, false);
084:
085: assertFalse(resource.contains(context, C));
086: assertTrue(resource.contains(context, newC));
087:
088: assertTrue(resource.contains(c));
089: assertFalse(resource.contains(context, c));
090:
091: assertFalse(resource.contains(x));
092: assertTrue(resource.contains(context, x));
093: }
094:
095: public void testUnion() {
096: Expression resource = registry.compile("A+B");
097: assertTrue(resource.contains(a));
098: assertTrue(resource.contains(b));
099: assertTrue(resource.contains(x));
100: assertFalse(resource.contains(c));
101: }
102:
103: public void testIntersection() {
104: Expression resource = registry.compile("A^B");
105: assertTrue(resource.contains(x));
106: assertFalse(resource.contains(a));
107: assertFalse(resource.contains(b));
108: }
109:
110: public void testSubtraction() {
111: Expression resource = registry.compile("A-B");
112: assertTrue(resource.contains(a));
113: assertFalse(resource.contains(b));
114: assertFalse(resource.contains(x));
115: }
116:
117: public void testExpression() {
118: Expression resource = registry.compile("A^B+C");
119: assertTrue(resource.contains(c));
120: assertTrue(resource.contains(x));
121: assertFalse(resource.contains(a));
122: assertFalse(resource.contains(b));
123: }
124:
125: public void testGroup() {
126: Expression resource = registry.compile("A ^ (B + C)");
127: assertTrue(resource.contains(x));
128: assertFalse(resource.contains(a));
129: assertFalse(resource.contains(b));
130: assertFalse(resource.contains(c));
131: }
132:
133: }
|