Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../img/srcFileCovDistChart6.png 73% of files have more coverage
43   159   14   7.17
6   102   0.33   6
6     2.33  
1    
 
  QedeqBoFactoryAssert       Line # 46 43 14 60% 0.6
 
  (8)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, 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;
17   
18    import java.lang.reflect.InvocationTargetException;
19   
20    import org.qedeq.base.io.IoUtility;
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.kernel.base.module.Qedeq;
25    import org.qedeq.kernel.bo.module.InternalKernelServices;
26    import org.qedeq.kernel.bo.module.QedeqFileDao;
27    import org.qedeq.kernel.bo.service.latex.QedeqBoDuplicateLanguageChecker;
28    import org.qedeq.kernel.bo.test.KernelFacade;
29    import org.qedeq.kernel.common.DummyPlugin;
30    import org.qedeq.kernel.common.LoadingState;
31    import org.qedeq.kernel.common.ModuleAddress;
32    import org.qedeq.kernel.common.ModuleDataException;
33    import org.qedeq.kernel.common.Plugin;
34    import org.qedeq.kernel.common.SourceFileExceptionList;
35    import org.qedeq.kernel.dto.module.QedeqVo;
36    import org.qedeq.kernel.xml.dao.XmlQedeqFileDao;
37    import org.qedeq.kernel.xml.mapper.Context2SimpleXPath;
38    import org.qedeq.kernel.xml.tracker.SimpleXPath;
39    import org.qedeq.kernel.xml.tracker.XPathLocationParser;
40   
41    /**
42    * For testing QEDEQ BO generation.
43    *
44    * @author Michael Meyling
45    */
 
46    public class QedeqBoFactoryAssert extends QedeqVoBuilder {
47   
48    /** This class. */
49    private static final Class CLASS = QedeqBoFactoryAssert.class;
50   
51    /**
52    * Constructor.
53    *
54    * @param address QEDEQ module address.
55    */
 
56  11 toggle public QedeqBoFactoryAssert(final ModuleAddress address) {
57  11 super(address);
58    }
59   
60    /**
61    * Create {@link QedeqBo} out of an {@link Qedeq} instance.
62    * During that procedure some basic checking is done. E.g. the uniqueness of entries
63    * is tested.
64    * The resulting business object has no references to the original
65    * {@link Qedeq} instance.
66    * <p>
67    * During the creation process the caller must assert that no modifications are made
68    * to the {@link Qedeq} instance including its referenced objects.
69    *
70    * @param prop Module informations.
71    * @param original Basic qedeq module object.
72    * @throws ModuleDataException Semantic or syntactic error occurred.
73    */
 
74  11 toggle public static void createQedeq(final DefaultKernelQedeqBo prop,
75    final Qedeq original) throws SourceFileExceptionList {
76  11 final QedeqBoFactoryAssert creator = new QedeqBoFactoryAssert(prop.getModuleAddress());
77  11 final QedeqVo vo;
78  11 try {
79  11 vo = creator.create(original);
80    } catch (ModuleDataException e) {
81  0 final SourceFileExceptionList xl
82    = prop.createSourceFileExceptionList(DummyPlugin.getInstance(), e, original);
83  0 prop.setLoadingFailureState(LoadingState.STATE_LOADING_INTO_MEMORY_FAILED, xl);
84  0 throw xl;
85    }
86  11 final InternalKernelServices services = (InternalKernelServices) IoUtility
87    .getFieldContent(KernelFacade.getKernelContext(), "services");
88  11 final QedeqFileDao loader = new XmlQedeqFileDao();
89  11 loader.setServices(services);
90  11 prop.setQedeqFileDao(loader);
91  11 prop.setQedeqVo(vo);
92  11 prop.setLoaded(vo, new ModuleLabelsCreator(DummyPlugin.getInstance(), prop).createLabels());
93  10 KernelFacade.getKernelContext().loadRequiredModules(prop.getModuleAddress());
94  10 KernelFacade.getKernelContext().checkModule(prop.getModuleAddress());
95  10 if (!prop.isChecked()) {
96  0 throw prop.getErrors();
97    }
98  10 QedeqBoDuplicateLanguageChecker.check(new Plugin() {
 
99  0 toggle public String getPluginId() {
100  0 return QedeqBoDuplicateLanguageChecker.class.getName();
101    }
102   
 
103  0 toggle public String getPluginName() {
104  0 return "duplicate language checker";
105    }
106   
 
107  0 toggle public String getPluginDescription() {
108  0 return "Test for duplicate language entries within LaTeX sections";
109    }
110   
111    }, prop);
112    }
113   
114    /**
115    * Set location information where we are within the module.
116    *
117    * @param locationWithinModule Location within module.
118    */
 
119  25604 toggle protected void setLocationWithinModule(final String locationWithinModule) {
120  25604 Trace.param(CLASS, "setLocationWithinModule(String)",
121    "locationWithinModule > ", locationWithinModule);
122  25604 getCurrentContext().setLocationWithinModule(locationWithinModule);
123   
124  25604 try {
125  25604 DynamicGetter.get(getQedeqOriginal(), getCurrentContext().getLocationWithinModule());
126    } catch (RuntimeException e) {
127  0 System.err.println(getCurrentContext().getLocationWithinModule());
128  0 throw e;
129    } catch (IllegalAccessException e) {
130  0 throw new RuntimeException(e);
131    } catch (InvocationTargetException e) {
132  0 throw new RuntimeException(e);
133    }
134   
135  25604 SimpleXPath xpath;
136  25604 try {
137  25604 xpath = Context2SimpleXPath.getXPath(getCurrentContext(), getQedeqOriginal());
138    } catch (ModuleDataException e) {
139  0 throw new RuntimeException(e);
140    }
141  25604 Trace.param(CLASS, "setLocationWithinModule(String)",
142    "xpath < ", xpath);
143  25604 final InternalKernelServices services = (InternalKernelServices) IoUtility
144    .getFieldContent(KernelFacade.getKernelContext(), "services");
145  25604 final SourceArea find = XPathLocationParser.findSourceArea(
146    services.getLocalFilePath(
147    getCurrentContext().getModuleLocation()), xpath);
148  25604 if (find.getStartPosition() == null) {
149  0 System.out.println(getCurrentContext());
150  0 throw new RuntimeException("start not found: " + find + "\ncontext: "
151    + getCurrentContext().getLocationWithinModule());
152    }
153  25604 if (find.getEndPosition() == null) {
154  0 System.out.println(getCurrentContext());
155  0 throw new RuntimeException("end not found: " + find + "\ncontext: "
156    + getCurrentContext().getLocationWithinModule());
157    }
158    }
159    }