e2c7ca6fdf3114d9d86bcfe1702b4e8361616483
[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 state value tests */
42 STATE_VALUE_FILE("test_xml_files/test_valid/test_state_values.xml"),
43 /** A valid file for conditions tests */
44 CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
45 /** A valid file for doubles tests */
46 DOUBLES_FILE("test_xml_files/test_valid/test_doubles.xml"),
47 /** A valid file for pattern tests */
48 VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"),
49 /** A valid pattern file to test the pattern segment **/
50 VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml"),
51 /** A valid file for consuming fsm test */
52 CONSUMING_FSM_TEST("test_xml_files/test_valid/test_consuming_fsm.xml");
53
54 private final String fPath;
55
56 private TmfXmlTestFiles(String file) {
57 fPath = file;
58 }
59
60 /**
61 * Get the absolute path of this test file
62 *
63 * @return The absolute path of this test file
64 */
65 public IPath getPath() {
66 IPath absPath = Activator.getAbsolutePath(new Path(fPath));
67 if (absPath == null) {
68 fail("Cannot find file path for '" + fPath + "'");
69 }
70 return absPath;
71 }
72
73 /**
74 * Returns the file object corresponding to the test XML file
75 *
76 * @return The file object for this test file
77 */
78 public File getFile() {
79 return getPath().toFile();
80 }
81
82 /**
83 * Get the XML {@link Document} for this test xml file
84 *
85 * @return The XML {@link Document}
86 */
87 public Document getXmlDocument() {
88 /* Initialize the state provider module */
89 Document doc = null;
90 try {
91 doc = XmlUtils.getDocumentFromFile(getFile());
92 } catch (ParserConfigurationException e) {
93 fail("Xml document parse exception");
94 } catch (SAXException e) {
95 fail("Exception parsing xml file");
96 } catch (IOException e) {
97 fail("File io exception");
98 }
99 return doc;
100 }
101
102 }
This page took 0.033977 seconds and 4 git commands to generate.