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