tmf: Split the state system in a separate plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.analysis.xml.core.tests / src / org / eclipse / linuxtools / tmf / analysis / xml / core / tests / stateprovider / StateProviderTest.java
CommitLineData
8945f67f
GB
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
13package org.eclipse.linuxtools.tmf.analysis.xml.core.tests.stateprovider;
14
15import static org.junit.Assert.assertFalse;
16import static org.junit.Assert.assertNotNull;
17import static org.junit.Assert.assertTrue;
18import static org.junit.Assert.fail;
19import static org.junit.Assume.assumeTrue;
20
21import java.io.IOException;
22import java.util.List;
23
24import javax.xml.parsers.DocumentBuilder;
25import javax.xml.parsers.DocumentBuilderFactory;
26import javax.xml.parsers.ParserConfigurationException;
27
28import org.eclipse.core.runtime.NullProgressMonitor;
29import org.eclipse.core.runtime.Path;
bcec0116 30import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
8945f67f
GB
31import org.eclipse.linuxtools.tmf.analysis.xml.core.module.XmlHeadInfo;
32import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
33import org.eclipse.linuxtools.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
34import org.eclipse.linuxtools.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
35import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
8945f67f 36import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
91e7f946 37import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
8945f67f
GB
38import org.junit.After;
39import org.junit.Before;
40import org.junit.Test;
41import org.w3c.dom.Document;
42import org.w3c.dom.Element;
43import org.w3c.dom.NodeList;
44import org.xml.sax.SAXException;
45
46/**
47 * Test suite for the xml state providers
48 *
49 * TODO: instead of using one of the test traces, we should make a custom trace
50 * to make sure it covers the different possibilities of the state provider
51 *
52 * @author Geneviève Bastien
53 */
54public class StateProviderTest {
55
56 private ITmfTrace fTrace;
57 private XmlStateSystemModule fModule;
58
59 /**
60 * Setup the test fields
61 */
62 @Before
63 public void setupTest() {
64 /* Initialize the trace */
65 assumeTrue(CtfTmfTestTrace.KERNEL.exists());
66 fTrace = CtfTmfTestTrace.KERNEL.getTrace();
67
68 /* Initialize the state provider module */
69 Document doc = null;
70 try {
71 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
72 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
73 doc = dBuilder.parse(TmfXmlTestFiles.VALID_FILE.getFile());
74 doc.getDocumentElement().normalize();
75 } catch (ParserConfigurationException e) {
76 fail("Xml document parse exception");
77 } catch (SAXException e) {
78 fail("Exception parsing xml file");
79 } catch (IOException e) {
80 fail("File io exception");
81 }
82 assertNotNull(doc);
83
84 /* get State Providers modules */
85 NodeList stateproviderNodes = doc.getElementsByTagName(TmfXmlStrings.STATE_PROVIDER);
86
87 Element node = (Element) stateproviderNodes.item(0);
88 fModule = new XmlStateSystemModule();
f47f1bbe 89 String moduleId = node.getAttribute(TmfXmlStrings.ID);
8945f67f
GB
90 fModule.setId(moduleId);
91
92 fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
93 NodeList head = node.getElementsByTagName(TmfXmlStrings.HEAD);
94 XmlHeadInfo headInfo = null;
95 if (head.getLength() == 1) {
96 headInfo = new XmlHeadInfo(head.item(0));
97 }
98 fModule.setHeadInfo(headInfo);
99 try {
100 fModule.setTrace(fTrace);
101 fModule.schedule();
102 } catch (TmfAnalysisException e) {
103 fail("Cannot set trace " + e.getMessage());
104 }
105 }
106
107 /**
108 * Cleanup after the test
109 */
110 @After
111 public void cleanupTest() {
112 CtfTmfTestTrace.KERNEL.dispose();
113 }
114
115 /**
116 * Test the building of the state system
117 */
118 @Test
119 public void testStateSystem() {
120 assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
121 ITmfStateSystem ss = fModule.getStateSystem();
122 assertNotNull(ss);
123
124 List<Integer> quarks = ss.getQuarks("*");
125 assertFalse(quarks.isEmpty());
126 }
127
128}
This page took 0.031134 seconds and 5 git commands to generate.