1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package test.wsmo4j.validator;
19
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.List;
23 import java.util.Vector;
24
25 import junit.framework.TestCase;
26
27 import org.omwg.logicalexpression.LogicalExpression;
28 import org.omwg.ontology.Axiom;
29 import org.omwg.ontology.Ontology;
30 import org.wsmo.factory.DataFactory;
31 import org.wsmo.factory.Factory;
32 import org.wsmo.factory.LogicalExpressionFactory;
33 import org.wsmo.factory.WsmoFactory;
34 import org.wsmo.validator.ValidationError;
35 import org.wsmo.validator.ValidationWarning;
36 import org.wsmo.wsml.Parser;
37
38
39
40
41
42
43 abstract public class ValidatorTestCase extends TestCase {
44
45 protected Parser parser;
46
47 protected WsmoFactory factory;
48
49 protected LogicalExpressionFactory leFactory;
50
51 protected DataFactory dataFactory;
52
53 protected List <LogicalExpression> leSet;
54
55 public Ontology ontology;
56
57 public Vector <ValidationError> errors;
58
59 public Vector <ValidationWarning> warnings;
60
61 public String ns = "http://ex.org#";
62
63 public Axiom axiom;
64
65 public LogicalExpression le;
66
67 protected String getOntHeader(){
68 return "namespace {_\""+ns+"\"} \n" +
69 "ontology ont"+System.currentTimeMillis()+"\n";
70 }
71
72 protected String getOntLocalName() {
73 return "ontology ont" + System.currentTimeMillis() + "\n";
74 }
75
76
77
78
79 protected void setUp() throws Exception {
80 super.setUp();
81
82 HashMap <String, Object> createParams = new HashMap <String, Object> ();
83 createParams.put(Factory.PROVIDER_CLASS,"org.deri.wsmo4j.factory.LogicalExpressionFactoryImpl");
84 leFactory = Factory.createLogicalExpressionFactory(createParams);
85 factory = Factory.createWsmoFactory(null);
86 dataFactory = Factory.createDataFactory(null);
87 createParams = new HashMap <String, Object> ();
88 createParams.put(Factory.WSMO_FACTORY, factory);
89 createParams.put(Factory.LE_FACTORY, leFactory);
90 createParams.put(Parser.CACHE_LOGICALEXPRESSION_STRING, "true");
91
92
93 parser = Factory.createParser(createParams);
94 errors = new Vector <ValidationError>();
95 warnings = new Vector <ValidationWarning>();
96
97 ontology = factory.createOntology(factory.createIRI(ns + "ont" + System.currentTimeMillis()));
98 ontology.setDefaultNamespace(factory.createIRI(ns));
99 axiom = factory.createAxiom(factory.createIRI(ns + "axiom" + System.currentTimeMillis()));
100 ontology.addAxiom(axiom);
101
102 leSet = new Vector <LogicalExpression>();
103 }
104
105
106
107
108
109
110 protected void createAxiomDef(String s) throws Exception {
111 le = leFactory.createLogicalExpression(s, ontology);
112 axiom.addDefinition(le);
113 }
114
115
116
117
118 protected void removeAxiomDef() throws Exception {
119 Iterator <LogicalExpression> it = axiom.listDefinitions().iterator();
120 while (it.hasNext()) {
121 leSet.add(it.next());
122 }
123 for (int i=0; i<leSet.size(); i++) {
124 LogicalExpression le = leSet.get(i);
125 axiom.removeDefinition(le);
126 }
127 }
128
129
130
131
132
133
134 protected void printError(java.util.List l){
135 for (int i=0; i<l.size(); i++) {
136 System.out.println("\nError " + (i+1) + ":\n" + l.get(i) + "\n\n --------------------------------");
137 }
138 }
139
140 protected void printWarning(List l) {
141 for (int i=0; i<l.size(); i++) {
142 System.out.println("\nWarning " + (i+1) + ":\n" + l.get(i) + "\n\n -------------------------------");
143 }
144 }
145
146
147
148
149 protected void tearDown(){
150 leFactory=null;
151 factory=null;
152 parser=null;
153 ontology=null;
154 axiom=null;
155 errors=null;
156 leSet.clear();
157 le=null;
158 System.gc();
159 }
160
161 }