1 /*******************************************************************************
2 * Copyright (c) 2014 École Polytechnique de Montréal
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
.linuxtools
.tmf
.analysis
.xml
.core
.tests
.module
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertTrue
;
18 import static org
.junit
.Assert
.fail
;
22 import org
.eclipse
.core
.resources
.IWorkspace
;
23 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
24 import org
.eclipse
.core
.runtime
.IPath
;
25 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
26 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
27 import org
.junit
.After
;
28 import org
.junit
.Test
;
31 * Tests for the {@link XmlUtils} class
33 * @author Geneviève Bastien
35 public class XmlUtilsTest
{
38 * Empty the XML directory after the test
41 public void emptyXmlFolder() {
42 File fFolder
= XmlUtils
.getXmlFilesPath().toFile();
43 if (!(fFolder
.isDirectory() && fFolder
.exists())) {
46 for (File xmlFile
: fFolder
.listFiles()) {
52 * Test the {@link XmlUtils#getXmlFilesPath()} method
55 public void testXmlPath() {
56 IPath xmlPath
= XmlUtils
.getXmlFilesPath();
58 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
59 IPath workspacePath
= workspace
.getRoot().getRawLocation();
60 workspacePath
= workspacePath
.addTrailingSeparator()
61 .append(".metadata").addTrailingSeparator().append(".plugins")
62 .addTrailingSeparator()
63 .append("org.eclipse.linuxtools.tmf.analysis.xml.core")
64 .addTrailingSeparator().append("xml_files");
66 assertEquals(xmlPath
, workspacePath
);
70 * test the {@link XmlUtils#xmlValidate(File)} method
73 public void testXmlValidate() {
74 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
75 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
76 fail("XML test file does not exist");
78 assertTrue(XmlUtils
.xmlValidate(testXmlFile
).isOK());
80 testXmlFile
= TmfXmlTestFiles
.INVALID_FILE
.getFile();
81 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
82 fail("XML test file does not exist");
84 assertFalse(XmlUtils
.xmlValidate(testXmlFile
).isOK());
88 * test the {@link XmlUtils#addXmlFile(File)} method
91 public void testXmlAddFile() {
92 /* Check the file does not exist */
93 IPath xmlPath
= XmlUtils
.getXmlFilesPath().addTrailingSeparator().append("test_valid.xml");
94 File destFile
= xmlPath
.toFile();
95 assertFalse(destFile
.exists());
97 /* Add test_valid.xml file */
98 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
99 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
100 fail("XML test file does not exist");
103 XmlUtils
.addXmlFile(testXmlFile
);
104 assertTrue(destFile
.exists());
This page took 0.034172 seconds and 6 git commands to generate.