Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
62   238   23   3.88
10   148   0.37   16
16     1.44  
1    
 
  QedeqBoFactoryTest       Line # 49 62 23 80.7% 0.8068182
 
  (9)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, 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.control;
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.UrlUtility;
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.bo.module.InternalServiceCall;
29    import org.qedeq.kernel.bo.service.control.DefaultKernelQedeqBo;
30    import org.qedeq.kernel.bo.service.control.ModuleLabelsCreator;
31    import org.qedeq.kernel.bo.test.DummyPlugin;
32    import org.qedeq.kernel.bo.test.KernelFacade;
33    import org.qedeq.kernel.bo.test.QedeqBoTestCase;
34    import org.qedeq.kernel.se.base.module.Author;
35    import org.qedeq.kernel.se.base.module.Qedeq;
36    import org.qedeq.kernel.se.common.ModuleAddress;
37    import org.qedeq.kernel.se.common.SourceFileException;
38    import org.qedeq.kernel.se.common.SourceFileExceptionList;
39    import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler;
40    import org.qedeq.kernel.xml.handler.module.QedeqHandler;
41    import org.qedeq.kernel.xml.parser.SaxParser;
42    import org.xml.sax.SAXException;
43   
44    /**
45    * For testing QEDEQ generation.
46    *
47    * @author Michael Meyling
48    */
 
49    public class QedeqBoFactoryTest extends QedeqBoTestCase {
50   
51    /** This class. */
52    private static final Class CLASS = QedeqBoFactoryTest.class;
53   
54    private Qedeq ok;
55   
56    private Qedeq error;
57   
58    private File okFile;
59   
60    private File errorFile;
61   
62    private InternalServiceCall call;
63   
 
64  6 toggle protected void setUp() throws Exception {
65  6 super.setUp();
66  6 try {
67  6 okFile = getFile("qedeq_sample1.xml");
68  6 errorFile = getFile("qedeq_error_sample_12.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 e.printStackTrace(System.out);
76  0 super.tearDown();
77  0 throw e;
78    }
79    }
80   
 
81  6 toggle protected void tearDown() throws Exception {
82  6 ok = null;
83  6 error = null;
84  6 endServiceCall(call);
85  6 super.tearDown();
86    }
87   
 
88  0 toggle public QedeqBoFactoryTest() {
89  0 super();
90    }
91   
 
92  6 toggle public QedeqBoFactoryTest(final String name) {
93  6 super(name);
94    }
95   
96    /**
97    * Class under test for QedeqBo create(String, Qedeq).
98    */
 
99  1 toggle public void testCreateStringQedeq1() throws Exception {
100  1 final String method = "testCreateStringQedeq()";
101  1 final ModuleAddress address = getServices().getModuleAddress(
102    UrlUtility.toUrl(errorFile.getCanonicalFile()));
103  1 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade
104    .getKernelContext().getQedeqBo(address);
105  1 try {
106  1 QedeqBoFactoryAssert.createQedeq(prop, error);
107    // TODO mime 20080306: move this test to another location, building doesn't include
108    // checking any longer
109  0 final ModuleLabelsCreator creator = new ModuleLabelsCreator(DummyPlugin.getInstance(), prop);
110  0 call = createServiceCall("testCreateStringQedeq1", prop);
111  0 creator.createLabels(call.getInternalServiceProcess());
112  0 fail("SourceFileExceptionList expected");
113    } catch (SourceFileExceptionList e) {
114  1 SourceFileException sf = e.get(0);
115  1 assertEquals(221, sf.getSourceArea().getStartPosition().getRow());
116  1 assertEquals(9, sf.getSourceArea().getStartPosition().getColumn());
117  1 assertEquals(267, sf.getSourceArea().getEndPosition().getRow());
118  1 assertEquals(16, sf.getSourceArea().getEndPosition().getColumn());
119  1 Trace.trace(CLASS, this, method, e);
120    } finally {
121  1 endServiceCall(call);
122    }
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("sample/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 if (slow()) {
160  1 loadQedeqAndAssertContext("math/qedeq_set_theory_v1.xml");
161    }
162    }
163   
164    /**
165    * Class under test for QedeqBo createQedeq(String, Qedeq).
166    *
167    * @throws Exception Unexpected failure of module creation.
168    */
 
169  1 toggle public void testCreateStringQedeq6() throws Exception {
170  1 if (slow()) {
171  1 loadQedeqAndAssertContext("math/qedeq_logic_v1.xml");
172    }
173    }
174   
 
175  5 toggle public void loadQedeqAndAssertContext(final String name) throws Exception,
176    ParserConfigurationException, SAXException,
177    SourceFileExceptionList {
178  5 loadQedeqAndAssertContext(getQedeqFile(name));
179    }
180   
 
181  16 toggle public static final void loadQedeqAndAssertContext(final File file) throws Exception,
182    ParserConfigurationException, SAXException,
183    SourceFileExceptionList {
184  16 final ModuleAddress address = KernelFacade.getKernelContext().getModuleAddress(
185    UrlUtility.toUrl(file.getCanonicalFile()));
186  16 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade
187    .getKernelContext().getQedeqBo(address);
188  16 QedeqBoFactoryAssert.createQedeq(prop, createQedeqFromFile(file));
189    }
190   
 
191  0 toggle public static Qedeq loadQedeq(final String name) throws IOException,
192    ParserConfigurationException, SAXException,
193    SourceFileExceptionList {
194  0 return loadQedeq(getQedeqFile(name));
195    }
196   
 
197  1 toggle public static Qedeq loadQedeq(final File file) throws ParserConfigurationException, SAXException,
198    SourceFileExceptionList {
199  1 return createQedeqFromFile(file);
200    }
201   
 
202  29 toggle public static final Qedeq createQedeqFromFile(final File file)
203    throws ParserConfigurationException, SAXException, SourceFileExceptionList {
204  29 SaxDefaultHandler handler = new SaxDefaultHandler(new DummyPlugin());
205  29 QedeqHandler simple = new QedeqHandler(handler);
206  29 handler.setBasisDocumentHandler(simple);
207  29 SaxParser parser = new SaxParser(DummyPlugin.getInstance(), handler);
208  29 parser.parse(file, null);
209  29 return simple.getQedeq();
210    }
211   
212    /**
213    * Get QEDEQ file.
214    *
215    * @param relativePath File path relative to documentation directory.
216    *
217    * @return Path to file.
218    * @throws IOException IO-Failure.
219    */
 
220  6 toggle public static File getQedeqFile(final String relativePath) throws IOException {
221  6 File docDir = new File("../QedeqDoc");
222    // test if we are in the normal development environment, where a project with name
223    // "../QedeqDoc" exists, otherwise we assume to run within the release directory
224    // structure where the docs are in the directory ../doc
225  6 if (!docDir.exists()) {
226  6 docDir = new File("../doc");
227  6 if (!docDir.exists()) {
228  6 docDir = (new QedeqTestCase(){ }).getFile("doc");
229  6 if (!docDir.exists()) {
230  0 throw new IOException("unknown source directory for QEDEQ modules");
231    }
232    }
233    }
234  6 final File qedeqFile = new File(docDir, relativePath);
235  6 return qedeqFile;
236    }
237   
238    }