Skip to content
Snippets Groups Projects
Commit cc023783 authored by ribeaudc's avatar ribeaudc
Browse files

[LMS-695] add: - Unit test for 'CommonServer.listVocabularies' and...

[LMS-695] add: - Unit test for 'CommonServer.listVocabularies' and 'VocabularyDAO.listVocabularies'.

SVN: 9436
parent bf33adab
No related branches found
No related tags found
No related merge requests found
......@@ -170,6 +170,9 @@ public interface ICommonClientService extends IClientService
/**
* Returns a list of all vocabularies.
* <p>
* Note that the vocabulary terms are included/loaded.
* </p>
*/
public List<Vocabulary> listVocabularies() throws UserFailureException;
......
......@@ -64,6 +64,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.GroupIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils;
/**
* Implementation of client-server interface.
......@@ -382,7 +383,12 @@ public final class CommonServer extends AbstractServer<ICommonServer> implements
assert sessionToken != null : "Unspecified session token";
// Not needed but just to refresh/check the session.
getSessionManager().getSession(sessionToken);
final List<VocabularyPE> vocabularies = getDAOFactory().getVocabularyDAO().listVocabularies();
final List<VocabularyPE> vocabularies =
getDAOFactory().getVocabularyDAO().listVocabularies();
for (final VocabularyPE vocabularyPE : vocabularies)
{
HibernateUtils.initialize(vocabularyPE.getTerms());
}
Collections.sort(vocabularies);
return vocabularies;
}
......
......@@ -212,7 +212,7 @@ public interface ICommonServer extends IServer
public List<PropertyTypePE> listPropertyTypes(final String sessionToken);
/**
* List data types.
* Lists data types.
*
* @return a sorted list of {@link DataTypePE}.
*/
......@@ -221,9 +221,10 @@ public interface ICommonServer extends IServer
public List<DataTypePE> listDataTypes(final String sessionToken);
/**
* List data types.
* Lists vocabularies.
*
* @return a sorted list of {@link VocabularyPE}.
* @return a sorted list of {@link VocabularyPE}. Note that the vocabulary terms are
* included/loaded.
*/
@Transactional(readOnly = true)
@RolesAllowed(RoleSet.OBSERVER)
......
......@@ -43,6 +43,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.PropertyTypePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.RoleAssignmentPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.RoleCode;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.DatabaseInstanceIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.ProjectIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
......@@ -527,6 +528,26 @@ public final class CommonServerTest extends AbstractServerTestCase
context.assertIsSatisfied();
}
@Test
public final void testListVocabularies()
{
final Session session = prepareGetSession();
context.checking(new Expectations()
{
{
one(daoFactory).getVocabularyDAO();
will(returnValue(vocabularyDAO));
one(vocabularyDAO).listVocabularies();
will(returnValue(Collections.emptyList()));
}
});
final List<VocabularyPE> vocabularies =
createServer().listVocabularies(session.getSessionToken());
assertEquals(0, vocabularies.size());
context.assertIsSatisfied();
}
@Test
public final void testRegisterPropertyType()
{
......
......@@ -22,6 +22,8 @@ import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.fail;
import java.util.List;
import org.springframework.dao.DataIntegrityViolationException;
import org.testng.annotations.Test;
......@@ -29,6 +31,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IVocabularyDAO;
import ch.systemsx.cisd.openbis.generic.shared.dto.PersonPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.VocabularyTermPE;
import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils;
/**
* Test cases for corresponding {@link VocabularyDAO} class.
......@@ -107,4 +110,13 @@ public final class VocabularyDAOTest extends AbstractDAOTest
assertEquals(3, savedVocabulary.getTerms().size());
}
@Test
public final void testListVocabularies()
{
final IVocabularyDAO vocabularyDAO = daoFactory.getVocabularyDAO();
final List<VocabularyPE> vocabularies = vocabularyDAO.listVocabularies();
assertEquals(3, vocabularies.size());
final VocabularyPE vocabularyPE = vocabularies.get(0);
assertFalse(HibernateUtils.isInitialized(vocabularyPE.getTerms()));
}
}
......@@ -44,6 +44,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPropertyTypeDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IRoleAssignmentDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleTypeDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IVocabularyDAO;
import ch.systemsx.cisd.openbis.generic.shared.dto.DatabaseInstancePE;
import ch.systemsx.cisd.openbis.generic.shared.dto.Session;
......@@ -103,6 +104,8 @@ public abstract class AbstractServerTestCase extends AssertJUnit
protected IPropertyTypeBO propertyTypeBO;
protected IVocabularyDAO vocabularyDAO;
@BeforeMethod
@SuppressWarnings("unchecked")
public void setUp()
......@@ -123,6 +126,7 @@ public abstract class AbstractServerTestCase extends AssertJUnit
projectDAO = context.mock(IProjectDAO.class);
sampleTypeDAO = context.mock(ISampleTypeDAO.class);
propertyTypeDAO = context.mock(IPropertyTypeDAO.class);
vocabularyDAO = context.mock(IVocabularyDAO.class);
// BO
groupBO = context.mock(IGroupBO.class);
sampleBO = context.mock(ISampleBO.class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment