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
.linuxtools
.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
;
22 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.module
.XmlUtils
;
23 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.core
.tests
.common
.TmfXmlTestFiles
;
24 import org
.eclipse
.linuxtools
.tmf
.analysis
.xml
.ui
.module
.XmlAnalysisModuleSource
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.IAnalysisModuleHelper
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAnalysisManager
;
27 import org
.junit
.After
;
28 import org
.junit
.Before
;
29 import org
.junit
.Test
;
32 * Test suite for the {@link XmlAnalysisModuleSource} class
34 * @author Geneviève Bastien
36 public class XmlAnalysisModuleSourceTest
{
38 private static final String SS_MODULE
= "kernel.linux.sp";
39 private static final String BUILTIN_MODULE
= "test.builtin.sp";
41 private static void emptyXmlFolder() {
42 File fFolder
= XmlUtils
.getXmlFilesPath().toFile();
43 if (!(fFolder
.isDirectory() && fFolder
.exists())) {
46 for (File xmlFile
: fFolder
.listFiles()) {
49 XmlAnalysisModuleSource
.notifyModuleChange();
53 * Empty the XML directory before the test, just in case
61 * Empty the XML directory after the test
64 public void cleanUp() {
69 * Test the {@link XmlAnalysisModuleSource#getAnalysisModules()} method
72 public void testPopulateModules() {
73 XmlAnalysisModuleSource module
= new XmlAnalysisModuleSource();
75 Iterable
<IAnalysisModuleHelper
> modules
= module
.getAnalysisModules();
76 assertFalse(findModule(modules
, SS_MODULE
));
78 /* Test that the builtin module is present */
79 assertTrue(findModule(modules
, BUILTIN_MODULE
));
81 /* use the valid XML test file */
82 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
83 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
84 fail("XML test file does not exist");
87 XmlUtils
.addXmlFile(testXmlFile
);
88 XmlAnalysisModuleSource
.notifyModuleChange();
89 modules
= module
.getAnalysisModules();
91 assertTrue(modules
.iterator().hasNext());
92 assertTrue(findModule(modules
, SS_MODULE
));
93 assertTrue(findModule(modules
, BUILTIN_MODULE
));
96 private static boolean findModule(Iterable
<IAnalysisModuleHelper
> modules
, String moduleName
) {
97 for (IAnalysisModuleHelper helper
: modules
) {
98 if (moduleName
.equals(helper
.getId())) {
106 * Test that XML modules are available through the analysis manager
109 public void testPopulateModulesWithAnalysisManager() {
112 * Make sure module sources are initialized. When run as unit test, the
113 * XML module source is sometimes missing
115 TmfAnalysisManager
.initialize();
117 Map
<String
, IAnalysisModuleHelper
> modules
= TmfAnalysisManager
.getAnalysisModules();
118 assertFalse(findModule(modules
.values(), SS_MODULE
));
119 /* Test that the builtin module is present */
120 assertTrue(findModule(modules
.values(), BUILTIN_MODULE
));
122 /* use the valid XML test file */
123 File testXmlFile
= TmfXmlTestFiles
.VALID_FILE
.getFile();
124 if ((testXmlFile
== null) || !testXmlFile
.exists()) {
125 fail("XML test file does not exist");
128 XmlUtils
.addXmlFile(testXmlFile
);
129 XmlAnalysisModuleSource
.notifyModuleChange();
130 modules
= TmfAnalysisManager
.getAnalysisModules();
131 assertTrue(findModule(modules
.values(), SS_MODULE
));
132 assertTrue(findModule(modules
.values(), BUILTIN_MODULE
));