]> SALOME platform Git repositories - tools/siman.git/commitdiff
Salome HOME
Test for delete method is added.
authorrkv <rkv@opencascade.com>
Mon, 15 Oct 2012 08:51:57 +0000 (08:51 +0000)
committerrkv <rkv@opencascade.com>
Mon, 15 Oct 2012 08:51:57 +0000 (08:51 +0000)
Workspace/Siman-Common/src/test/splat/dao/TestKnowledgeElementDAO.java

index 965cef0cec2e86b377e6e882bdabd180a4a7f718..252f4ff019bc8ef7ced9639517cd5d5bca94377f 100644 (file)
@@ -208,7 +208,7 @@ public class TestKnowledgeElementDAO extends BaseTest {
         * <B>Outcome results:</B><BR>
         * <i>
         * <ul>
-        * <li>Object is found in the database successfully<BR>
+        * <li>Object is update in the database successfully<BR>
         * </li>
         * <li>Exception is thrown<BR>
         * </li>
@@ -250,12 +250,106 @@ public class TestKnowledgeElementDAO extends BaseTest {
 
                compareObjects(aKelmFound, aKelm);
 
+               // Call DAO's create method for a knowledge element with non-zero id.
+               KnowledgeElement aBadKelm = new KnowledgeElement(
+                               (new KnowledgeElement.Properties())
+                                               .setTitle("Test knowledge element")
+                                               .setAuthor(aKelm.getAuthor())
+                                               .setOwnerScenario(aKelm.getOwnerScenario())
+                                               .setType(aKelm.getType())
+                                               .setDate(aKelm.getDate())
+                                               .setValue(
+                                                               "This is another test knowledge element.\nIt is created by the unit test."));
+               // aBadKelm.setIndex(aKelmFound.getIndex());
+               try {
+                       _knowledgeElementDAO.update(aBadKelm);
+                       getHibernateTemplate().flush();
+                       Assert.fail("Update with not existing id must be failed.");
+               } catch (Exception e) {
+                       LOG.debug("Expected exception is thrown: "
+                                       + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
+               // Call update with bad data (null title).
+               aBadKelm.setIndex(aKelmFound.getIndex());
+               aBadKelm.setTitle(null);
+               try {
+                       _knowledgeElementDAO.update(aBadKelm);
+                       getHibernateTemplate().flush();
+                       Assert.fail("Update with null title must be failed.");
+               } catch (Exception e) {
+                       LOG.debug("Expected exception is thrown: "
+                                       + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
+               // Call update with bad data (null state).
+               aBadKelm.setTitle(aKelmFound.getTitle());
+               aBadKelm.setProgressState(null);
+               try {
+                       _knowledgeElementDAO.update(aBadKelm);
+                       getHibernateTemplate().flush();
+                       Assert.fail("Update with null state must be failed.");
+               } catch (Exception e) {
+                       LOG.debug("Expected exception is thrown: "
+                                       + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
                LOG.debug(">>>>> END testUpdate()");
        }
 
+       /**
+        * Test of deleting a knowledge element.<BR>
+        * <B>Description :</B> <BR>
+        * <i>Create a knowledge element and try to delete it.</i><BR>
+        * <B>Action : </B><BR>
+        * <i>1. call DAO's delete method for an existing id.</i><BR>
+        * <i>2. call DAO's delete method for a not existing id.</i><BR>
+        * <B>Test data : </B><BR>
+        * <i>no input parameters</i><BR>
+        * <i>no input parameters</i><BR>
+        * 
+        * <B>Outcome results:</B><BR>
+        * <i>
+        * <ul>
+        * <li>Object is found in the database successfully<BR>
+        * </li>
+        * <li>Exception is thrown<BR>
+        * </li>
+        * </ul>
+        * </i>
+        * 
+        * @throws InvalidPropertyException
+        *             if an invalid property is used when creating objects
+        * @throws MultiplyDefinedException
+        *             when trying to create an object with already existing id
+        * @throws MissedPropertyException
+        *             if a mandatory property is not defined for an object to be created
+        * 
+        */
        @Test
-       public void testDelete() {
+       public void testDelete() throws InvalidPropertyException,
+                       MissedPropertyException, MultiplyDefinedException {
                LOG.debug(">>>>> BEGIN testDelete()");
+               KnowledgeElement aKelm = getKnowledgeElement();
+               // Call DAO's create method for a good transient knowledge element.
+               Long id = _knowledgeElementDAO.create(aKelm);
+               Assert.assertNotNull(id,
+                               "Create method returns null instead of a new id.");
+               Assert.assertTrue(id > 0, "The new id is not a positive number.");
+
+               // Call DAO's delete method for an existing id.
+               _knowledgeElementDAO.delete(aKelm);
+
+               // Check that the object has been deleted.
+               KnowledgeElement aKelmFound = _knowledgeElementDAO.get(id);
+
+               Assert.assertNull(aKelmFound, "Deleted object must not be found.");
+               // Call DAO's delete method for a not existing id.
+               try {
+                       _knowledgeElementDAO.delete(aKelm);
+                       getHibernateTemplate().flush();
+                       Assert.fail("Delete with with not existing id must be failed.");
+               } catch (Exception e) {
+                       LOG.debug("Expected exception is thrown: "
+                                       + e.getClass().getSimpleName() + ": " + e.getMessage());
+               }
                LOG.debug(">>>>> END testDelete()");
        }