xml: remove dependency to ui element from the module source
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.analysis.xml.ui.tests / src / org / eclipse / tracecompass / tmf / analysis / xml / ui / tests / module / XmlAnalysisModuleSourceTest.java
CommitLineData
97ed0cf0
FW
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
2bdf0193 13package org.eclipse.tracecompass.tmf.analysis.xml.ui.tests.module;
97ed0cf0
FW
14
15import static org.junit.Assert.assertFalse;
16import static org.junit.Assert.assertTrue;
17import static org.junit.Assert.fail;
18
19import java.io.File;
97ed0cf0 20
2bdf0193
AM
21import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
22import org.eclipse.tracecompass.tmf.analysis.xml.core.tests.common.TmfXmlTestFiles;
23import org.eclipse.tracecompass.tmf.analysis.xml.ui.module.XmlAnalysisModuleSource;
24import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
25import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisManager;
97ed0cf0
FW
26import org.junit.After;
27import org.junit.Before;
28import org.junit.Test;
29
9897c39c
GB
30import com.google.common.collect.Multimap;
31
97ed0cf0
FW
32/**
33 * Test suite for the {@link XmlAnalysisModuleSource} class
34 *
35 * @author Geneviève Bastien
36 */
37public class XmlAnalysisModuleSourceTest {
38
f47f1bbe 39 private static final String SS_MODULE = "kernel.linux.sp";
896c0834 40 private static final String BUILTIN_MODULE = "test.builtin.sp";
97ed0cf0
FW
41
42 private static void emptyXmlFolder() {
43 File fFolder = XmlUtils.getXmlFilesPath().toFile();
44 if (!(fFolder.isDirectory() && fFolder.exists())) {
45 return;
46 }
47 for (File xmlFile : fFolder.listFiles()) {
48 xmlFile.delete();
49 }
50 XmlAnalysisModuleSource.notifyModuleChange();
51 }
52
53 /**
54 * Empty the XML directory before the test, just in case
55 */
56 @Before
57 public void setUp() {
58 emptyXmlFolder();
59 }
60
61 /**
62 * Empty the XML directory after the test
63 */
64 @After
65 public void cleanUp() {
66 emptyXmlFolder();
67 }
68
69 /**
70 * Test the {@link XmlAnalysisModuleSource#getAnalysisModules()} method
71 */
72 @Test
73 public void testPopulateModules() {
74 XmlAnalysisModuleSource module = new XmlAnalysisModuleSource();
75
76 Iterable<IAnalysisModuleHelper> modules = module.getAnalysisModules();
9a0aa59e 77 assertFalse("Module present", findModule(modules, SS_MODULE));
896c0834
GB
78
79 /* Test that the builtin module is present */
9a0aa59e 80 assertTrue("builtin module present", findModule(modules, BUILTIN_MODULE));
97ed0cf0
FW
81
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");
86 }
87
88 XmlUtils.addXmlFile(testXmlFile);
89 XmlAnalysisModuleSource.notifyModuleChange();
90 modules = module.getAnalysisModules();
91
9a0aa59e
GB
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));
97ed0cf0
FW
95 }
96
896c0834 97 private static boolean findModule(Iterable<IAnalysisModuleHelper> modules, String moduleName) {
97ed0cf0 98 for (IAnalysisModuleHelper helper : modules) {
896c0834 99 if (moduleName.equals(helper.getId())) {
97ed0cf0
FW
100 return true;
101 }
102 }
103 return false;
104 }
105
106 /**
107 * Test that XML modules are available through the analysis manager
108 */
109 @Test
110 public void testPopulateModulesWithAnalysisManager() {
111
112 /*
113 * Make sure module sources are initialized. When run as unit test, the
114 * XML module source is sometimes missing
115 */
d8ad88cc 116 TmfAnalysisManager.initialize();
97ed0cf0 117
9897c39c 118 Multimap<String, IAnalysisModuleHelper> modules = TmfAnalysisManager.getAnalysisModules();
896c0834
GB
119 assertFalse(findModule(modules.values(), SS_MODULE));
120 /* Test that the builtin module is present */
121 assertTrue(findModule(modules.values(), BUILTIN_MODULE));
97ed0cf0
FW
122
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");
127 }
128
129 XmlUtils.addXmlFile(testXmlFile);
130 XmlAnalysisModuleSource.notifyModuleChange();
131 modules = TmfAnalysisManager.getAnalysisModules();
896c0834
GB
132 assertTrue(findModule(modules.values(), SS_MODULE));
133 assertTrue(findModule(modules.values(), BUILTIN_MODULE));
97ed0cf0
FW
134 }
135}
This page took 0.087053 seconds and 5 git commands to generate.