Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0e3d3430a5beb59a024258e9efda355b4b953709 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*******************************************************************************
 * Copyright (c) 2013 CEA LIST.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Cedric Dumoulin - cedric.dumoulin@lifl.fr
 ******************************************************************************/
package org.eclipse.papyrus.layers.stackmodel.layers.impl;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

import java.util.Arrays;
import java.util.List;

import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.layers.stackmodel.LayersException;
import org.eclipse.papyrus.layers.stackmodel.command.ComputePropertyValueCommand;
import org.eclipse.papyrus.layers.stackmodel.layers.Layer;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersFactory;
import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
import org.eclipse.papyrus.layers.stackmodel.layers.Property;
import org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry;
import org.eclipse.papyrus.layers.stackmodel.layers.TypeInstance;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;


/**
 * Test the {@link AbstractLayer#getComputePropertyValueCommand(...)} commands
 *
 * @author cedric dumoulin
 *
 */
public class LayerImplGetComputeCommandTest {

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.layers.stackmodel.layers.impl.LayerImpl#LayerImpl()}.
	 */
	@Test
	public void testLayerImpl() {
		Layer layer = LayersFactory.eINSTANCE.createLayer();
		assertNotNull("object created", layer);

	}

	/**
	 * Test method for {@link org.eclipse.papyrus.layers.stackmodel.layers.impl.AbstractLayerImpl#getComputePropertyValueCommand(org.eclipse.gmf.runtime.notation.View, org.eclipse.papyrus.layers.stackmodel.layers.Property)}.
	 * 
	 * @throws LayersException
	 */
	@Test
	public void testGetComputePropertyValueCommand() throws LayersException {
		// Create objets to test
		LayerImpl layer = (LayerImpl) LayersFactory.eINSTANCE.createLayer();
		LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication();
		layer.setApplication(application);
		PropertyRegistry propertyRegistry = application.getPropertyRegistry();

		// Fill the map with an instance for the 2 first properties
		int index = 0;
		Property property = propertyRegistry.getProperties().get(index);
		TypeInstance instance = property.createInstance();
		layer.getPropertyValueMap().put(property.getName(), instance);

		Property property2 = propertyRegistry.getProperties().get(++index);
		TypeInstance instance2 = property2.createInstance();
		layer.getPropertyValueMap().put(property2.getName(), instance2);

		Property property3 = propertyRegistry.getProperties().get(++index);

		// Add views
		View view1 = NotationFactory.eINSTANCE.createShape();
		layer.getViews().add(view1);
		View view2 = NotationFactory.eINSTANCE.createShape();

		// Check
		ComputePropertyValueCommand cmd = layer.getComputePropertyValueCommand(view1, property);
		assertNotNull("cmd created", cmd);
		assertSame("cmd s the property instance", instance, cmd);

		// Check wrong view2
		ComputePropertyValueCommand cmd2 = layer.getComputePropertyValueCommand(view2, property);
		assertNull("cmd created", cmd2);

		// Check wrong property
		ComputePropertyValueCommand cmd3 = layer.getComputePropertyValueCommand(view2, property3);
		assertNull("cmd created", cmd3);

	}

	/**
	 * Test method for {@link org.eclipse.papyrus.layers.stackmodel.layers.impl.AbstractLayerImpl#getViewsComputePropertyValueCommand(java.util.List, org.eclipse.papyrus.layers.stackmodel.layers.Property)}.
	 * 
	 * @throws LayersException
	 */
	@Test
	public void testGetViewsComputePropertyValueCommandListOfViewProperty() throws LayersException {
		// Create objets to test
		LayerImpl layer = (LayerImpl) LayersFactory.eINSTANCE.createLayer();
		LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication();
		layer.setApplication(application);
		PropertyRegistry propertyRegistry = application.getPropertyRegistry();

		// Fill the map with an instance for the 2 first properties
		int index = 0;
		Property property = propertyRegistry.getProperties().get(index);
		TypeInstance instance = property.createInstance();
		layer.getPropertyValueMap().put(property.getName(), instance);

		Property property2 = propertyRegistry.getProperties().get(++index);
		TypeInstance instance2 = property2.createInstance();
		layer.getPropertyValueMap().put(property2.getName(), instance2);

		Property property3 = propertyRegistry.getProperties().get(++index);

		// Add views
		View view1 = NotationFactory.eINSTANCE.createShape();
		layer.getViews().add(view1);
		View view2 = NotationFactory.eINSTANCE.createShape();
		View view3 = NotationFactory.eINSTANCE.createShape();
		layer.getViews().add(view3);

		// Check view
		List<ComputePropertyValueCommand> cmds = layer.getViewsComputePropertyValueCommand(Arrays.asList(view1, view3), property);
		assertNotNull("cmd created", cmds);
		assertSame("cmd size is equals to views size", 2, cmds.size());
		int i = 0;
		assertSame("cmd is the property instance", instance, cmds.get(i++));
		assertSame("cmd is the property instance", instance, cmds.get(i++));

		// Check wrong view2
		List<ComputePropertyValueCommand> cmds2 = layer.getViewsComputePropertyValueCommand(Arrays.asList(view1, view2), property);
		assertNotNull("cmd created", cmds2);
		assertSame("cmd size is equals to views size", 2, cmds2.size());
		i = 0;
		assertSame("cmd is the property instance", instance, cmds2.get(i++));
		assertSame("cmd is the property instance", null, cmds2.get(i++));

		// Check wrong view2
		List<ComputePropertyValueCommand> cmds21 = layer.getViewsComputePropertyValueCommand(Arrays.asList(view2), property);
		assertNull("cmd created", cmds21);

		// Check wrong property
		List<ComputePropertyValueCommand> cmds3 = layer.getViewsComputePropertyValueCommand(Arrays.asList(view1), property3);
		assertNull("cmd created", cmds3);

		// Check list with null
		cmds = layer.getViewsComputePropertyValueCommand(Arrays.asList(view1, null, view3), property);
		assertNotNull("cmd created", cmds);
		assertSame("cmd size is equals to views size", 3, cmds.size());
		i = 0;
		assertSame("cmd is the property instance", instance, cmds.get(i++));
		assertSame("cmd is null", null, cmds.get(i++));
		assertSame("cmd is the property instance", instance, cmds.get(i++));
	}

	/**
	 * Test method for {@link org.eclipse.papyrus.layers.stackmodel.layers.impl.AbstractLayerImpl#getPropertiesComputePropertyValueCommand(org.eclipse.gmf.runtime.notation.View, java.util.List)}.
	 * 
	 * @throws LayersException
	 */
	@Test
	public void testGetPropertiesComputePropertyValueCommandViewListOfProperty() throws LayersException {
		// Create objets to test
		LayerImpl layer = (LayerImpl) LayersFactory.eINSTANCE.createLayer();
		LayersStackApplication application = LayersFactory.eINSTANCE.createLayersStackApplication();
		layer.setApplication(application);
		PropertyRegistry propertyRegistry = application.getPropertyRegistry();

		// Fill the map with an instance for the 2 first properties
		int index = 0;
		Property property = propertyRegistry.getProperties().get(index);
		TypeInstance instance = property.createInstance();
		layer.getPropertyValueMap().put(property.getName(), instance);

		Property property2 = propertyRegistry.getProperties().get(++index);
		TypeInstance instance2 = property2.createInstance();
		layer.getPropertyValueMap().put(property2.getName(), instance2);

		Property property3 = propertyRegistry.getProperties().get(++index);

		// Add views
		View view1 = NotationFactory.eINSTANCE.createShape();
		layer.getViews().add(view1);
		View view2 = NotationFactory.eINSTANCE.createShape();
		View view3 = NotationFactory.eINSTANCE.createShape();
		layer.getViews().add(view3);

		// Check view
		List<ComputePropertyValueCommand> cmds = layer.getPropertiesComputePropertyValueCommand(view1, Arrays.asList(property, property2));
		assertNotNull("cmd created", cmds);
		assertSame("cmd size is equals to views size", 2, cmds.size());
		int i = 0;
		assertSame("cmd is the property instance", instance, cmds.get(i++));
		assertSame("cmd is the property instance", instance2, cmds.get(i++));

		// Check wrong property3
		cmds = layer.getPropertiesComputePropertyValueCommand(view1, Arrays.asList(property, property3));
		assertNotNull("cmd created", cmds);
		assertSame("cmd size is equals to views size", 2, cmds.size());
		i = 0;
		assertSame("cmd is the property instance", instance, cmds.get(i++));
		assertSame("cmd is the property instance", null, cmds.get(i++));

		// Check wrong view2
		cmds = layer.getPropertiesComputePropertyValueCommand(view1, Arrays.asList(property3));
		assertNull("cmd created", cmds);

		// Check wrong view
		cmds = layer.getPropertiesComputePropertyValueCommand(view2, Arrays.asList(property, property2));
		assertNull("cmd created", cmds);

		// Check list with null
		cmds = layer.getPropertiesComputePropertyValueCommand(view1, Arrays.asList(property, null, property2));
		assertNotNull("cmd created", cmds);
		assertSame("cmd size is equals to views size", 3, cmds.size());
		i = 0;
		assertSame("cmd is the property instance", instance, cmds.get(i++));
		assertSame("cmd is null", null, cmds.get(i++));
		assertSame("cmd is the property instance", instance2, cmds.get(i++));

	}

}

Back to the top