tmf: Add some nonNull annotation to the tmf.core.analysis package
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.analysis.xml.core.tests / src / org / eclipse / tracecompass / tmf / analysis / xml / core / tests / stateprovider / StateProviderTest.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.tracecompass.tmf.analysis.xml.core.tests.stateprovider;
14
15 import static org.junit.Assert.assertFalse;
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.IOException;
22 import java.util.List;
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.tracecompass.statesystem.core.ITmfStateSystem;
31 import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.TmfXmlStrings;
32 import org.eclipse.tracecompass.tmf.analysis.xml.core.stateprovider.XmlStateSystemModule;
33 import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
34 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
35 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
36 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
37 import org.junit.After;
38 import org.junit.Before;
39 import org.junit.Test;
40 import org.w3c.dom.Document;
41 import org.w3c.dom.Element;
42 import org.w3c.dom.NodeList;
43 import 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 */
53 public 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 ITmfTrace trace = CtfTmfTestTrace.KERNEL.getTrace();
66 fTrace = trace;
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();
89 String moduleId = node.getAttribute(TmfXmlStrings.ID);
90 assertNotNull(moduleId);
91 fModule.setId(moduleId);
92
93 fModule.setXmlFile(new Path(TmfXmlTestFiles.VALID_FILE.getFile().getAbsolutePath()));
94
95 try {
96 fModule.setTrace(trace);
97 fModule.schedule();
98 } catch (TmfAnalysisException e) {
99 fail("Cannot set trace " + e.getMessage());
100 }
101 }
102
103 /**
104 * Cleanup after the test
105 */
106 @After
107 public void cleanupTest() {
108 fTrace.dispose();
109 }
110
111 /**
112 * Test the building of the state system
113 */
114 @Test
115 public void testStateSystem() {
116 assertTrue(fModule.waitForCompletion(new NullProgressMonitor()));
117 ITmfStateSystem ss = fModule.getStateSystem();
118 assertNotNull(ss);
119
120 List<Integer> quarks = ss.getQuarks("*");
121 assertFalse(quarks.isEmpty());
122 }
123
124 }
This page took 0.034481 seconds and 5 git commands to generate.