ctf: Depend on the tracecompass-test-traces project
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.core.tests / src / org / eclipse / tracecompass / tmf / analysis / xml / core / tests / stateprovider / StateProviderModuleTest.java
CommitLineData
8945f67f 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
8945f67f
GB
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
2bdf0193 13package org.eclipse.tracecompass.tmf.analysis.xml.core.tests.stateprovider;
8945f67f
GB
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNotNull;
17import static org.junit.Assert.assertTrue;
18import static org.junit.Assert.fail;
8945f67f 19
8945f67f 20import org.eclipse.core.runtime.NullProgressMonitor;
c4d57ac1 21import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
2bdf0193
AM
22import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
23import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
24import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
25import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
c4d57ac1 26import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
9722e5d7 27import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
8945f67f
GB
28import org.junit.Test;
29import org.w3c.dom.Document;
30import org.w3c.dom.Element;
31import org.w3c.dom.NodeList;
8945f67f
GB
32
33/**
34 * Test suite for the XmlStateSystemModule Test. It tests the reading of the
35 * file, the header and the module's proper functioning as a module, but not the
36 * state system building, which is covered by another test suite.
37 *
38 * @author Geneviève Bastien
39 */
40public class StateProviderModuleTest {
41
f47f1bbe 42 private static String ANALYSIS_ID = "kernel.linux.sp";
8945f67f
GB
43 private static String ANALYSIS_NAME = "Xml kernel State System";
44
45 private XmlStateSystemModule fModule;
46
8945f67f
GB
47 /**
48 * Test the module construction
49 */
50 @Test
51 public void testModuleConstruction() {
52
9a0aa59e 53 Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
8945f67f
GB
54 assertNotNull(doc);
55
56 /* get State Providers modules */
57 NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
58 assertTrue(stateproviderNodes.getLength() > 0);
59
60 Element node = (Element) stateproviderNodes.item(0);
61 fModule = new XmlStateSystemModule();
f47f1bbe 62 String moduleId = node.getAttribute(TmfXmlStrings.ID);
ba27dd38 63 assertNotNull(moduleId);
8945f67f
GB
64 fModule.setId(moduleId);
65 assertEquals(ANALYSIS_ID, fModule.getId());
66
9a0aa59e 67 fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
8945f67f
GB
68
69 assertEquals(ANALYSIS_NAME, fModule.getName());
70 }
71
72 /**
73 * Test the module executes correctly
74 */
75 @Test
76 public void testModuleExecution() {
9a0aa59e 77 Document doc = TmfXmlTestFiles.VALID_FILE.getXmlDocument();
8945f67f
GB
78 assertNotNull(doc);
79
80 /* get State Providers modules */
81 NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
82
83 Element node = (Element) stateproviderNodes.item(0);
84 fModule = new XmlStateSystemModule();
f47f1bbe 85 String moduleId = node.getAttribute(TmfXmlStrings.ID);
ba27dd38 86 assertNotNull(moduleId);
8945f67f
GB
87 fModule.setId(moduleId);
88
9a0aa59e 89 fModule.setXmlFile(TmfXmlTestFiles.VALID_FILE.getPath());
8945f67f 90
c4d57ac1 91 CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(CtfTestTrace.KERNEL);
0ff9e595 92 try {
8945f67f
GB
93 fModule.setTrace(trace);
94 fModule.schedule();
95 assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
0ff9e595 96
8945f67f
GB
97 } catch (TmfAnalysisException e) {
98 fail("Cannot set trace " + e.getMessage());
0ff9e595
AM
99 } finally {
100 trace.dispose();
8945f67f
GB
101 }
102
103 }
104}
This page took 0.094116 seconds and 5 git commands to generate.