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
.core
.runtime
.IStatus
;
26 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
27 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
28 import org
.junit
.After
;
29 import org
.junit
.Test
;
32 * Tests for the {@link XmlUtils} class
34 * @author Geneviève Bastien
36 public class XmlUtilsTest
{
39 * Empty the XML directory after the test
42 public void emptyXmlFolder() {
43 File fFolder
= XmlUtils
.getXmlFilesPath().toFile();
44 if (!(fFolder
.isDirectory() && fFolder
.exists())) {
47 for (File xmlFile
: fFolder
.listFiles()) {
53 * Test the {@link XmlUtils#getXmlFilesPath()} method
56 public void testXmlPath() {
57 IPath xmlPath
= XmlUtils
.getXmlFilesPath();
59 IWorkspace workspace
= ResourcesPlugin
.getWorkspace();
60 IPath workspacePath
= workspace
.getRoot().getRawLocation();
61 workspacePath
= workspacePath
.addTrailingSeparator()
62 .append(".metadata").addTrailingSeparator().append(".plugins")
63 .addTrailingSeparator()
64 .append("org.eclipse.linuxtools.tmf.analysis.xml.core")
65 .addTrailingSeparator().append("xml_files");
67 assertEquals(xmlPath
, workspacePath
);
71 * test the {@link XmlUtils#xmlValidate(File)} method
74 public void testXmlValidate() {
75 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
76 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
77 fail("XML test file does not exist");
79 IStatus status
= XmlUtils
.xmlValidate(testXmlFile
);
81 fail(status
.getMessage());
84 testXmlFile
= TmfXmlTestFiles
.INVALID_FILE
.getFile();
85 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
86 fail("XML test file does not exist");
88 assertFalse(XmlUtils
.xmlValidate(testXmlFile
).isOK());
92 * test the {@link XmlUtils#addXmlFile(File)} method
95 public void testXmlAddFile() {
96 /* Check the file does not exist */
97 IPath xmlPath
= XmlUtils
.getXmlFilesPath().addTrailingSeparator().append("test_valid.xml");
98 File destFile
= xmlPath
.toFile();
99 assertFalse(destFile
.exists());
101 /* Add test_valid.xml file */
102 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
103 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
104 fail("XML test file does not exist");
107 XmlUtils
.addXmlFile(testXmlFile
);
108 assertTrue(destFile
.exists());
This page took 0.04215 seconds and 5 git commands to generate.