tmf: Enable the ctfadaptor and statistics unit tests
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.tests / src / org / eclipse / linuxtools / tmf / ui / tests / views / uml2sd / load / LoadersManagerTest.java
CommitLineData
73005152
BH
1/**********************************************************************
2 * Copyright (c) 2011 Ericsson.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
abbdd66a
AM
7 *
8 * Contributors:
73005152
BH
9 * Bernd Hufmann - Initial API and implementation
10 **********************************************************************/
11package org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.load;
12
13import junit.framework.TestCase;
14
15import org.eclipse.jface.preference.IPreferenceStore;
8fd82db5 16import org.eclipse.linuxtools.internal.tmf.ui.Activator;
73005152
BH
17import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDView;
18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.IUml2SDLoader;
19import org.eclipse.linuxtools.tmf.ui.views.uml2sd.load.LoadersManager;
20import org.eclipse.swt.widgets.Display;
21import org.eclipse.ui.PlatformUI;
22
64636df8
BH
23/**
24 * Test cases class to test loader manager of UML2SD extension point.
25 */
73005152
BH
26public class LoadersManagerTest extends TestCase {
27
28 private final static String SDVIEW_WITH_ONE_LOADER = "org.eclipse.linuxtools.tmf.ui.tests.testSDView1Loader"; //$NON-NLS-1$
29 private final static String SDVIEW_WITH_MULTIPLE_LOADER = "org.eclipse.linuxtools.tmf.ui.tests.testSDView2Loaders"; //$NON-NLS-1$
30 private final static String TEST_LOADER_CLASS_NAME = "org.eclipse.linuxtools.tmf.ui.tests.uml2sd.load.TestLoaders"; //$NON-NLS-1$
df0b8ff4 31 private final static String TMF_UML2SD_LOADER_CLASS_NAME = "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader"; //$NON-NLS-1$
abbdd66a 32
73005152
BH
33 private static final String LOADER_TAG = "uml2SDLoader"; //$NON-NLS-1$
34 private static final String LOADER_PREFIX = LOADER_TAG + "."; //$NON-NLS-1$
35
36 @Override
37 public void setUp() throws Exception {
38 super.setUp();
39 }
40
41 @Override
42 public void tearDown() throws Exception {
43 super.tearDown();
44 }
45
64636df8
BH
46 /**
47 * Tests of loader manager singleton class.
48 */
73005152
BH
49 @SuppressWarnings("nls")
50 public void testLoaderManager() {
51
52 SDView view = null;
53 try {
54
55 /*
abbdd66a 56 * Test creation of a loader (one per SD view)
73005152 57 */
abbdd66a 58
73005152
BH
59 // Open view
60 // Note this will create the default loader!
61 view = (SDView)PlatformUI.getWorkbench()
62 .getActiveWorkbenchWindow()
63 .getActivePage()
64 .showView(SDVIEW_WITH_ONE_LOADER);
65
66 IUml2SDLoader defaultLoader = LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_ONE_LOADER, view);
67 assertNotNull("testLoaderManager", defaultLoader);
abbdd66a 68
73005152
BH
69 // Test createLoader where loader doesn't exist
70 assertNull("testLoaderManager", LoadersManager.getInstance().createLoader("blabla", view));
71
abbdd66a 72 // Test createLoader
73005152
BH
73 IUml2SDLoader loader = LoadersManager.getInstance().createLoader(TEST_LOADER_CLASS_NAME, view);
74
75 assertNotNull("testLoaderManager", loader);
abbdd66a 76 assertEquals("testLoaderManager", "Test Loader", loader.getTitleString());
73005152 77 assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_ONE_LOADER));
abbdd66a
AM
78
79 // compare loader and default loader. Even if they are the same class, they are different instances
73005152
BH
80 assertFalse("testLoaderManager", loader==defaultLoader);
81
82 // test getCurrentLoader(viewId, view)
83 IUml2SDLoader loader2 = LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_ONE_LOADER, view);
84 assertEquals("testLoaderManager", loader, loader2);
85
86 // Hide the view
87 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view);
88
89 // test that view restores the previous associated loader
90 view = (SDView)PlatformUI.getWorkbench()
91 .getActiveWorkbenchWindow()
92 .getActivePage()
93 .showView(SDVIEW_WITH_ONE_LOADER);
94
95 // Well, this is the only way test which loader is set
96 assertEquals("testLoaderManager", "Sequence Diagram - First Page", view.getFrame().getName());
abbdd66a 97
73005152
BH
98 // Test view == null
99 assertNull("testLoaderManager", LoadersManager.getInstance().createLoader(TEST_LOADER_CLASS_NAME, null));
100
101 // Hide the view
102 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view);
103
104 /*
abbdd66a 105 * Test creation of loaders with re-uses the same SD view
73005152
BH
106 */
107
108 // test that view restores the previous associated loader
109 view = (SDView)PlatformUI.getWorkbench()
110 .getActiveWorkbenchWindow()
111 .getActivePage()
112 .showView(SDVIEW_WITH_MULTIPLE_LOADER);
113
114 // Test that default loader is set. Note that 2 default loaders are define in the plugin.xml and the
115 // the first one should be selected.
116
117 // Well, this is the only way test which loader is set
118 assertEquals("testLoaderManager", "Sequence Diagram - First Page", view.getFrame().getName());
119
120 loader = LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER, view);
121 assertNotNull("testLoaderManager", loader);
abbdd66a 122 assertEquals("testLoaderManager", "Test Loader", loader.getTitleString());
73005152
BH
123 assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER));
124
abbdd66a 125 // Test createLoader for loader with class name TMF_UML2SD_LOADER_CLASS_NAME
73005152
BH
126 loader = LoadersManager.getInstance().createLoader(TMF_UML2SD_LOADER_CLASS_NAME, view);
127
128 assertNotNull("testLoaderManager", loader);
abbdd66a 129 assertEquals("testLoaderManager", "Component Interactions", loader.getTitleString());
73005152
BH
130 assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER));
131
132 // Verify if the correct loader is stored in the preferences as the current loader for this view
133 assertEquals("testLoaderManager", TMF_UML2SD_LOADER_CLASS_NAME, getSavedLoader(SDVIEW_WITH_MULTIPLE_LOADER));
134
abbdd66a 135 // Test createLoader for loader with class name TEST_LOADER_CLASS_NAME
73005152
BH
136 loader = LoadersManager.getInstance().createLoader(TEST_LOADER_CLASS_NAME, view);
137
138 assertNotNull("testLoaderManager", loader);
abbdd66a 139 assertEquals("testLoaderManager", "Test Loader", loader.getTitleString());
73005152
BH
140 assertEquals("testLoaderManager", loader, LoadersManager.getInstance().getCurrentLoader(SDVIEW_WITH_MULTIPLE_LOADER));
141
142 // Verify if the correct loader is stored in the preferences as the current loader for this view
143 assertEquals("testLoaderManager", TEST_LOADER_CLASS_NAME, getSavedLoader(SDVIEW_WITH_MULTIPLE_LOADER));
144 assertEquals("testLoaderManager", TEST_LOADER_CLASS_NAME, LoadersManager.getInstance().getSavedLoader(SDVIEW_WITH_MULTIPLE_LOADER));
145
146 // Hide the view
147 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(view);
148
149 // Test reset loader
150 LoadersManager.getInstance().resetLoader(SDVIEW_WITH_MULTIPLE_LOADER);
151
152 } catch (Exception e) {
153 e.printStackTrace();
154 fail();
155 }
156 }
157
158 @SuppressWarnings("unused")
abbdd66a 159 private static void delay(long waitTimeMillis) {
73005152
BH
160 Display display = Display.getCurrent();
161 if (display != null) {
162 long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
163 while(System.currentTimeMillis() < endTimeMillis) {
164 if (!display.readAndDispatch()) {
165 display.sleep();
166 }
167 display.update();
168 }
169 } else {
170 try {
171 Thread.sleep(waitTimeMillis);
172 } catch (InterruptedException e) {
173 // Ignored
174 }
175 }
176 }
177
abbdd66a 178 private static String getSavedLoader(String viewId) {
8fd82db5 179 IPreferenceStore p = Activator.getDefault().getPreferenceStore();
73005152
BH
180 return p.getString(LOADER_PREFIX + viewId);
181 }
182}
This page took 0.039402 seconds and 5 git commands to generate.