1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.magicproject.xml.test;
22
23 import java.io.OutputStream;
24 import java.util.Iterator;
25
26 import net.sf.magicproject.test.IdTest;
27 import net.sf.magicproject.tools.MToolKit;
28 import net.sf.magicproject.xml.XmlConfiguration;
29 import net.sf.magicproject.xml.XmlParser;
30 import net.sf.magicproject.xml.XmlTest;
31 import net.sf.magicproject.xml.XmlToMDB;
32 import net.sf.magicproject.xml.tbs.Tbs;
33
34 /***
35 * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
36 * @since 0.82
37 */
38 public class Test implements XmlToMDB {
39
40 /***
41 * Write the contained test of the specified node <br>
42 * <ul>
43 * Structure of stream : Data[size]
44 * <li>test identifiant [1]</li>
45 * <li>tested on identifiant [1]</li>
46 * <li>depending on the test [...]</li>
47 * </ul>
48 *
49 * @param node
50 * the XML test container structure
51 * @param out
52 * outputstream where the card structure will be saved
53 * @return the amount of written action, so return alway ZERO.
54 * @see net.sf.magicproject.test.IdTest
55 */
56 public final int buildMdb(XmlParser.Node node, OutputStream out) {
57 try {
58 if (node == null) {
59
60 IdTest.TRUE.serialize(out);
61 } else {
62 String referenceName = node.getAttribute("ref");
63 if (referenceName != null) {
64
65 if ("context.test".equals(node.getAttribute("ref").toString())) {
66 IdTest.CONTEXT_TEST.serialize(out);
67 } else {
68 if (Tbs.resolveReferences) {
69 if (Tbs.referencedTest.get(referenceName) == null) {
70 XmlConfiguration.error++;
71 System.out.println("\t>> Referenced test '" + referenceName
72 + "' is unknown");
73 return 0;
74 }
75 }
76 IdTest.REFERENCED_TEST.serialize(out);
77 MToolKit.writeString(out, referenceName);
78 }
79 } else {
80 final Iterator<?> it = node.iterator();
81 while (it.hasNext()) {
82 Object obj = it.next();
83 if (obj instanceof XmlParser.Node) {
84 return XmlTest.getTest(((XmlParser.Node) obj).getTag()).buildMdb(
85 (XmlParser.Node) obj, out);
86 }
87 }
88
89 IdTest.TRUE.serialize(out);
90 }
91 }
92 } catch (Throwable e2) {
93 XmlConfiguration.error++;
94 System.out.println("\t>> Error found in test '"
95 + (node == null ? "null" : node.getTag()) + "' : " + e2.getMessage()
96 + ". Context=" + (node == null ? "null" : node.toString()));
97 }
98 return 0;
99 }
100
101 }