diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java index 018aa4f9353551d38a501c28c605b68d363c70b3..64ea94b0d814ea67ae334573ae59d0488b5cc3d3 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java @@ -25,6 +25,9 @@ import java.text.DateFormat; import java.util.*; import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.*; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.entitytype.EntityKind; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.create.MaterialCreation; +import ch.ethz.sis.openbis.generic.asapi.v3.dto.material.id.MaterialPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.create.VocabularyCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.create.VocabularyTermCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.VocabularyPermId; @@ -526,6 +529,33 @@ public abstract class AbstractSearchPropertyTest extends AbstractTest assertEquals(entities.size(), 1); } + @Test + public void testSearchWithPropertyMatchingMaterialProperty() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + final EntityTypePermId materialType = createAMaterialType(sessionToken, false); + + final MaterialCreation materialCreation = new MaterialCreation(); + materialCreation.setCode("MATERIAL_PROPERTY_TEST"); + materialCreation.setTypeId(materialType); + + final MaterialPermId materialPermId = v3api.createMaterials(sessionToken, + Collections.singletonList(materialCreation)).get(0); + + final String materialTypePermId = materialType.getPermId(); + final PropertyTypePermId propertyTypeId = createAMaterialPropertyType(sessionToken, + new EntityTypePermId(materialTypePermId, EntityKind.MATERIAL)); + + createEntity(sessionToken, propertyTypeId, materialPermId.toString()); + + final AbstractEntitySearchCriteria<?> searchCriteria = createSearchCriteria(); + searchCriteria.withOrOperator(); + searchCriteria.withProperty(propertyTypeId.getPermId()).thatEquals(materialPermId.getCode()); + + final List<? extends IPermIdHolder> entities = search(sessionToken, searchCriteria); + assertEquals(entities.size(), 1); + } + private ObjectPermId createEntity(String sessionToken, PropertyTypePermId propertyTypeId, String value) { EntityTypePermId entityTypeId = createEntityType(sessionToken, propertyTypeId); diff --git a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java index 42acafb249de0beb8cd739ac3b271919511b7c8f..c6e6d9d8e5f1e0d7053a7ac3ae73550a53d75e4b 100644 --- a/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java +++ b/openbis/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java @@ -1429,7 +1429,19 @@ public class AbstractTest extends SystemTestCase creation.setSampleTypeId(sampleTypeId); creation.setLabel("label"); creation.setDescription("description"); - return v3api.createPropertyTypes(sessionToken, Arrays.asList(creation)).get(0); + return v3api.createPropertyTypes(sessionToken, Collections.singletonList(creation)).get(0); + } + + protected PropertyTypePermId createAMaterialPropertyType(final String sessionToken, + final IEntityTypeId materialTypeId) + { + final PropertyTypeCreation creation = new PropertyTypeCreation(); + creation.setCode("TYPE-" + System.currentTimeMillis()); + creation.setDataType(DataType.MATERIAL); + creation.setMaterialTypeId(materialTypeId); + creation.setLabel("label"); + creation.setDescription("description"); + return v3api.createPropertyTypes(sessionToken, Collections.singletonList(creation)).get(0); } protected EntityTypePermId createASampleType(String sessionToken, boolean mandatory, PropertyTypePermId... propertyTypes) @@ -1522,7 +1534,7 @@ public class AbstractTest extends SystemTestCase private String getSampleIdentifier(String permId) { Session session = sessionFactory.getCurrentSession(); - NativeQuery query = session.createSQLQuery("select sample_identifier from samples where perm_id = :permId") + NativeQuery query = session.createNativeQuery("select sample_identifier from samples where perm_id = :permId") .setParameter("permId", permId); List<?> result = query.getResultList(); try