da47fe0bb8587e9a1626fdd62c0cb7b82fb3289d
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / swtbot / tests / ControlViewSwtBotUtil.java
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
10 package org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests;
11
12 import java.util.Arrays;
13
14 import org.eclipse.swtbot.swt.finder.waits.ICondition;
15 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
16 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
17 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
18 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
19 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
20 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers.SWTBotTestCondition;
21
22 /**
23 * SWTBot utilities for ControlView test
24 *
25 * @author Bernd Hufmann
26 */
27 class ControlViewSwtBotUtil {
28
29 public static final String USER_HOME = System.getProperty("user.home");
30 public static final String DEFAULT_CHANNEL_NAME = "channel0";
31 public static final String KERNEL_DOMAIN_NAME = "Kernel";
32 public static final String UST_DOMAIN_NAME = "UST global";
33 public static final String SESSION_GROUP_NAME = "Sessions";
34 public static final String PROVIDER_GROUP_NAME = "Provider";
35 public static final String ALL_EVENTS_NAME = "*";
36 public static final String SCHED_SWITCH_EVENT_NAME = "sched_switch";
37 public static final String PROFILE_SUFFIX = ".lttng";
38 public static final String KERNEL_TRACE_NAME = "kernel";
39
40 // Menu strings
41 public static final String CONNECT_MENU_ITEM = "Connect";
42 public static final String CREATE_SESSION_MENU_ITEM = "Create Session...";
43 public static final String ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM = "Enable Event (default channel)...";
44 public static final String ENABLE_CHANNEL_MENU_ITEM = "Enable Channel...";
45 public static final String ENABLE_EVENT_MENU_ITEM = "Enable Event...";
46 public static final String START_MENU_ITEM = "Start";
47 public static final String STOP_MENU_ITEM = "Stop";
48 public static final String IMPORT_MENU_ITEM = "Import...";
49 public static final String DESTROY_MENU_ITEM = "Destroy Session...";
50 public static final String DISCONNECT_MENU_ITEM = "Disconnect";
51 public static final String SAVE_MENU_ITEM = "Save...";
52 public static final String LOAD_MENU_ITEM = "Load...";
53
54 // Dialog strings
55 public static final String CREATE_SESSION_DIALOG_TITLE = "Create Session";
56 public static final String SESSION_NAME_LABEL = "Session Name";
57 public static final String DIALOG_OK_BUTTON = "Ok";
58 public static final String CONFIRM_DIALOG_OK_BUTTON = "OK";
59 public static final String ENABLE_EVENT_DIALOG_TITLE = "Enable Events";
60 public static final String ALL_TREE_NODE = "All";
61 public static final String SYSCALL_GROUP_NAME = "All Syscalls";
62 public static final String GROUP_SELECT_NAME = "Select";
63 public static final String ENABLE_CHANNEL_DIALOG_TITLE = "Enable Channel";
64 public static final String DOMAIN_GROUP_NAME = "Domain";
65 public static final String UST_GROUP_NAME = "UST";
66 public static final String BUFFERTYPE_GROUP_NAME = "Buffer Type";
67 public static final String BUFFERTYPE_PER_UID = "Per UID buffers";
68 public static final String FILTER_EXPRESSION_LABEL = "Filter Expression";
69 public static final String SESSION_LIST_GROUP_NAME = "Session List";
70
71 public static final String DESTROY_CONFIRM_DIALOG_TITLE = "Destroy Confirmation";
72 public static final String CHANNEL_NAME_LABEL = "Channel Name";
73
74 public static final String SAVE_DIALOG_TITLE = "Save Sessions";
75 public static final String LOAD_DIALOG_TITLE = "Load Sessions";
76 public static final String REMOTE_RADIO_BUTTON_LABEL = "Remote";
77
78 // Remote import strings
79 public static final String IMPORT_WIZARD_TITLE = "Fetch Remote Traces";
80 public static final String DEFAULT_REMOTE_PROJECT = "Remote";
81 public static final String FINISH_BUTTON = "Finish";
82 public static final String CANCEL_BUTTON = "Cancel";
83 public static final String OPTION_GROUP_NAME = "Options";
84
85 private ControlViewSwtBotUtil() { }
86
87 /**
88 * Tests for Target node state
89 *
90 * @param node
91 * target node component
92 * @param state
93 * the state to wait
94 * @return the condition instance
95 */
96 public static ICondition isStateChanged(final TargetNodeComponent node, final TargetNodeState state) {
97 return new SWTBotTestCondition() {
98 @Override
99 public boolean test() throws Exception {
100 if (node.getTargetNodeState() != state) {
101 return false;
102 }
103 return true;
104 }
105 };
106 }
107
108 /**
109 * Tests for session state
110 *
111 * @param session
112 * the session component
113 * @param state
114 * the state to wait
115 * @return the condition instance
116 */
117 public static ICondition isSessionStateChanged(final TraceSessionComponent session, final TraceSessionState state) {
118 return new SWTBotTestCondition() {
119 @Override
120 public boolean test() throws Exception {
121 if (session.getSessionState() != state) {
122 return false;
123 }
124 return true;
125 }
126 };
127 }
128
129 /**
130 * Finds a session for given node
131 *
132 * @param target
133 * target node component
134 * @param sessionName
135 * session name to find
136 * @return the session component or null
137 */
138 public static TraceSessionComponent getSessionComponent(TargetNodeComponent target, String sessionName) {
139 final TraceSessionComponent[] sessions = target.getSessions();
140 if (sessions != null) {
141 for (int i = 0; i < sessions.length; i++) {
142 if (sessionName.equals(sessions[i].getName())) {
143 return sessions[i];
144 }
145 }
146 }
147 return null;
148 }
149
150 /**
151 * Finds a {@link ITraceControlComponent} in a tree for given path.
152 *
153 * @param root
154 * root component
155 * @param path
156 * path to element
157 * @return the matched component or null
158 */
159 public static ITraceControlComponent getComponent(ITraceControlComponent root, String... path) {
160 ITraceControlComponent newRoot = root;
161 for (String segment : path) {
162 newRoot = Arrays.asList(newRoot.getChildren()).stream()
163 .filter(child -> (child.getName().equals(segment)))
164 .findFirst()
165 .orElse(null);
166 if (newRoot == null) {
167 return null;
168 }
169 }
170 return newRoot;
171 }
172
173 }
This page took 0.034699 seconds and 4 git commands to generate.