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 |
} |