Skip to content

Package: ViewModelBuilder_PTest

ViewModelBuilder_PTest

nameinstructionbranchcomplexitylinemethod
ViewModelBuilder_PTest()
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%
noAutoBuild()
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
noRedundancyWithValidationNature()
M: 0 C: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
notAViewModelProject()
M: 0 C: 34
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
validProject()
M: 0 C: 33
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
validationErrors()
M: 0 C: 53
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
validationMarkerAttributes()
M: 0 C: 83
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 20
100%
M: 0 C: 1
100%
validationProblemsFixed()
M: 0 C: 70
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 20
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: * EclipseSource - initial API and implementation
13: * Christian W. Damus - bugs 544499, 545418, 548592
14: ******************************************************************************/
15: package org.eclipse.emfforms.ide.builder;
16:
17: import static org.hamcrest.Matchers.both;
18: import static org.hamcrest.Matchers.endsWith;
19: import static org.hamcrest.Matchers.greaterThan;
20: import static org.hamcrest.Matchers.hasItemInArray;
21: import static org.hamcrest.Matchers.is;
22: import static org.junit.Assert.assertThat;
23:
24: import java.io.IOException;
25: import java.io.InputStream;
26: import java.util.Collections;
27:
28: import org.eclipse.core.resources.IFile;
29: import org.eclipse.core.resources.IMarker;
30: import org.eclipse.core.resources.IProject;
31: import org.eclipse.core.runtime.CoreException;
32: import org.eclipse.core.runtime.IProgressMonitor;
33: import org.eclipse.core.runtime.NullProgressMonitor;
34: import org.eclipse.emf.ecore.EValidator;
35: import org.eclipse.emfforms.ide.internal.builder.ProjectNature;
36: import org.eclipse.emfforms.ide.internal.builder.ValidationNature;
37: import org.eclipse.emfforms.ide.internal.builder.ViewModelBuilder;
38: import org.eclipse.emfforms.ide.internal.builder.ViewModelNature;
39: import org.junit.Assert;
40: import org.junit.Test;
41:
42: /**
43: * Test for Class {@link ViewModelBuilder}
44: */
45: public class ViewModelBuilder_PTest extends AbstractBuilderTest {
46:
47:         @Test
48:         public void validProject() throws CoreException, IOException {
49:                 // initial state
50:                 final String projectName = "ValidModel"; //$NON-NLS-1$
51:                 final IProgressMonitor monitor = new NullProgressMonitor();
52:                 final IProject project = createAndPopulateProject(projectName, monitor);
53:                 IMarker[] markers = findMarkersOnResource(project);
54:                 // No build yet => no markers
55:                 Assert.assertArrayEquals(Collections.<IMarker> emptyList().toArray(), markers);
56:
57:                 // trigger builder by adding nature to the project and auto-build is on
58:                 setAutoBuild(true);
59:                 ProjectNature.toggleNature(project, ViewModelNature.NATURE_ID);
60:                 waitForAutoBuild();
61:
62:                 // final state
63:                 markers = findMarkersOnResource(project);
64:                 // valid Files => No marker
65:                 Assert.assertArrayEquals(Collections.<IMarker> emptyList().toArray(), markers);
66:         }
67:
68:         @Test
69:         public void notAViewModelProject() throws CoreException, IOException {
70:                 final String projectName = "NotAViewModel"; //$NON-NLS-1$
71:                 final IProgressMonitor monitor = new NullProgressMonitor();
72:                 final IProject project = createAndPopulateProject(projectName, monitor);
73:                 IMarker[] markers = findMarkersOnResource(project);
74:                 // No build yet => no markers
75:                 Assert.assertArrayEquals(Collections.<IMarker> emptyList().toArray(), markers);
76:
77:                 // trigger builder by adding nature to the project and auto-build is on
78:                 setAutoBuild(true);
79:                 ProjectNature.toggleNature(project, ViewModelNature.NATURE_ID);
80:                 waitForAutoBuild();
81:
82:                 // final state
83:                 markers = findMarkersOnResource(project);
84:                 // no view files (wrong XMI, not XML file, etc.) => Mark them with an error.
85:                 Assert.assertEquals(2, markers.length);
86:         }
87:
88:         @Test
89:         public void validationErrors() throws CoreException, IOException {
90:                 final String projectName = "ValidationErrors";//$NON-NLS-1$
91:                 final IProgressMonitor monitor = new NullProgressMonitor();
92:                 final IProject project = createAndPopulateProject(projectName, monitor);
93:                 IMarker[] markers = findMarkersOnResource(project);
94:                 // No build yet => no markers
95:                 Assert.assertArrayEquals(Collections.<IMarker> emptyList().toArray(), markers);
96:
97:                 // trigger builder by adding nature to the project and auto-build is on
98:                 setAutoBuild(true);
99:                 ProjectNature.toggleNature(project, ViewModelNature.NATURE_ID);
100:                 waitForAutoBuild();
101:
102:                 // final state
103:                 markers = findMarkersOnResource(project);
104:
105:                 // 4 errors:
106:                 // 2 unresolved DMR and one missing DMR as ECP pure validation errros
107:                 // an annotation with a missing key as a simple EMF error
108:•                for (final IMarker marker : markers) {
109:                         System.err.println(marker);
110:                 }
111:                 Assert.assertEquals(4, markers.length);
112:         }
113:
114:         @Test
115:         public void noAutoBuild() throws CoreException, IOException {
116:                 final String projectName = "ValidationErrors"; //$NON-NLS-1$
117:                 final IProgressMonitor monitor = new NullProgressMonitor();
118:                 final IProject project = createAndPopulateProject(projectName, monitor);
119:                 IMarker[] markers = findMarkersOnResource(project);
120:                 // No build yet => no markers
121:                 Assert.assertArrayEquals(Collections.<IMarker> emptyList().toArray(), markers);
122:
123:                 // trigger builder by adding nature to the project and auto-build is on
124:                 setAutoBuild(false);
125:                 ProjectNature.toggleNature(project, ViewModelNature.NATURE_ID);
126:                 waitForAutoBuild();
127:
128:                 // final state
129:                 markers = findMarkersOnResource(project);
130:                 // valid Files => No marker
131:                 Assert.assertArrayEquals(Collections.<IMarker> emptyList().toArray(), markers);
132:         }
133:
134:         @Test
135:         public void noRedundancyWithValidationNature() throws CoreException, IOException {
136:                 final String projectName = "ValidationErrors";//$NON-NLS-1$
137:                 final IProgressMonitor monitor = new NullProgressMonitor();
138:                 final IProject project = createAndPopulateProject(projectName, monitor);
139:                 IMarker[] markers = findMarkersOnResource(project);
140:                 // No build yet => no markers
141:                 Assert.assertArrayEquals(Collections.<IMarker> emptyList().toArray(), markers);
142:
143:                 // trigger builder by adding both natures to the project and auto-build is on
144:                 setAutoBuild(true);
145:                 ProjectNature.toggleNature(project, ValidationNature.NATURE_ID);
146:                 ProjectNature.toggleNature(project, ViewModelNature.NATURE_ID);
147:                 waitForAutoBuild();
148:
149:                 // final state
150:                 markers = findMarkersOnResource(project);
151:
152:                 // Only 4 errors, not 8 which would happen if both builders did their work
153:                 Assert.assertEquals(4, markers.length);
154:         }
155:
156:         /**
157:          * Test that markers are correctly cleared on incremental validation when
158:          * problems are fixed.
159:          */
160:         @Test
161:         public void validationProblemsFixed() throws CoreException, IOException {
162:                 final String projectName = "ValidationErrors";//$NON-NLS-1$
163:                 final IProgressMonitor monitor = new NullProgressMonitor();
164:                 final IProject project = createAndPopulateProject(projectName, monitor);
165:                 IMarker[] markers = findMarkersOnResource(project);
166:                 // No build yet => no markers
167:                 assertThat("Should not have error markers, yet", markers, is(new IMarker[0]));
168:
169:                 // trigger builder by adding nature to the project and auto-build is on
170:                 setAutoBuild(true);
171:                 ProjectNature.toggleNature(project, ViewModelNature.NATURE_ID);
172:                 waitForAutoBuild();
173:
174:                 // Should have some problems, now
175:                 markers = findMarkersOnResource(project);
176:                 assertThat("No problems", markers.length, greaterThan(0));
177:
178:                 // Fix them
179:                 final IFile problemFile = project.getFile("ValidationError.view");
180:                 final IFile goodFile = project.getFile("goodModel.view");
181:                 final InputStream input = goodFile.getContents();
182:                 try {
183:                         problemFile.setContents(input, true, true, null);
184:                 } finally {
185:                         input.close();
186:                 }
187:
188:                 waitForAutoBuild();
189:                 markers = findMarkersOnResource(project);
190:                 // Problems solved
191:                 assertThat("Should not have error markers", markers, is(new IMarker[0]));
192:         }
193:
194:         @Test
195:         public void validationMarkerAttributes() throws CoreException, IOException {
196:                 final String projectName = "ValidationErrors";//$NON-NLS-1$
197:                 final IProgressMonitor monitor = new NullProgressMonitor();
198:                 final IProject project = createAndPopulateProject(projectName, monitor);
199:                 IMarker[] markers = findMarkersOnResource(project);
200:                 // No build yet => no markers
201:                 assertThat("Should not have any markers", markers.length, is(0));
202:
203:                 // trigger builder by adding nature to the project and auto-build is on
204:                 setAutoBuild(true);
205:                 ProjectNature.toggleNature(project, ViewModelNature.NATURE_ID);
206:                 waitForAutoBuild();
207:
208:                 // final state
209:                 markers = findMarkersOnResource(project);
210:
211:                 // at least 4 errors:
212:                 // 2 unresolved DMR and one missing DMR as ECP pure validation errros
213:                 // an annotation with a missing key as a simple EMF error
214:                 assertThat("Too few markers", markers.length, greaterThan(3));
215:                 assertThat("No marker on DMR unresolved structural feature", markers,
216:                         hasItemInArray(both(hasAttributeThat(EValidator.URI_ATTRIBUTE, endsWith("#_mfPLkEWAEeWfKJaajyNdyA"))).and(
217:                                 hasAttributeThat(EValidator.RELATED_URIS_ATTRIBUTE, endsWith("/domainModelReference")))));
218:                 assertThat("No marker on control that has no DMR", markers,
219:                         hasItemInArray(both(hasAttributeThat(EValidator.URI_ATTRIBUTE, endsWith("#_mfPLkEWAEeWfKJaajyNdyC"))).and(
220:                                 hasAttributeThat(EValidator.RELATED_URIS_ATTRIBUTE, endsWith("/domainModelReference")))));
221:                 assertThat("No marker on keyless annotation", markers,
222:                         hasItemInArray(both(hasAttributeThat(EValidator.URI_ATTRIBUTE, endsWith("#_ZE-1ABs2EemWJdWNOROymw"))).and(
223:                                 hasAttributeThat(EValidator.RELATED_URIS_ATTRIBUTE, endsWith("/key")))));
224:         }
225:
226: }