tmf.xml: Bug 500195. Modify initial state behavior
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core.tests / common / org / eclipse / tracecompass / tmf / analysis / xml / core / tests / common / TmfXmlTestFiles.java
CommitLineData
e11e382c
FW
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
2bdf0193 13package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common;
e11e382c 14
9a0aa59e
GB
15import static org.junit.Assert.fail;
16
e11e382c 17import java.io.File;
9a0aa59e
GB
18import java.io.IOException;
19
9a0aa59e
GB
20import javax.xml.parsers.ParserConfigurationException;
21
22import org.eclipse.core.runtime.IPath;
23import org.eclipse.core.runtime.Path;
f10786aa 24import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlUtils;
9a0aa59e
GB
25import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator;
26import org.w3c.dom.Document;
27import org.xml.sax.SAXException;
e11e382c
FW
28
29/**
30 * Provides some test XML files to use
31 *
32 * @author Geneviève Bastien
33 */
34public enum TmfXmlTestFiles {
35 /** A valid XML test file */
9a0aa59e 36 VALID_FILE("test_xml_files/test_valid/test_valid.xml"),
e11e382c 37 /** An invalid test file */
d2e62865
GB
38 INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml"),
39 /** A valid file for state attribute tests */
900cbf89 40 ATTRIBUTE_FILE("test_xml_files/test_valid/test_attributes.xml"),
8ab1a965
GB
41 /** A valid file for state value tests */
42 STATE_VALUE_FILE("test_xml_files/test_valid/test_state_values.xml"),
900cbf89 43 /** A valid file for conditions tests */
74f8a7ec 44 CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
8765f95a
MK
45 /** A valid file for doubles tests */
46 DOUBLES_FILE("test_xml_files/test_valid/test_doubles.xml"),
74f8a7ec 47 /** A valid file for pattern tests */
2fd6b087
JCK
48 VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"),
49 /** A valid pattern file to test the pattern segment **/
2109b361
JCK
50 VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml"),
51 /** A valid file for consuming fsm test */
5bf3f444
JCK
52 CONSUMING_FSM_TEST("test_xml_files/test_valid/test_consuming_fsm.xml"),
53 /** A valid pattern file to test the initialState element */
54 INITIAL_STATE_ELEMENT_TEST_FILE_1("test_xml_files/test_valid/test_initialState_element1.xml"),
55 /** A valid pattern file to test the initialState element */
56 INITIAL_STATE_ELEMENT_TEST_FILE_2("test_xml_files/test_valid/test_initialState_element2.xml");
e11e382c
FW
57
58 private final String fPath;
59
60 private TmfXmlTestFiles(String file) {
61 fPath = file;
62 }
63
64 /**
9a0aa59e 65 * Get the absolute path of this test file
e11e382c 66 *
9a0aa59e 67 * @return The absolute path of this test file
e11e382c 68 */
9a0aa59e
GB
69 public IPath getPath() {
70 IPath absPath = Activator.getAbsolutePath(new Path(fPath));
71 if (absPath == null) {
72 fail("Cannot find file path for '" + fPath + "'");
73 }
74 return absPath;
e11e382c
FW
75 }
76
77 /**
78 * Returns the file object corresponding to the test XML file
79 *
80 * @return The file object for this test file
81 */
82 public File getFile() {
9a0aa59e
GB
83 return getPath().toFile();
84 }
85
86 /**
87 * Get the XML {@link Document} for this test xml file
88 *
89 * @return The XML {@link Document}
90 */
91 public Document getXmlDocument() {
92 /* Initialize the state provider module */
93 Document doc = null;
94 try {
f10786aa 95 doc = XmlUtils.getDocumentFromFile(getFile());
9a0aa59e
GB
96 } catch (ParserConfigurationException e) {
97 fail("Xml document parse exception");
98 } catch (SAXException e) {
99 fail("Exception parsing xml file");
100 } catch (IOException e) {
101 fail("File io exception");
102 }
103 return doc;
e11e382c
FW
104 }
105
106}
This page took 0.083396 seconds and 5 git commands to generate.