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 3e95aeb6a0c1fb4a34954b0d163c00e31e0a9c13..ba13550854e59c78f3a6213c6d2d59447c72810e 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 @@ -22,12 +22,12 @@ import static ch.ethz.sis.openbis.generic.server.asapi.v3.search.translator.cond import static org.testng.Assert.*; import java.text.DateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; +import java.util.*; import ch.ethz.sis.openbis.generic.asapi.v3.dto.common.search.*; +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; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -444,6 +444,72 @@ public abstract class AbstractSearchPropertyTest extends AbstractTest assertEquals(hasMatch, found); } + @DataProvider + protected Object[][] withControlledVocabularyPropertyExamples() + { + return new Object[][] { + { "WINTER", "== WINTER", true }, + { "WINTER", "== SUMMER", false }, + { "WINTER", "<= WINTER", true }, + { "SUMMER", "<= WINTER", true }, + { "WINTER", "<= SUMMER", false }, + { "WINTER", "< WINTER", false }, + { "SUMMER", "< WINTER", true }, + { "WINTER", "< SUMMER", false }, + { "WINTER", ">= WINTER", true }, + { "WINTER", ">= SUMMER", true }, + { "SUMMER", ">= WINTER", false }, + { "WINTER", "> WINTER", false }, + { "WINTER", "> SUMMER", true }, + { "SUMMER", "> WINTER", false }, + + { "WINTER", "contains I and endsWith ER", true }, + { "SUMMER", "contains I and endsWith ER", false }, + { "SPRING", "contains I and endsWith ER", false }, + { "SUMMER", "startsWith SU", true }, + { "SPRING", "startsWith SU", false }, + }; + } + + @Test(dataProvider = "withControlledVocabularyPropertyExamples") + public void testWithControlledVocabularyProperty(final String value, final String queryString, final boolean found) + { + // Given + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final VocabularyTermCreation vocabularyTermCreation1 = new VocabularyTermCreation(); + vocabularyTermCreation1.setCode("WINTER"); + final VocabularyTermCreation vocabularyTermCreation2 = new VocabularyTermCreation(); + vocabularyTermCreation2.setCode("SPRING"); + final VocabularyTermCreation vocabularyTermCreation3 = new VocabularyTermCreation(); + vocabularyTermCreation3.setCode("SUMMER"); + final VocabularyTermCreation vocabularyTermCreation4 = new VocabularyTermCreation(); + vocabularyTermCreation4.setCode("AUTUMN"); + + final VocabularyCreation vocabularyCreation = new VocabularyCreation(); + vocabularyCreation.setCode("SEASONS"); + vocabularyCreation.setTerms(Arrays.asList(vocabularyTermCreation1, vocabularyTermCreation2, + vocabularyTermCreation3, vocabularyTermCreation4)); + final VocabularyPermId vocabularyPermId = + v3api.createVocabularies(sessionToken, Collections.singletonList(vocabularyCreation)).get(0); + + final PropertyTypePermId propertyTypeId = createAPropertyType(sessionToken, DataType.CONTROLLEDVOCABULARY, + vocabularyPermId); + final ObjectPermId entityPermId = createEntity(sessionToken, propertyTypeId, value); + final AbstractEntitySearchCriteria<?> searchCriteria = createSearchCriteria(); + new StringQueryInjector(searchCriteria, propertyTypeId, false).buildCriteria(queryString); + + // When + final List<? extends IPermIdHolder> entities = search(sessionToken, searchCriteria); + + // Then + assertEquals(entities.size(), found ? 1 : 0); + if (found) + { + assertEquals(entities.get(0).getPermId().toString(), entityPermId.getPermId()); + } + } + 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 9650e83f17a0763924259f6fc76040d573ab21c5..42acafb249de0beb8cd739ac3b271919511b7c8f 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 @@ -1401,18 +1401,24 @@ public class AbstractTest extends SystemTestCase } } - protected PropertyTypePermId createAPropertyType(String sessionToken, DataType dataType) + protected PropertyTypePermId createAPropertyType(final String sessionToken, final DataType dataType) { - PropertyTypeCreation creation = new PropertyTypeCreation(); + return createAPropertyType(sessionToken, dataType, new VocabularyPermId("ORGANISM")); + } + + protected PropertyTypePermId createAPropertyType(final String sessionToken, final DataType dataType, + final VocabularyPermId vocabularyPermId) + { + final PropertyTypeCreation creation = new PropertyTypeCreation(); creation.setCode("TYPE-" + System.currentTimeMillis()); creation.setDataType(dataType); creation.setLabel("label"); creation.setDescription("description"); if (dataType == DataType.CONTROLLEDVOCABULARY) { - creation.setVocabularyId(new VocabularyPermId("ORGANISM")); + creation.setVocabularyId(vocabularyPermId); } - return v3api.createPropertyTypes(sessionToken, Arrays.asList(creation)).get(0); + return v3api.createPropertyTypes(sessionToken, Collections.singletonList(creation)).get(0); } protected PropertyTypePermId createASamplePropertyType(String sessionToken, IEntityTypeId sampleTypeId)