1   /*
2     wsmo4j - a WSMO API and Reference Implementation
3   
4   
5    Copyright (c) 2005, University of Innsbruck, Austria
6   
7    This library is free software; you can redistribute it and/or modify it under
8    the terms of the GNU Lesser General Public License as published by the Free
9    Software Foundation; either version 2.1 of the License, or (at your option)
10   any later version.
11   This library is distributed in the hope that it will be useful, but WITHOUT
12   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14   details.
15   You should have received a copy of the GNU Lesser General Public License along
16   with this library; if not, write to the Free Software Foundation, Inc.,
17   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18   */
19  package test.wsmo4j.logicalexpression;
20  
21  import java.util.*;
22  
23  import org.omwg.logicalexpression.*;
24  import org.omwg.logicalexpression.terms.*;
25  import org.omwg.ontology.*;
26  import org.wsmo.common.*;
27  import org.wsmo.common.exception.*;
28  import org.wsmo.wsml.*;
29  
30  /**
31   * Interface or class description    
32   * 
33   * <pre>
34   * 
35   *  Created on Aug 1, 2005
36   *  Committed by $Author$
37   *  
38   * </pre>
39   * 
40   * @author Holger Lausen (holger.lausen@deri.org)
41   * @version $Revision$ $Date$
42   */
43  public class LogicalExpressionFactoryTest extends LogicalExpressionTestCase {
44  
45      public void testCreateMemberShipMolecules() throws Exception {
46          IRI a = factory.createIRI(ns + "a");
47          IRI b = factory.createIRI(ns + "b");
48          IRI c = factory.createIRI(ns + "c");
49          List <IRI> concepts = new LinkedList <IRI> ();
50          concepts.add(a);
51          CompoundMolecule expression;
52          try {
53              expression = leFactory.createMemberShipMolecules(a, null);
54              fail("Should raise IllegalArgumentException");
55          }
56          catch (IllegalArgumentException e) {
57          }
58  
59          try {
60              expression = leFactory.createMemberShipMolecules(a, concepts);
61              fail("Should raise IllegalArgumentException");
62          }
63          catch (IllegalArgumentException e) {
64          }
65          concepts.add(c);
66          expression = leFactory.createMemberShipMolecules(a, concepts);
67          assertEquals(expression.listOperands().size(),2);
68      }            
69      
70      
71      public void testCreateUnary() throws ParserException{
72          try {
73          	LogicalExpression expression = leFactory.createLogicalExpression("!- ?x memberOf b", topEntity);
74              leFactory.createConstraint(expression);
75              fail("Should raise IllegalArgumentException");
76          } catch (IllegalArgumentException e) {
77          }
78          
79          try {
80              leFactory.createConstraint(leFactory.createLogicalExpression("!- ?x memberOf b", topEntity));
81              fail("Should raise IllegalArgumentException");
82          } catch (IllegalArgumentException e) {
83          }
84      }    
85  
86      public void testCreateBinary() throws ParserException {
87          try {
88              leFactory.createConjunction(leFactory.createLogicalExpression("!- ?x memberOf b", topEntity),
89                      leFactory.createLogicalExpression("c", topEntity));
90              fail("Should raise IllegalArgumentException");
91          } catch (IllegalArgumentException e) {
92          }
93          try {
94              leFactory.createConjunction(
95                      null,
96                      leFactory.createLogicalExpression("c", topEntity));
97              fail("Should raise IllegalArgumentException");
98          } catch (IllegalArgumentException e) {
99          }
100     }
101 
102     public void testCreateQuantified() throws ParserException {
103         Set s = new HashSet();
104         try {
105         	s.add(leFactory.createVariable("test"));
106         } catch (IllegalArgumentException e) {
107         	throw new ParserException("",e);
108         }
109         NumberedAnonymousID aid = leFactory.createAnonymousID((byte)4); 
110         s.add(aid);
111         try{
112             leFactory.createExistentialQuantification(s,
113                     leFactory.createLogicalExpression("?x memberOf b", topEntity));
114             fail("Should raise IllegalArgumentException");
115         }catch(Exception e){
116         }
117         s.remove(aid);
118         try{
119             leFactory.createExistentialQuantification(s,
120                     leFactory.createLogicalExpression("!- ?x memberOf b", topEntity));
121             fail("Should raise IllegalArgumentException");
122         }catch(Exception e){
123         }
124         try{
125             leFactory.createExistentialQuantification((Set <Variable>) null,
126                     leFactory.createLogicalExpression("?x memberOf b", topEntity));
127             fail("Should raise IllegalArgumentException");
128         }catch(Exception e){
129         }
130         leFactory.createExistentialQuantification(s,
131                 leFactory.createLogicalExpression("?x memberOf b", topEntity));
132     }
133 
134 
135     public void testCreateConstructedTerm() {
136         try{
137             List l = new LinkedList();
138             l.add(new Integer(1));
139             leFactory.createConstructedTerm(factory.createIRI(ns+"test"),l);
140             fail("should cause exception");
141         }catch(IllegalArgumentException e){
142         }
143         Term t = leFactory.createConstructedTerm(factory.createIRI(ns+"test"),null);
144         assertNotNull(t);
145     }
146         
147 
148     public void testCreateVariable() throws InvalidModelException {
149         Variable x = leFactory.createVariable("?x");
150         assertEquals("x",x.getName());
151         
152         try{
153             leFactory.createVariable("x_s_x");
154             fail("should cause exception");
155         }catch (IllegalArgumentException e){}
156          
157     	Variable v = leFactory.createVariable("xyz");
158     	assertNotNull(v);
159         assertEquals("xyz",v.getName());
160         assertEquals("?xyz",v.toString());
161     }
162 
163 
164 
165 
166 }