Skip to content

Package: RuleConditionDmrOpenInNewContextStrategyProvider_PTest

RuleConditionDmrOpenInNewContextStrategyProvider_PTest

nameinstructionbranchcomplexitylinemethod
RuleConditionDmrOpenInNewContextStrategyProvider_PTest()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
executeHandles(EObject, EReference)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
initStrategyProvider()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$0(Boolean[], OpenInNewContextStrategy, VDomainModelReference)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$1()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
lambda$2(Boolean[], OpenInNewContextStrategy, VDomainModelReference)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$3()
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
strategy()
M: 0 C: 52
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
strategy_cancel()
M: 0 C: 40
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.internal.editor.handler;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertNotNull;
18: import static org.junit.Assert.assertNotSame;
19: import static org.junit.Assert.assertSame;
20: import static org.junit.Assert.assertTrue;
21:
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EReference;
24: import org.eclipse.emf.ecp.test.common.MultiTry;
25: import org.eclipse.emf.ecp.test.common.MultiTryTestRule;
26: import org.eclipse.emf.ecp.ui.view.swt.reference.OpenInNewContextStrategy;
27: import org.eclipse.emf.ecp.view.internal.editor.handler.RuleConditionDmrOpenInNewContextStrategyProvider_PTest.EditRuleConditionDmrTestProvider;
28: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
29: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
30: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
31: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTTestUtil;
32: import org.eclipse.swt.widgets.Button;
33: import org.eclipse.swt.widgets.Display;
34: import org.eclipse.swt.widgets.Shell;
35: import org.eclipse.swt.widgets.Tree;
36: import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
37: import org.junit.Rule;
38: import org.junit.Test;
39:
40: /**
41: * Test cases for {@link LeafConditionDmrOpenInNewContextStrategyProvider}.
42: *
43: * @author Lucas Koehler
44: */
45: public class RuleConditionDmrOpenInNewContextStrategyProvider_PTest
46:         extends AbstractRuleConditionDmrStrategyProviderTest<EditRuleConditionDmrTestProvider> {
47:
48:         @Rule
49:         public final MultiTryTestRule multiTryRule = new MultiTryTestRule(2, false);
50:
51:         @Test
52:         @MultiTry
53:         public void strategy() {
54:                 final OpenInNewContextStrategy strategy = getStrategyProvider().createOpenInNewContextStrategy();
55:                 assertNotNull(strategy);
56:                 final VDomainModelReference dmr = VViewFactory.eINSTANCE.createDomainModelReference();
57:                 getLeafCondition().setDomainModelReference(dmr);
58:
59:                 final Boolean[] result = new Boolean[1];
60:                 UIThreadRunnable.asyncExec(() -> {
61:                         result[0] = strategy.openInNewContext(getLeafCondition(),
62:                                 RulePackage.Literals.LEAF_CONDITION__DOMAIN_MODEL_REFERENCE,
63:                                 dmr);
64:                 });
65:
66:                 waitForShell("Edit Domain Model Reference"); //$NON-NLS-1$
67:
68:                 UIThreadRunnable.syncExec(() -> {
69:                         final Shell wShell = Display.getDefault().getActiveShell();
70:                         final Tree tree = SWTTestUtil.findControl(wShell, 0, Tree.class);
71:                         SWTTestUtil.selectTreeItem(tree, 0);
72:                         final Button finish = SWTTestUtil.findControl(wShell, 4, Button.class);
73:                         SWTTestUtil.clickButton(finish);
74:                 });
75:
76:                 final Boolean strategyResult = waitUntilNotNull(result);
77:                 assertTrue(strategyResult);
78:                 // strategy create a new dmr which replaces the old one
79:                 assertNotSame(dmr, getLeafCondition().getDomainModelReference());
80:                 assertNotNull(getLeafCondition().getDomainModelReference());
81:                 assertEquals(1, getLeafCondition().getDomainModelReference().getSegments().size());
82:         }
83:
84:         @Test
85:         @MultiTry
86:         public void strategy_cancel() {
87:                 final OpenInNewContextStrategy strategy = getStrategyProvider().createOpenInNewContextStrategy();
88:                 assertNotNull(strategy);
89:                 final VDomainModelReference dmr = VViewFactory.eINSTANCE.createDomainModelReference();
90:                 getLeafCondition().setDomainModelReference(dmr);
91:
92:                 final Boolean[] result = new Boolean[1];
93:                 UIThreadRunnable.asyncExec(() -> {
94:                         result[0] = strategy.openInNewContext(getLeafCondition(),
95:                                 RulePackage.Literals.LEAF_CONDITION__DOMAIN_MODEL_REFERENCE,
96:                                 dmr);
97:                 });
98:
99:                 waitForShell("Edit Domain Model Reference"); //$NON-NLS-1$
100:
101:                 UIThreadRunnable.syncExec(() -> {
102:                         final Shell wShell = Display.getDefault().getActiveShell();
103:                         final Tree tree = SWTTestUtil.findControl(wShell, 0, Tree.class);
104:                         final Button cancel = SWTTestUtil.findControl(wShell, 3, Button.class);
105:                         SWTTestUtil.selectTreeItem(tree, 1);
106:                         SWTTestUtil.clickButton(cancel);
107:                 });
108:
109:                 final Boolean strategyResult = waitUntilNotNull(result);
110:                 assertTrue(strategyResult);
111:                 assertSame(dmr, getLeafCondition().getDomainModelReference());
112:         }
113:
114:         @Override
115:         protected void initStrategyProvider() {
116:                 setStrategyProvider(new EditRuleConditionDmrTestProvider());
117:         }
118:
119:         @Override
120:         protected boolean executeHandles(EObject owner, EReference reference) {
121:                 return getStrategyProvider().handles(owner, reference);
122:         }
123:
124:         /** Allows to mock the segment tooling enabled flag without the need to provide a runtime parameter. */
125:         class EditRuleConditionDmrTestProvider extends RuleConditionDmrOpenInNewContextStrategyProvider
126:                 implements TestableStrategyProvider {
127:                 private boolean segmentToolingEnabled;
128:
129:                 /**
130:                  * @param segmentToolingEnabled true to enable segment mode
131:                  */
132:                 @Override
133:                 public void setSegmentToolingEnabled(boolean segmentToolingEnabled) {
134:                         this.segmentToolingEnabled = segmentToolingEnabled;
135:                 }
136:
137:                 @Override
138:                 protected boolean isSegmentToolingEnabled() {
139:                         return segmentToolingEnabled;
140:                 }
141:         }
142: }