From 2660f0d0b030e758abdc69f90c23896ce1bf288c Mon Sep 17 00:00:00 2001
From: felmer <felmer>
Date: Thu, 26 Mar 2009 13:34:09 +0000
Subject: [PATCH] LMS-788 Server side implemented with unit tests. GUI improved

SVN: 10388
---
 .../client/web/client/application/Dict.java   |  2 +
 .../ui/vocabulary/VocabularyTermGrid.java     |  6 +-
 .../vocabulary/VocabularyTermValidator.java   | 17 +++---
 .../application/ui/widget/SimpleDialog.java   |  5 +-
 .../openbis/generic/server/CommonServer.java  | 10 +++-
 .../server/business/bo/IVocabularyBO.java     |  9 ++-
 .../server/business/bo/VocabularyBO.java      | 31 ++++++++---
 .../server/dataaccess/IVocabularyDAO.java     |  4 +-
 .../server/dataaccess/db/VocabularyDAO.java   |  4 +-
 .../generic/shared/dto/VocabularyPE.java      | 16 ++++++
 .../cisd/openbis/public/common-dictionary.js  |  3 +-
 .../generic/server/CommonServerTest.java      | 22 ++++++++
 .../business/bo/PropertyTypeBOTest.java       |  2 +-
 .../server/business/bo/VocabularyBOTest.java  | 55 ++++++++++++++++++-
 .../dataaccess/db/VocabularyDAOTest.java      |  6 +-
 15 files changed, 156 insertions(+), 36 deletions(-)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java
index 8638774c6bb..0150c39b1cc 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/Dict.java
@@ -238,6 +238,8 @@ public abstract class Dict {
 
 	public static final String VOCABULARY_TERMS_EMPTY = "vocabulary_terms_empty";
 
+    public static final String MISSING_VOCABULARY_TERMS = "missing_vocabulary_terms";
+
 	public static final String MANDATORY = "mandatory";
 
 	public static final String DEFAULT_VALUE = "default_value";
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java
index 46e0b7f1a9e..61ff92e5638 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermGrid.java
@@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.vocabu
 
 import java.util.List;
 
+import com.extjs.gxt.ui.client.Style.Scroll;
 import com.extjs.gxt.ui.client.event.ButtonEvent;
 import com.extjs.gxt.ui.client.event.ComponentEvent;
 import com.extjs.gxt.ui.client.event.KeyListener;
@@ -92,6 +93,7 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm
                 }
             });
         pagingToolbar.add(new AdapterToolItem(button));
+        allowMultipleSelection();
     }
 
     public static String createGridId(String vocabularyCode)
@@ -149,8 +151,9 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm
         HorizontalPanel panel = new HorizontalPanel();
         panel.setWidth(300);
         panel.add(textArea);
-        panel.setBorders(true);
+        panel.setBorders(false);
         final SimpleDialog dialog = new SimpleDialog(panel, heading, okButtonLabel, viewContext);
+        dialog.setScrollMode(Scroll.NONE);
         textArea.addKeyListener(new KeyListener()
             {
                 @Override
@@ -169,6 +172,7 @@ public class VocabularyTermGrid extends AbstractSimpleBrowserGrid<VocabularyTerm
                             new VoidCallback(viewContext));
                 }
             });
+        dialog.setEnableOfAcceptButton(false);
         dialog.show();
     }
 }
\ No newline at end of file
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermValidator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermValidator.java
index f83409e2945..c73e0123891 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermValidator.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/vocabulary/VocabularyTermValidator.java
@@ -43,13 +43,16 @@ final class VocabularyTermValidator implements Validator<String, TextArea>
 
     final static List<String> getTerms(final String value)
     {
-        final String[] split = value.split("[,\n\r\t\f ]");
         final List<String> terms = new ArrayList<String>();
-        for (final String text : split)
+        if (StringUtils.isBlank(value) == false)
         {
-            if (StringUtils.isBlank(text) == false)
+            final String[] split = value.split("[,\n\r\t\f ]");
+            for (final String text : split)
             {
-                terms.add(text);
+                if (StringUtils.isBlank(text) == false)
+                {
+                    terms.add(text);
+                }
             }
         }
         return terms;
@@ -61,14 +64,10 @@ final class VocabularyTermValidator implements Validator<String, TextArea>
 
     public final String validate(final TextArea field, final String value)
     {
-        if (StringUtils.isBlank(value))
-        {
-            return null;
-        }
         final List<String> terms = VocabularyTermValidator.getTerms(value);
         if (terms.size() == 0)
         {
-            return null;
+            return messageProvider.getMessage(Dict.MISSING_VOCABULARY_TERMS);
         }
         for (final String term : terms)
         {
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleDialog.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleDialog.java
index 88657cf1d7a..483d3c6c9b5 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleDialog.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/widget/SimpleDialog.java
@@ -129,9 +129,12 @@ public class SimpleDialog extends Dialog
 
     private void fireCancel()
     {
-        if (acceptActionOrNull != null)
+        if (cancelActionOrNull != null)
         {
             cancelActionOrNull.execute();
+        } else
+        {
+            close();
         }
     }
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
index 14e58611b38..b85ffa89325 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CommonServer.java
@@ -515,8 +515,14 @@ public final class CommonServer extends AbstractServer<ICommonServer> implements
     public void addVocabularyTerms(String sessionToken, String vocabularyCode,
             List<String> vocabularyTerms)
     {
-        System.out.println(vocabularyCode + ":" + vocabularyTerms);
+        assert sessionToken != null : "Unspecified session token";
+        assert vocabularyCode != null : "Unspecified vocabulary code";
 
+        final Session session = getSessionManager().getSession(sessionToken);
+        final IVocabularyBO vocabularyBO = businessObjectFactory.createVocabularyBO(session);
+        vocabularyBO.load(vocabularyCode);
+        vocabularyBO.addNewTerms(vocabularyTerms);
+        vocabularyBO.save();
     }
 
     public void registerProject(String sessionToken, ProjectIdentifier projectIdentifier,
@@ -717,7 +723,7 @@ public final class CommonServer extends AbstractServer<ICommonServer> implements
     {
         final Session session = getSessionManager().getSession(sessionToken);
         final IVocabularyBO vocabularyBO = businessObjectFactory.createVocabularyBO(session);
-        vocabularyBO.load(vocabulary);
+        vocabularyBO.load(vocabulary.getCode());
         return vocabularyBO.countTermsUsageStatistics();
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IVocabularyBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IVocabularyBO.java
index 10920d59daf..af19809cb57 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IVocabularyBO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/IVocabularyBO.java
@@ -49,11 +49,16 @@ public interface IVocabularyBO extends IBusinessObject
     /**
      * Loads specified vocabulary from the database.
      * 
-     * @throws UserFailureException if given <var>vocabulary</var> does not exist.
+     * @throws UserFailureException if no vocabulary found for <code>vocabularyCode</code>.
      */
-    public void load(Vocabulary vocabulary) throws UserFailureException;
+    public void load(String vocabularyCode) throws UserFailureException;
 
     /** @return terms with their usage statistics for the loaded vocabulary */
     public List<VocabularyTermWithStats> countTermsUsageStatistics();
+    
+    /**
+     * Add the specified terms to a loaded vocabulary.
+     */
+    public void addNewTerms(List<String> newTerms);
 
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java
index 3d3a026666d..04dd7e01655 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBO.java
@@ -61,19 +61,32 @@ public class VocabularyBO extends AbstractBusinessObject implements IVocabularyB
         vocabularyPE.setRegistrator(findRegistrator());
         for (final VocabularyTerm term : vocabulary.getTerms())
         {
-            final VocabularyTermPE vocabularyTermPE = new VocabularyTermPE();
-            vocabularyTermPE.setCode(term.getCode());
-            vocabularyTermPE.setRegistrator(findRegistrator());
-            vocabularyPE.addTerm(vocabularyTermPE);
+            addTerm(term.getCode());
         }
     }
 
+    public void addNewTerms(List<String> newTerms)
+    {
+        for (String term : newTerms)
+        {
+            addTerm(term);
+        }
+    }
+
+    private void addTerm(String term)
+    {
+        final VocabularyTermPE vocabularyTermPE = new VocabularyTermPE();
+        vocabularyTermPE.setCode(term);
+        vocabularyTermPE.setRegistrator(findRegistrator());
+        vocabularyPE.addTerm(vocabularyTermPE);
+    }
+
     public void save() throws UserFailureException
     {
         assert vocabularyPE != null : "Unspecified vocabulary";
         try
         {
-            getVocabularyDAO().createVocabulary(vocabularyPE);
+            getVocabularyDAO().createOrUpdateVocabulary(vocabularyPE);
         } catch (final DataAccessException e)
         {
             throwException(e, String.format("Vocabulary '%s'.", vocabularyPE.getCode()));
@@ -111,13 +124,13 @@ public class VocabularyBO extends AbstractBusinessObject implements IVocabularyB
         return stats;
     }
 
-    public void load(Vocabulary vocabulary) throws UserFailureException
+    public void load(String vocabularyCode) throws UserFailureException
     {
-        vocabularyPE = getVocabularyDAO().tryFindVocabularyByCode(vocabulary.getCode());
+        vocabularyPE = getVocabularyDAO().tryFindVocabularyByCode(vocabularyCode);
         if (vocabularyPE == null)
         {
-            throw UserFailureException.fromTemplate("Vocabulary '%s' does not exist.", vocabulary
-                    .getCode());
+            throw UserFailureException.fromTemplate("Vocabulary '%s' does not exist.",
+                    vocabularyCode);
         }
     }
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IVocabularyDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IVocabularyDAO.java
index 16d4d6a5adb..50de85d7c20 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IVocabularyDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/IVocabularyDAO.java
@@ -31,9 +31,9 @@ public interface IVocabularyDAO
 {
 
     /**
-     * Creates the <var>vocabularyCode</var> in the database.
+     * Creates or updates the specified vocabulary in the database.
      */
-    void createVocabulary(final VocabularyPE vocabularyPE);
+    void createOrUpdateVocabulary(final VocabularyPE vocabularyPE);
 
     /**
      * Returns the {@link VocabularyPE} object for the given <var>vocabularyCode</var>, or
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAO.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAO.java
index 75ed1ea65fb..f88d8259390 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAO.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAO.java
@@ -59,7 +59,7 @@ final class VocabularyDAO extends AbstractDAO implements IVocabularyDAO
     // IVocabularyDAO
     //
 
-    public final void createVocabulary(final VocabularyPE vocabularyPE)
+    public final void createOrUpdateVocabulary(final VocabularyPE vocabularyPE)
     {
         assert vocabularyPE != null : "Given vocabulary can not be null.";
         validatePE(vocabularyPE);
@@ -69,7 +69,7 @@ final class VocabularyDAO extends AbstractDAO implements IVocabularyDAO
         template.flush();
         if (operationLog.isInfoEnabled())
         {
-            operationLog.info(String.format("ADD: vocabulary '%s'.", vocabularyPE));
+            operationLog.info(String.format("ADD/UPDATE: vocabulary '%s'.", vocabularyPE));
         }
 
     }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/VocabularyPE.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/VocabularyPE.java
index 927a47dcb8f..db5c0a84911 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/VocabularyPE.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/dto/VocabularyPE.java
@@ -17,6 +17,7 @@
 package ch.systemsx.cisd.openbis.generic.shared.dto;
 
 import java.io.Serializable;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -34,6 +35,7 @@ import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
 import javax.persistence.Transient;
 import javax.persistence.UniqueConstraint;
+import javax.persistence.Version;
 
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
@@ -80,6 +82,8 @@ public class VocabularyPE extends HibernateAbstractRegistrationHolder implements
 
     private DatabaseInstancePE databaseInstance;
 
+    private Date modificationDate;
+
     public VocabularyPE()
     {
     }
@@ -102,6 +106,18 @@ public class VocabularyPE extends HibernateAbstractRegistrationHolder implements
         this.simpleCode = simpleCode;
     }
 
+    @Version
+    @Column(name = ColumnNames.MODIFICATION_TIMESTAMP_COLUMN, nullable = false)
+    public Date getModificationDate()
+    {
+        return modificationDate;
+    }
+
+    public void setModificationDate(Date versionDate)
+    {
+        this.modificationDate = versionDate;
+    }
+
     @Column(name = ColumnNames.DESCRIPTION_COLUMN)
     @Length(max = 80, message = ValidationMessages.DESCRIPTION_LENGTH_MESSAGE)
     public String getDescription()
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js
index 9d15068eedf..7b775fdac32 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/public/common-dictionary.js
@@ -145,7 +145,8 @@ var common = {
   type_of: "Entity",
   vocabulary: "Vocabulary",
   vocabulary_terms: "Terms",
-  vocabulary_terms_empty: "Space or comma separated list",
+  vocabulary_terms_empty: "Space or comma separated list of terms.",
+  missing_vocabulary_terms: "Missing vocabulary term.",
   mandatory: "Mandatory",
   default_value: "Initial Value",
   default_value_tooltip: "The value of the assigned property for all currently existing entities.",
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java
index ee4f0da5f78..d7fe68f1387 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/CommonServerTest.java
@@ -648,6 +648,28 @@ public final class CommonServerTest extends AbstractServerTestCase
         createServer().registerVocabulary(SESSION_TOKEN, new Vocabulary());
         context.assertIsSatisfied();
     }
+    
+    @Test
+    public void testAddVocabularyTerms()
+    {
+        final List<String> terms = Arrays.asList("a", "b");
+        prepareGetSession();
+        context.checking(new Expectations()
+            {
+                {
+                    one(commonBusinessObjectFactory).createVocabularyBO(SESSION);
+                    will(returnValue(vocabularyBO));
+
+                    one(vocabularyBO).load("v-code");
+                    one(vocabularyBO).addNewTerms(terms);
+                    one(vocabularyBO).save();
+                }
+            });
+        
+        createServer().addVocabularyTerms(SESSION_TOKEN, "v-code", terms);
+        
+        context.assertIsSatisfied();
+    }
 
     @Test
     public final void testAssignPropertyType()
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBOTest.java
index 636ccfd1cc9..6c9adbafc54 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBOTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/PropertyTypeBOTest.java
@@ -225,7 +225,7 @@ public final class PropertyTypeBOTest extends AbstractBOTest
 
                     one(vocabularyDAO).tryFindVocabularyByCode(vocabulary.getCode());
 
-                    one(vocabularyDAO).createVocabulary(with(aNonNull(VocabularyPE.class)));
+                    one(vocabularyDAO).createOrUpdateVocabulary(with(aNonNull(VocabularyPE.class)));
                 }
             });
         final PropertyTypeBO propertyTypeBO = createPropertyTypeBO();
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBOTest.java
index 2760cf3a4b4..b810ee48c05 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBOTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/business/bo/VocabularyBOTest.java
@@ -16,8 +16,12 @@
 
 package ch.systemsx.cisd.openbis.generic.server.business.bo;
 
+import static ch.systemsx.cisd.openbis.generic.server.business.ManagerTestTool.EXAMPLE_SESSION;
+
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.Set;
 
 import org.jmock.Expectations;
 import org.springframework.dao.DataIntegrityViolationException;
@@ -28,6 +32,7 @@ import ch.systemsx.cisd.openbis.generic.server.business.ManagerTestTool;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.Vocabulary;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.VocabularyTerm;
 import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE;
+import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE;
 
 /**
  * Test cases for corresponding {@link VocabularyBO} class.
@@ -42,7 +47,7 @@ public final class VocabularyBOTest extends AbstractBOTest
 
     private final VocabularyBO createVocabularyBO()
     {
-        return new VocabularyBO(daoFactory, ManagerTestTool.EXAMPLE_SESSION);
+        return new VocabularyBO(daoFactory, EXAMPLE_SESSION);
     }
 
     static final Vocabulary createVocabulary()
@@ -141,7 +146,7 @@ public final class VocabularyBOTest extends AbstractBOTest
                     one(daoFactory).getHomeDatabaseInstance();
                     will(returnValue(ManagerTestTool.EXAMPLE_DATABASE_INSTANCE));
 
-                    one(vocabularyDAO).createVocabulary(with(aNonNull(VocabularyPE.class)));
+                    one(vocabularyDAO).createOrUpdateVocabulary(with(aNonNull(VocabularyPE.class)));
                 }
             });
         final Vocabulary vocabulary = createVocabulary();
@@ -160,7 +165,7 @@ public final class VocabularyBOTest extends AbstractBOTest
                     one(daoFactory).getHomeDatabaseInstance();
                     will(returnValue(ManagerTestTool.EXAMPLE_DATABASE_INSTANCE));
 
-                    one(vocabularyDAO).createVocabulary(with(aNonNull(VocabularyPE.class)));
+                    one(vocabularyDAO).createOrUpdateVocabulary(with(aNonNull(VocabularyPE.class)));
                     will(throwException(new DataIntegrityViolationException(null)));
                 }
             });
@@ -176,4 +181,48 @@ public final class VocabularyBOTest extends AbstractBOTest
         }
         context.assertIsSatisfied();
     }
+    
+    @Test
+    public void testLoad()
+    {
+        final VocabularyPE vocabulary = new VocabularyPE();
+        context.checking(new Expectations()
+            {
+                {
+                    one(vocabularyDAO).tryFindVocabularyByCode("voc-code");
+                    will(returnValue(vocabulary));
+                }
+            });
+        
+        VocabularyBO vocabularyBO = createVocabularyBO();
+        vocabularyBO.load("voc-code");
+        
+        assertSame(vocabulary, vocabularyBO.getVocabulary());
+        context.assertIsSatisfied();
+    }
+    
+    @Test
+    public void testAddNewTerms()
+    {
+        final VocabularyPE vocabulary = new VocabularyPE();
+        context.checking(new Expectations()
+            {
+                {
+                    one(vocabularyDAO).tryFindVocabularyByCode("voc-code");
+                    will(returnValue(vocabulary));
+                }
+            });
+        
+        VocabularyBO vocabularyBO = createVocabularyBO();
+        vocabularyBO.load("voc-code");
+        List<String> newTerms = Arrays.asList("a");
+        vocabularyBO.addNewTerms(newTerms);
+        
+        Set<VocabularyTermPE> terms = vocabularyBO.getVocabulary().getTerms();
+        assertEquals(1, terms.size());
+        VocabularyTermPE term = terms.iterator().next();
+        assertEquals("A", term.getCode());
+        assertSame(EXAMPLE_SESSION.tryGetPerson(), term.getRegistrator());
+        context.assertIsSatisfied();
+    }
 }
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAOTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAOTest.java
index 3a1d9c8c775..c19d0afdb68 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAOTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/dataaccess/db/VocabularyDAOTest.java
@@ -74,7 +74,7 @@ public final class VocabularyDAOTest extends AbstractDAOTest
         boolean fail = true;
         try
         {
-            vocabularyDAO.createVocabulary(null);
+            vocabularyDAO.createOrUpdateVocabulary(null);
         } catch (final AssertionError e)
         {
             fail = false;
@@ -92,7 +92,7 @@ public final class VocabularyDAOTest extends AbstractDAOTest
         vocabularyPE.addTerm(createVocabularyTerm("BIG"));
         try
         {
-            vocabularyDAO.createVocabulary(vocabularyPE);
+            vocabularyDAO.createOrUpdateVocabulary(vocabularyPE);
             fail(String.format("'%s' expected.", DataIntegrityViolationException.class
                     .getSimpleName()));
         } catch (final DataIntegrityViolationException ex)
@@ -100,7 +100,7 @@ public final class VocabularyDAOTest extends AbstractDAOTest
             // Nothing to do here.
         }
         vocabularyPE.setCode("USER.FORMAT");
-        vocabularyDAO.createVocabulary(vocabularyPE);
+        vocabularyDAO.createOrUpdateVocabulary(vocabularyPE);
         // Check saved vocabulary.
         assertNull(vocabularyDAO.tryFindVocabularyByCode(vocabularyCode));
         final VocabularyPE savedVocabulary =
-- 
GitLab