tmf : Add test suite for the pattern segment builder
[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
20import javax.xml.parsers.DocumentBuilder;
21import javax.xml.parsers.DocumentBuilderFactory;
22import javax.xml.parsers.ParserConfigurationException;
23
24import org.eclipse.core.runtime.IPath;
25import org.eclipse.core.runtime.Path;
26import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator;
27import org.w3c.dom.Document;
28import org.xml.sax.SAXException;
e11e382c
FW
29
30/**
31 * Provides some test XML files to use
32 *
33 * @author Geneviève Bastien
34 */
35public enum TmfXmlTestFiles {
36 /** A valid XML test file */
9a0aa59e 37 VALID_FILE("test_xml_files/test_valid/test_valid.xml"),
e11e382c 38 /** An invalid test file */
d2e62865
GB
39 INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml"),
40 /** A valid file for state attribute tests */
900cbf89
JCK
41 ATTRIBUTE_FILE("test_xml_files/test_valid/test_attributes.xml"),
42 /** A valid file for conditions tests */
74f8a7ec
JCK
43 CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml"),
44 /** A valid file for pattern tests */
2fd6b087
JCK
45 VALID_PATTERN_FILE("test_xml_files/test_valid/test_valid_pattern.xml"),
46 /** A valid pattern file to test the pattern segment **/
47 VALID_PATTERN_SEGMENT("test_xml_files/test_valid/test_pattern_segment.xml");
e11e382c
FW
48
49 private final String fPath;
50
51 private TmfXmlTestFiles(String file) {
52 fPath = file;
53 }
54
55 /**
9a0aa59e 56 * Get the absolute path of this test file
e11e382c 57 *
9a0aa59e 58 * @return The absolute path of this test file
e11e382c 59 */
9a0aa59e
GB
60 public IPath getPath() {
61 IPath absPath = Activator.getAbsolutePath(new Path(fPath));
62 if (absPath == null) {
63 fail("Cannot find file path for '" + fPath + "'");
64 }
65 return absPath;
e11e382c
FW
66 }
67
68 /**
69 * Returns the file object corresponding to the test XML file
70 *
71 * @return The file object for this test file
72 */
73 public File getFile() {
9a0aa59e
GB
74 return getPath().toFile();
75 }
76
77 /**
78 * Get the XML {@link Document} for this test xml file
79 *
80 * @return The XML {@link Document}
81 */
82 public Document getXmlDocument() {
83 /* Initialize the state provider module */
84 Document doc = null;
85 try {
86 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
87 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
88 doc = dBuilder.parse(getFile());
89 doc.getDocumentElement().normalize();
90 } catch (ParserConfigurationException e) {
91 fail("Xml document parse exception");
92 } catch (SAXException e) {
93 fail("Exception parsing xml file");
94 } catch (IOException e) {
95 fail("File io exception");
96 }
97 return doc;
e11e382c
FW
98 }
99
100}
This page took 0.078838 seconds and 5 git commands to generate.