View | Details | Raw Unified | Return to bug 115700 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+6 lines)
Lines 62-66 Link Here
62
               nsURI="http:///com/ibm/xtools/emf/msl/core/tests/logrestest.ecore"/>
62
               nsURI="http:///com/ibm/xtools/emf/msl/core/tests/logrestest.ecore"/>
63
      </policy>
63
      </policy>
64
   </extension>
64
   </extension>
65
   <extension
66
         point="org.eclipse.emf.ecore.extension_parser">
67
      <parser
68
            class="org.eclipse.gmf.tests.runtime.emf.core.internal.listener.MListenerTest$BrokenResourceFactory"
69
            type="broken"/>
70
   </extension>
65
   
71
   
66
</plugin>
72
</plugin>
(-)src/org/eclipse/gmf/tests/runtime/emf/core/AllTests.java (+4 lines)
Lines 26-31 Link Here
26
import org.eclipse.gmf.tests.runtime.emf.core.internal.commands.MSLUndoStackTestCase;
26
import org.eclipse.gmf.tests.runtime.emf.core.internal.commands.MSLUndoStackTestCase;
27
import org.eclipse.gmf.tests.runtime.emf.core.internal.domain.MSLEditingDomainTestCase;
27
import org.eclipse.gmf.tests.runtime.emf.core.internal.domain.MSLEditingDomainTestCase;
28
import org.eclipse.gmf.tests.runtime.emf.core.internal.expressions.EObjectPropertyTesterTest;
28
import org.eclipse.gmf.tests.runtime.emf.core.internal.expressions.EObjectPropertyTesterTest;
29
import org.eclipse.gmf.tests.runtime.emf.core.internal.listener.MFilterTests;
30
import org.eclipse.gmf.tests.runtime.emf.core.internal.listener.MListenerTest;
29
import org.eclipse.gmf.tests.runtime.emf.core.internal.listener.MSemProcProviderTests;
31
import org.eclipse.gmf.tests.runtime.emf.core.internal.listener.MSemProcProviderTests;
30
import org.eclipse.gmf.tests.runtime.emf.core.internal.listener.ResourceContentTests;
32
import org.eclipse.gmf.tests.runtime.emf.core.internal.listener.ResourceContentTests;
31
import org.eclipse.gmf.tests.runtime.emf.core.internal.multithread.testcases.ReadOperationTest;
33
import org.eclipse.gmf.tests.runtime.emf.core.internal.multithread.testcases.ReadOperationTest;
Lines 85-90 Link Here
85
		suite.addTestSuite(ReadWriteOperationTest.class);
87
		suite.addTestSuite(ReadWriteOperationTest.class);
86
		suite.addTestSuite(EditingDomainExtensibilityTests.class);
88
		suite.addTestSuite(EditingDomainExtensibilityTests.class);
87
		suite.addTestSuite(MSLEditingDomainTestCase.class);
89
		suite.addTestSuite(MSLEditingDomainTestCase.class);
90
		suite.addTestSuite(MFilterTests.class);
91
		suite.addTestSuite(MListenerTest.class);
88
92
89
		return suite;
93
		return suite;
90
	}
94
	}
(-)src/org/eclipse/gmf/tests/runtime/emf/core/BaseCoreTests.java (-2 / +4 lines)
Lines 51-57 Link Here
51
 */
51
 */
52
public class BaseCoreTests
52
public class BaseCoreTests
53
	extends TestCase {
53
	extends TestCase {
54
	static final Bundle MslCoreTestsBundle =
54
	public static final Bundle MslCoreTestsBundle =
55
		Platform.getBundle("org.eclipse.gmf.tests.runtime.emf.core"); //$NON-NLS-1$
55
		Platform.getBundle("org.eclipse.gmf.tests.runtime.emf.core"); //$NON-NLS-1$
56
56
57
	private MRunnable mrun;
57
	private MRunnable mrun;
Lines 95-104 Link Here
95
					domain.runAsWrite(new MRunnable() {
95
					domain.runAsWrite(new MRunnable() {
96
						public Object run() {
96
						public Object run() {
97
							try {
97
							try {
98
								Resource originalRes = domain.loadResource(URI
98
								Resource originalRes = domain.createResource(URI
99
									.createURI(MslCoreTestsBundle.getEntry(
99
									.createURI(MslCoreTestsBundle.getEntry(
100
										"/test_models/test_model.extlibrary") //$NON-NLS-1$
100
										"/test_models/test_model.extlibrary") //$NON-NLS-1$
101
										.toString()).toString(), MResourceOption.URI);
101
										.toString()).toString(), MResourceOption.URI);
102
								domain.loadResource(originalRes);
103
								
102
								originalRes.setURI(URI.createPlatformResourceURI(RESOURCE_NAME));
104
								originalRes.setURI(URI.createPlatformResourceURI(RESOURCE_NAME));
103
								originalRes.save(Collections.EMPTY_MAP);
105
								originalRes.save(Collections.EMPTY_MAP);
104
								testResource = originalRes;
106
								testResource = originalRes;
(-)src/org/eclipse/gmf/tests/runtime/emf/core/MetamodelProviderTestCase.java (-1 / +1 lines)
Lines 79-85 Link Here
79
		throws Exception {
79
		throws Exception {
80
80
81
		ResourceSet rset = resource.getResourceSet();
81
		ResourceSet rset = resource.getResourceSet();
82
		ResourceUtil.unload(resource);
82
		resource.unload();
83
		rset.getResources().remove(resource);
83
		rset.getResources().remove(resource);
84
84
85
		epackage = null;
85
		epackage = null;
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/OperationListenerTestCase.java (-1 / +1 lines)
Lines 75-81 Link Here
75
		listener = null;
75
		listener = null;
76
76
77
		ResourceSet rset = res.getResourceSet();
77
		ResourceSet rset = res.getResourceSet();
78
		ResourceUtil.unload(res);
78
		res.unload();
79
		rset.getResources().remove(res);
79
		rset.getResources().remove(res);
80
80
81
		super.tearDown();
81
		super.tearDown();
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/OperationUtilTestCase.java (-1 / +1 lines)
Lines 522-528 Link Here
522
		model = null;
522
		model = null;
523
		
523
		
524
		ResourceSet rset = res.getResourceSet();
524
		ResourceSet rset = res.getResourceSet();
525
		ResourceUtil.unload(res);
525
		res.unload();
526
		rset.getResources().remove(res);
526
		rset.getResources().remove(res);
527
		
527
		
528
		super.tearDown();
528
		super.tearDown();
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/domain/MSLEditingDomainTestCase.java (-1 / +67 lines)
Lines 3-13 Link Here
3
import junit.framework.TestCase;
3
import junit.framework.TestCase;
4
4
5
import org.eclipse.emf.common.command.Command;
5
import org.eclipse.emf.common.command.Command;
6
import org.eclipse.emf.common.util.URI;
6
import org.eclipse.emf.ecore.resource.Resource;
7
import org.eclipse.emf.ecore.resource.Resource;
7
import org.eclipse.emf.edit.command.SetCommand;
8
import org.eclipse.emf.edit.command.SetCommand;
8
import org.eclipse.emf.examples.extlibrary.EXTLibraryPackage;
9
import org.eclipse.emf.examples.extlibrary.EXTLibraryPackage;
9
import org.eclipse.emf.examples.extlibrary.Library;
10
import org.eclipse.emf.examples.extlibrary.Library;
10
import org.eclipse.gmf.runtime.emf.core.edit.MEditingDomain;
11
import org.eclipse.gmf.runtime.emf.core.edit.MEditingDomain;
12
import org.eclipse.gmf.runtime.emf.core.edit.MResourceOption;
13
import org.eclipse.gmf.tests.runtime.emf.core.BaseCoreTests;
11
14
12
15
13
public class MSLEditingDomainTestCase
16
public class MSLEditingDomainTestCase
Lines 15-21 Link Here
15
18
16
	public void testCreateAndExecuteEMFStyleCommand() {
19
	public void testCreateAndExecuteEMFStyleCommand() {
17
		MEditingDomain domain = MEditingDomain.createNewDomain();
20
		MEditingDomain domain = MEditingDomain.createNewDomain();
18
		Resource r = domain.createResource("file://C:/temp/foo.extlibrary", EXTLibraryPackage.eINSTANCE.getLibrary()); //$NON-NLS-1$
21
		Resource r = domain.createResource("file:///tmp/foo.extlibrary", EXTLibraryPackage.eINSTANCE.getLibrary()); //$NON-NLS-1$
19
		
22
		
20
		Library l = (Library)r.getContents().get(0);
23
		Library l = (Library)r.getContents().get(0);
21
		
24
		
Lines 25-28 Link Here
25
		domain.getCommandStack().execute(cmd);
28
		domain.getCommandStack().execute(cmd);
26
		assertNull(l.getName());
29
		assertNull(l.getName());
27
	}
30
	}
31
	
32
	public void testResourceCreationAndLoading() {
33
		MEditingDomain domain = MEditingDomain.createNewDomain();
34
		
35
		Resource r = domain.createResource("/tmp/foo.extlibrary"); //$NON-NLS-1$
36
		assertNotNull(r);
37
		
38
		// Resource should not yet be loaded
39
		assertFalse(r.isLoaded());
40
		
41
		Resource r2 = domain.createResource("/tmp/foo.extlibrary"); //$NON-NLS-1$
42
		assertNotNull(r2);
43
		assertFalse(r2.isLoaded());
44
		assertSame(r,r2);
45
		
46
		r = domain.createResource(URI
47
			.createURI(BaseCoreTests.MslCoreTestsBundle.getEntry(
48
				"/test_models/test_model.extlibrary") //$NON-NLS-1$
49
				.toString()).toString(), MResourceOption.URI);
50
		
51
		assertNotNull(r);
52
		assertFalse(r.isLoaded());
53
		
54
		domain.loadResource(r);
55
		assertTrue(r.isLoaded());
56
		
57
		try {
58
			r = domain.createResource(URI
59
				.createURI(BaseCoreTests.MslCoreTestsBundle.getEntry(
60
					"/test_models/test_model.extlibrary") //$NON-NLS-1$
61
					.toString()).toString(), MResourceOption.URI);
62
			fail("We should not be allowed to create a resource that is already loaded."); //$NON-NLS-1$
63
		} catch (IllegalStateException e) {
64
			// SUCCESS
65
		}
66
		
67
		r2 = domain.findResource(URI
68
			.createURI(BaseCoreTests.MslCoreTestsBundle.getEntry(
69
			"/test_models/test_model.extlibrary") //$NON-NLS-1$
70
			.toString()).toString(), MResourceOption.URI);
71
		
72
		// We should find that we couldn't create this resource because it
73
		//  was already in the resource set and loaded.
74
		assertSame(r, r2);
75
		
76
		r = domain.createResource(URI
77
			.createURI(BaseCoreTests.MslCoreTestsBundle.getEntry(
78
			"/test_models/test_corrupted_model.extlibrary") //$NON-NLS-1$
79
			.toString()).toString(), MResourceOption.URI);
80
		
81
		assertNotNull(r);
82
		assertFalse(r.isLoaded());
83
		
84
		try {
85
			domain.loadResource(r);
86
			assertTrue(false);
87
		} catch (Exception e) {
88
			assertTrue(true);
89
		}
90
		
91
		// TODO Change this line when we turn off automatic unloading of resources during load.
92
		assertFalse(r.isLoaded());
93
	}
28
}
94
}
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/expressions/EObjectPropertyTesterTest.java (-1 / +1 lines)
Lines 64-70 Link Here
64
		tester = null;
64
		tester = null;
65
		resource.getContents().remove(element);
65
		resource.getContents().remove(element);
66
		ResourceSet rset = resource.getResourceSet();
66
		ResourceSet rset = resource.getResourceSet();
67
		ResourceUtil.unload(resource);
67
		resource.unload();
68
		rset.getResources().remove(resource);
68
		rset.getResources().remove(resource);
69
		element = null;
69
		element = null;
70
	}
70
	}
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/listener/MFilterTests.java (-4 / +4 lines)
Lines 29-35 Link Here
29
public class MFilterTests
29
public class MFilterTests
30
	extends BaseCoreTests {
30
	extends BaseCoreTests {
31
31
32
	private static final String EXTLIBRARY_CONTENTTYPE = "org.eclipse.emf.examples.library.rationalModelingPlatformLibrary"; //$NON-NLS-1$
32
	private static final String EXTLIBRARY_CONTENTTYPE = "org.eclipse.emf.examples.library.extendedLibrary"; //$NON-NLS-1$
33
33
34
	public MFilterTests() {
34
	public MFilterTests() {
35
		super();
35
		super();
Lines 53-59 Link Here
53
53
54
		/* Load the resource */
54
		/* Load the resource */
55
		domain.loadResource(testResource);
55
		domain.loadResource(testResource);
56
		domain.unloadResource(testResource);
56
		testResource.unload();
57
		regularListener.stopListening();
57
		regularListener.stopListening();
58
		
58
		
59
		assertTrue(eventsCounter[0] > 0);
59
		assertTrue(eventsCounter[0] > 0);
Lines 72-78 Link Here
72
72
73
		/* Load the resource */
73
		/* Load the resource */
74
		domain.loadResource(testResource);
74
		domain.loadResource(testResource);
75
		domain.unloadResource(testResource);
75
		testResource.unload();
76
		regularListener.stopListening();
76
		regularListener.stopListening();
77
		
77
		
78
		assertTrue(eventsCounter[0] == 0);
78
		assertTrue(eventsCounter[0] == 0);
Lines 117-123 Link Here
117
		});
117
		});
118
		
118
		
119
		regularListener.stopListening();
119
		regularListener.stopListening();
120
		domain.unloadResource(testResource);
120
		testResource.unload();
121
		
121
		
122
		// We shouldn't get any events because we are only interested in resource-level
122
		// We shouldn't get any events because we are only interested in resource-level
123
		//  events.
123
		//  events.
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/listener/ResourceContentTests.java (-2 / +2 lines)
Lines 70-76 Link Here
70
70
71
		/* Load the resource */
71
		/* Load the resource */
72
		domain.loadResource(testResource);
72
		domain.loadResource(testResource);
73
		domain.unloadResource(testResource);
73
		testResource.unload();
74
		regularListener.stopListening();
74
		regularListener.stopListening();
75
		
75
		
76
		assertTrue(eventsCounter[0] == 2);		
76
		assertTrue(eventsCounter[0] == 2);		
Lines 176-182 Link Here
176
		demuxedListener.startListening();
176
		demuxedListener.startListening();
177
177
178
		/* UnLoad the resource */
178
		/* UnLoad the resource */
179
		domain.unloadResource(testResource);
179
		testResource.unload();
180
		demuxedListener.stopListening();
180
		demuxedListener.stopListening();
181
		
181
		
182
		assertTrue(eventsCounter[0] == 1);				
182
		assertTrue(eventsCounter[0] == 1);				
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/resources/LogicalResourcePolicyManagerTest.java (-1 / +1 lines)
Lines 201-207 Link Here
201
	protected void tearDown()
201
	protected void tearDown()
202
		throws Exception {
202
		throws Exception {
203
		
203
		
204
		MEditingDomain.INSTANCE.unloadResource(res);
204
		res.unload();
205
		MEditingDomain.INSTANCE.getResourceSet().getResources().remove(res);
205
		MEditingDomain.INSTANCE.getResourceSet().getResources().remove(res);
206
		
206
		
207
		TestPolicy.shouldThrow = false;
207
		TestPolicy.shouldThrow = false;
(-)src/org/eclipse/gmf/tests/runtime/emf/core/internal/listener/MListenerTest.java (+77 lines)
Added Link Here
1
package org.eclipse.gmf.tests.runtime.emf.core.internal.listener;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.util.Map;
6
7
import junit.framework.TestCase;
8
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.common.util.URI;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.ecore.resource.Resource;
13
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
14
import org.eclipse.gmf.runtime.emf.core.edit.DemuxedMListener;
15
import org.eclipse.gmf.runtime.emf.core.edit.MEditingDomain;
16
17
18
public class MListenerTest
19
	extends TestCase {
20
	
21
	public static class BrokenResourceFactory implements Resource.Factory {
22
		public Resource createResource(URI uri) {
23
			return new ResourceImpl() {
24
			  public void load(Map options)
25
					throws IOException {
26
					if (!isLoaded) {
27
						load(null, options);
28
					}
29
				}
30
				
31
				protected void doLoad(InputStream inputStream, Map options)
32
					throws IOException {
33
					
34
					IOException e = new IOException();
35
					
36
					getErrors().add(e);
37
					
38
					// We can never load without errors.
39
					throw e;
40
				}
41
			};
42
		}
43
	}
44
	
45
	public void testResourceLoadEventsWhenError() {
46
		// TODO Change this test case come the next iteration when we change the behaviour of resource load
47
		MEditingDomain domain = MEditingDomain.createNewDomain();
48
		
49
		final boolean[] results = new boolean[2];
50
		results[0] = true;
51
		results[1] = true;
52
		
53
		DemuxedMListener listener = new DemuxedMListener(domain) {
54
			public void handleResourceLoadedEvent(Notification notification, Resource resource) {
55
				results[0] = false;
56
			}
57
			
58
			public void handleResourceUnloadedEvent(Notification notification, Resource resource, EObject modelRoot) {
59
				results[1] = false;
60
			}
61
		};
62
		
63
		listener.startListening();
64
		
65
		Resource r = domain.createResource("/tmp/brokenfile.broken"); //$NON-NLS-1$
66
		assertNotNull(r);
67
		
68
		try {
69
			domain.loadResource(r);
70
		} catch (Exception e) {
71
			// Ignore this exception.
72
		}
73
		
74
		assertTrue(results[0]);
75
		assertTrue(results[1]);
76
	}
77
}

Return to bug 115700