tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / SDViewTest.java
CommitLineData
608d90e7
MK
1/*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
13
14import static org.junit.Assert.assertArrayEquals;
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNotNull;
17
18import java.io.File;
19import java.io.IOException;
20import java.util.ArrayList;
21import java.util.List;
22
23import org.apache.log4j.ConsoleAppender;
24import org.apache.log4j.Logger;
25import org.apache.log4j.SimpleLayout;
4ad44445 26import org.eclipse.core.runtime.Platform;
608d90e7
MK
27import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
28import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
9afd04ae 29import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
608d90e7
MK
30import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
31import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
32import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
33import org.eclipse.tracecompass.tmf.core.io.BufferedRandomAccessFile;
34import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
f0beeb4a 35import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
608d90e7
MK
36import org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView;
37import org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Frame;
38import org.junit.After;
39import org.junit.AfterClass;
40import org.junit.Before;
41import org.junit.BeforeClass;
42import org.junit.Test;
9afd04ae 43import org.junit.runner.RunWith;
608d90e7
MK
44
45/**
46 * Test for Sequence Diagram view in trace compass
47 */
9afd04ae 48@RunWith(SWTBotJunit4ClassRunner.class)
608d90e7
MK
49public class SDViewTest {
50
51 private static final String UML2DVIEW_ID = "org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView";
52
53 private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
54
55 private static final String TRACE_START = "<trace>";
56 private static final String EVENT_BEGIN = "<event timestamp=\"";
57 private static final String EVENT_MIDDLE1 = " \" name=\"";
58 private static final String EVENT_MIDDLE2 = "\">";
59 private static final String FIELD_SENDER = "<field name=\"sender\" value=\"";
60 private static final String FIELD_RECEIVER = "<field name=\"receiver\" value=\"";
61 private static final String FIELD_SIGNAL = "<field name=\"signal\" value=\"";
62 private static final String FIELD_END = "\" type=\"string\" />";
63 private static final String EVENT_END = "</event>";
64 private static final String TRACE_END = "</trace>";
65
66 private static final String PROJECT_NAME = "TestForFiltering";
67
68 /** The Log4j logger instance. */
69 private static final Logger fLogger = Logger.getRootLogger();
70 private static SWTWorkbenchBot fBot;
71
72 private static String makeEvent(int ts, String eventName, String send, String recv, String signal) {
73 return EVENT_BEGIN + Integer.toString(ts) + EVENT_MIDDLE1 + eventName + EVENT_MIDDLE2 + FIELD_SENDER + send + FIELD_END + FIELD_RECEIVER + recv + FIELD_END + FIELD_SIGNAL + signal + FIELD_END + EVENT_END + "\n";
74 }
75
76 private static File fFileLocation;
77
78 /**
79 * Initialization, creates a temp trace
80 *
81 * @throws IOException
82 * should not happen
83 */
84 @BeforeClass
85 public static void init() throws IOException {
5785ab49 86 SWTBotUtils.initialize();
608d90e7
MK
87 Thread.currentThread().setName("SWTBot Thread"); // for the debugger
88 /* set up for swtbot */
89 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
f10c30a0 90 fLogger.removeAllAppenders();
608d90e7
MK
91 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
92 fBot = new SWTWorkbenchBot();
93
94 SWTBotUtils.closeView("welcome", fBot);
95
96 SWTBotUtils.switchToTracingPerspective();
97 /* finish waiting for eclipse to load */
f0beeb4a 98 WaitUtils.waitForJobs();
608d90e7
MK
99 fFileLocation = File.createTempFile("sample", ".xml");
100 String eventNames[] = { "test:SEND", "test:RECEIVE" };
101 String targets[] = { "peer1", "peer2" };
102
103 try (BufferedRandomAccessFile braf = new BufferedRandomAccessFile(fFileLocation, "rw")) {
104 braf.writeBytes(TRACE_START);
105 for (int i = 0; i < 100; i++) {
106 braf.writeBytes(makeEvent(i * i * 100, eventNames[i % 2], targets[i % 2], targets[(i + 1) % 2], Integer.toString(i % 2 + 1000)));
107 }
108 braf.writeBytes(TRACE_END);
109 }
110 }
111
112 /**
113 * Open a trace in an editor
114 */
115 @Before
116 public void beforeTest() {
117 SWTBotUtils.createProject(PROJECT_NAME);
118 SWTBotTreeItem treeItem = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME);
119 assertNotNull(treeItem);
120 SWTBotUtils.openTrace(PROJECT_NAME, fFileLocation.getAbsolutePath(), XMLSTUB_ID);
121 SWTBotUtils.openView(UML2DVIEW_ID);
122 }
123
124 /**
125 * Delete the file
126 */
127 @AfterClass
128 public static void cleanUp() {
2c3fabad 129 SWTBotUtils.closeViewById(UML2DVIEW_ID, fBot);
608d90e7 130 fFileLocation.delete();
f10c30a0 131 fLogger.removeAllAppenders();
608d90e7
MK
132 }
133
134 /**
135 * Close the editor
136 */
137 @After
138 public void tearDown() {
139 fBot.closeAllEditors();
140 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
141 }
142
143 /**
144 * Test Sequence diagram view, counting the columns
145 */
146 @Test
147 public void testSDView() {
148 SWTBotView viewBot = fBot.viewById(UML2DVIEW_ID);
149
150 assertNotNull(viewBot);
151 viewBot.setFocus();
f0beeb4a 152 WaitUtils.waitForJobs();
608d90e7
MK
153 List<SWTBotToolbarButton> viewButtons = viewBot.getToolbarButtons();
154 List<String> titles = new ArrayList<>();
155 for (SWTBotToolbarButton buttonBot : viewButtons) {
156 titles.add(buttonBot.getToolTipText());
157 }
4ad44445
MAL
158
159 final char commandKeyChar = (char) 0x2318;
160 final String findShortcut = (Platform.getOS().equals(Platform.OS_MACOSX) ? commandKeyChar : "Ctrl+") + "F";
608d90e7
MK
161 String[] expected = { "Reset zoom factor", "Select",
162 "Zoom in the diagram", "Zoom out the diagram",
163 "Go to next page", "Go to previous page",
164 "Go to first page", "Go to last page",
4ad44445 165 "Find... (" + findShortcut + ")"
608d90e7
MK
166 };
167 assertArrayEquals("Buttons", expected, titles.toArray(new String[0]));
168 SDView view = (SDView) viewBot.getViewReference().getPart(false);
169 Frame frame = view.getFrame();
170 assertEquals(2, frame.lifeLinesCount());
171 }
172}
This page took 0.066069 seconds and 5 git commands to generate.