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

[LMS-1327] rewrote DAO test into listing query test

SVN: 14144
parent 2157f10c
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ package ch.systemsx.cisd.openbis.generic.server.dataaccess;
import java.util.List;
import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialLister;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialIdentifier;
import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialPE;
import ch.systemsx.cisd.openbis.generic.shared.dto.MaterialTypePE;
......@@ -31,10 +32,13 @@ public interface IMaterialDAO extends IGenericDAO<MaterialPE>
{
/**
* Lists materials of given type. Fetches also properties and inhibitor.
* Lists materials of given type. Fetches also properties.
*
* @deprecated Because of performance issues use this method only in tests, otherwise use
* {@link IMaterialLister#list(ch.systemsx.cisd.openbis.generic.shared.basic.dto.MaterialType)}
*/
@Deprecated
public List<MaterialPE> listMaterialsWithPropertiesAndInhibitor(MaterialTypePE type);
public List<MaterialPE> listMaterialsWithProperties(MaterialTypePE type);
/** Inserts given {@link MaterialPE}s into the database. */
public void createMaterials(List<MaterialPE> materials);
......
......@@ -54,8 +54,8 @@ public class MaterialDAO extends AbstractGenericEntityDAO<MaterialPE> implements
super(sessionFactory, databaseInstance, ENTITY_CLASS);
}
public List<MaterialPE> listMaterialsWithPropertiesAndInhibitor(
final MaterialTypePE materialType) throws DataAccessException
public List<MaterialPE> listMaterialsWithProperties(final MaterialTypePE materialType)
throws DataAccessException
{
assert materialType != null : "Unspecified material type.";
......
......@@ -26,6 +26,8 @@ import it.unimi.dsi.fastutil.longs.LongSet;
import java.sql.SQLException;
import java.util.List;
import junit.framework.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
......@@ -36,8 +38,6 @@ import ch.systemsx.cisd.openbis.generic.server.business.bo.common.EntityListingT
import ch.systemsx.cisd.openbis.generic.server.business.bo.common.GenericEntityPropertyRecord;
import ch.systemsx.cisd.openbis.generic.server.business.bo.common.MaterialEntityPropertyRecord;
import ch.systemsx.cisd.openbis.generic.server.business.bo.common.VocabularyTermRecord;
import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.IMaterialListingQuery;
import ch.systemsx.cisd.openbis.generic.server.business.bo.materiallister.MaterialListerDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IDAOFactory;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.AbstractDAOTest;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
......@@ -54,17 +54,25 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.dto.PropertyType;
public class MaterialListingQueryTest extends AbstractDAOTest
{
private static final long BACTERIUM_MATERIAL_TYPE = 6L;
private static final int NUMBER_OF_BACTERIA = 4;
// ID of the BACTERIA which has ORGANISM property filled
private static final long MATERIAL_ID_TEST_1 = 34;
private static final long MATERIAL_ID_TEST_2 = 35;
private Long dbInstanceId;
private IMaterialListingQuery query;
@BeforeClass(alwaysRun = true)
public void init() throws SQLException
{
query = createMaterialListerDAO(daoFactory).getQuery();
MaterialListerDAO materialListerDAO = createMaterialListerDAO(daoFactory);
dbInstanceId = materialListerDAO.getDatabaseInstanceId();
query = materialListerDAO.getQuery();
}
private static MaterialListerDAO createMaterialListerDAO(IDAOFactory daoFactory)
......@@ -137,4 +145,23 @@ public class MaterialListingQueryTest extends AbstractDAOTest
MATERIAL_ID_TEST_1);
}
@Test
public void testMaterials()
{
Iterable<MaterialRecord> materials =
query.getMaterialsForMaterialType(dbInstanceId, BACTERIUM_MATERIAL_TYPE);
int count = 0;
for (MaterialRecord materialRecord : materials)
{
assertEquals(dbInstanceId, materialRecord.dbin_id);
assertEquals(BACTERIUM_MATERIAL_TYPE, materialRecord.maty_id);
if (count == 0)
{
Assert.assertEquals("BACTERIUM-X", materialRecord.code);
}
count++;
}
assertEquals(NUMBER_OF_BACTERIA, count);
}
}
......@@ -47,6 +47,7 @@ import ch.systemsx.cisd.openbis.generic.shared.dto.properties.EntityKind;
*/
@Test(groups =
{ "db", "material" })
@SuppressWarnings("deprecation")
public final class MaterialDAOTest extends AbstractDAOTest
{
private static final String BACTERIUM = "BACTERIUM";
......@@ -55,19 +56,6 @@ public final class MaterialDAOTest extends AbstractDAOTest
final int NUMBER_OF_BACTERIA = 4;
@Test
public void testListMaterials() throws Exception
{
MaterialTypePE type =
(MaterialTypePE) daoFactory.getEntityTypeDAO(EntityKind.MATERIAL)
.tryToFindEntityTypeByCode(BACTERIUM);
List<MaterialPE> list =
daoFactory.getMaterialDAO().listMaterialsWithPropertiesAndInhibitor(type);
Assert.assertEquals(NUMBER_OF_BACTERIA, list.size());
Collections.sort(list);
Assert.assertEquals(list.get(0).getCode(), "BACTERIUM-X");
}
@Test
public void testCreateMaterials() throws Exception
{
......@@ -75,7 +63,7 @@ public final class MaterialDAOTest extends AbstractDAOTest
(MaterialTypePE) daoFactory.getEntityTypeDAO(EntityKind.MATERIAL)
.tryToFindEntityTypeByCode(BACTERIUM);
List<MaterialPE> bacteria_before =
daoFactory.getMaterialDAO().listMaterialsWithPropertiesAndInhibitor(type);
daoFactory.getMaterialDAO().listMaterialsWithProperties(type);
Assert.assertEquals(NUMBER_OF_BACTERIA, bacteria_before.size());
List<MaterialPE> newMaterials = new ArrayList<MaterialPE>();
newMaterials.add(createMaterial(type, "BRAND_NEW_BACTERIUM_1"));
......@@ -83,7 +71,7 @@ public final class MaterialDAOTest extends AbstractDAOTest
Collections.sort(newMaterials);
daoFactory.getMaterialDAO().createMaterials(newMaterials);
List<MaterialPE> bacteria_after =
daoFactory.getMaterialDAO().listMaterialsWithPropertiesAndInhibitor(type);
daoFactory.getMaterialDAO().listMaterialsWithProperties(type);
Assert.assertEquals(NUMBER_OF_BACTERIA + newMaterials.size(), bacteria_after.size());
bacteria_after.removeAll(bacteria_before);
Collections.sort(bacteria_after);
......@@ -112,7 +100,7 @@ public final class MaterialDAOTest extends AbstractDAOTest
(MaterialTypePE) daoFactory.getEntityTypeDAO(EntityKind.MATERIAL)
.tryToFindEntityTypeByCode(BACTERIUM);
List<MaterialPE> bacteria_before =
daoFactory.getMaterialDAO().listMaterialsWithPropertiesAndInhibitor(type);
daoFactory.getMaterialDAO().listMaterialsWithProperties(type);
String existingBacteriumCode = bacteria_before.get(0).getCode();
List<MaterialPE> newMaterials = new ArrayList<MaterialPE>();
newMaterials.add(createMaterial(type, existingBacteriumCode));
......
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