Skip to content

Package: ViewNsMigrationUtil_Test

ViewNsMigrationUtil_Test

nameinstructionbranchcomplexitylinemethod
ViewNsMigrationUtil_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%
checkMigration_migrationNecessary()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
checkMigration_noMigrationNecessary()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
checkMigration_noModelViewEcore()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
checkMigration_noRegisteredViewEcore()
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
readAllLines(File)
M: 0 C: 32
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
setUp()
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
testMigrateViewEcoreNsUri()
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%
testMigrateViewEcoreNsUri_noMigrationNecessary()
M: 0 C: 24
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
testMigrateViewEcoreNsUri_noRegisteredViewEcore()
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2018 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: * Lucas Koehler - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emf.ecp.spi.view.migrator;
15:
16: import static org.junit.Assert.assertEquals;
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertTrue;
19: import static org.mockito.Mockito.mock;
20:
21: import java.io.BufferedReader;
22: import java.io.File;
23: import java.io.FileReader;
24: import java.io.IOException;
25:
26: import org.eclipse.emf.ecore.EPackage;
27: import org.eclipse.emf.ecore.EPackage.Registry;
28: import org.junit.Before;
29: import org.junit.Test;
30:
31: /**
32: * JUnit tests for the {@link ViewNsMigrationUtil}.
33: *
34: * @author Lucas Koehler
35: *
36: */
37: public class ViewNsMigrationUtil_Test {
38:
39:         private File outputFile;
40:
41:         /**
42:          * @throws java.lang.Exception
43:          */
44:         @Before
45:         public void setUp() throws Exception {
46:                 outputFile = new File("testdata/tmp.template");
47:•                if (outputFile.exists()) {
48:                         outputFile.delete();
49:                 }
50:                 EPackage.Registry.INSTANCE.clear();
51:         }
52:
53:         @Test
54:         public void testMigrateViewEcoreNsUri() throws IOException {
55:                 final Registry instance = EPackage.Registry.INSTANCE;
56:                 instance.put("http://org/eclipse/emf/ecp/view/model/1180", mock(EPackage.class));
57:
58:                 final File modelFile = new File("testdata/migrate_140.template");
59:                 final File expectedResultFile = new File("testdata/migrate_expected.template");
60:                 ViewNsMigrationUtil.migrateViewEcoreNsUri(modelFile, outputFile);
61:
62:                 final String output = readAllLines(outputFile);
63:                 final String expected = readAllLines(expectedResultFile);
64:
65:                 assertEquals("The migrated file does not match the expected output.", output.trim(), expected.trim());
66:         }
67:
68:         @Test
69:         public void testMigrateViewEcoreNsUri_noMigrationNecessary() throws IOException {
70:                 final Registry instance = EPackage.Registry.INSTANCE;
71:                 instance.put("http://org/eclipse/emf/ecp/view/model/1180", mock(EPackage.class));
72:
73:                 final File modelFile = new File("testdata/migrate_current.template");
74:                 ViewNsMigrationUtil.migrateViewEcoreNsUri(modelFile, outputFile);
75:
76:                 assertFalse("If no migration is necessary, nothing should be written to the output file.",
77:                         outputFile.exists());
78:         }
79:
80:         @Test
81:         public void testMigrateViewEcoreNsUri_noRegisteredViewEcore() throws IOException {
82:                 final File modelFile = new File("testdata/migrate_140.template");
83:                 ViewNsMigrationUtil.migrateViewEcoreNsUri(modelFile, outputFile);
84:
85:                 assertFalse(
86:                         "If no view ecore is necessary, no migration should be performed and, thus, nothing should be written to the output file.",
87:                         outputFile.exists());
88:         }
89:
90:         @Test
91:         public void checkMigration_migrationNecessary() throws IOException {
92:                 final Registry instance = EPackage.Registry.INSTANCE;
93:                 instance.put("http://org/eclipse/emf/ecp/view/model/1180", mock(EPackage.class));
94:
95:                 final File modelFile = new File("testdata/migrate_140.template");
96:                 final boolean checkMigration = ViewNsMigrationUtil.checkMigration(modelFile);
97:                 assertFalse(checkMigration);
98:         }
99:
100:         @Test
101:         public void checkMigration_noMigrationNecessary() throws IOException {
102:                 final Registry instance = EPackage.Registry.INSTANCE;
103:                 instance.put("http://org/eclipse/emf/ecp/view/model/1180", mock(EPackage.class));
104:
105:                 final File modelFile = new File("testdata/migrate_current.template");
106:                 final boolean checkMigration = ViewNsMigrationUtil.checkMigration(modelFile);
107:                 assertTrue(checkMigration);
108:         }
109:
110:         @Test
111:         public void checkMigration_noRegisteredViewEcore() throws IOException {
112:                 final File modelFile = new File("testdata/migrate_140.template");
113:                 final boolean checkMigration = ViewNsMigrationUtil.checkMigration(modelFile);
114:                 assertTrue(checkMigration);
115:         }
116:
117:         @Test
118:         public void checkMigration_noModelViewEcore() throws IOException {
119:                 final Registry instance = EPackage.Registry.INSTANCE;
120:                 instance.put("http://org/eclipse/emf/ecp/view/model/1180", mock(EPackage.class));
121:
122:                 final File modelFile = new File("testdata/no_view_uri.template");
123:                 final boolean checkMigration = ViewNsMigrationUtil.checkMigration(modelFile);
124:                 assertTrue(checkMigration);
125:         }
126:
127:         private String readAllLines(File file) throws IOException {
128:                 final BufferedReader reader = new BufferedReader(new FileReader(file));
129:                 final StringBuilder builder = new StringBuilder();
130:                 try {
131:                         String line;
132:•                        while ((line = reader.readLine()) != null) {
133:                                 builder.append(line);
134:                                 builder.append('\n');
135:                         }
136:                 } finally {
137:                         reader.close();
138:                 }
139:                 return builder.toString();
140:         }
141: }