svn commit: r13805 - trunk/tests/org/argouml/persistence/TestXmiFilePersister.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: euluis
Date: 2007-11-21 15:42:04-0800
New Revision: 13805

Modified:
   trunk/tests/org/argouml/persistence/TestXmiFilePersister.java

Log:
No issue: attempt to reproduce the problems existing in org.argouml.kernel.TestProjectWithProfiles.testRemoveProfileWithModelThatRefersToProfile(), but, it doesn't occur here. Nevertheless, this is a useful test case. Also removed useless try clauses in the other two tests.

Modified: trunk/tests/org/argouml/persistence/TestXmiFilePersister.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/tests/org/argouml/persistence/TestXmiFilePersister.java?view=diff&rev=13805&p1=trunk/tests/org/argouml/persistence/TestXmiFilePersister.java&p2=trunk/tests/org/argouml/persistence/TestXmiFilePersister.java&r1=13804&r2=13805
==============================================================================
--- trunk/tests/org/argouml/persistence/TestXmiFilePersister.java	(original)
+++ trunk/tests/org/argouml/persistence/TestXmiFilePersister.java	2007-11-21 15:42:04-0800
@@ -61,48 +61,73 @@
     /**
      * This is a regression test for issue 1504.
      * Test basic serialization to XMI file.
+     * 
+     * @throws Exception if saving fails.
      */
-    public void testSave() {
-
-        try {
-            Project p = ProjectManager.getManager().makeEmptyProject();
-            Object clazz = Model.getCoreFactory().buildClass(p.getModel());
-            Object returnType =
-                ProjectManager.getManager()
-                	.getCurrentProject().getDefaultReturnType();
-            Object oper =
-                Model.getCoreFactory().buildOperation(clazz, returnType);
-            Model.getCoreHelper().setType(
-                    Model.getFacade().getParameter(oper, 0),
-                    p.findType("String"));
-            File file = new File("test.xmi");
-            XmiFilePersister persister = new XmiFilePersister();
-            p.preSave();
-            persister.save(p, file);
-            p.postSave();
-        } catch (Exception e) {
-            fail("Save resulted in an exception");
-        }
+    public void testSave() throws Exception {
+        Project p = ProjectManager.getManager().makeEmptyProject();
+        Object clazz = Model.getCoreFactory().buildClass(p.getModel());
+        Object returnType =
+            ProjectManager.getManager()
+            	.getCurrentProject().getDefaultReturnType();
+        Object oper =
+            Model.getCoreFactory().buildOperation(clazz, returnType);
+        Model.getCoreHelper().setType(
+                Model.getFacade().getParameter(oper, 0),
+                p.findType("String"));
+        File file = new File("test.xmi");
+        XmiFilePersister persister = new XmiFilePersister();
+        p.preSave();
+        persister.save(p, file);
+        p.postSave();
+    }
+    
+    /**
+     * This is more like a functional test, exercising several sub-systems 
+     * of ArgoUML, including persistence, kernel and model.
+     * It is composed of the following steps:
+     * <ol>
+     * <li>create a model with a class in it, then assert that the class is 
+     * found in the project;</li>
+     * <li>save the model as an XMI file;</li>
+     * <li>load the model and create a project around it, then assert that 
+     * the class is found again.</li>
+     * </ol>
+     * 
+     * @throws Exception when any of the activities fails
+     */
+    public void testCreateSaveAndLoadYeldsCorrectModel() throws Exception {
+        Project project = ProjectManager.getManager().makeEmptyProject();
+        Object model = project.getModel();
+        assertNotNull(model);
+        Model.getCoreFactory().buildClass("Foo", model);
+        assertNotNull(project.findType("Foo", false));
+        File file = new File("testCreateSaveAndLoadYeldsCorrectModel.xmi");
+        XmiFilePersister persister = new XmiFilePersister();
+        project.preSave();
+        persister.save(project, file);
+        project.postSave();
+
+        ProjectManager.getManager().makeEmptyProject();
+        
+        persister = new XmiFilePersister();
+        project = persister.doLoad(file);
+        assertNotNull(project.findType("Foo", false));
     }
 
     /**
      * This is a regression test for issue 1504.
      * Test loading from minimal XMI file.
+     * 
+     * @throws Exception if loading project fails
      */
-    public void testLoadProject() {
-
-        try {
-            File file = new File("test.xmi");
+    public void testLoadProject() throws Exception {
+        File file = new File("test.xmi");
 
-            XmiFilePersister persister = new XmiFilePersister();
+        XmiFilePersister persister = new XmiFilePersister();
 
-            ProjectManager.getManager().makeEmptyProject();
+        ProjectManager.getManager().makeEmptyProject();
 
-            persister.doLoad(file);
-        } catch (OpenException e) {
-            fail("Load resulted in an exception");
-        } catch (InterruptedException e) {
-            fail("Load resulted in an exception");
-        }
+        persister.doLoad(file);
     }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.