tmf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.analysis.xml.ui.tests / src / org / eclipse / linuxtools / tmf / analysis / xml / ui / tests / module / XmlAnalysisModuleSourceTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014 É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 implementation
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.analysis.xml.ui.tests.module;
14
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertTrue;
17 import static org.junit.Assert.fail;
18
19 import java.io.File;
20 import java.util.Map;
21
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;
30
31 /**
32 * Test suite for the {@link XmlAnalysisModuleSource} class
33 *
34 * @author Geneviève Bastien
35 */
36 public class XmlAnalysisModuleSourceTest {
37
38 private static final String SS_MODULE = "kernel.linux.sp";
39 private static final String BUILTIN_MODULE = "test.builtin.sp";
40
41 private static void emptyXmlFolder() {
42 File fFolder = XmlUtils.getXmlFilesPath().toFile();
43 if (!(fFolder.isDirectory() && fFolder.exists())) {
44 return;
45 }
46 for (File xmlFile : fFolder.listFiles()) {
47 xmlFile.delete();
48 }
49 XmlAnalysisModuleSource.notifyModuleChange();
50 }
51
52 /**
53 * Empty the XML directory before the test, just in case
54 */
55 @Before
56 public void setUp() {
57 emptyXmlFolder();
58 }
59
60 /**
61 * Empty the XML directory after the test
62 */
63 @After
64 public void cleanUp() {
65 emptyXmlFolder();
66 }
67
68 /**
69 * Test the {@link XmlAnalysisModuleSource#getAnalysisModules()} method
70 */
71 @Test
72 public void testPopulateModules() {
73 XmlAnalysisModuleSource module = new XmlAnalysisModuleSource();
74
75 Iterable<IAnalysisModuleHelper> modules = module.getAnalysisModules();
76 assertFalse(findModule(modules, SS_MODULE));
77
78 /* Test that the builtin module is present */
79 assertTrue(findModule(modules, BUILTIN_MODULE));
80
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");
85 }
86
87 XmlUtils.addXmlFile(testXmlFile);
88 XmlAnalysisModuleSource.notifyModuleChange();
89 modules = module.getAnalysisModules();
90
91 assertTrue(modules.iterator().hasNext());
92 assertTrue(findModule(modules, SS_MODULE));
93 assertTrue(findModule(modules, BUILTIN_MODULE));
94 }
95
96 private static boolean findModule(Iterable<IAnalysisModuleHelper> modules, String moduleName) {
97 for (IAnalysisModuleHelper helper : modules) {
98 if (moduleName.equals(helper.getId())) {
99 return true;
100 }
101 }
102 return false;
103 }
104
105 /**
106 * Test that XML modules are available through the analysis manager
107 */
108 @Test
109 public void testPopulateModulesWithAnalysisManager() {
110
111 /*
112 * Make sure module sources are initialized. When run as unit test, the
113 * XML module source is sometimes missing
114 */
115 TmfAnalysisManager.initialize();
116
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));
121
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");
126 }
127
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));
133 }
134 }
This page took 0.051131 seconds and 5 git commands to generate.