TMF: Add XML state provider analysis module and XML utilities
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.core.tests / src / org / eclipse / linuxtools / tmf / analysis / xml / core / tests / module / XmlUtilsTest.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 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
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.analysis.xml.core.tests.module;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
17import static org.junit.Assert.assertTrue;
18import static org.junit.Assert.fail;
19
20import java.io.File;
21
22import org.eclipse.core.resources.IWorkspace;
23import org.eclipse.core.resources.ResourcesPlugin;
24import org.eclipse.core.runtime.IPath;
25import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlUtils;
26import org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
27import org.junit.After;
28import org.junit.Test;
29
30/**
31 * Tests for the {@link XmlUtils} class
32 *
33 * @author Geneviève Bastien
34 */
35public class XmlUtilsTest {
36
37 /**
38 * Empty the XML directory after the test
39 */
40 @After
41 public void emptyXmlFolder() {
42 File fFolder = XmlUtils.getXmlFilesPath().toFile();
43 if (!(fFolder.isDirectory() && fFolder.exists())) {
44 return;
45 }
46 for (File xmlFile : fFolder.listFiles()) {
47 xmlFile.delete();
48 }
49 }
50
51 /**
52 * Test the {@link XmlUtils#getXmlFilesPath()} method
53 */
54 @Test
55 public void testXmlPath() {
56 IPath xmlPath = XmlUtils.getXmlFilesPath();
57
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");
65
66 assertEquals(xmlPath, workspacePath);
67 }
68
69 /**
70 * test the {@link XmlUtils#xmlValidate(File)} method
71 */
72 @Test
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");
77 }
78 assertTrue(XmlUtils.xmlValidate(testXmlFile).isOK());
79
80 testXmlFile = TmfXmlTestFiles.INVALID_FILE.getFile();
81 if ((testXmlFile == null) || !testXmlFile.exists()) {
82 fail("XML test file does not exist");
83 }
84 assertFalse(XmlUtils.xmlValidate(testXmlFile).isOK());
85 }
86
87 /**
88 * test the {@link XmlUtils#addXmlFile(File)} method
89 */
90 @Test
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());
96
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");
101 }
102
103 XmlUtils.addXmlFile(testXmlFile);
104 assertTrue(destFile.exists());
105 }
106
107}
This page took 0.033079 seconds and 5 git commands to generate.