01: /*
02: * XML 2 Java Binding (X2JB) - the excellent Java tool.
03: * Copyright 2007, by Richard Opalka.
04: *
05: * This is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as
07: * published by the Free Software Foundation; either version 2.1 of
08: * the License, or (at your option) any later version.
09: *
10: * This software 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 GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this software; if not see the FSF site:
17: * http://www.fsf.org/ and search for the LGPL License document there.
18: */
19: package test.org.x2jb.bind;
20:
21: import org.w3c.dom.Node;
22: import org.w3c.dom.Text;
23:
24: /**
25: * XML2Java Test Helper
26: *
27: * @author <a href="mailto:richard_opalka@yahoo.com">Richard Opalka</a>
28: * @version 1.0
29: */
30: public final class Helper {
31:
32: private static final boolean verbose = Boolean
33: .getBoolean("org.x2jb.bind.test.verbose");
34:
35: private Helper() {
36: // no instances
37: }
38:
39: public static void assertContains(Exception exception,
40: String[] expectedSubstrings) throws Exception {
41: if (verbose) {
42: exception.printStackTrace(System.out);
43: }
44: String exceptionMessage = exception.getMessage();
45:
46: // validate incomming parameters
47: if (exceptionMessage == null)
48: throw new IllegalArgumentException();
49:
50: for (int i = 0; i < expectedSubstrings.length; i++)
51: if (expectedSubstrings[i] == null)
52: throw new IllegalArgumentException();
53:
54: // perform checks
55: for (int i = 0; i < expectedSubstrings.length; i++) {
56: String s = expectedSubstrings[i];
57: if (exceptionMessage.indexOf(s) == -1)
58: throw new RuntimeException("String '" + s
59: + "' not found in '" + exceptionMessage + "'");
60: }
61:
62: if (verbose) {
63: System.out.println("Expected exception caught: "
64: + exceptionMessage);
65: }
66: }
67:
68: public static String getTextContent(Node e) {
69: Node childNode = e.getFirstChild();
70: if ((childNode == null) || (!(childNode instanceof Text))) {
71: return null;
72: } else {
73: return ((Text) childNode).getData();
74: }
75: }
76:
77: }
|