Skip to content
Snippets Groups Projects
Commit 5f98ec5a authored by buczekp's avatar buczekp
Browse files

fixed & extended VocabularyBO test

SVN: 12715
parent c0e72f56
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.IPropertyTypeDAO;
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.server.dataaccess.IVocabularyTermDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.IPermIdDAO;
/**
......@@ -82,6 +83,8 @@ public abstract class AbstractBOTest extends AssertJUnit
IVocabularyDAO vocabularyDAO;
IVocabularyTermDAO vocabularyTermDAO;
IEntityPropertiesConverter propertiesConverter;
IDataSetTypeDAO dataSetTypeDAO;
......@@ -118,6 +121,7 @@ public abstract class AbstractBOTest extends AssertJUnit
propertyTypeDAO = context.mock(IPropertyTypeDAO.class);
entityPropertyTypeDAO = context.mock(IEntityPropertyTypeDAO.class);
vocabularyDAO = context.mock(IVocabularyDAO.class);
vocabularyTermDAO = context.mock(IVocabularyTermDAO.class);
materialDAO = context.mock(IMaterialDAO.class);
dataSetTypeDAO = context.mock(IDataSetTypeDAO.class);
fileFormatTypeDAO = context.mock(IFileFormatTypeDAO.class);
......@@ -152,6 +156,8 @@ public abstract class AbstractBOTest extends AssertJUnit
will(returnValue(dataStoreDAO));
allowing(daoFactory).getVocabularyDAO();
will(returnValue(vocabularyDAO));
allowing(daoFactory).getVocabularyTermDAO();
will(returnValue(vocabularyTermDAO));
allowing(daoFactory).getEventDAO();
will(returnValue(eventDAO));
allowing(daoFactory).getAuthorizationGroupDAO();
......
......@@ -148,16 +148,19 @@ public final class VocabularyBOTest extends AbstractBOTest
public final void testSave()
{
final VocabularyBO vocabularyBO = createVocabularyBO();
final NewVocabulary vocabulary = createVocabulary();
context.checking(new Expectations()
{
{
one(daoFactory).getHomeDatabaseInstance();
will(returnValue(ManagerTestTool.EXAMPLE_DATABASE_INSTANCE));
exactly(vocabulary.getTerms().size()).of(vocabularyTermDAO).validate(
with(aNonNull(VocabularyTermPE.class)));
one(vocabularyDAO).createOrUpdateVocabulary(with(aNonNull(VocabularyPE.class)));
}
});
final NewVocabulary vocabulary = createVocabulary();
vocabularyBO.define(vocabulary);
vocabularyBO.save();
context.assertIsSatisfied();
......@@ -167,17 +170,47 @@ public final class VocabularyBOTest extends AbstractBOTest
public final void testSaveWithException()
{
final VocabularyBO vocabularyBO = createVocabularyBO();
final NewVocabulary vocabulary = createVocabulary();
context.checking(new Expectations()
{
{
one(daoFactory).getHomeDatabaseInstance();
will(returnValue(ManagerTestTool.EXAMPLE_DATABASE_INSTANCE));
exactly(vocabulary.getTerms().size()).of(vocabularyTermDAO).validate(
with(aNonNull(VocabularyTermPE.class)));
one(vocabularyDAO).createOrUpdateVocabulary(with(aNonNull(VocabularyPE.class)));
will(throwException(new DataIntegrityViolationException(null)));
}
});
vocabularyBO.define(vocabulary);
try
{
vocabularyBO.save();
fail(String.format("'%s' expected.", UserFailureException.class.getSimpleName()));
} catch (final UserFailureException ex)
{
// Nothing to do here.
}
context.assertIsSatisfied();
}
@Test
public final void testSaveWithTermValidationException()
{
final VocabularyBO vocabularyBO = createVocabularyBO();
final NewVocabulary vocabulary = createVocabulary();
context.checking(new Expectations()
{
{
one(daoFactory).getHomeDatabaseInstance();
will(returnValue(ManagerTestTool.EXAMPLE_DATABASE_INSTANCE));
one(vocabularyTermDAO).validate(with(aNonNull(VocabularyTermPE.class)));
will(throwException(new DataIntegrityViolationException(null)));
}
});
vocabularyBO.define(vocabulary);
try
{
......@@ -344,9 +377,8 @@ public final class VocabularyBOTest extends AbstractBOTest
fail("IllegalArgumentException expected.");
} catch (IllegalArgumentException e)
{
assertEquals(
"Invalid vocabulary replacement because of unknown replacement: 2 -> [1]", e
.getMessage());
assertEquals("Invalid vocabulary replacement because of unknown replacement: 2 -> [1]",
e.getMessage());
}
context.assertIsSatisfied();
}
......@@ -377,9 +409,8 @@ public final class VocabularyBOTest extends AbstractBOTest
fail("IllegalArgumentException expected.");
} catch (IllegalArgumentException e)
{
assertEquals(
"Invalid vocabulary replacement because of unknown replacement: 1 -> [3]", e
.getMessage());
assertEquals("Invalid vocabulary replacement because of unknown replacement: 1 -> [3]",
e.getMessage());
}
context.assertIsSatisfied();
}
......
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