1 /*******************************************************************************
2 * Copyright (c) 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 implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.tests
.module
;
15 import static org
.junit
.Assert
.assertFalse
;
16 import static org
.junit
.Assert
.assertTrue
;
17 import static org
.junit
.Assert
.fail
;
21 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
22 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
23 import org
.eclipse
.tracecompass
.tmf
.analysis
.xml
.ui
.module
.XmlAnalysisModuleSource
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAnalysisManager
;
26 import org
.junit
.After
;
27 import org
.junit
.Before
;
28 import org
.junit
.Test
;
30 import com
.google
.common
.collect
.Multimap
;
33 * Test suite for the {@link XmlAnalysisModuleSource} class
35 * @author Geneviève Bastien
37 public class XmlAnalysisModuleSourceTest
{
39 private static final String SS_MODULE
= "kernel.linux.sp";
40 private static final String BUILTIN_MODULE
= "test.builtin.sp";
42 private static void emptyXmlFolder() {
43 File fFolder
= XmlUtils
.getXmlFilesPath().toFile();
44 if (!(fFolder
.isDirectory() && fFolder
.exists())) {
47 for (File xmlFile
: fFolder
.listFiles()) {
50 XmlAnalysisModuleSource
.notifyModuleChange();
54 * Empty the XML directory before the test, just in case
62 * Empty the XML directory after the test
65 public void cleanUp() {
70 * Test the {@link XmlAnalysisModuleSource#getAnalysisModules()} method
73 public void testPopulateModules() {
74 XmlAnalysisModuleSource module
= new XmlAnalysisModuleSource();
76 Iterable
<IAnalysisModuleHelper
> modules
= module
.getAnalysisModules();
77 assertFalse("Module present", findModule(modules
, SS_MODULE
));
79 /* Test that the builtin module is present */
80 assertTrue("builtin module present", findModule(modules
, BUILTIN_MODULE
));
82 /* use the valid XML test file */
83 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
84 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
85 fail("XML test file does not exist");
88 XmlUtils
.addXmlFile(testXmlFile
);
89 XmlAnalysisModuleSource
.notifyModuleChange();
90 modules
= module
.getAnalysisModules();
92 assertTrue("Modules available from source", modules
.iterator().hasNext());
93 assertTrue("Module present after add file", findModule(modules
, SS_MODULE
));
94 assertTrue("Builtin module present after add file", findModule(modules
, BUILTIN_MODULE
));
97 private static boolean findModule(Iterable
<IAnalysisModuleHelper
> modules
, String moduleName
) {
98 for (IAnalysisModuleHelper helper
: modules
) {
99 if (moduleName
.equals(helper
.getId())) {
107 * Test that XML modules are available through the analysis manager
110 public void testPopulateModulesWithAnalysisManager() {
113 * Make sure module sources are initialized. When run as unit test, the
114 * XML module source is sometimes missing
116 TmfAnalysisManager
.initialize();
118 Multimap
<String
, IAnalysisModuleHelper
> modules
= TmfAnalysisManager
.getAnalysisModules();
119 assertFalse(findModule(modules
.values(), SS_MODULE
));
120 /* Test that the builtin module is present */
121 assertTrue(findModule(modules
.values(), BUILTIN_MODULE
));
123 /* use the valid XML test file */
124 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
125 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
126 fail("XML test file does not exist");
129 XmlUtils
.addXmlFile(testXmlFile
);
130 XmlAnalysisModuleSource
.notifyModuleChange();
131 modules
= TmfAnalysisManager
.getAnalysisModules();
132 assertTrue(findModule(modules
.values(), SS_MODULE
));
133 assertTrue(findModule(modules
.values(), BUILTIN_MODULE
));