Skip to content

Package: EcoreHelperNoDependencies_PTest

EcoreHelperNoDependencies_PTest

nameinstructionbranchcomplexitylinemethod
EcoreHelperNoDependencies_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%
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%
setUp()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
setUpBeforeClass()
M: 2 C: 14
88%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 6
86%
M: 0 C: 1
100%
static {...}
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%
tearDown()
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%
testMultipleRegistration()
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
testRegisterUnregisterIndependentEcore()
M: 0 C: 23
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
testUnregisterPackageNotInRegitry()
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
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.junit.After;
31: import org.junit.Before;
32: import org.junit.BeforeClass;
33: import org.junit.Test;
34:
35: /**
36: * @author Alexandra Buzila
37: *
38: */
39: public class EcoreHelperNoDependencies_PTest {
40:         private final Registry packageRegistry = EPackage.Registry.INSTANCE;
41:         private static String aEcorePath = "/TestEcoreHelperProjectResources/A.ecore";
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:                         installResourcesProject();
56:                 }
57:         }
58:
59:         private static void installResourcesProject() throws Exception {
60:                 final ProjectInstallerWizard wiz = new ProjectInstallerWizard();
61:                 wiz.installExample(new NullProgressMonitor());
62:         }
63:         // END SUPRESS CATCH EXCEPTION
64:
65:         /**
66:          * @throws java.lang.Exception
67:          */
68:         @Before
69:         public void setUp() throws Exception {
70:                 // make sure none of the packages exists in the registry
71:         }
72:
73:         /**
74:          * @throws java.lang.Exception
75:          */
76:         @After
77:         public void tearDown() throws Exception {
78:                 EcoreHelper.unregisterEcore(aEcorePath);
79:         }
80:
81:         /**
82:          * Test method for {@link EcoreHelper#registerEcore(String)}
83:          *
84:          * @throws IOException
85:          */
86:         @Test
87:         public void testRegisterUnregisterIndependentEcore() throws IOException {
88:
89:                 // check initial setup
90:                 assertFalse("Package is already in the registry!",
91:                         packageRegistry.containsKey("a.nsuri"));
92:
93:                 // register
94:                 EcoreHelper.registerEcore(aEcorePath);
95:                 assertTrue("Package not in the registry!",
96:                         packageRegistry.containsKey("a.nsuri"));
97:
98:                 // unregister
99:                 EcoreHelper.unregisterEcore(aEcorePath);
100:                 assertFalse("Package is still in the registry!",
101:                         packageRegistry.containsKey("a.nsuri"));
102:
103:         }
104:
105:         /**
106:          * Test method for {@link EcoreHelper#registerEcore(String)}
107:          *
108:          * @throws IOException
109:          */
110:         @Test
111:         public void testUnregisterPackageNotInRegitry() throws IOException {
112:                 // check initial setup
113:                 assertFalse("Package is already in the registry!",
114:                         packageRegistry.containsKey("a.nsuri"));
115:                 // unregister
116:                 EcoreHelper.unregisterEcore(aEcorePath);
117:                 EcoreHelper.unregisterEcore(aEcorePath);
118:                 assertFalse("Package is still in the registry!",
119:                         packageRegistry.containsKey("a.nsuri"));
120:         }
121:
122:         @Test
123:         public void testMultipleRegistration() throws IOException {
124:                 // check initial setup
125:                 assertFalse("Package is already in the registry!",
126:                         packageRegistry.containsKey("a.nsuri"));
127:
128:                 // register
129:                 EcoreHelper.registerEcore(aEcorePath);
130:                 assertTrue("Package not in the registry!",
131:                         packageRegistry.containsKey("a.nsuri"));
132:
133:                 // register a second time
134:                 EcoreHelper.registerEcore(aEcorePath);
135:                 assertTrue("Package not in the registry!",
136:                         packageRegistry.containsKey("a.nsuri"));
137:
138:                 // unregister
139:                 EcoreHelper.unregisterEcore(aEcorePath);
140:                 assertTrue("Package not in the registry!",
141:                         packageRegistry.containsKey("a.nsuri"));
142:
143:                 // unregister a second time
144:                 EcoreHelper.unregisterEcore(aEcorePath);
145:                 assertFalse("Package is still in the registry!",
146:                         packageRegistry.containsKey("a.nsuri"));
147:         }
148:
149: }