Skip to content

Package: LocalizationViewModelService_Test

LocalizationViewModelService_Test

nameinstructionbranchcomplexitylinemethod
LocalizationViewModelService_Test()
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%
getLocalizableString(String)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setup()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
testGetPriority()
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%
testInstantiateDynamicAddSingleControlOnChild()
M: 0 C: 80
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 19
100%
M: 0 C: 1
100%
testInstantiateDynamicAddSingleControlOnRoot()
M: 0 C: 64
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
testInstantiateDynamicAddSubTreeOnChild()
M: 0 C: 108
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 26
100%
M: 0 C: 1
100%
testInstantiateDynamicAddSubTreeOnRoot()
M: 0 C: 92
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 22
100%
M: 0 C: 1
100%
testInstantiateDynamicNameChange()
M: 0 C: 88
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
testInstantiateStatic()
M: 0 C: 120
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 31
100%
M: 0 C: 1
100%
testInstantiateStaticNoLocalizationAdapter()
M: 0 C: 41
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-2015 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: * Eugen - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.internal.view.model.localization;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.mockito.Mockito.mock;
18: import static org.mockito.Mockito.spy;
19: import static org.mockito.Mockito.when;
20:
21: import org.eclipse.emf.common.notify.impl.AdapterImpl;
22: import org.eclipse.emf.ecore.EcoreFactory;
23: import org.eclipse.emf.ecp.view.internal.context.ArrayOnceViewModelServiceProvider;
24: import org.eclipse.emf.ecp.view.internal.context.ViewModelContextImpl;
25: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
26: import org.eclipse.emf.ecp.view.spi.model.LocalizationAdapter;
27: import org.eclipse.emf.ecp.view.spi.model.VControl;
28: import org.eclipse.emf.ecp.view.spi.model.VView;
29: import org.eclipse.emf.ecp.view.spi.model.VViewFactory;
30: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalFactory;
31: import org.eclipse.emf.ecp.view.spi.vertical.model.VVerticalLayout;
32: import org.junit.Before;
33: import org.junit.Test;
34:
35: @SuppressWarnings("restriction")
36: public class LocalizationViewModelService_Test {
37:
38:         private LocalizationViewModelService localizationViewModelService;
39:
40:         @Before
41:         public void setup() {
42:                 localizationViewModelService = spy(new LocalizationViewModelService());
43:         }
44:
45:         private String getLocalizableString(String name) {
46:                 return name.substring(1);
47:         }
48:
49:         /**
50:          * Test method for
51:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)}
52:          * .
53:          */
54:         @Test
55:         public void testInstantiateStatic() {
56:                 final String viewName = "%view"; //$NON-NLS-1$
57:                 final String layoutName = "%layout"; //$NON-NLS-1$
58:                 final String controlName = "%control"; //$NON-NLS-1$
59:                 final String control2Name = "Fix control name"; //$NON-NLS-1$
60:                 final String viewLabel = "My super View"; //$NON-NLS-1$
61:                 final String layoutLabel = "My super Layout"; //$NON-NLS-1$
62:                 final String controlLabel = "My super Control"; //$NON-NLS-1$
63:
64:                 final VView view = VViewFactory.eINSTANCE.createView();
65:                 view.setName(viewName);
66:                 final VVerticalLayout layout = VVerticalFactory.eINSTANCE.createVerticalLayout();
67:                 layout.setName(layoutName);
68:                 view.getChildren().add(layout);
69:                 final VControl control1 = VViewFactory.eINSTANCE.createControl();
70:                 control1.setName(controlName);
71:                 layout.getChildren().add(control1);
72:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
73:                 control2.setName(control2Name);
74:                 layout.getChildren().add(control2);
75:
76:                 final ViewModelContext viewModelContext = mock(ViewModelContext.class);
77:                 when(viewModelContext.getViewModel()).thenReturn(view);
78:                 final LocalizationAdapter adapter = mock(LocalizationAdapter.class);
79:                 when(adapter.localize(getLocalizableString(viewName))).thenReturn(viewLabel);
80:                 when(adapter.localize(getLocalizableString(layoutName))).thenReturn(layoutLabel);
81:                 when(adapter.localize(getLocalizableString(controlName))).thenReturn(controlLabel);
82:                 view.eAdapters().add(adapter);
83:
84:                 localizationViewModelService.instantiate(viewModelContext);
85:
86:                 assertEquals(viewLabel, view.getLabel());
87:                 assertEquals(layoutLabel, layout.getLabel());
88:                 assertEquals(controlLabel, control1.getLabel());
89:                 assertEquals(control2Name, control2.getLabel());
90:         }
91:
92:         /**
93:          * Test method for
94:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)}
95:          * .
96:          */
97:         @Test
98:         public void testInstantiateStaticNoLocalizationAdapter() {
99:
100:                 final VView view = VViewFactory.eINSTANCE.createView();
101:                 final VControl control = VViewFactory.eINSTANCE.createControl();
102:                 view.getChildren().add(control);
103:                 view.eAdapters().add(new AdapterImpl());
104:
105:                 final ViewModelContext viewModelContext = mock(ViewModelContext.class);
106:                 when(viewModelContext.getViewModel()).thenReturn(view);
107:
108:                 localizationViewModelService.instantiate(viewModelContext);
109:
110:                 assertEquals("", view.getLabel()); //$NON-NLS-1$
111:                 assertEquals("", control.getLabel()); //$NON-NLS-1$
112:         }
113:
114:         /**
115:          * Test method for
116:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)}
117:          * .
118:          */
119:         @Test
120:         public void testInstantiateDynamicNameChange() {
121:
122:                 final String controlName = "%control"; //$NON-NLS-1$
123:                 final String controlName2 = "%control2"; //$NON-NLS-1$
124:                 final String controlLabel = "My super Control"; //$NON-NLS-1$
125:                 final String controlLabel2 = "My super Control Two"; //$NON-NLS-1$
126:
127:                 final VView view = VViewFactory.eINSTANCE.createView();
128:                 final VVerticalLayout layout = VVerticalFactory.eINSTANCE.createVerticalLayout();
129:                 view.getChildren().add(layout);
130:                 final VControl control = VViewFactory.eINSTANCE.createControl();
131:                 control.setName(controlName);
132:                 layout.getChildren().add(control);
133:
134:                 final LocalizationAdapter adapter = mock(LocalizationAdapter.class);
135:                 when(adapter.localize(getLocalizableString(controlName))).thenReturn(controlLabel);
136:                 when(adapter.localize(getLocalizableString(controlName2))).thenReturn(controlLabel2);
137:                 view.eAdapters().add(adapter);
138:
139:                 final ViewModelContext viewModelContext = spy(new ViewModelContextImpl(view,
140:                         EcoreFactory.eINSTANCE.createEObject(),
141:                         new ArrayOnceViewModelServiceProvider(localizationViewModelService)));
142:
143:                 localizationViewModelService.instantiate(viewModelContext);
144:                 control.setName(controlName2);
145:
146:                 assertEquals(controlLabel2, control.getLabel());
147:         }
148:
149:         /**
150:          * Test method for
151:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)}
152:          * .
153:          */
154:         @Test
155:         public void testInstantiateDynamicAddSingleControlOnRoot() {
156:
157:                 final String controlName = "%control"; //$NON-NLS-1$
158:                 final String controlLabel = "My super Control"; //$NON-NLS-1$
159:                 final VView view = VViewFactory.eINSTANCE.createView();
160:
161:                 final LocalizationAdapter adapter = mock(LocalizationAdapter.class);
162:                 when(adapter.localize(getLocalizableString(controlName))).thenReturn(controlLabel);
163:                 view.eAdapters().add(adapter);
164:
165:                 final ViewModelContext viewModelContext = spy(new ViewModelContextImpl(view,
166:                         EcoreFactory.eINSTANCE.createEObject(),
167:                         new ArrayOnceViewModelServiceProvider(localizationViewModelService)));
168:
169:                 localizationViewModelService.instantiate(viewModelContext);
170:
171:                 final VControl control = VViewFactory.eINSTANCE.createControl();
172:                 control.setName(controlName);
173:                 view.getChildren().add(control);
174:                 assertEquals(controlLabel, control.getLabel());
175:         }
176:
177:         /**
178:          * Test method for
179:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)}
180:          * .
181:          */
182:         @Test
183:         public void testInstantiateDynamicAddSingleControlOnChild() {
184:
185:                 final String controlName = "%control"; //$NON-NLS-1$
186:
187:                 final String controlLabel = "My super Control"; //$NON-NLS-1$
188:
189:                 final VView view = VViewFactory.eINSTANCE.createView();
190:                 final VVerticalLayout layout = VVerticalFactory.eINSTANCE.createVerticalLayout();
191:                 view.getChildren().add(layout);
192:                 final VControl control = VViewFactory.eINSTANCE.createControl();
193:                 layout.getChildren().add(control);
194:
195:                 final LocalizationAdapter adapter = mock(LocalizationAdapter.class);
196:                 when(adapter.localize(getLocalizableString(controlName))).thenReturn(controlLabel);
197:                 view.eAdapters().add(adapter);
198:
199:                 final ViewModelContext viewModelContext = spy(new ViewModelContextImpl(view,
200:                         EcoreFactory.eINSTANCE.createEObject(),
201:                         new ArrayOnceViewModelServiceProvider(localizationViewModelService)));
202:
203:                 localizationViewModelService.instantiate(viewModelContext);
204:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
205:                 control2.setName(controlName);
206:                 layout.getChildren().add(control2);
207:
208:                 assertEquals(controlLabel, control2.getLabel());
209:         }
210:
211:         /**
212:          * Test method for
213:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)}
214:          * .
215:          */
216:         @Test
217:         public void testInstantiateDynamicAddSubTreeOnRoot() {
218:
219:                 final String layoutName = "%layout"; //$NON-NLS-1$
220:                 final String controlName = "%control"; //$NON-NLS-1$
221:                 final String layoutLabel = "My super Layout"; //$NON-NLS-1$
222:                 final String controlLabel = "My super Control"; //$NON-NLS-1$
223:
224:                 final VView view = VViewFactory.eINSTANCE.createView();
225:
226:                 final LocalizationAdapter adapter = mock(LocalizationAdapter.class);
227:                 when(adapter.localize(getLocalizableString(controlName))).thenReturn(controlLabel);
228:                 when(adapter.localize(getLocalizableString(layoutName))).thenReturn(layoutLabel);
229:                 view.eAdapters().add(adapter);
230:
231:                 final ViewModelContext viewModelContext = spy(new ViewModelContextImpl(view,
232:                         EcoreFactory.eINSTANCE.createEObject(),
233:                         new ArrayOnceViewModelServiceProvider(localizationViewModelService)));
234:
235:                 localizationViewModelService.instantiate(viewModelContext);
236:                 final VVerticalLayout layout = VVerticalFactory.eINSTANCE.createVerticalLayout();
237:                 layout.setName(layoutName);
238:                 final VControl control = VViewFactory.eINSTANCE.createControl();
239:                 control.setName(controlName);
240:                 layout.getChildren().add(control);
241:
242:                 view.getChildren().add(layout);
243:
244:                 assertEquals(controlLabel, control.getLabel());
245:                 assertEquals(layoutLabel, layout.getLabel());
246:         }
247:
248:         /**
249:          * Test method for
250:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#instantiate(org.eclipse.emf.ecp.view.spi.context.ViewModelContext)}
251:          * .
252:          */
253:         @Test
254:         public void testInstantiateDynamicAddSubTreeOnChild() {
255:
256:                 final String layoutName = "%layout"; //$NON-NLS-1$
257:                 final String controlName = "%control"; //$NON-NLS-1$
258:                 final String layoutLabel = "My super Layout"; //$NON-NLS-1$
259:                 final String controlLabel = "My super Control"; //$NON-NLS-1$
260:
261:                 final VView view = VViewFactory.eINSTANCE.createView();
262:                 final VVerticalLayout layout = VVerticalFactory.eINSTANCE.createVerticalLayout();
263:                 view.getChildren().add(layout);
264:                 final VControl control = VViewFactory.eINSTANCE.createControl();
265:                 layout.getChildren().add(control);
266:
267:                 final LocalizationAdapter adapter = mock(LocalizationAdapter.class);
268:                 when(adapter.localize(getLocalizableString(controlName))).thenReturn(controlLabel);
269:                 when(adapter.localize(getLocalizableString(layoutName))).thenReturn(layoutLabel);
270:                 view.eAdapters().add(adapter);
271:                 final ViewModelContext viewModelContext = spy(new ViewModelContextImpl(view,
272:                         EcoreFactory.eINSTANCE.createEObject(),
273:                         new ArrayOnceViewModelServiceProvider(localizationViewModelService)));
274:
275:                 localizationViewModelService.instantiate(viewModelContext);
276:
277:                 final VVerticalLayout layout2 = VVerticalFactory.eINSTANCE.createVerticalLayout();
278:                 layout2.setName(layoutName);
279:                 final VControl control2 = VViewFactory.eINSTANCE.createControl();
280:                 control2.setName(controlName);
281:                 layout2.getChildren().add(control2);
282:
283:                 layout.getChildren().add(layout2);
284:
285:                 assertEquals(controlLabel, control2.getLabel());
286:                 assertEquals(layoutLabel, layout2.getLabel());
287:         }
288:
289:         /**
290:          * Test method for
291:          * {@link org.eclipse.emfforms.internal.view.model.localization.LocalizationViewModelService#getPriority()}.
292:          */
293:         @Test
294:         public void testGetPriority() {
295:                 assertEquals(-100, localizationViewModelService.getPriority());
296:         }
297:
298: }