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