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
.linuxtools
.tmf
.core
.tests
.analysis
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertFalse
;
17 import static org
.junit
.Assert
.assertNotNull
;
18 import static org
.junit
.Assert
.assertNull
;
19 import static org
.junit
.Assert
.assertTrue
;
20 import static org
.junit
.Assert
.fail
;
21 import static org
.junit
.Assume
.assumeTrue
;
23 import org
.eclipse
.core
.runtime
.Platform
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModule
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.Messages
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisModuleHelperConfigElement
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfAnalysisException
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.TmfTestTrace
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfTrace
;
35 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.analysis
.TestAnalysis
;
36 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.analysis
.TestCtfAnalysis
;
37 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.ctf
.CtfTmfTraceStub
;
38 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
39 import org
.eclipse
.osgi
.util
.NLS
;
40 import org
.junit
.After
;
41 import org
.junit
.Before
;
42 import org
.junit
.Test
;
43 import org
.osgi
.framework
.Bundle
;
46 * Test suite for the {@link TmfAnalysisModuleHelperConfigElement} class
48 * @author Geneviève Bastien
50 public class AnalysisModuleHelperTest
{
52 private IAnalysisModuleHelper fModule
;
53 private IAnalysisModuleHelper fCtfModule
;
56 * Gets the module helpers for 2 test modules
59 public void getModules() {
60 fModule
= TmfAnalysisManager
.getAnalysisModule(AnalysisManagerTest
.MODULE_PARAM
);
61 assertNotNull(fModule
);
62 assertTrue(fModule
instanceof TmfAnalysisModuleHelperConfigElement
);
63 fCtfModule
= TmfAnalysisManager
.getAnalysisModule(AnalysisManagerTest
.MODULE_CTF
);
64 assertNotNull(fCtfModule
);
65 assertTrue(fCtfModule
instanceof TmfAnalysisModuleHelperConfigElement
);
69 * Some tests use traces, let's clean them here
72 public void cleanupTraces() {
73 TmfTestTrace
.A_TEST_10K
.dispose();
74 CtfTmfTestTrace
.KERNEL
.dispose();
78 * Test the helper's getters and setters
81 public void testHelperGetters() {
82 /* With first module */
83 assertEquals(AnalysisManagerTest
.MODULE_PARAM
, fModule
.getId());
84 assertEquals("Test analysis", fModule
.getName());
85 assertFalse(fModule
.isAutomatic());
87 Bundle helperbundle
= fModule
.getBundle();
88 Bundle thisbundle
= Platform
.getBundle("org.eclipse.linuxtools.tmf.core.tests");
89 assertNotNull(helperbundle
);
90 assertEquals(thisbundle
, helperbundle
);
93 assertEquals(AnalysisManagerTest
.MODULE_CTF
, fCtfModule
.getId());
94 assertEquals("Test analysis ctf", fCtfModule
.getName());
95 assertTrue(fCtfModule
.isAutomatic());
99 * Test the {@link TmfAnalysisModuleHelperConfigElement#appliesToTraceType(Class)}
100 * method for the 2 modules
103 public void testAppliesToTrace() {
105 assertFalse(fModule
.appliesToTraceType(TmfTrace
.class));
106 assertTrue(fModule
.appliesToTraceType(TmfTraceStub
.class));
107 assertFalse(fModule
.appliesToTraceType(CtfTmfTraceStub
.class));
110 assertFalse(fCtfModule
.appliesToTraceType(TmfTrace
.class));
111 assertFalse(fCtfModule
.appliesToTraceType(TmfTraceStub
.class));
112 assertTrue(fCtfModule
.appliesToTraceType(CtfTmfTraceStub
.class));
116 * Test the {@link TmfAnalysisModuleHelperConfigElement#newModule(ITmfTrace)} method
120 public void testNewModule() {
121 /* Test analysis module with traceStub */
122 Exception exception
= null;
123 IAnalysisModule module
= null;
125 module
= fModule
.newModule(TmfTestTrace
.A_TEST_10K
.getTrace());
126 } catch (TmfAnalysisException e
) {
129 assertNull(exception
);
130 assertNotNull(module
);
131 assertTrue(module
instanceof TestAnalysis
);
133 /* Test Analysis module with ctf trace, should return an exception */
134 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
135 CtfTmfTraceStub ctfTrace
= (CtfTmfTraceStub
) CtfTmfTestTrace
.KERNEL
.getTrace();
138 module
= fModule
.newModule(ctfTrace
);
139 } catch (TmfAnalysisException e
) {
142 assertNotNull(exception
);
143 assertEquals(NLS
.bind(Messages
.TmfAnalysisModuleHelper_AnalysisDoesNotApply
, fModule
.getName()), exception
.getMessage());
145 /* Test analysis CTF module with ctf trace stub */
149 module
= fCtfModule
.newModule(ctfTrace
);
150 } catch (TmfAnalysisException e
) {
153 assertNull(exception
);
154 assertNotNull(module
);
155 assertTrue(module
instanceof TestCtfAnalysis
);
159 * Test for the initialization of parameters from the extension points
162 public void testParameters() {
163 assumeTrue(CtfTmfTestTrace
.KERNEL
.exists());
164 CtfTmfTrace ctftrace
= CtfTmfTestTrace
.KERNEL
.getTrace();
165 ITmfTrace trace
= TmfTestTrace
.A_TEST_10K
.getTrace();
168 * This analysis has a parameter, but no default value. we should be
169 * able to set the parameter
171 IAnalysisModuleHelper helper
= TmfAnalysisManager
.getAnalysisModule(AnalysisManagerTest
.MODULE_PARAM
);
172 IAnalysisModule module
;
174 module
= helper
.newModule(trace
);
175 } catch (TmfAnalysisException e1
) {
176 fail(e1
.getMessage());
180 assertNull(module
.getParameter(TestAnalysis
.PARAM_TEST
));
181 module
.setParameter(TestAnalysis
.PARAM_TEST
, 1);
182 assertEquals(1, module
.getParameter(TestAnalysis
.PARAM_TEST
));
184 /* This module has a parameter with default value */
185 helper
= TmfAnalysisManager
.getAnalysisModule(AnalysisManagerTest
.MODULE_PARAM_DEFAULT
);
187 module
= helper
.newModule(trace
);
188 } catch (TmfAnalysisException e1
) {
189 fail(e1
.getMessage());
192 assertEquals(3, module
.getParameter(TestAnalysis
.PARAM_TEST
));
193 module
.setParameter(TestAnalysis
.PARAM_TEST
, 1);
194 assertEquals(1, module
.getParameter(TestAnalysis
.PARAM_TEST
));
197 * This module does not have a parameter so setting it should throw an
200 helper
= TmfAnalysisManager
.getAnalysisModule(AnalysisManagerTest
.MODULE_CTF
);
202 module
= helper
.newModule(ctftrace
);
203 } catch (TmfAnalysisException e1
) {
204 fail(e1
.getMessage());
207 assertNull(module
.getParameter(TestAnalysis
.PARAM_TEST
));
208 Exception exception
= null;
210 module
.setParameter(TestAnalysis
.PARAM_TEST
, 1);
211 } catch (RuntimeException e
) {
214 assertNotNull(exception
);