1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Fix assertion messages
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
;
16 import static org
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertTrue
;
19 import java
.util
.Collection
;
20 import java
.util
.List
;
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
;
38 * Tests perspectives to make sure they have all the views
40 * @author Matthew Khouzam
42 @RunWith(SWTBotJunit4ClassRunner
.class)
43 public abstract class AbstractPerspectiveChecker
{
45 private static SWTWorkbenchBot fBot
;
46 /** The Log4j logger instance. */
47 private static final Logger fLogger
= Logger
.getRootLogger();
52 protected String fPerspectiveId
;
54 * the view id collection
56 protected Collection
<String
> fViewIds
;
58 /** Test Class setup */
60 public static void beforeInit() {
61 SWTBotUtils
.initialize();
63 /* set up for swtbot */
64 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
65 fLogger
.removeAllAppenders();
66 fLogger
.addAppender(new NullAppender());
67 fBot
= new SWTWorkbenchBot();
69 SWTBotUtils
.closeView("welcome", fBot
);
77 public static void terminate() {
78 fLogger
.removeAllAppenders();
82 * Gets the perspective and checks if all the views specified in the list
83 * are present in the perspective
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
>() {
93 public boolean matches(Object item
) {
94 if (!(item
instanceof IViewReference
)) {
97 IViewReference reference
= (IViewReference
) item
;
98 return reference
.getId().equals(viewID
);
102 public void describeTo(Description description
) {
106 assertEquals("view " + viewID
+ " is present", 1, view
.size());
111 * Gets the perspective and checks if all the views of that perspective are
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()));