tmf: Add getDocumentFromFile() to XmlUtils
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core.tests / common / org / eclipse / tracecompass / tmf / analysis / xml / core / tests / common / TmfXmlTestFiles.java
1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common;
14
15 import static org.junit.Assert.fail;
16
17 import java.io.File;
18 import java.io.IOException;
19
20 import javax.xml.parsers.ParserConfigurationException;
21
22 import org.eclipse.core.runtime.IPath;
23 import org.eclipse.core.runtime.Path;
24 import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
25 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator;
26 import org.w3c.dom.Document;
27 import org.xml.sax.SAXException;
28
29 /**
30 * Provides some test XML files to use
31 *
32 * @author Geneviève Bastien
33 */
34 public enum TmfXmlTestFiles {
35 /** A valid XML test file */
36 VALID_FILE("test_xml_files/test_valid/test_valid.xml"),
37 /** An invalid test file */
38 INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml"),
39 /** A valid file for state attribute tests */
40 ATTRIBUTE_FILE("test_xml_files/test_valid/test_attributes.xml"),
41 /** A valid file for conditions tests */
42 CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
43 /** A valid file for doubles tests */
44 DOUBLES_FILE("test_xml_files/test_valid/test_doubles.xml"),
45 /** A valid file for pattern tests */
46 VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"),
47 /** A valid pattern file to test the pattern segment **/
48 VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml");
49
50 private final String fPath;
51
52 private TmfXmlTestFiles(String file) {
53 fPath = file;
54 }
55
56 /**
57 * Get the absolute path of this test file
58 *
59 * @return The absolute path of this test file
60 */
61 public IPath getPath() {
62 IPath absPath = Activator.getAbsolutePath(new Path(fPath));
63 if (absPath == null) {
64 fail("Cannot find file path for '" + fPath + "'");
65 }
66 return absPath;
67 }
68
69 /**
70 * Returns the file object corresponding to the test XML file
71 *
72 * @return The file object for this test file
73 */
74 public File getFile() {
75 return getPath().toFile();
76 }
77
78 /**
79 * Get the XML {@link Document} for this test xml file
80 *
81 * @return The XML {@link Document}
82 */
83 public Document getXmlDocument() {
84 /* Initialize the state provider module */
85 Document doc = null;
86 try {
87 doc = XmlUtils.getDocumentFromFile(getFile());
88 } catch (ParserConfigurationException e) {
89 fail("Xml document parse exception");
90 } catch (SAXException e) {
91 fail("Exception parsing xml file");
92 } catch (IOException e) {
93 fail("File io exception");
94 }
95 return doc;
96 }
97
98 }
This page took 0.032209 seconds and 5 git commands to generate.