Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
63   239   23   3.94
10   149   0.37   16
16     1.44  
1    
 
  QedeqBoFactoryTest       Line # 49 63 23 79.8% 0.7977528
 
  (9)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2014, 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.basis;
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.InternalModuleServiceCall;
29    import org.qedeq.kernel.bo.module.ModuleLabels;
30    import org.qedeq.kernel.bo.service.internal.DefaultKernelQedeqBo;
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 InternalModuleServiceCall 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 final ModuleLabels labels = new ModuleLabels();
112  0 creator.createLabels(call.getInternalServiceProcess(), labels);
113  0 fail("SourceFileExceptionList expected");
114    } catch (SourceFileExceptionList e) {
115  1 SourceFileException sf = e.get(0);
116  1 assertEquals(221, sf.getSourceArea().getStartPosition().getRow());
117  1 assertEquals(9, sf.getSourceArea().getStartPosition().getColumn());
118  1 assertEquals(267, sf.getSourceArea().getEndPosition().getRow());
119  1 assertEquals(16, sf.getSourceArea().getEndPosition().getColumn());
120  1 Trace.trace(CLASS, this, method, e);
121    } finally {
122  1 endServiceCall(call);
123    }
124   
125    }
126   
127    /**
128    * Class under test for QedeqBo createQedeq(String, Qedeq).
129    *
130    * @throws Exception Unexpected failure of module creation.
131    */
 
132  1 toggle public void testCreateStringQedeq2() throws Exception {
133  1 loadQedeqAndAssertContext("project/qedeq_basic_concept.xml");
134    }
135   
136    /**
137    * Class under test for QedeqBo createQedeq(String, Qedeq).
138    *
139    * @throws Exception Unexpected failure of module creation.
140    */
 
141  1 toggle public void testCreateStringQedeq3() throws Exception {
142  1 loadQedeqAndAssertContext("project/qedeq_logic_language.xml");
143    }
144   
145    /**
146    * Class under test for QedeqBo createQedeq(String, Qedeq).
147    *
148    * @throws Exception Unexpected failure of module creation.
149    */
 
150  1 toggle public void testCreateStringQedeq4() throws Exception {
151  1 loadQedeqAndAssertContext("sample/qedeq_sample1.xml");
152    }
153   
154    /**
155    * Class under test for QedeqBo createQedeq(String, Qedeq).
156    *
157    * @throws Exception Unexpected failure of module creation.
158    */
 
159  1 toggle public void testCreateStringQedeq5() throws Exception {
160  1 if (slow()) {
161  1 loadQedeqAndAssertContext("math/qedeq_set_theory_v1.xml");
162    }
163    }
164   
165    /**
166    * Class under test for QedeqBo createQedeq(String, Qedeq).
167    *
168    * @throws Exception Unexpected failure of module creation.
169    */
 
170  1 toggle public void testCreateStringQedeq6() throws Exception {
171  1 if (slow()) {
172  1 loadQedeqAndAssertContext("math/qedeq_logic_v1.xml");
173    }
174    }
175   
 
176  5 toggle public void loadQedeqAndAssertContext(final String name) throws Exception,
177    ParserConfigurationException, SAXException,
178    SourceFileExceptionList {
179  5 loadQedeqAndAssertContext(getQedeqFile(name));
180    }
181   
 
182  17 toggle public static final void loadQedeqAndAssertContext(final File file) throws Exception,
183    ParserConfigurationException, SAXException,
184    SourceFileExceptionList {
185  17 final ModuleAddress address = KernelFacade.getKernelContext().getModuleAddress(
186    UrlUtility.toUrl(file.getCanonicalFile()));
187  17 final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade
188    .getKernelContext().getQedeqBo(address);
189  17 QedeqBoFactoryAssert.createQedeq(prop, createQedeqFromFile(file));
190    }
191   
 
192  0 toggle public static Qedeq loadQedeq(final String name) throws IOException,
193    ParserConfigurationException, SAXException,
194    SourceFileExceptionList {
195  0 return loadQedeq(getQedeqFile(name));
196    }
197   
 
198  1 toggle public static Qedeq loadQedeq(final File file) throws ParserConfigurationException, SAXException,
199    SourceFileExceptionList {
200  1 return createQedeqFromFile(file);
201    }
202   
 
203  30 toggle public static final Qedeq createQedeqFromFile(final File file)
204    throws ParserConfigurationException, SAXException, SourceFileExceptionList {
205  30 SaxDefaultHandler handler = new SaxDefaultHandler(new DummyPlugin());
206  30 QedeqHandler simple = new QedeqHandler(handler);
207  30 handler.setBasisDocumentHandler(simple);
208  30 SaxParser parser = new SaxParser(DummyPlugin.getInstance(), handler);
209  30 parser.parse(file, null);
210  30 return simple.getQedeq();
211    }
212   
213    /**
214    * Get QEDEQ file.
215    *
216    * @param relativePath File path relative to documentation directory.
217    *
218    * @return Path to file.
219    * @throws IOException IO-Failure.
220    */
 
221  6 toggle public static File getQedeqFile(final String relativePath) throws IOException {
222  6 File docDir = new File("../QedeqDoc");
223    // test if we are in the normal development environment, where a project with name
224    // "../QedeqDoc" exists, otherwise we assume to run within the release directory
225    // structure where the docs are in the directory ../doc
226  6 if (!docDir.exists()) {
227  6 docDir = new File("../doc");
228  6 if (!docDir.exists()) {
229  6 docDir = (new QedeqTestCase(){ }).getFile("doc");
230  6 if (!docDir.exists()) {
231  0 throw new IOException("unknown source directory for QEDEQ modules");
232    }
233    }
234    }
235  6 final File qedeqFile = new File(docDir, relativePath);
236  6 return qedeqFile;
237    }
238   
239    }