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