Skip to content

Package: UnsetRuleIntegration_PTest

UnsetRuleIntegration_PTest

nameinstructionbranchcomplexitylinemethod
UnsetRuleIntegration_PTest()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
addControlToView(VFeaturePathDomainModelReference)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
after()
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
before()
M: 0 C: 42
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 10
100%
M: 0 C: 1
100%
merchandiseNameReferenceFromFan()
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
services(EObject)
M: 0 C: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testInitUnset()
M: 0 C: 35
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
testMultiUnset()
M: 0 C: 64
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 17
100%
M: 0 C: 1
100%
testPriorities()
M: 1 C: 17
94%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
testUnset()
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testVCategorizationElementHideCategory()
M: 0 C: 169
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 45
100%
M: 0 C: 1
100%
testVCategorizationElementHideCategoryInCategorization()
M: 0 C: 187
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 49
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: * Johannes Faltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.unset.test;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertTrue;
19:
20: import java.math.BigDecimal;
21:
22: import org.eclipse.emf.ecore.EObject;
23: import org.eclipse.emf.ecore.EStructuralFeature;
24: import org.eclipse.emf.ecp.test.common.DefaultRealm;
25: import org.eclipse.emf.ecp.view.internal.rule.RuleService;
26: import org.eclipse.emf.ecp.view.internal.rule.RuleServiceHelperImpl;
27: import org.eclipse.emf.ecp.view.internal.unset.UnsetService;
28: import org.eclipse.emf.ecp.view.rule.test.CommonRuleTest;
29: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorization;
30: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationElement;
31: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategorizationFactory;
32: import org.eclipse.emf.ecp.view.spi.categorization.model.VCategory;
33: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
34: import org.eclipse.emf.ecp.view.spi.context.ViewModelContextFactory;
35: import org.eclipse.emf.ecp.view.spi.model.VControl;
36: import org.eclipse.emf.ecp.view.spi.model.VFeaturePathDomainModelReference;
37: import org.eclipse.emf.ecp.view.spi.model.VView;
38: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
39: import org.eclipse.emf.ecp.view.spi.rule.model.RuleFactory;
40: import org.eclipse.emf.ecp.view.spi.rule.model.ShowRule;
41: import org.eclipse.emf.emfstore.bowling.BowlingFactory;
42: import org.eclipse.emf.emfstore.bowling.BowlingPackage;
43: import org.eclipse.emf.emfstore.bowling.Fan;
44: import org.eclipse.emf.emfstore.bowling.League;
45: import org.eclipse.emf.emfstore.bowling.Merchandise;
46: import org.eclipse.emf.emfstore.bowling.Player;
47: import org.junit.After;
48: import org.junit.Before;
49: import org.junit.Test;
50:
51: /**
52: * @author jfaltermeier
53: *
54: */
55: public class UnsetRuleIntegration_PTest extends CommonRuleTest {
56:
57:         private static final String FOO = "foo";
58:         private Fan fan;
59:         private Merchandise merchandise;
60:
61:         private final EStructuralFeature merchandiseNameFeature = BowlingPackage.eINSTANCE.getMerchandise_Name();
62:         private final EStructuralFeature fanNameFeature = BowlingPackage.eINSTANCE.getFan_Name();
63:         private final BigDecimal price = new BigDecimal(19.84);
64:         private final String mercName = "Wimpel";
65:         private final String fanName = "Max Morlock";
66:
67:         private VView view;
68:
69:         private ViewModelContext context;
70:         private DefaultRealm realm;
71:
72:         @Before
73:         public void before() {
74:                 realm = new DefaultRealm();
75:                 fan = BowlingFactory.eINSTANCE.createFan();
76:                 merchandise = BowlingFactory.eINSTANCE.createMerchandise();
77:                 merchandise.setPrice(price);
78:                 merchandise.setName(mercName);
79:                 fan.setFavouriteMerchandise(merchandise);
80:                 fan.setName(fanName);
81:
82:                 view = VViewFactory.eINSTANCE.createView();
83:                 view.setRootEClass(fan.eClass());
84:         }
85:
86:         @After
87:         public void after() {
88:•                if (context != null) {
89:                         context.dispose();
90:                 }
91:                 realm.dispose();
92:         }
93:
94:         @Test
95:         public void testPriorities() {
96:                 final RuleService rule = new RuleService();
97:                 final UnsetService unset = new UnsetService();
98:•                assertTrue(rule.getPriority() < unset.getPriority());
99:         }
100:
101:         @Test
102:         public void testUnset() {
103:                 final VControl control1 = addControlToView(merchandiseNameReferenceFromFan());
104:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getFan_Name(), FOO);
105:
106:                 fan.setName(FOO);
107:                 merchandise.setName("bar");
108:
109:                 services(fan);
110:
111:                 fan.setName("quux");
112:                 assertFalse(control1.isVisible());
113:                 assertEquals(merchandiseNameFeature.getDefaultValue(), merchandise.getName());
114:         }
115:
116:         @Test
117:         public void testMultiUnset() {
118:                 final League league = BowlingFactory.eINSTANCE.createLeague();
119:                 final Player player = BowlingFactory.eINSTANCE.createPlayer();
120:                 league.getPlayers().add(player);
121:
122:                 view.setRootEClass(BowlingPackage.eINSTANCE.getLeague());
123:
124:                 final VControl control = VViewFactory.eINSTANCE.createControl();
125:
126:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
127:                         .createFeaturePathDomainModelReference();
128:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getLeague_Players());
129:                 control.setDomainModelReference(domainModelReference);
130:
131:                 view.getChildren().add(control);
132:
133:                 addShowRule(control, true, BowlingPackage.eINSTANCE.getLeague_Name(), "League");
134:                 league.setName("League");
135:                 services(league);
136:                 assertEquals(1, league.getPlayers().size());
137:                 league.setName("Liga");
138:                 assertEquals(0, league.getPlayers().size());
139:         }
140:
141:         @Test
142:         public void testInitUnset() {
143:                 final VControl control1 = addControlToView(merchandiseNameReferenceFromFan());
144:                 addShowRule(control1, true, BowlingPackage.eINSTANCE.getFan_Name(), FOO);
145:
146:                 merchandise.setName("bar");
147:                 fan.setName("quux");
148:                 services(fan);
149:                 assertFalse(control1.isVisible());
150:                 assertEquals(merchandiseNameFeature.getDefaultValue(), merchandise.getName());
151:         }
152:
153:         @Test
154:         public void testVCategorizationElementHideCategory() {
155:                 // set up view model
156:                 final VCategorizationElement element = VCategorizationFactory.eINSTANCE.createCategorizationElement();
157:                 view.getChildren().add(element);
158:
159:                 final VCategorization categorization = VCategorizationFactory.eINSTANCE.createCategorization();
160:                 element.getCategorizations().add(categorization);
161:
162:                 final VCategory categoryInCategorization = VCategorizationFactory.eINSTANCE.createCategory();
163:                 categorization.getCategorizations().add(categoryInCategorization);
164:
165:                 final VControl fanNameC = VViewFactory.eINSTANCE.createControl();
166:                 categoryInCategorization.setComposite(fanNameC);
167:                 final VFeaturePathDomainModelReference fanDMR = VViewFactory.eINSTANCE
168:                         .createFeaturePathDomainModelReference();
169:                 fanDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_Name());
170:                 fanNameC.setDomainModelReference(fanDMR);
171:
172:                 final VCategory category = VCategorizationFactory.eINSTANCE.createCategory();
173:                 element.getCategorizations().add(category);
174:
175:                 final VControl merchName = VViewFactory.eINSTANCE.createControl();
176:                 category.setComposite(merchName);
177:                 final VFeaturePathDomainModelReference merchDMR = VViewFactory.eINSTANCE
178:                         .createFeaturePathDomainModelReference();
179:                 merchDMR.getDomainModelEReferencePath().add(BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise());
180:                 merchDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getMerchandise_Name());
181:                 merchName.setDomainModelReference(merchDMR);
182:
183:                 // set up rules
184:                 addShowRule(category, false, BowlingPackage.eINSTANCE.getFan_Name(), FOO);
185:
186:                 // init services
187:                 services(fan);
188:                 assertTrue(element.isVisible());
189:                 assertTrue(categorization.isVisible());
190:                 assertTrue(categoryInCategorization.isVisible());
191:                 assertTrue(fanNameC.isVisible());
192:                 assertTrue(category.isVisible());
193:                 assertTrue(merchName.isVisible());
194:                 assertTrue(fan.eIsSet(fanNameFeature));
195:                 assertTrue(merchandise.eIsSet(merchandiseNameFeature));
196:                 assertEquals(fanName, fan.getName());
197:                 assertEquals(mercName, merchandise.getName());
198:
199:                 // act
200:                 fan.setName(FOO);
201:
202:                 // assert
203:                 assertTrue(element.isVisible());
204:                 assertTrue(categorization.isVisible());
205:                 assertTrue(categoryInCategorization.isVisible());
206:                 assertTrue(fanNameC.isVisible());
207:                 assertFalse(category.isVisible());
208:                 assertFalse(merchName.isVisible());
209:                 assertTrue(fan.eIsSet(fanNameFeature));
210:                 assertEquals(FOO, fan.getName());
211:                 assertFalse(merchandise.eIsSet(merchandiseNameFeature));
212:                 assertEquals(merchandiseNameFeature.getDefaultValue(), merchandise.getName());
213:         }
214:
215:         @Test
216:         public void testVCategorizationElementHideCategoryInCategorization() {
217:                 // set up view model
218:                 final VCategorizationElement element = VCategorizationFactory.eINSTANCE.createCategorizationElement();
219:                 view.getChildren().add(element);
220:
221:                 final VCategorization categorization = VCategorizationFactory.eINSTANCE.createCategorization();
222:                 element.getCategorizations().add(categorization);
223:
224:                 final VCategory categoryInCategorization = VCategorizationFactory.eINSTANCE.createCategory();
225:                 categorization.getCategorizations().add(categoryInCategorization);
226:
227:                 final VControl fanNameC = VViewFactory.eINSTANCE.createControl();
228:                 categoryInCategorization.setComposite(fanNameC);
229:                 final VFeaturePathDomainModelReference fanDMR = VViewFactory.eINSTANCE
230:                         .createFeaturePathDomainModelReference();
231:                 fanDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getFan_Name());
232:                 fanNameC.setDomainModelReference(fanDMR);
233:
234:                 final VCategory category = VCategorizationFactory.eINSTANCE.createCategory();
235:                 element.getCategorizations().add(category);
236:
237:                 final VControl merchName = VViewFactory.eINSTANCE.createControl();
238:                 category.setComposite(merchName);
239:                 final VFeaturePathDomainModelReference merchDMR = VViewFactory.eINSTANCE
240:                         .createFeaturePathDomainModelReference();
241:                 merchDMR.getDomainModelEReferencePath().add(BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise());
242:                 merchDMR.setDomainModelEFeature(BowlingPackage.eINSTANCE.getMerchandise_Name());
243:                 merchName.setDomainModelReference(merchDMR);
244:
245:                 // set up rules
246:                 final ShowRule rule = RuleFactory.eINSTANCE.createShowRule();
247:                 rule.setHide(true);
248:                 rule.setCondition(createLeafCondition(BowlingPackage.eINSTANCE.getMerchandise_Name(), FOO,
249:                         BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise()));
250:                 categoryInCategorization.getAttachments().add(rule);
251:
252:                 // init services
253:                 services(fan);
254:                 assertTrue(element.isVisible());
255:                 assertTrue(categorization.isVisible());
256:                 assertTrue(categoryInCategorization.isVisible());
257:                 assertTrue(fanNameC.isVisible());
258:                 assertTrue(category.isVisible());
259:                 assertTrue(merchName.isVisible());
260:                 assertTrue(fan.eIsSet(fanNameFeature));
261:                 assertTrue(merchandise.eIsSet(merchandiseNameFeature));
262:                 assertEquals(fanName, fan.getName());
263:                 assertEquals(mercName, merchandise.getName());
264:
265:                 // act
266:                 merchandise.setName(FOO);
267:
268:                 // assert
269:                 assertTrue(element.isVisible());
270:                 assertTrue(categorization.isVisible());
271:                 assertFalse(categoryInCategorization.isVisible());
272:                 assertFalse(fanNameC.isVisible());
273:                 assertTrue(category.isVisible());
274:                 assertTrue(merchName.isVisible());
275:                 assertFalse(fan.eIsSet(fanNameFeature));
276:                 assertEquals(fanNameFeature.getDefaultValue(), fan.getName());
277:                 assertTrue(merchandise.eIsSet(merchandiseNameFeature));
278:                 assertEquals(FOO, merchandise.getName());
279:         }
280:
281:         // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
282:         // Factory methods
283:         // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
284:
285:         private void services(EObject domain) {
286:                 context = ViewModelContextFactory.INSTANCE.createViewModelContext(view, domain);
287:
288:                 final UnsetService unsetService = new UnsetService();
289:                 unsetService.instantiate(context);
290:
291:                 final RuleService ruleService = new RuleService();
292:                 final RuleServiceHelperImpl ruleServiceHelper = new RuleServiceHelperImpl();
293:                 ruleService.instantiate(context);
294:                 ruleServiceHelper.instantiate(context);
295:         }
296:
297:         /**
298:          * Adds a control with the given feature path domain model reference as a direct child of the view.
299:          *
300:          * @param domainModelReference
301:          * @return the created control
302:          */
303:         private VControl addControlToView(VFeaturePathDomainModelReference domainModelReference) {
304:                 final VControl control = VViewFactory.eINSTANCE.createControl();
305:                 control.setDomainModelReference(domainModelReference);
306:                 view.getChildren().add(control);
307:                 return control;
308:         }
309:
310:         private VFeaturePathDomainModelReference merchandiseNameReferenceFromFan() {
311:                 final VFeaturePathDomainModelReference domainModelReference = VViewFactory.eINSTANCE
312:                         .createFeaturePathDomainModelReference();
313:                 domainModelReference.setDomainModelEFeature(BowlingPackage.eINSTANCE.getMerchandise_Name());
314:                 domainModelReference.getDomainModelEReferencePath().add(BowlingPackage.eINSTANCE.getFan_FavouriteMerchandise());
315:                 return domainModelReference;
316:         }
317:
318: }