ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.core.tests / src / org / eclipse / linuxtools / tmf / analysis / xml / core / tests / stateprovider / StateProviderModuleTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013 École Polytechnique de Montréal
3 *
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
8 *
9 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.analysis.xml.core.tests.stateprovider;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertTrue;
18 import static org.junit.Assert.fail;
19 import static org.junit.Assume.assumeTrue;
20
21 import java.io.File;
22 import java.io.IOException;
23
24 import javax.xml.parsers.DocumentBuilder;
25 import javax.xml.parsers.DocumentBuilderFactory;
26 import javax.xml.parsers.ParserConfigurationException;
27
28 import org.eclipse.core.runtime.NullProgressMonitor;
29 import org.eclipse.core.runtime.Path;
30 import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
31 import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
32 import org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
33 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
34 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
35 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
36 import org.junit.Test;
37 import org.w3c.dom.Document;
38 import org.w3c.dom.Element;
39 import org.w3c.dom.NodeList;
40 import org.xml.sax.SAXException;
41
42 /**
43 * Test suite for the XmlStateSystemModule Test. It tests the reading of the
44 * file, the header and the module's proper functioning as a module, but not the
45 * state system building, which is covered by another test suite.
46 *
47 * @author Geneviève Bastien
48 */
49 public class StateProviderModuleTest {
50
51 private static String ANALYSIS_ID = "kernel.linux.sp";
52 private static String ANALYSIS_NAME = "Xml kernel State System";
53
54 private XmlStateSystemModule fModule;
55
56 private static Document getXmlDocumentFromFile(File file) {
57 /* Initialize the state provider module */
58 try {
59 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
60 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
61
62 Document doc = dBuilder.parse(file);
63
64 doc.getDocumentElement().normalize();
65 return doc;
66 } catch (ParserConfigurationException e) {
67 fail("Xml document parse exception");
68 } catch (SAXException e) {
69 fail("Exception parsing xml file");
70 } catch (IOException e) {
71 fail("File io exception");
72 }
73 return null;
74 }
75
76 /**
77 * Test the module construction
78 */
79 @Test
80 public void testModuleConstruction() {
81
82 Document doc = getXmlDocumentFromFile(TmfXmlTestFiles.VALID_FILE.getFile());
83 assertNotNull(doc);
84
85 /* get State Providers modules */
86 NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
87 assertTrue(stateproviderNodes.getLength() > 0);
88
89 Element node = (Element) stateproviderNodes.item(0);
90 fModule = new XmlStateSystemModule();
91 String moduleId = node.getAttribute(TmfXmlStrings.ID);
92 fModule.setId(moduleId);
93 assertEquals(ANALYSIS_ID, fModule.getId());
94
95 fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
96
97 assertEquals(ANALYSIS_NAME, fModule.getName());
98 }
99
100 /**
101 * Test the module executes correctly
102 */
103 @Test
104 public void testModuleExecution() {
105 assumeTrue(CtfTmfTestTrace.KERNEL.exists());
106
107 Document doc = getXmlDocumentFromFile(TmfXmlTestFiles.VALID_FILE.getFile());
108 assertNotNull(doc);
109
110 /* get State Providers modules */
111 NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
112
113 Element node = (Element) stateproviderNodes.item(0);
114 fModule = new XmlStateSystemModule();
115 String moduleId = node.getAttribute(TmfXmlStrings.ID);
116 fModule.setId(moduleId);
117
118 fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
119
120 try (CtfTmfTrace trace = CtfTmfTestTrace.KERNEL.getTrace();) {
121 fModule.setTrace(trace);
122 fModule.schedule();
123
124 assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
125 } catch (TmfAnalysisException e) {
126 fail("Cannot set trace " + e.getMessage());
127 }
128
129 }
130 }
This page took 0.034382 seconds and 5 git commands to generate.