Skip to content

Package: CommonRuleTest

CommonRuleTest

nameinstructionbranchcomplexitylinemethod
CommonRuleTest()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
addEnableRule(VElement, boolean)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addEnableRule(VElement, boolean, EAttribute, Object)
M: 0 C: 24
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
addLeagueEnableRule(VElement, boolean)
M: 0 C: 35
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
addLeagueEnableRuleWithAndCondition(VElement, boolean, Condition[])
M: 2 C: 41
95%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 8
100%
M: 0 C: 1
100%
addLeagueEnableRuleWithOrCondition(VElement, boolean, Condition[])
M: 2 C: 41
95%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 8
100%
M: 0 C: 1
100%
addLeagueShowRule(VElement, boolean)
M: 0 C: 25
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
addLeagueShowRuleWithAndCondition(VElement, boolean, Condition[])
M: 0 C: 43
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
addLeagueShowRuleWithOrCondition(VElement, boolean, Condition[])
M: 0 C: 43
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
addShowRule(VElement, boolean)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addShowRule(VElement, boolean, EAttribute, Object)
M: 0 C: 24
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
createLeafCondition(EAttribute, Object, EReference[])
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 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: * Edgar - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.rule.test;
15:
16: import java.util.Arrays;
17:
18: import org.eclipse.emf.ecore.EAttribute;
19: import org.eclipse.emf.ecore.EReference;
20: import org.eclipse.emf.ecp.view.spi.model.VElement;
21: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
22: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
23: import org.eclipse.emf.ecp.view.spi.rule.model.AndCondition;
24: import org.eclipse.emf.ecp.view.spi.rule.model.Condition;
25: import org.eclipse.emf.ecp.view.spi.rule.model.EnableRule;
26: import org.eclipse.emf.ecp.view.spi.rule.model.LeafCondition;
27: import org.eclipse.emf.ecp.view.spi.rule.model.OrCondition;
28: import org.eclipse.emf.ecp.view.spi.rule.model.RuleFactory;
29: import org.eclipse.emf.ecp.view.spi.rule.model.ShowRule;
30: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
31:
32: /**
33: * @author Edgar
34: *
35: */
36: public class CommonRuleTest {
37:
38:         /**
39:          * Adds the league show rule.
40:          *
41:          * @param control the control
42:          * @param showOnRightValue the visible on right value
43:          */
44:         protected void addLeagueShowRule(VElement control, boolean showOnRightValue) {
45:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
46:•                rule.setHide(!showOnRightValue);
47:                 rule.setCondition(createLeafCondition(BowlingPackage.eINSTANCE.getLeague_Name(), "League"));
48:                 control.getAttachments().add(rule);
49:         }
50:
51:         /**
52:          * Adds a {@link ShowRule} to the given {@link VElement} and allows specifying
53:          * the condition to be fulfilled.
54:          *
55:          * @param control
56:          * the {@link VElement} to which the show rule should be attached
57:          * @param showOnRightValue
58:          * whether the show rule should cause the {@link VElement} to be
59:          * hidden or show if the condition is fulfilled
60:          * @param attribute
61:          * the attribute the condition is pointing to
62:          * @param expectedValue
63:          * the expected value of the attribute
64:          */
65:         protected void addShowRule(VElement control, boolean showOnRightValue, EAttribute attribute,
66:                 Object expectedValue) {
67:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
68:•                rule.setHide(!showOnRightValue);
69:                 rule.setCondition(createLeafCondition(attribute, expectedValue));
70:                 control.getAttachments().add(rule);
71:         }
72:
73:         /**
74:          * Adds a {@link ShowRule} to the given {@link VElement} without a condition.
75:          */
76:         protected ShowRule addShowRule(VElement control, boolean isHide) {
77:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
78:                 rule.setHide(isHide);
79:                 control.getAttachments().add(rule);
80:                 return rule;
81:         }
82:
83:         /**
84:          * Adds a {@link EnableRule} to the given {@link VElement} without a condition.
85:          */
86:         protected void addEnableRule(VElement control, boolean isDisabled) {
87:                 final EnableRule rule = RuleFactory.eINSTANCE.createEnableRule();
88:                 rule.setDisable(isDisabled);
89:                 control.getAttachments().add(rule);
90:         }
91:
92:         protected void addEnableRule(VElement control, boolean enableOnRightValue, EAttribute attribute,
93:                 Object expectedValue) {
94:                 final EnableRule rule = RuleFactory.eINSTANCE.createEnableRule();
95:•                rule.setDisable(!enableOnRightValue);
96:                 rule.setCondition(createLeafCondition(attribute, expectedValue));
97:                 control.getAttachments().add(rule);
98:         }
99:
100:         protected LeafCondition createLeafCondition(EAttribute attribute, Object expectedValue, EReference... eReferences) {
101:                 final LeafCondition condition = RuleFactory.eINSTANCE.createLeafCondition();
102:                 final VFeaturePathDomainModelReference modelReference = VViewFactory.eINSTANCE
103:                         .createFeaturePathDomainModelReference();
104:                 modelReference.setDomainModelEFeature(attribute);
105:                 modelReference.getDomainModelEReferencePath().addAll(Arrays.asList(eReferences));
106:                 condition.setDomainModelReference(modelReference);
107:                 condition.setExpectedValue(expectedValue);
108:                 return condition;
109:         }
110:
111:         protected void addLeagueShowRuleWithOrCondition(VElement control, boolean hideOnRightValue,
112:                 Condition... childConditions) {
113:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
114:•                rule.setHide(!hideOnRightValue);
115:                 final OrCondition condition = RuleFactory.eINSTANCE.createOrCondition();
116:•                for (final Condition childCondition : childConditions) {
117:                         condition.getConditions().add(childCondition);
118:                 }
119:                 rule.setCondition(condition);
120:                 control.getAttachments().add(rule);
121:         }
122:
123:         protected void addLeagueEnableRuleWithOrCondition(VElement control, boolean disableOnRightValue,
124:                 Condition... childConditions) {
125:                 final EnableRule rule = RuleFactory.eINSTANCE.createEnableRule();
126:•                rule.setDisable(!disableOnRightValue);
127:                 final OrCondition condition = RuleFactory.eINSTANCE.createOrCondition();
128:•                for (final Condition childCondition : childConditions) {
129:                         condition.getConditions().add(childCondition);
130:                 }
131:                 rule.setCondition(condition);
132:                 control.getAttachments().add(rule);
133:         }
134:
135:         protected void addLeagueShowRuleWithAndCondition(VElement control, boolean hideOnRightValue,
136:                 Condition... childConditions) {
137:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
138:•                rule.setHide(!hideOnRightValue);
139:                 final AndCondition condition = RuleFactory.eINSTANCE.createAndCondition();
140:•                for (final Condition childCondition : childConditions) {
141:                         condition.getConditions().add(childCondition);
142:                 }
143:                 rule.setCondition(condition);
144:                 control.getAttachments().add(rule);
145:         }
146:
147:         protected void addLeagueEnableRuleWithAndCondition(VElement control, boolean disableOnRightValue,
148:                 Condition... childConditions) {
149:                 final EnableRule rule = RuleFactory.eINSTANCE.createEnableRule();
150:•                rule.setDisable(!disableOnRightValue);
151:                 final AndCondition condition = RuleFactory.eINSTANCE.createAndCondition();
152:•                for (final Condition childCondition : childConditions) {
153:                         condition.getConditions().add(childCondition);
154:                 }
155:                 rule.setCondition(condition);
156:                 control.getAttachments().add(rule);
157:         }
158:
159:         /**
160:          * Adds the league enable rule.
161:          *
162:          * @param control the control
163:          * @param enableOnRightValue the enable on right value
164:          */
165:         protected void addLeagueEnableRule(VElement control, boolean enableOnRightValue) {
166:                 final EnableRule rule = RuleFactory.eINSTANCE.createEnableRule();
167:•                rule.setDisable(!enableOnRightValue);
168:                 final LeafCondition condition = RuleFactory.eINSTANCE.createLeafCondition();
169:                 rule.setCondition(condition);
170:                 final VFeaturePathDomainModelReference modelReference = VViewFactory.eINSTANCE
171:                         .createFeaturePathDomainModelReference();
172:                 modelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getLeague_Name());
173:                 condition.setDomainModelReference(modelReference);
174:                 condition.setExpectedValue("League");
175:                 control.getAttachments().add(rule);
176:         }
177:
178: }