output.. = bin/
bin.includes = META-INF/,\
.,\
- about.html
+ about.html,\
+ test_xml_files/
src.includes = about.html
additional.bundles = org.eclipse.jdt.annotation
jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common;
+import static org.junit.Assert.fail;
+
import java.io.File;
+import java.io.IOException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.Activator;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
/**
* Provides some test XML files to use
*/
public enum TmfXmlTestFiles {
/** A valid XML test file */
- VALID_FILE("../org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_valid/test_valid.xml"),
+ VALID_FILE("test_xml_files/test_valid/test_valid.xml"),
/** An invalid test file */
- INVALID_FILE("../org.eclipse.tracecompass.tmf.analysis.xml.core.tests/test_xml_files/test_invalid/test_invalid.xml");
+ INVALID_FILE("test_xml_files/test_invalid/test_invalid.xml");
private final String fPath;
}
/**
- * Get the file name part of the file
+ * Get the absolute path of this test file
*
- * @return The path of this test file
+ * @return The absolute path of this test file
*/
- public String getPath() {
- return fPath;
+ public IPath getPath() {
+ IPath absPath = Activator.getAbsolutePath(new Path(fPath));
+ if (absPath == null) {
+ fail("Cannot find file path for '" + fPath + "'");
+ }
+ return absPath;
}
/**
* @return The file object for this test file
*/
public File getFile() {
- return new File(fPath);
+ return getPath().toFile();
+ }
+
+ /**
+ * Get the XML {@link Document} for this test xml file
+ *
+ * @return The XML {@link Document}
+ */
+ public Document getXmlDocument() {
+ /* Initialize the state provider module */
+ Document doc = null;
+ try {
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ doc = dBuilder.parse(getFile());
+ doc.getDocumentElement().normalize();
+ } catch (ParserConfigurationException e) {
+ fail("Xml document parse exception");
+ } catch (SAXException e) {
+ fail("Exception parsing xml file");
+ } catch (IOException e) {
+ fail("File io exception");
+ }
+ return doc;
}
}
package org.eclipse.tracecompass.tmf.analysis.xml.core.tests;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
import org.osgi.framework.BundleContext;
return plugin;
}
+ /**
+ * Gets the absolute path from a path relative to this plugin's root
+ *
+ * @param relativePath
+ * The path relative to this plugin
+ * @return The absolute path corresponding to this relative path
+ */
+ public static IPath getAbsolutePath(Path relativePath) {
+ Activator plugin2 = getDefault();
+ if (plugin2 == null) {
+ /*
+ * Shouldn't happen but at least throw something to get the test to
+ * fail early
+ */
+ return null;
+ }
+ URL location = FileLocator.find(plugin2.getBundle(), relativePath, null);
+ try {
+ IPath path = new Path(FileLocator.toFileURL(location).getPath());
+ return path;
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
}
import static org.junit.Assert.fail;
import java.io.File;
-import java.io.IOException;
-import java.net.URL;
import java.util.List;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
private static final Path PATH_INVALID = new Path("test_xml_files/test_invalid");
private static final Path PATH_VALID = new Path("test_xml_files/test_valid");
- private static IPath getAbsolutePath(Path relativePath) {
- Activator plugin = Activator.getDefault();
- if (plugin == null) {
- /*
- * Shouldn't happen but at least throw something to get the test to
- * fail early
- */
- throw new IllegalStateException();
- }
- URL location = FileLocator.find(plugin.getBundle(), relativePath, null);
- try {
- IPath path = new Path(FileLocator.toFileURL(location).getPath());
- return path;
- } catch (IOException e) {
- throw new IllegalStateException();
- }
- }
-
/**
* Empty the XML directory after the test
*/
*/
@Test
public void testXmlValidateInvalid() {
- IPath path = getAbsolutePath(PATH_INVALID);
+ IPath path = Activator.getAbsolutePath(PATH_INVALID);
File file = path.toFile();
File[] invalidFiles = file.listFiles();
*/
@Test
public void testXmlValidateValid() {
- IPath path = getAbsolutePath(PATH_VALID);
+ IPath path = Activator.getAbsolutePath(PATH_VALID);
File file = path.toFile();
File[] validFiles = file.listFiles();
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
-import java.io.File;
-import java.io.IOException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
/**
* Test suite for the XmlStateSystemModule Test. It tests the reading of the
private XmlStateSystemModule fModule;
- private static Document getXmlDocumentFromFile(File file) {
- /* Initialize the state provider module */
- try {
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-
- Document doc = dBuilder.parse(file);
-
- doc.getDocumentElement().normalize();
- return doc;
- } catch (ParserConfigurationException e) {
- fail("Xml document parse exception");
- } catch (SAXException e) {
- fail("Exception parsing xml file");
- } catch (IOException e) {
- fail("File io exception");
- }
- return null;
- }
-
/**
* Test the module construction
*/
@Test
public void testModuleConstruction() {
- Document doc = getXmlDocumentFromFile(TmfXmlTestFiles.VALID_FILE.getFile());
+ Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
assertNotNull(doc);
/* get State Providers modules */
fModule.setId(moduleId);
assertEquals(ANALYSIS_ID, fModule.getId());
- fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
+ fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
assertEquals(ANALYSIS_NAME, fModule.getName());
}
public void testModuleExecution() {
assumeTrue(CtfTmfTestTrace.KERNEL.exists());
- Document doc = getXmlDocumentFromFile(TmfXmlTestFiles.VALID_FILE.getFile());
+ Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
assertNotNull(doc);
/* get State Providers modules */
assertNotNull(moduleId);
fModule.setId(moduleId);
- fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
+ fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
try (CtfTmfTrace trace = CtfTmfTestTrace.KERNEL.getTrace();) {
fModule.setTrace(trace);
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
-import java.io.IOException;
import java.util.List;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
/**
* Test suite for the xml state providers
fTrace = trace;
/* Initialize the state provider module */
- Document doc = null;
- try {
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- doc = dBuilder.parse(TmfXmlTestFiles.VALID_FILE.getFile());
- doc.getDocumentElement().normalize();
- } catch (ParserConfigurationException e) {
- fail("Xml document parse exception");
- } catch (SAXException e) {
- fail("Exception parsing xml file");
- } catch (IOException e) {
- fail("File io exception");
- }
+ Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
assertNotNull(doc);
/* get State Providers modules */
* Sets the file path of the XML file containing the state provider
*
* @param file
- * The full path to the XML file
+ * The absolute path to the XML file
*/
public void setXmlFile(IPath file) {
fXmlFile = file;
XmlAnalysisModuleSource module = new XmlAnalysisModuleSource();
Iterable<IAnalysisModuleHelper> modules = module.getAnalysisModules();
- assertFalse(findModule(modules, SS_MODULE));
+ assertFalse("Module present", findModule(modules, SS_MODULE));
/* Test that the builtin module is present */
- assertTrue(findModule(modules, BUILTIN_MODULE));
+ assertTrue("builtin module present", findModule(modules, BUILTIN_MODULE));
/* use the valid XML test file */
File testXmlFile = TmfXmlTestFiles.VALID_FILE.getFile();
XmlAnalysisModuleSource.notifyModuleChange();
modules = module.getAnalysisModules();
- assertTrue(modules.iterator().hasNext());
- assertTrue(findModule(modules, SS_MODULE));
- assertTrue(findModule(modules, BUILTIN_MODULE));
+ assertTrue("Modules available from source", modules.iterator().hasNext());
+ assertTrue("Module present after add file", findModule(modules, SS_MODULE));
+ assertTrue("Builtin module present after add file", findModule(modules, BUILTIN_MODULE));
}
private static boolean findModule(Iterable<IAnalysisModuleHelper> modules, String moduleName) {