tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / shared / org / eclipse / tracecompass / tmf / ui / swtbot / tests / shared / AbstractPerspectiveChecker.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 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 * Patrick Tasse - Fix assertion messages
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertTrue;
18
19 import java.util.Collection;
20 import java.util.List;
21
22 import org.apache.log4j.Logger;
23 import org.apache.log4j.varia.NullAppender;
24 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
25 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
26 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
27 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
28 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
29 import org.eclipse.ui.IViewReference;
30 import org.hamcrest.BaseMatcher;
31 import org.hamcrest.Description;
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36
37 /**
38 * Tests perspectives to make sure they have all the views
39 *
40 * @author Matthew Khouzam
41 */
42 @RunWith(SWTBotJunit4ClassRunner.class)
43 public abstract class AbstractPerspectiveChecker {
44
45 private static SWTWorkbenchBot fBot;
46 /** The Log4j logger instance. */
47 private static final Logger fLogger = Logger.getRootLogger();
48
49 /**
50 * The perspective id
51 */
52 protected String fPerspectiveId;
53 /**
54 * the view id collection
55 */
56 protected Collection<String> fViewIds;
57
58 /** Test Class setup */
59 @BeforeClass
60 public static void beforeInit() {
61 SWTBotUtils.initialize();
62
63 /* set up for swtbot */
64 SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
65 fLogger.removeAllAppenders();
66 fLogger.addAppender(new NullAppender());
67 fBot = new SWTWorkbenchBot();
68
69 SWTBotUtils.closeView("welcome", fBot);
70
71 }
72
73 /**
74 * Test Class teardown
75 */
76 @AfterClass
77 public static void terminate() {
78 fLogger.removeAllAppenders();
79 }
80
81 /**
82 * Gets the perspective and checks if all the views specified in the list
83 * are present in the perspective
84 */
85 @Test
86 public void testPerspectiveForViews() {
87 SWTBotUtils.switchToPerspective(fPerspectiveId);
88 WaitUtils.waitForJobs();
89 for (final String viewID : fViewIds) {
90 List<SWTBotView> view = fBot.views(new BaseMatcher<String>() {
91
92 @Override
93 public boolean matches(Object item) {
94 if (!(item instanceof IViewReference)) {
95 return false;
96 }
97 IViewReference reference = (IViewReference) item;
98 return reference.getId().equals(viewID);
99 }
100
101 @Override
102 public void describeTo(Description description) {
103 }
104
105 });
106 assertEquals("view " + viewID + " is present", 1, view.size());
107 }
108 }
109
110 /**
111 * Gets the perspective and checks if all the views of that perspective are
112 * in the list
113 */
114 @Test
115 public void testPerspectiveComplete() {
116 SWTBotUtils.switchToPerspective(fPerspectiveId);
117 WaitUtils.waitForJobs();
118 for (SWTBotView view : fBot.views()) {
119 assertTrue("view " + view.getViewReference().getId() + " is present", fViewIds.contains(view.getViewReference().getId()));
120 }
121 }
122
123 }
This page took 0.033134 seconds and 5 git commands to generate.