1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.common
;
15 import static org
.junit
.Assert
.fail
;
18 import java
.io
.IOException
;
20 import javax
.xml
.parsers
.DocumentBuilder
;
21 import javax
.xml
.parsers
.DocumentBuilderFactory
;
22 import javax
.xml
.parsers
.ParserConfigurationException
;
24 import org
.eclipse
.core
.runtime
.IPath
;
25 import org
.eclipse
.core
.runtime
.Path
;
26 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.Activator
;
27 import org
.w3c
.dom
.Document
;
28 import org
.xml
.sax
.SAXException
;
31 * Provides some test XML files to use
33 * @author Geneviève Bastien
35 public enum TmfXmlTestFiles
{
36 /** A valid XML test file */
37 VALID_FILE("test_xml_files/test_valid/test_valid.xml"),
38 /** An invalid test file */
39 INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml"),
40 /** A valid file for state attribute tests */
41 ATTRIBUTE_FILE("test_xml_files/test_valid/test_attributes.xml"),
42 /** A valid file for conditions tests */
43 CONDITION_FILE("test_xml_files/test_valid/test_conditions.xml");
45 private final String fPath
;
47 private TmfXmlTestFiles(String file
) {
52 * Get the absolute path of this test file
54 * @return The absolute path of this test file
56 public IPath
getPath() {
57 IPath absPath
= Activator
.getAbsolutePath(new Path(fPath
));
58 if (absPath
== null) {
59 fail("Cannot find file path for '" + fPath
+ "'");
65 * Returns the file object corresponding to the test XML file
67 * @return The file object for this test file
69 public File
getFile() {
70 return getPath().toFile();
74 * Get the XML {@link Document} for this test xml file
76 * @return The XML {@link Document}
78 public Document
getXmlDocument() {
79 /* Initialize the state provider module */
82 DocumentBuilderFactory dbFactory
= DocumentBuilderFactory
.newInstance();
83 DocumentBuilder dBuilder
= dbFactory
.newDocumentBuilder();
84 doc
= dBuilder
.parse(getFile());
85 doc
.getDocumentElement().normalize();
86 } catch (ParserConfigurationException e
) {
87 fail("Xml document parse exception");
88 } catch (SAXException e
) {
89 fail("Exception parsing xml file");
90 } catch (IOException e
) {
91 fail("File io exception");