Skip to content

Package: RuleConditionDmrNewModelElementStrategyProvider_PTest

RuleConditionDmrNewModelElementStrategyProvider_PTest

nameinstructionbranchcomplexitylinemethod
RuleConditionDmrNewModelElementStrategyProvider_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(Optional[], CreateNewModelElementStrategy)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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(Optional[], CreateNewModelElementStrategy)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
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: 38
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
strategy_cancel()
M: 0 C: 31
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
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.assertFalse;
17: import static org.junit.Assert.assertNotNull;
18: import static org.junit.Assert.assertNull;
19: import static org.junit.Assert.assertTrue;
20:
21: import org.eclipse.emf.ecore.EObject;
22: import org.eclipse.emf.ecore.EReference;
23: import org.eclipse.emf.ecp.test.common.MultiTry;
24: import org.eclipse.emf.ecp.test.common.MultiTryTestRule;
25: import org.eclipse.emf.ecp.ui.view.swt.reference.CreateNewModelElementStrategy;
26: import org.eclipse.emf.ecp.view.internal.editor.handler.RuleConditionDmrNewModelElementStrategyProvider_PTest.CreateRuleConditionDmrTestProvider;
27: import org.eclipse.emf.ecp.view.spi.model.VDomainModelReference;
28: import org.eclipse.emf.ecp.view.spi.rule.model.RulePackage;
29: import org.eclipse.emf.ecp.view.test.common.swt.spi.SWTTestUtil;
30: import org.eclipse.emfforms.common.Optional;
31: import org.eclipse.swt.widgets.Button;
32: import org.eclipse.swt.widgets.Display;
33: import org.eclipse.swt.widgets.Shell;
34: import org.eclipse.swt.widgets.Tree;
35: import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
36: import org.junit.Rule;
37: import org.junit.Test;
38:
39: /**
40: * Tests for {@link RuleConditionDmrNewModelElementStrategyProvider}.
41: *
42: * @author Lucas Koehler
43: */
44: public class RuleConditionDmrNewModelElementStrategyProvider_PTest
45:         extends AbstractRuleConditionDmrStrategyProviderTest<CreateRuleConditionDmrTestProvider> {
46:
47:         @Rule
48:         public final MultiTryTestRule multiTryRule = new MultiTryTestRule(2, false);
49:
50:         @Override
51:         protected void initStrategyProvider() {
52:                 setStrategyProvider(new CreateRuleConditionDmrTestProvider());
53:         }
54:
55:         @Override
56:         protected boolean executeHandles(EObject owner, EReference reference) {
57:                 return getStrategyProvider().handles(owner, reference);
58:         }
59:
60:         @Test
61:         @MultiTry
62:         public void strategy() {
63:                 final CreateNewModelElementStrategy strategy = getStrategyProvider().createCreateNewModelElementStrategy();
64:                 assertNotNull(strategy);
65:
66:                 @SuppressWarnings("unchecked")
67:                 final Optional<EObject>[] result = new Optional[1];
68:                 UIThreadRunnable.asyncExec(() -> {
69:                         result[0] = strategy.createNewModelElement(getLeafCondition(),
70:                                 RulePackage.Literals.LEAF_CONDITION__DOMAIN_MODEL_REFERENCE);
71:                 });
72:
73:                 waitForShell("New Domain Model Reference"); //$NON-NLS-1$
74:
75:                 UIThreadRunnable.syncExec(() -> {
76:                         final Shell wShell = Display.getDefault().getActiveShell();
77:                         final Tree tree = SWTTestUtil.findControl(wShell, 0, Tree.class);
78:                         SWTTestUtil.selectTreeItem(tree, 0);
79:                         final Button finish = SWTTestUtil.findControl(wShell, 4, Button.class);
80:                         SWTTestUtil.clickButton(finish);
81:                 });
82:
83:                 final Optional<EObject> strategyResult = waitUntilNotNull(result);
84:                 assertTrue(strategyResult.isPresent());
85:                 assertTrue("Result must be a VDomainModelReference.", result[0].get() instanceof VDomainModelReference); //$NON-NLS-1$
86:                 // strategy should not add the dmr to the table control.
87:                 assertNull(getLeafCondition().getDomainModelReference());
88:         }
89:
90:         @Test
91:         @MultiTry
92:         public void strategy_cancel() {
93:                 final CreateNewModelElementStrategy strategy = getStrategyProvider().createCreateNewModelElementStrategy();
94:                 assertNotNull(strategy);
95:
96:                 @SuppressWarnings("unchecked")
97:                 final Optional<EObject>[] result = new Optional[1];
98:                 UIThreadRunnable.asyncExec(() -> {
99:                         result[0] = strategy.createNewModelElement(getLeafCondition(),
100:                                 RulePackage.Literals.LEAF_CONDITION__DOMAIN_MODEL_REFERENCE);
101:                 });
102:
103:                 waitForShell("New Domain Model Reference"); //$NON-NLS-1$
104:
105:                 UIThreadRunnable.syncExec(() -> {
106:                         final Shell wShell = Display.getDefault().getActiveShell();
107:                         final Tree tree = SWTTestUtil.findControl(wShell, 0, Tree.class);
108:                         final Button cancel = SWTTestUtil.findControl(wShell, 3, Button.class);
109:                         SWTTestUtil.selectTreeItem(tree, 1);
110:                         SWTTestUtil.clickButton(cancel);
111:                 });
112:
113:                 final Optional<EObject> strategyResult = waitUntilNotNull(result);
114:                 assertFalse(strategyResult.isPresent());
115:                 assertNull(getLeafCondition().getDomainModelReference());
116:         }
117:
118:         /** Allows to mock the segment tooling enabled flag without the need to provide a runtime parameter. */
119:         class CreateRuleConditionDmrTestProvider extends RuleConditionDmrNewModelElementStrategyProvider
120:                 implements TestableStrategyProvider {
121:                 private boolean segmentToolingEnabled;
122:
123:                 /**
124:                  * @param segmentToolingEnabled true to enable segment mode
125:                  */
126:                 @Override
127:                 public void setSegmentToolingEnabled(boolean segmentToolingEnabled) {
128:                         this.segmentToolingEnabled = segmentToolingEnabled;
129:                 }
130:
131:                 @Override
132:                 protected boolean isSegmentToolingEnabled() {
133:                         return segmentToolingEnabled;
134:                 }
135:         }
136:
137: }