Skip to content

Package: AbstractMigrationTest

AbstractMigrationTest

nameinstructionbranchcomplexitylinemethod
AbstractMigrationTest()
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%
assertDMRwithEmptyPath(VFeaturePathDomainModelReference, EStructuralFeature)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
assertUUIDPresent(EObject)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
before()
M: 0 C: 30
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
copy(InputStream, File)
M: 3 C: 26
90%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 2 C: 8
80%
M: 0 C: 1
100%
getMigratedView()
M: 0 C: 37
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
getMigrator()
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%
getURI()
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%
testMigration()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: * jfaltermeier - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.view.edapt.test;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertNotNull;
18: import static org.junit.Assert.assertSame;
19:
20: import java.io.File;
21: import java.io.FileOutputStream;
22: import java.io.IOException;
23: import java.io.InputStream;
24: import java.io.OutputStream;
25: import java.util.Map;
26:
27: import org.eclipse.core.runtime.Platform;
28: import org.eclipse.emf.common.util.URI;
29: import org.eclipse.emf.ecore.EObject;
30: import org.eclipse.emf.ecore.EStructuralFeature;
31: import org.eclipse.emf.ecore.resource.Resource;
32: import org.eclipse.emf.ecore.resource.ResourceSet;
33: import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
34: import org.eclipse.emf.ecore.xmi.XMIResource;
35: import org.eclipse.emf.ecp.view.edapt.EdaptViewModelMigrator;
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.VViewPackage;
39: import org.eclipse.emf.ecp.view.spi.model.util.VViewResourceFactoryImpl;
40: import org.junit.Before;
41: import org.junit.Rule;
42: import org.junit.Test;
43: import org.junit.rules.TemporaryFolder;
44: import org.osgi.framework.Bundle;
45:
46: public abstract class AbstractMigrationTest {
47:
48:         @Rule
49:         // REUSED CLASS
50:         public TemporaryFolder testFolder = new TemporaryFolder();// END REUSED CLASS
51:
52:         private EdaptViewModelMigrator migrator;
53:         private URI resourceURI;
54:
55:         @Before
56:         public void before() throws IOException {
57:                 final File newFile = testFolder.newFile();
58:                 newFile.deleteOnExit();
59:                 final Bundle bundle = Platform.getBundle(Constants.PLUGIN_ID);
60:                 final InputStream openStream = bundle.getEntry(getPath()).openStream();
61:                 copy(openStream, newFile);
62:                 migrator = new EdaptViewModelMigrator();
63:                 resourceURI = URI.createFileURI(newFile.getAbsolutePath());
64:         }
65:
66:         @Test
67:         // BEGIN SUPRESS CATCH EXCEPTION
68:         public void testMigration() throws Exception {// END SUPRESS CATCH EXCEPTION
69:                 performTest();
70:         }
71:
72:         protected static void assertDMRwithEmptyPath(
73:                 VFeaturePathDomainModelReference dmr, EStructuralFeature feature) {
74:                 assertSame(feature, dmr.getDomainModelEFeature());
75:                 assertEquals(0, dmr.getDomainModelEReferencePath().size());
76:         }
77:
78:         protected static void assertUUIDPresent(EObject object) {
79:                 assertNotNull(XMIResource.class.cast(object.eResource()).getID(object));
80:         }
81:
82:         // BEGIN SUPRESS CATCH EXCEPTION
83:         protected abstract void performTest() throws Exception;// END SUPRESS CATCH EXCEPTION
84:
85:         protected abstract String getPath();
86:
87:         protected EdaptViewModelMigrator getMigrator() {
88:                 return migrator;
89:         }
90:
91:         protected URI getURI() {
92:                 return resourceURI;
93:         }
94:
95:         protected VView getMigratedView() throws IOException {
96:                 final ResourceSet resourceSet = new ResourceSetImpl();
97:                 final Map<String, Object> extensionToFactoryMap = resourceSet
98:                         .getResourceFactoryRegistry().getExtensionToFactoryMap();
99:                 extensionToFactoryMap.put(Resource.Factory.Registry.DEFAULT_EXTENSION,
100:                         new VViewResourceFactoryImpl());
101:                 resourceSet.getPackageRegistry().put(VViewPackage.eNS_URI,
102:                         VViewPackage.eINSTANCE);
103:                 final Resource resource = resourceSet.createResource(resourceURI);
104:                 resource.load(null);
105:                 final VView view = (VView) resource.getContents().get(0);
106:                 return view;
107:         }
108:
109:         private void copy(InputStream in, File file) {
110:                 try {
111:                         final OutputStream out = new FileOutputStream(file);
112:                         final byte[] buf = new byte[1024];
113:                         int len;
114:•                        while ((len = in.read(buf)) > 0) {
115:                                 out.write(buf, 0, len);
116:                         }
117:                         out.close();
118:                         in.close();
119:                 }
120:                 // BEGIN SUPRESS CATCH EXCEPTION
121:                 catch (final Exception e) {// END SUPRESS CATCH EXCEPTION
122:                         e.printStackTrace();
123:                 }
124:         }
125:
126: }