Skip to content

Package: EcoreHelperCyclicDependencies_PTest

EcoreHelperCyclicDependencies_PTest

nameinstructionbranchcomplexitylinemethod
EcoreHelperCyclicDependencies_PTest()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
cleanupAfterClass()
M: 4 C: 3
43%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 2 C: 2
50%
M: 0 C: 1
100%
installResourcesProject()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setUpBeforeClass()
M: 6 C: 14
70%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 2 C: 6
75%
M: 0 C: 1
100%
static {...}
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
tearDown()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
testRegisterUnregister()
M: 0 C: 59
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 21
100%
M: 0 C: 1
100%
testUnregisterMultipleUsage()
M: 0 C: 85
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 31
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: * EclipseSource Munich - initial API and implementation
13: *
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.ide.util.test;
16:
17: import static org.junit.Assert.assertFalse;
18: import static org.junit.Assert.assertTrue;
19:
20: import java.io.IOException;
21:
22: import org.eclipse.core.resources.IProject;
23: import org.eclipse.core.resources.IWorkspaceRoot;
24: import org.eclipse.core.resources.ResourcesPlugin;
25: import org.eclipse.core.runtime.NullProgressMonitor;
26: import org.eclipse.emf.ecore.EPackage;
27: import org.eclipse.emf.ecore.EPackage.Registry;
28: import org.eclipse.emf.ecp.ide.spi.util.EcoreHelper;
29: import org.eclipse.jface.resource.JFaceResources;
30: import org.eclipse.swt.widgets.Shell;
31: import org.junit.After;
32: import org.junit.AfterClass;
33: import org.junit.BeforeClass;
34: import org.junit.Test;
35:
36: public class EcoreHelperCyclicDependencies_PTest {
37:         private final Registry packageRegistry = EPackage.Registry.INSTANCE;
38:         private static String dEcorePath = "/TestEcoreHelperProjectResources/D.ecore";
39:         private static String eEcorePath = "/TestEcoreHelperProjectResources/E.ecore";
40:         private static String fEcorePath = "/TestEcoreHelperProjectResources/F.ecore";
41:         private static Shell SHELL;
42:
43:         // BEGIN SUPRESS CATCH EXCEPTION
44:         @BeforeClass
45:         public static void setUpBeforeClass() throws Exception {
46:                 try {
47:                         JFaceResources.getImageRegistry();
48:                 } catch (final RuntimeException e) {
49:                         // expected fail, some strange initialization error is happing
50:                 }
51:                 final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
52:                 final IProject project = root.getProject("TestEcoreHelperProjectResources");
53:                 // create resources to register and unregister
54:•                if (!project.exists()) {
55:                         SHELL = new Shell();
56:                         installResourcesProject();
57:                 }
58:         }
59:
60:         @AfterClass
61:         public static void cleanupAfterClass() throws Exception {
62:•                if (SHELL != null) {
63:                         SHELL.dispose();
64:                         SHELL = null;
65:                 }
66:         }
67:
68:         private static void installResourcesProject() throws Exception {
69:                 final ProjectInstallerWizard wiz = new ProjectInstallerWizard();
70:                 wiz.installExample(new NullProgressMonitor());
71:         }
72:         // END SUPRESS CATCH EXCEPTION
73:
74:         @Test
75:         public void testRegisterUnregister() throws IOException {
76:                 // check initial state
77:                 assertFalse("Package D is already in the registry!",
78:                         packageRegistry.containsKey("d.nsuri"));
79:                 assertFalse("Package E is already in the registry!",
80:                         packageRegistry.containsKey("e.nsuri"));
81:                 assertFalse("Package F is already in the registry!",
82:                         packageRegistry.containsKey("f.nsuri"));
83:
84:                 // register D references E references F references D
85:                 EcoreHelper.registerEcore(dEcorePath);
86:                 assertTrue("Package D not in the registry!",
87:                         packageRegistry.containsKey("d.nsuri"));
88:                 assertTrue("Package E not in the registry!",
89:                         packageRegistry.containsKey("e.nsuri"));
90:                 assertTrue("Package F not in the registry!",
91:                         packageRegistry.containsKey("f.nsuri"));
92:
93:                 // unregister
94:                 EcoreHelper.unregisterEcore(dEcorePath);
95:                 assertFalse("Package D is still in the registry!",
96:                         packageRegistry.containsKey("d.nsuri"));
97:                 assertFalse("Package E is still in the registry!",
98:                         packageRegistry.containsKey("e.nsuri"));
99:                 assertFalse("Package F is still in the registry!",
100:                         packageRegistry.containsKey("f.nsuri"));
101:         }
102:
103:         @Test
104:         public void testUnregisterMultipleUsage() throws IOException {
105:                 // setup
106:                 EcoreHelper.registerEcore(dEcorePath);
107:                 EcoreHelper.registerEcore(eEcorePath);
108:                 EcoreHelper.registerEcore(fEcorePath);
109:                 assertTrue("Package D not in the registry!",
110:                         packageRegistry.containsKey("d.nsuri"));
111:                 assertTrue("Package E not in the registry!",
112:                         packageRegistry.containsKey("e.nsuri"));
113:                 assertTrue("Package F not in the registry!",
114:                         packageRegistry.containsKey("f.nsuri"));
115:
116:                 // unregister D references E
117:                 EcoreHelper.unregisterEcore(dEcorePath);
118:                 assertTrue("Package D not in the registry!",
119:                         packageRegistry.containsKey("d.nsuri"));
120:                 assertTrue("Package E not in the registry!",
121:                         packageRegistry.containsKey("e.nsuri"));
122:                 assertTrue("Package F not in the registry!",
123:                         packageRegistry.containsKey("f.nsuri"));
124:
125:                 // unregister E references F
126:                 EcoreHelper.unregisterEcore(eEcorePath);
127:                 assertTrue("Package D not in the registry!",
128:                         packageRegistry.containsKey("d.nsuri"));
129:                 assertTrue("Package E not in the registry!",
130:                         packageRegistry.containsKey("e.nsuri"));
131:                 assertTrue("Package F not in the registry!",
132:                         packageRegistry.containsKey("f.nsuri"));
133:
134:                 // unregister F references D
135:                 EcoreHelper.unregisterEcore(fEcorePath);
136:                 assertFalse("Package D is still in the registry!",
137:                         packageRegistry.containsKey("d.nsuri"));
138:                 assertFalse("Package E is still in the registry!",
139:                         packageRegistry.containsKey("e.nsuri"));
140:                 assertFalse("Package F is still in the registry!",
141:                         packageRegistry.containsKey("f.nsuri"));
142:         }
143:
144:         /**
145:          * @throws java.lang.Exception
146:          */
147:         @After
148:         public void tearDown() throws Exception {
149:                 EcoreHelper.unregisterEcore(dEcorePath);
150:                 EcoreHelper.unregisterEcore(eEcorePath);
151:                 EcoreHelper.unregisterEcore(fEcorePath);
152:         }
153:
154: }