Skip to content

Package: EcoreHelperTwoDependencies_PTest

EcoreHelperTwoDependencies_PTest

nameinstructionbranchcomplexitylinemethod
EcoreHelperTwoDependencies_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: /**
37: * @author Alexandra Buzila
38: *
39: */
40: public class EcoreHelperTwoDependencies_PTest {
41:
42:         private final Registry packageRegistry = EPackage.Registry.INSTANCE;
43:         private static String cEcorePath = "/TestEcoreHelperProjectResources/C.ecore";
44:         private static String aEcorePath = "/TestEcoreHelperProjectResources/A.ecore";
45:         private static String bEcorePath = "/TestEcoreHelperProjectResources/B.ecore";
46:         private static Shell SHELL;
47:
48:         // BEGIN SUPRESS CATCH EXCEPTION
49:         @BeforeClass
50:         public static void setUpBeforeClass() throws Exception {
51:                 try {
52:                         JFaceResources.getImageRegistry();
53:                 } catch (final RuntimeException e) {
54:                         // expected fail, some strange initialization error is happing
55:                 }
56:                 final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
57:                 final IProject project = root.getProject("TestEcoreHelperProjectResources");
58:                 // create resources to register and unregister
59:•                if (!project.exists()) {
60:                         SHELL = new Shell();
61:                         installResourcesProject();
62:                 }
63:         }
64:
65:         @AfterClass
66:         public static void cleanupAfterClass() throws Exception {
67:•                if (SHELL != null) {
68:                         SHELL.dispose();
69:                         SHELL = null;
70:                 }
71:         }
72:
73:         private static void installResourcesProject() throws Exception {
74:                 final ProjectInstallerWizard wiz = new ProjectInstallerWizard();
75:                 wiz.installExample(new NullProgressMonitor());
76:         }
77:         // END SUPRESS CATCH EXCEPTION
78:
79:         @Test
80:         public void testRegisterUnregister() throws IOException {
81:
82:                 // check initial state
83:                 assertFalse("Package A is already in the registry!",
84:                         packageRegistry.containsKey("a.nsuri"));
85:                 assertFalse("Package B is already in the registry!",
86:                         packageRegistry.containsKey("b.nsuri"));
87:                 assertFalse("Package C is already in the registry!",
88:                         packageRegistry.containsKey("c.nsuri"));
89:
90:                 // register C references B references A
91:                 EcoreHelper.registerEcore(cEcorePath);
92:                 assertTrue("Package A not in the registry!",
93:                         packageRegistry.containsKey("a.nsuri"));
94:                 assertTrue("Package B not in the registry!",
95:                         packageRegistry.containsKey("b.nsuri"));
96:                 assertTrue("Package C not in the registry!",
97:                         packageRegistry.containsKey("c.nsuri"));
98:
99:                 EcoreHelper.unregisterEcore(cEcorePath);
100:                 assertFalse("Package A is already in the registry!",
101:                         packageRegistry.containsKey("a.nsuri"));
102:                 assertFalse("Package B is already in the registry!",
103:                         packageRegistry.containsKey("b.nsuri"));
104:                 assertFalse("Package C is already in the registry!",
105:                         packageRegistry.containsKey("c.nsuri"));
106:         }
107:
108:         @Test
109:         public void testUnregisterMultipleUsage() throws IOException {
110:                 // register
111:                 EcoreHelper.registerEcore(aEcorePath);
112:                 EcoreHelper.registerEcore(bEcorePath);
113:                 EcoreHelper.registerEcore(cEcorePath);
114:                 assertTrue("Package A not in the registry!",
115:                         packageRegistry.containsKey("a.nsuri"));
116:                 assertTrue("Package B not in the registry!",
117:                         packageRegistry.containsKey("b.nsuri"));
118:                 assertTrue("Package C not in the registry!",
119:                         packageRegistry.containsKey("c.nsuri"));
120:
121:                 // unregister C references B
122:                 EcoreHelper.unregisterEcore(cEcorePath);
123:                 assertTrue("Package A not in the registry!",
124:                         packageRegistry.containsKey("a.nsuri"));
125:                 assertTrue("Package B not in the registry!",
126:                         packageRegistry.containsKey("b.nsuri"));
127:                 assertFalse("Package C is already in the registry!",
128:                         packageRegistry.containsKey("c.nsuri"));
129:
130:                 // unregister B references A
131:                 EcoreHelper.unregisterEcore(bEcorePath);
132:                 assertTrue("Package A not in the registry!",
133:                         packageRegistry.containsKey("a.nsuri"));
134:                 assertFalse("Package B is already in the registry!",
135:                         packageRegistry.containsKey("b.nsuri"));
136:                 assertFalse("Package C is already in the registry!",
137:                         packageRegistry.containsKey("c.nsuri"));
138:
139:                 // unregister A
140:                 EcoreHelper.unregisterEcore(aEcorePath);
141:                 assertFalse("Package A is already in the registry!",
142:                         packageRegistry.containsKey("a.nsuri"));
143:                 assertFalse("Package B is already in the registry!",
144:                         packageRegistry.containsKey("b.nsuri"));
145:                 assertFalse("Package C is already in the registry!",
146:                         packageRegistry.containsKey("c.nsuri"));
147:         }
148:
149:         /**
150:          * @throws java.lang.Exception
151:          */
152:         @After
153:         public void tearDown() throws Exception {
154:                 EcoreHelper.unregisterEcore(cEcorePath);
155:                 EcoreHelper.unregisterEcore(aEcorePath);
156:                 EcoreHelper.unregisterEcore(bEcorePath);
157:
158:         }
159:
160: }