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