1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.bo.service.logic; |
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.Parameters; |
24 |
|
import org.qedeq.base.io.UrlUtility; |
25 |
|
import org.qedeq.base.trace.Trace; |
26 |
|
import org.qedeq.base.utility.YodaUtility; |
27 |
|
import org.qedeq.kernel.bo.common.Element2Utf8; |
28 |
|
import org.qedeq.kernel.bo.logic.common.FormulaChecker; |
29 |
|
import org.qedeq.kernel.bo.logic.common.LogicalCheckException; |
30 |
|
import org.qedeq.kernel.bo.module.InternalModuleServiceCall; |
31 |
|
import org.qedeq.kernel.bo.module.KernelModuleReferenceList; |
32 |
|
import org.qedeq.kernel.bo.module.ModuleLabels; |
33 |
|
import org.qedeq.kernel.bo.module.QedeqFileDao; |
34 |
|
import org.qedeq.kernel.bo.service.basis.ModuleLabelsCreator; |
35 |
|
import org.qedeq.kernel.bo.service.basis.QedeqVoBuilder; |
36 |
|
import org.qedeq.kernel.bo.service.internal.DefaultKernelQedeqBo; |
37 |
|
import org.qedeq.kernel.bo.service.internal.Element2LatexImpl; |
38 |
|
import org.qedeq.kernel.bo.service.internal.Element2Utf8Impl; |
39 |
|
import org.qedeq.kernel.bo.test.DummyPlugin; |
40 |
|
import org.qedeq.kernel.bo.test.KernelFacade; |
41 |
|
import org.qedeq.kernel.bo.test.QedeqBoTestCase; |
42 |
|
import org.qedeq.kernel.se.common.ModuleAddress; |
43 |
|
import org.qedeq.kernel.se.common.ModuleDataException; |
44 |
|
import org.qedeq.kernel.se.common.SourceFileException; |
45 |
|
import org.qedeq.kernel.se.common.SourceFileExceptionList; |
46 |
|
import org.qedeq.kernel.se.dto.module.QedeqVo; |
47 |
|
import org.qedeq.kernel.xml.dao.XmlQedeqFileDao; |
48 |
|
import org.qedeq.kernel.xml.handler.common.SaxDefaultHandler; |
49 |
|
import org.qedeq.kernel.xml.handler.module.QedeqHandler; |
50 |
|
import org.qedeq.kernel.xml.parser.SaxParser; |
51 |
|
import org.xml.sax.SAXException; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
@author |
57 |
|
|
|
|
| 93.3% |
Uncovered Elements: 6 (90) |
Complexity: 13 |
Complexity Density: 0.16 |
|
58 |
|
public final class QedeqBoFormalLogicCheckerDirectTest extends QedeqBoTestCase { |
59 |
|
|
60 |
|
|
61 |
|
private static final Class CLASS = FormulaChecker.class; |
62 |
|
private InternalModuleServiceCall call; |
63 |
|
|
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
65 |
5
|
protected void tearDown() throws Exception {... |
66 |
5
|
endServiceCall(call); |
67 |
5
|
super.tearDown(); |
68 |
|
} |
69 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1
PASS
|
|
70 |
1
|
public void testNegative00() throws Exception {... |
71 |
1
|
try { |
72 |
1
|
check(getFile("qedeq_error_sample_00.xml")); |
73 |
0
|
fail("SourceFileExceptionList expected"); |
74 |
|
} catch (SourceFileExceptionList ex) { |
75 |
1
|
Trace.trace(CLASS, this, "testNegative00", ex); |
76 |
1
|
assertEquals(1, ex.size()); |
77 |
1
|
final SourceFileException check = ex.get(0); |
78 |
|
|
79 |
1
|
assertEquals(9001, check.getErrorCode()); |
80 |
1
|
assertEquals(36, check.getSourceArea().getStartPosition().getRow()); |
81 |
1
|
assertEquals(1, check.getSourceArea().getStartPosition().getColumn()); |
82 |
1
|
assertEquals(36, check.getSourceArea().getEndPosition().getRow()); |
83 |
1
|
assertEquals(20, check.getSourceArea().getEndPosition().getColumn()); |
84 |
|
} |
85 |
|
} |
86 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1
PASS
|
|
87 |
1
|
public void testNegative01() throws Exception {... |
88 |
1
|
try { |
89 |
1
|
check(getFile("qedeq_error_sample_01.xml")); |
90 |
0
|
fail("SourceFileExceptionList expected"); |
91 |
|
} catch (SourceFileExceptionList ex) { |
92 |
1
|
Trace.trace(CLASS, this, "testNegative01", ex); |
93 |
1
|
assertEquals(1, ex.size()); |
94 |
1
|
final SourceFileException check = ex.get(0); |
95 |
1
|
assertEquals(9001, check.getErrorCode()); |
96 |
1
|
assertEquals(39, check.getSourceArea().getStartPosition().getRow()); |
97 |
1
|
assertEquals(1, check.getSourceArea().getStartPosition().getColumn()); |
98 |
1
|
assertEquals(39, check.getSourceArea().getEndPosition().getRow()); |
99 |
1
|
assertEquals(35, check.getSourceArea().getEndPosition().getColumn()); |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
1
PASS
|
|
103 |
1
|
public void testNegative02() throws Exception {... |
104 |
1
|
try { |
105 |
1
|
check(getFile("qedeq_error_sample_02.xml")); |
106 |
0
|
fail("SourceFileExceptionList expected"); |
107 |
|
} catch (SourceFileExceptionList sfl) { |
108 |
1
|
Trace.trace(CLASS, this, "testNegative02", sfl); |
109 |
1
|
final Exception e = (Exception) sfl.get(0).getCause(); |
110 |
1
|
Trace.param(CLASS, this, "testNegative02", "name", e.getClass().getName()); |
111 |
1
|
assertTrue(e instanceof LogicalCheckException); |
112 |
1
|
final LogicalCheckException check = (LogicalCheckException) e; |
113 |
1
|
assertEquals(30550, check.getErrorCode()); |
114 |
1
|
assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1).getList()", check.getContext().getLocationWithinModule()); |
115 |
1
|
assertNull(check.getReferenceContext()); |
116 |
|
} |
117 |
|
} |
118 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1
PASS
|
|
119 |
1
|
public void testNegative03() throws Exception {... |
120 |
1
|
try { |
121 |
1
|
check(getFile("qedeq_error_sample_03.xml")); |
122 |
0
|
fail("SourceFileExceptionList expected"); |
123 |
|
} catch (SourceFileExceptionList sfl) { |
124 |
1
|
Trace.trace(CLASS, this, "testNegative03", sfl); |
125 |
1
|
final Exception e = (Exception) sfl.get(0).getCause(); |
126 |
1
|
assertTrue(e instanceof LogicalCheckException); |
127 |
1
|
final LogicalCheckException check = (LogicalCheckException) e; |
128 |
1
|
assertEquals(30770, check.getErrorCode()); |
129 |
1
|
assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1)", check.getContext().getLocationWithinModule()); |
130 |
1
|
assertNull(check.getReferenceContext()); |
131 |
|
} |
132 |
|
} |
133 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
1
PASS
|
|
134 |
1
|
public void testNegative04() throws Exception {... |
135 |
1
|
try { |
136 |
1
|
check(getFile("qedeq_error_sample_04.xml")); |
137 |
0
|
fail("SourceFileExceptionList expected"); |
138 |
|
} catch (SourceFileExceptionList sfl) { |
139 |
1
|
Trace.trace(CLASS, this, "testNegative04", sfl); |
140 |
1
|
final Exception e = (Exception) sfl.get(0).getCause(); |
141 |
1
|
assertTrue(e instanceof LogicalCheckException); |
142 |
1
|
final LogicalCheckException check = (LogicalCheckException) e; |
143 |
1
|
assertEquals(30780, check.getErrorCode()); |
144 |
1
|
assertEquals("getChapterList().get(0).getSectionList().get(0).getSubsectionList().get(0).getNode().getNodeType().getAxiom().getFormula().getElement().getList().getElement(1)", check.getContext().getLocationWithinModule()); |
145 |
1
|
assertNull(check.getReferenceContext()); |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@param |
153 |
|
|
|
|
| 96.4% |
Uncovered Elements: 1 (28) |
Complexity: 2 |
Complexity Density: 0.08 |
|
154 |
5
|
public void check(final File xmlFile) throws IOException,... |
155 |
|
ParserConfigurationException, SAXException, ModuleDataException, |
156 |
|
SourceFileExceptionList, NoSuchFieldException { |
157 |
5
|
final ModuleAddress context = getServices().getModuleAddress( |
158 |
|
UrlUtility.toUrl(xmlFile.getAbsoluteFile())); |
159 |
5
|
SaxDefaultHandler handler = new SaxDefaultHandler(new DummyPlugin()); |
160 |
5
|
QedeqHandler simple = new QedeqHandler(handler); |
161 |
5
|
handler.setBasisDocumentHandler(simple); |
162 |
5
|
SaxParser parser = new SaxParser(DummyPlugin.getInstance(), handler); |
163 |
5
|
parser.parse(xmlFile, xmlFile.getPath()); |
164 |
3
|
final QedeqVo qedeq = (QedeqVo) simple.getQedeq(); |
165 |
3
|
final QedeqFileDao loader = new XmlQedeqFileDao(); |
166 |
3
|
loader.setServices(getInternalServices()); |
167 |
3
|
final DefaultKernelQedeqBo prop = (DefaultKernelQedeqBo) KernelFacade |
168 |
|
.getKernelContext().getQedeqBo(context); |
169 |
3
|
prop.setQedeqFileDao(loader); |
170 |
3
|
YodaUtility.setFieldContent(prop, "qedeq", qedeq); |
171 |
3
|
final ModuleLabelsCreator creator = new ModuleLabelsCreator(DummyPlugin.getInstance(), |
172 |
|
prop); |
173 |
3
|
call = createServiceCall("check", prop); |
174 |
3
|
final ModuleLabels labels = new ModuleLabels(); |
175 |
3
|
final Element2LatexImpl converter = new Element2LatexImpl(labels); |
176 |
3
|
final Element2Utf8 textConverter = new Element2Utf8Impl(converter); |
177 |
3
|
creator.createLabels(call.getInternalServiceProcess(), labels); |
178 |
3
|
prop.setLoaded(QedeqVoBuilder.createQedeq(prop.getModuleAddress(), qedeq), |
179 |
|
labels, converter, textConverter); |
180 |
3
|
prop.setLoadedImports(new KernelModuleReferenceList()); |
181 |
3
|
prop.setLoadedRequiredModules(); |
182 |
3
|
final WellFormedCheckerPlugin plugin = new WellFormedCheckerPlugin(); |
183 |
3
|
final Parameters parameters = getInternalServices().getConfig().getServiceEntries(plugin); |
184 |
3
|
plugin.createExecutor(prop, parameters).executePlugin(call, null); |
185 |
3
|
if (prop.hasErrors()) { |
186 |
3
|
throw prop.getErrors(); |
187 |
|
} |
188 |
|
} |
189 |
|
|
190 |
|
} |