Clover Coverage Report
Coverage timestamp: Fri Feb 14 2014 07:28:57 UTC
../../../../../../img/srcFileCovDistChart7.png 74% of files have more coverage
67   208   19   11.17
8   152   0.28   6
6     3.17  
1    
 
  QedeqBoFactoryAssert       Line # 58 67 19 70.4% 0.7037037
 
  (8)
 
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.lang.reflect.InvocationTargetException;
19   
20    import org.qedeq.base.io.Parameters;
21    import org.qedeq.base.io.SourceArea;
22    import org.qedeq.base.test.DynamicGetter;
23    import org.qedeq.base.trace.Trace;
24    import org.qedeq.base.utility.YodaUtility;
25    import org.qedeq.kernel.bo.common.Element2Utf8;
26    import org.qedeq.kernel.bo.job.InternalModuleServiceCallImpl;
27    import org.qedeq.kernel.bo.module.InternalKernelServices;
28    import org.qedeq.kernel.bo.module.InternalModuleServiceCall;
29    import org.qedeq.kernel.bo.module.InternalServiceJob;
30    import org.qedeq.kernel.bo.module.KernelQedeqBo;
31    import org.qedeq.kernel.bo.module.ModuleLabels;
32    import org.qedeq.kernel.bo.module.QedeqFileDao;
33    import org.qedeq.kernel.bo.service.internal.DefaultInternalKernelServices;
34    import org.qedeq.kernel.bo.service.internal.DefaultKernelQedeqBo;
35    import org.qedeq.kernel.bo.service.internal.Element2LatexImpl;
36    import org.qedeq.kernel.bo.service.internal.Element2Utf8Impl;
37    import org.qedeq.kernel.bo.service.internal.ServiceProcessManager;
38    import org.qedeq.kernel.bo.service.latex.QedeqBoDuplicateLanguageChecker;
39    import org.qedeq.kernel.bo.test.DummyPlugin;
40    import org.qedeq.kernel.bo.test.KernelFacade;
41    import org.qedeq.kernel.se.base.module.Qedeq;
42    import org.qedeq.kernel.se.common.ModuleAddress;
43    import org.qedeq.kernel.se.common.ModuleDataException;
44    import org.qedeq.kernel.se.common.SourceFileExceptionList;
45    import org.qedeq.kernel.se.dto.module.QedeqVo;
46    import org.qedeq.kernel.se.state.LoadingState;
47    import org.qedeq.kernel.se.visitor.InterruptException;
48    import org.qedeq.kernel.xml.dao.XmlQedeqFileDao;
49    import org.qedeq.kernel.xml.mapper.Context2SimpleXPath;
50    import org.qedeq.kernel.xml.tracker.SimpleXPath;
51    import org.qedeq.kernel.xml.tracker.XPathLocationParser;
52   
53    /**
54    * For testing QEDEQ BO generation.
55    *
56    * @author Michael Meyling
57    */
 
58    public class QedeqBoFactoryAssert extends QedeqVoBuilder {
59   
60    /** This class. */
61    private static final Class CLASS = QedeqBoFactoryAssert.class;
62   
63    /**
64    * Constructor.
65    *
66    * @param address QEDEQ module address.
67    */
 
68  18 toggle public QedeqBoFactoryAssert(final ModuleAddress address) {
69  18 super(address);
70    }
71   
 
72  54 toggle public static DefaultInternalKernelServices getInternalServices() {
73  54 try {
74  54 return (DefaultInternalKernelServices) YodaUtility.getFieldValue(
75    KernelFacade.getKernelContext(), "services");
76    } catch (NoSuchFieldException e) {
77  0 throw new RuntimeException(e);
78    }
79    }
80   
 
81  18 toggle public static InternalModuleServiceCall createServiceCall(final String name, final KernelQedeqBo prop)
82    throws InterruptException {
83  18 final InternalServiceJob process;
84  18 try {
85  18 process = ((ServiceProcessManager) YodaUtility.getFieldValue(getInternalServices(), "processManager"))
86    .createServiceProcess(name);
87    } catch (NoSuchFieldException e) {
88  0 e.printStackTrace();
89  0 throw new RuntimeException(e);
90    }
91  18 final InternalModuleServiceCallImpl call = new InternalModuleServiceCallImpl(DummyPlugin.getInstance(), prop, Parameters.EMPTY, Parameters.EMPTY, process, null);
92  18 return call;
93    }
94   
 
95  18 toggle public static void endServiceCall(final InternalModuleServiceCall call) {
96  18 if (call == null) {
97  0 return;
98    }
99  18 try {
100  18 ((ServiceProcessManager) YodaUtility.getFieldValue(getInternalServices(), "processManager"))
101    .endServiceCall(call);
102    } catch (NoSuchFieldException e) {
103  0 e.printStackTrace();
104  0 throw new RuntimeException(e);
105    }
106    }
107   
108    /**
109    * Create {@link QedeqBo} out of an {@link Qedeq} instance.
110    * During that procedure some basic checking is done. E.g. the uniqueness of entries
111    * is tested.
112    * The resulting business object has no references to the original
113    * {@link Qedeq} instance.
114    * <p>
115    * During the creation process the caller must assert that no modifications are made
116    * to the {@link Qedeq} instance including its referenced objects.
117    *
118    * @param prop Module informations.
119    * @param original Basic qedeq module object.
120    */
 
121  18 toggle public static void createQedeq(final DefaultKernelQedeqBo prop,
122    final Qedeq original) throws SourceFileExceptionList, InterruptException {
123  18 final QedeqBoFactoryAssert creator = new QedeqBoFactoryAssert(prop.getModuleAddress());
124  18 final QedeqVo vo;
125  18 try {
126  18 vo = creator.create(original);
127    } catch (ModuleDataException e) {
128  0 final SourceFileExceptionList xl
129    = prop.createSourceFileExceptionList(DummyPlugin.getInstance(), e, original);
130  0 prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl);
131  0 throw xl;
132    }
133  18 final QedeqFileDao loader = new XmlQedeqFileDao();
134  18 loader.setServices(getInternalServices());
135  18 prop.setQedeqFileDao(loader);
136  18 prop.setQedeqVo(vo);
137  18 final ModuleLabelsCreator mc = new ModuleLabelsCreator(DummyPlugin.getInstance(),
138    prop);
139  18 InternalModuleServiceCall call = null;
140  18 final ModuleLabels labels = new ModuleLabels();
141  18 final Element2LatexImpl converter = new Element2LatexImpl(labels);
142  18 final Element2Utf8 textConverter = new Element2Utf8Impl(converter);
143  18 try {
144  18 call = createServiceCall("createQedeq", prop);
145  18 mc.createLabels(call.getInternalServiceProcess(), labels);
146    } finally {
147  18 endServiceCall(call);
148    }
149  17 prop.setLoaded(vo, labels, converter, textConverter);
150  17 KernelFacade.getKernelContext().loadRequiredModules(prop.getModuleAddress());
151  17 KernelFacade.getKernelContext().checkWellFormedness(prop.getModuleAddress());
152  17 if (!prop.isWellFormed()) {
153  0 throw prop.getErrors();
154    }
155  17 QedeqBoDuplicateLanguageChecker.check(call);
156    }
157   
158    /**
159    * Set location information where we are within the module.
160    *
161    * @param locationWithinModule Location within module.
162    */
 
163  58656 toggle protected void setLocationWithinModule(final String locationWithinModule) {
164  58656 Trace.param(CLASS, "setLocationWithinModule(String)",
165    "locationWithinModule > ", locationWithinModule);
166  58656 getCurrentContext().setLocationWithinModule(locationWithinModule);
167   
168  58656 try {
169  58656 DynamicGetter.get(getQedeqOriginal(), getCurrentContext().getLocationWithinModule());
170    } catch (RuntimeException e) {
171  0 System.err.println(getCurrentContext().getLocationWithinModule());
172  0 throw e;
173    } catch (IllegalAccessException e) {
174  0 throw new RuntimeException(e);
175    } catch (InvocationTargetException e) {
176  0 throw new RuntimeException(e);
177    }
178   
179  58656 SimpleXPath xpath;
180  58656 try {
181  58656 xpath = Context2SimpleXPath.getXPath(getCurrentContext(), getQedeqOriginal());
182    } catch (ModuleDataException e) {
183  0 throw new RuntimeException(e);
184    }
185  58656 Trace.param(CLASS, "setLocationWithinModule(String)",
186    "xpath < ", xpath);
187  58656 InternalKernelServices services;
188  58656 try {
189  58656 services = (InternalKernelServices) YodaUtility
190    .getFieldValue(KernelFacade.getKernelContext(), "services");
191    } catch (NoSuchFieldException e) {
192  0 throw new RuntimeException(e);
193    }
194  58656 final SourceArea find = XPathLocationParser.findSourceArea(
195    services.getLocalFilePath(
196    getCurrentContext().getModuleLocation()), xpath);
197  58656 if (find.getStartPosition() == null) {
198  0 System.out.println(getCurrentContext());
199  0 throw new RuntimeException("start not found: " + find + "\ncontext: "
200    + getCurrentContext().getLocationWithinModule());
201    }
202  58656 if (find.getEndPosition() == null) {
203  0 System.out.println(getCurrentContext());
204  0 throw new RuntimeException("end not found: " + find + "\ncontext: "
205    + getCurrentContext().getLocationWithinModule());
206    }
207    }
208    }