Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.internal.workbench.UIEventPublisher;
import org.eclipse.e4.ui.model.application.MApplicationElement;
import org.eclipse.e4.ui.tests.rules.HeadlessApplicationRule;
import org.eclipse.e4.ui.tests.rules.HeadlessApplicationExtension;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.emf.common.notify.Notifier;
import org.junit.Before;
import org.junit.Rule;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;

public abstract class HeadlessApplicationElementTest {

protected MApplicationElement applicationElement;
protected EModelService ems;

@Rule
public HeadlessApplicationRule rule = new HeadlessApplicationRule();
@RegisterExtension
public HeadlessApplicationExtension extension = new HeadlessApplicationExtension();

@Before
@BeforeEach
public void setUp() throws Exception {
IEclipseContext applicationContext = rule.getApplicationContext();
IEclipseContext applicationContext = extension.getApplicationContext();
applicationElement = createApplicationElement(applicationContext);
ems = applicationContext.get(EModelService.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

package org.eclipse.e4.ui.tests.application;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -49,17 +49,17 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public abstract class HeadlessApplicationTest extends HeadlessApplicationElementTest {

protected MApplication application;

protected IPresentationEngine renderer;

@Before
@BeforeEach
@Override

public void setUp() throws Exception {
Expand All @@ -76,7 +76,7 @@ public void setUp() throws Exception {
}
}

@After
@AfterEach
public void tearDown() throws Exception {
for (MWindow window : application.getChildren()) {
renderer.removeGui(window);
Expand Down Expand Up @@ -233,10 +233,10 @@ protected MApplicationElement createApplicationElement(
protected abstract String getURI();

protected IPresentationEngine createPresentationEngine(String renderingEngineURI) throws Exception {
IContributionFactory contributionFactory = rule.getApplicationContext()
IContributionFactory contributionFactory = extension.getApplicationContext()
.get(IContributionFactory.class);
Object newEngine = contributionFactory.create(renderingEngineURI,
rule.getApplicationContext());
extension.getApplicationContext());
return (IPresentationEngine) newEngine;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

package org.eclipse.e4.ui.tests.application;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Arrays;
import org.eclipse.e4.core.contexts.IEclipseContext;
Expand All @@ -25,8 +25,8 @@
import org.eclipse.e4.ui.model.application.MApplicationFactory;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.emf.common.util.EList;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.osgi.service.event.Event;

/**
Expand All @@ -42,11 +42,11 @@ protected MApplicationElement createApplicationElement(IEclipseContext appContex
return MApplicationFactory.INSTANCE.createApplication();
}

@Before
@BeforeEach
@Override
public void setUp() throws Exception {
super.setUp();
IEventBroker appEB = rule.getApplicationContext().get(IEventBroker.class);
IEventBroker appEB = extension.getApplicationContext().get(IEventBroker.class);

eventCount = 0;
appEB.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, event -> {
Expand Down Expand Up @@ -174,8 +174,8 @@ public void testMove() {
assertEquals(UIEvents.ApplicationElement.TAGS, event.getProperty(UIEvents.EventTags.ATTNAME));
assertEquals(UIEvents.EventTypes.MOVE, event.getProperty(UIEvents.EventTags.TYPE));
assertEquals("2", event.getProperty(UIEvents.EventTags.NEW_VALUE));
assertEquals("former position", 2, event.getProperty(UIEvents.EventTags.OLD_VALUE));
assertEquals("new position", 0, event.getProperty(UIEvents.EventTags.POSITION));
assertEquals(2, event.getProperty(UIEvents.EventTags.OLD_VALUE), "former position");
assertEquals(0, event.getProperty(UIEvents.EventTags.POSITION), "new position");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

package org.eclipse.e4.ui.tests.application;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -47,7 +47,7 @@
import org.eclipse.e4.ui.workbench.UIEvents.UILabel;
import org.eclipse.e4.ui.workbench.UIEvents.Window;
import org.eclipse.emf.common.notify.Notifier;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.osgi.service.event.EventHandler;

public class UIEventsTest extends HeadlessApplicationElementTest {
Expand All @@ -62,14 +62,14 @@ static class EventTester {
EventHandler attListener = event -> {
// In case of * topic check that that event topic starts with the same prefix
if (topic.endsWith("*")) {
assertTrue("Incorrect Topic.", event.getTopic().startsWith(topic.substring(0, topic.length() - 2)));
assertTrue(event.getTopic().startsWith(topic.substring(0, topic.length() - 2)), "Incorrect Topic.");
} else {
assertEquals("Incorrect Topic.", topic, event.getTopic());
assertEquals(topic, event.getTopic(), "Incorrect Topic.");
}

String attId = (String) event.getProperty(EventTags.ATTNAME);
int attIndex = getAttIndex(attId);
assertTrue("Unknown Attribite: " + attId, attIndex >= 0); //$NON-NLS-1$
assertTrue(attIndex >= 0, "Unknown Attribite: " + attId); //$NON-NLS-1$
hasFired[attIndex] = true;
};

Expand Down Expand Up @@ -201,7 +201,7 @@ protected MApplicationElement createApplicationElement(

@Test
public void testAllTopics() {
IEventBroker eventBroker = rule.getApplicationContext().get(IEventBroker.class);
IEventBroker eventBroker = extension.getApplicationContext().get(IEventBroker.class);

// Create a tester for each topic
AppElementTester appTester = new AppElementTester(eventBroker);
Expand All @@ -225,9 +225,9 @@ public void testAllTopics() {

// Create the test harness and hook up the event publisher
MTestHarness allData = MTestFactory.eINSTANCE.createTestHarness();
final UIEventPublisher ep = new UIEventPublisher(rule.getApplicationContext());
final UIEventPublisher ep = new UIEventPublisher(extension.getApplicationContext());
((Notifier) allData).eAdapters().add(ep);
rule.getApplicationContext().set(UIEventPublisher.class, ep);
extension.getApplicationContext().set(UIEventPublisher.class, ep);

// AppElement
reset(allTesters);
Expand All @@ -241,8 +241,7 @@ public void testAllTopics() {
// Test that no-ops don't throw events
appTester.reset();
allData.setElementId(newId);
assertTrue("event thrown on No-Op",
appTester.getAttIds(true).length == 0);
assertTrue(appTester.getAttIds(true).length == 0, "event thrown on No-Op");

// Command
reset(allTesters);
Expand Down Expand Up @@ -318,11 +317,11 @@ public void testAllTopics() {
@Test
public void testBrokerCleanup() {
final String testTopic = "test/374534";
IEventBroker appEB = rule.getApplicationContext().get(IEventBroker.class);
IEventBroker appEB = extension.getApplicationContext().get(IEventBroker.class);

IEclipseContext childContext = rule.getApplicationContext().createChild();
IEclipseContext childContext = extension.getApplicationContext().createChild();
IEventBroker childEB = childContext.get(IEventBroker.class);
assertNotEquals("child context has same IEventBroker", appEB, childEB);
assertNotEquals(appEB, childEB, "child context has same IEventBroker");

final boolean[] seen = { false };
childEB.subscribe(testTopic, event -> seen[0] = true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

package org.eclipse.e4.ui.tests.application;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.e4.core.contexts.IEclipseContext;
Expand All @@ -30,16 +30,16 @@
import org.eclipse.e4.ui.workbench.IResourceUtilities;
import org.eclipse.jface.databinding.swt.DisplayRealm;
import org.eclipse.swt.widgets.Display;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.css.CSSStyleDeclaration;

public abstract class UIStartupTest extends HeadlessApplicationTest {

protected Display display;

@Before
@BeforeEach
@Override
public void setUp() throws Exception {
display = Display.getDefault();
Expand All @@ -48,7 +48,7 @@ public void setUp() throws Exception {
}
}

@After
@AfterEach
@Override
public void tearDown() throws Exception {
super.tearDown();
Expand Down Expand Up @@ -158,7 +158,7 @@ private static IEclipseContext getActiveChildContext(
protected IEclipseContext createApplicationContext() {
final IEclipseContext[] contexts = new IEclipseContext[1];
Realm.runWithDefault(DisplayRealm.getRealm(display), () -> {
contexts[0] = rule.getApplicationContext();
contexts[0] = extension.getApplicationContext();
contexts[0].set(IResourceUtilities.class.getName(), new ResourceUtility());
contexts[0].set(IStylingEngine.class, new IStylingEngine() {
@Override
Expand Down Expand Up @@ -196,4 +196,5 @@ protected void createGUI(final MUIElement uiRoot) {
Realm.runWithDefault(DisplayRealm.getRealm(display), () -> UIStartupTest.super.createGUI(uiRoot));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2018 vogella GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Lars Vogel <[email protected]> - initial API and implementation
******************************************************************************/

package org.eclipse.e4.ui.tests.rules;

import org.eclipse.e4.core.commands.CommandServiceAddon;
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.ui.internal.workbench.swt.E4Application;
import org.eclipse.e4.ui.services.ContextServiceAddon;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;


public class HeadlessApplicationExtension implements BeforeEachCallback, AfterEachCallback {
private IEclipseContext applicationContext;

/**
* @return the applicationContext
*/
public IEclipseContext getApplicationContext() {
return applicationContext;
}

@Override
public void beforeEach(ExtensionContext context) throws Exception {
applicationContext = createApplicationContext();
}

@Override
public void afterEach(ExtensionContext context) throws Exception {
if (applicationContext != null) {
applicationContext.dispose();
}
}

protected IEclipseContext createApplicationContext() {
final IEclipseContext appContext = E4Application.createDefaultContext();
ContextInjectionFactory.make(CommandServiceAddon.class, appContext);
ContextInjectionFactory.make(ContextServiceAddon.class, appContext);
return appContext;
}
}
Loading