1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 École Polytechnique de Montréal
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
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.stateprovider
;
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
;
21 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
22 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.TmfXmlStrings
;
23 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.stateprovider
.XmlStateSystemModule
;
24 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
26 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
27 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
28 import org
.junit
.Test
;
29 import org
.w3c
.dom
.Document
;
30 import org
.w3c
.dom
.Element
;
31 import org
.w3c
.dom
.NodeList
;
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.
38 * @author Geneviève Bastien
40 public class StateProviderModuleTest
{
42 private static String ANALYSIS_ID
= "kernel.linux.sp";
43 private static String ANALYSIS_NAME
= "Xml kernel State System";
45 private XmlStateSystemModule fModule
;
48 * Test the module construction
51 public void testModuleConstruction() {
53 Document doc
= TmfXmlTestFiles
.VALID_FILE
.getXmlDocument();
56 /* get State Providers modules */
57 NodeList stateproviderNodes
= doc
.getElementsByTagName(TmfXmlStrings
.STATE_PROVIDER
);
58 assertTrue(stateproviderNodes
.getLength() > 0);
60 Element node
= (Element
) stateproviderNodes
.item(0);
61 fModule
= new XmlStateSystemModule();
62 String moduleId
= node
.getAttribute(TmfXmlStrings
.ID
);
63 assertNotNull(moduleId
);
64 fModule
.setId(moduleId
);
65 assertEquals(ANALYSIS_ID
, fModule
.getId());
67 fModule
.setXmlFile(TmfXmlTestFiles
.VALID_FILE
.getPath());
69 assertEquals(ANALYSIS_NAME
, fModule
.getName());
73 * Test the module executes correctly
76 public void testModuleExecution() {
77 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
79 Document doc
= TmfXmlTestFiles
.VALID_FILE
.getXmlDocument();
82 /* get State Providers modules */
83 NodeList stateproviderNodes
= doc
.getElementsByTagName(TmfXmlStrings
.STATE_PROVIDER
);
85 Element node
= (Element
) stateproviderNodes
.item(0);
86 fModule
= new XmlStateSystemModule();
87 String moduleId
= node
.getAttribute(TmfXmlStrings
.ID
);
88 assertNotNull(moduleId
);
89 fModule
.setId(moduleId
);
91 fModule
.setXmlFile(TmfXmlTestFiles
.VALID_FILE
.getPath());
93 try (CtfTmfTrace trace
= CtfTmfTestTrace
.KERNEL
.getTrace();) {
94 fModule
.setTrace(trace
);
97 assertTrue(fModule
.waitForCompletion(new NullProgressMonitor()));
98 } catch (TmfAnalysisException e
) {
99 fail("Cannot set trace " + e
.getMessage());