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 junit.framework.*;
24  
25  import org.deri.wsmo4j.io.serializer.wsml.*;
26  import org.omwg.logicalexpression.*;
27  import org.wsmo.common.*;
28  import org.wsmo.factory.*;
29  import org.wsmo.wsml.*;
30  
31  /**
32   * Base Test Case for Logical Expression API
33   * 
34   * provides serializer, parser, and default topEntity
35   *
36   * <pre>
37   * Created on Aug 1, 2005
38   * Committed by $Author$
39   * </pre>
40   *
41   * @author Holger Lausen (holger.lausen@deri.org)
42   *
43   * @version $Revision$ $Date$
44   */
45  abstract public class LogicalExpressionTestCase extends TestCase {
46      protected Parser parser;
47      protected Serializer serializer;
48      protected WsmoFactory factory;
49      protected LogicalExpressionFactory leFactory;
50      protected TopEntity topEntity;
51      protected String ns = "http://ex.org#";
52          
53      protected void setUp() throws Exception {
54          super.setUp();
55          HashMap <String, Object> createParams = new HashMap <String, Object> ();
56          createParams.put(Factory.PROVIDER_CLASS,
57                  "org.deri.wsmo4j.factory.LogicalExpressionFactoryImpl");
58          leFactory = Factory.createLogicalExpressionFactory(createParams);
59          factory = Factory.createWsmoFactory(null);
60          createParams = new HashMap <String, Object> ();
61          createParams.put(Factory.WSMO_FACTORY, factory);
62          createParams.put(Factory.LE_FACTORY, leFactory);
63  
64          parser = Factory.createParser(createParams);
65          serializer = Factory.createSerializer(null);
66          
67          topEntity = factory.createOntology(factory.createIRI("http://ex.org#ont"+System.currentTimeMillis()));
68          topEntity.setDefaultNamespace(factory.createIRI(ns));
69          topEntity.addNamespace(factory.createNamespace("wsml", 
70                  factory.createIRI("http://www.wsmo.org/wsml/wsml-syntax#")));
71      }
72      
73      protected void tearDown(){
74          leFactory=null;
75          factory=null;
76          parser=null;
77          serializer=null;
78          topEntity=null;
79          System.gc();
80      }
81      
82      protected String serialize(TopEntity top){
83          StringBuffer str = new StringBuffer();
84          TopEntity[] tops = {top};
85          serializer.serialize(tops,str);
86          return str.toString();
87      }
88      
89      protected static String serialize(LogicalExpression logExp, TopEntity nsContainer){
90          return new LogExprSerializerWSML(nsContainer).serialize(logExp);
91      }
92  
93      protected String serialize(LogicalExpression logExp){
94          return serialize(logExp,topEntity);
95      }
96  
97  }