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