Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
57   235   21   3.56
6   142   0.37   16
16     1.31  
1    
 
  QedeqBoFactoryTest       Line # 50 57 21 84.8% 0.84810126
 
  (9)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.service;
17   
18    import java.io.File;
19    import java.io.IOException;
20   
21    import javax.xml.parsers.ParserConfigurationException;
22   
23    import org.qedeq.base.io.IoUtility;
24    import org.qedeq.base.test.DynamicGetter;
25    import org.qedeq.base.test.ObjectProxy;
26    import org.qedeq.base.test.QedeqTestCase;
27    import org.qedeq.base.trace.Trace;
28    import org.qedeq.kernel.base.module.Author;
29    import org.qedeq.kernel.base.module.Qedeq;
30    import org.qedeq.kernel.bo.service.DefaultKernelQedeqBo;
31    import org.qedeq.kernel.bo.service.ModuleLabelsCreator;
32    import org.qedeq.kernel.bo.test.KernelFacade;
33    import org.qedeq.kernel.common.DummyPlugin;
34    import org.qedeq.kernel.common.IllegalModuleDataException;
35    import org.qedeq.kernel.common.ModuleAddress;
36    import org.qedeq.kernel.common.ModuleDataException;
37    import org.qedeq.kernel.common.SourceFileException;
38    import org.qedeq.kernel.common.SourceFileExceptionList;
39    import org.qedeq.kernel.xml.handler.module.QedeqHandler;
40    import org.qedeq.kernel.xml.parser.SaxDefaultHandler;
41    import org.qedeq.kernel.xml.parser.SaxParser;
42    import org.xml.sax.SAXException;
43   
44    /**
45    * For testing QEDEQ generation.
46    *
47    * @version $Revision: 1.1 $
48    * @author Michael Meyling
49    */
 
50    public class QedeqBoFactoryTest extends QedeqTestCase {
51   
52    /** This class. */
53    private static final Class CLASS = QedeqBoFactoryTest.class;
54   
55    private Qedeq ok;
56   
57    private Qedeq error;
58   
59    private File okFile;
60   
61    private File errorFile;
62   
 
63  6 toggle protected void setUp() throws Exception {
64  6 super.setUp();
65  6 KernelFacade.startup();
66  6 try {
67  6 okFile = getFile("qedeq_sample1.xml");
68  6 errorFile = getFile("qedeq_sample2_error.xml");
69  6 ok = (Qedeq) ObjectProxy.createProxy(createQedeqFromFile(okFile));
70  6 ok.getHeader().getAuthorList().get(0);
71  6 assertTrue(DynamicGetter.get(ok, "getHeader().getAuthorList().get(0)") instanceof Author);
72  6 ok = (Qedeq) ObjectProxy.createProxy(ok);
73  6 error = (Qedeq) ObjectProxy.createProxy(createQedeqFromFile(errorFile));
74    } catch (Exception e) {
75  0 KernelFacade.shutdown();
76    }
77    }
78   
 
79  6 toggle protected void tearDown() throws Exception {
80  6 KernelFacade.shutdown();
81  6 ok = null;
82  6 error = null;
83  6 super.tearDown();
84    }
85   
 
86  0 toggle public QedeqBoFactoryTest() {
87  0 super();
88    }
89   
 
90  6 toggle public QedeqBoFactoryTest(final String name) {
91  6 super(name);
92    }
93   
94    /**
95    * Class under test for QedeqBo create(String, Qedeq).
96    *
97    * @throws IOException Module creation failed due to IO error.
98    * @throws SAXException Module parsing failed.
99    * @throws ParserConfigurationException Parser configuration problem.
100    */
 
101  1 toggle public void testCreateStringQedeq1() throws IOException, ParserConfigurationException,
102    SAXException, ModuleDataException, SourceFileExceptionList {
103  1 final String method = "testCreateStringQedeq()";
104  1 final ModuleAddress address = KernelFacade.getKernelContext().getModuleAddress(
105    IoUtility.toUrl(errorFile.getCanonicalFile()));
106  1 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade
107    .getKernelContext().getQedeqBo(address);
108  1 try {
109  1 QedeqBoFactoryAssert.createQedeq(prop, error);
110    // TODO mime 20080306: move this test to another location, building doesn't include
111    // checking any longer
112  0 final ModuleLabelsCreator creator = new ModuleLabelsCreator(DummyPlugin.getInstance(), prop);
113  0 creator.createLabels();
114  0 fail("SourceFileExceptionList expected");
115    } catch (SourceFileExceptionList e) {
116  1 SourceFileException sf = e.get(0);
117  1 assertEquals(221, sf.getSourceArea().getStartPosition().getRow());
118  1 assertEquals(9, sf.getSourceArea().getStartPosition().getColumn());
119  1 assertEquals(265, sf.getSourceArea().getEndPosition().getRow());
120  1 assertEquals(16, sf.getSourceArea().getEndPosition().getColumn());
121  1 Trace.trace(CLASS, this, method, e);
122    }
123    }
124   
125    /**
126    * Class under test for QedeqBo createQedeq(String, Qedeq).
127    *
128    * @throws Exception Unexpected failure of module creation.
129    */
 
130  1 toggle public void testCreateStringQedeq2() throws Exception {
131  1 loadQedeqAndAssertContext("project/qedeq_basic_concept.xml");
132    }
133   
134    /**
135    * Class under test for QedeqBo createQedeq(String, Qedeq).
136    *
137    * @throws Exception Unexpected failure of module creation.
138    */
 
139  1 toggle public void testCreateStringQedeq3() throws Exception {
140  1 loadQedeqAndAssertContext("project/qedeq_logic_language.xml");
141    }
142   
143    /**
144    * Class under test for QedeqBo createQedeq(String, Qedeq).
145    *
146    * @throws Exception Unexpected failure of module creation.
147    */
 
148  1 toggle public void testCreateStringQedeq4() throws Exception {
149  1 loadQedeqAndAssertContext("math/qedeq_sample1.xml");
150    }
151   
152    /**
153    * Class under test for QedeqBo createQedeq(String, Qedeq).
154    *
155    * @throws Exception Unexpected failure of module creation.
156    */
 
157  1 toggle public void testCreateStringQedeq5() throws Exception {
158  1 loadQedeqAndAssertContext("math/qedeq_set_theory_v1.xml");
159    }
160   
161    /**
162    * Class under test for QedeqBo createQedeq(String, Qedeq).
163    *
164    * @throws Exception Unexpected failure of module creation.
165    */
 
166  1 toggle public void testCreateStringQedeq6() throws Exception {
167  1 loadQedeqAndAssertContext("math/qedeq_logic_v1.xml");
168    }
169   
 
170  5 toggle public void loadQedeqAndAssertContext(final String name) throws IOException,
171    ModuleDataException, ParserConfigurationException, SAXException,
172    SourceFileExceptionList {
173  5 loadQedeqAndAssertContext(getQedeqFile(name));
174    }
175   
 
176  10 toggle public static final void loadQedeqAndAssertContext(final File file) throws IOException,
177    ModuleDataException, ParserConfigurationException, SAXException,
178    SourceFileExceptionList {
179  10 final ModuleAddress address = KernelFacade.getKernelContext().getModuleAddress(
180    IoUtility.toUrl(file.getCanonicalFile()));
181  10 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade
182    .getKernelContext().getQedeqBo(address);
183  10 QedeqBoFactoryAssert.createQedeq(prop, createQedeqFromFile(file));
184    }
185   
 
186  0 toggle public static Qedeq loadQedeq(final String name) throws IOException,
187    IllegalModuleDataException, ParserConfigurationException, SAXException,
188    SourceFileExceptionList {
189  0 return loadQedeq(getQedeqFile(name));
190    }
191   
 
192  1 toggle public static Qedeq loadQedeq(final File file) throws IOException,
193    ParserConfigurationException, SAXException,
194    SourceFileExceptionList {
195  1 return createQedeqFromFile(file);
196    }
197   
 
198  23 toggle public static final Qedeq createQedeqFromFile(final File file)
199    throws ParserConfigurationException, SAXException, IOException,
200    SourceFileExceptionList {
201  23 SaxDefaultHandler handler = new SaxDefaultHandler(new DummyPlugin());
202  23 QedeqHandler simple = new QedeqHandler(handler);
203  23 handler.setBasisDocumentHandler(simple);
204  23 SaxParser parser = new SaxParser(DummyPlugin.getInstance(), handler);
205  23 parser.parse(file, null);
206  23 return simple.getQedeq();
207    }
208   
209    /**
210    * Get QEDEQ file.
211    *
212    * @param relativePath File path relative to documentation directory.
213    *
214    * @return Path to file.
215    * @throws IOException IO-Failure.
216    */
 
217  6 toggle public static File getQedeqFile(final String relativePath) throws IOException {
218  6 File docDir = new File("../QedeqDoc");
219    // test if we are in the normal development environment, where a project with name
220    // "../QedeqDoc" exists, otherwise we assume to run within the release directory
221    // structure where the docs are in the directory ../doc
222  6 if (!docDir.exists()) {
223  6 docDir = new File("../doc");
224  6 if (!docDir.exists()) {
225  6 docDir = (new QedeqTestCase(){ }).getFile("doc");
226  6 if (!docDir.exists()) {
227  0 throw new IOException("unknown source directory for QEDEQ modules");
228    }
229    }
230    }
231  6 final File qedeqFile = new File(docDir, relativePath);
232  6 return qedeqFile;
233    }
234   
235    }