diff --git a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java index 3d0fd0816d8c0de0d110f77c8eb8c0e09a9fac6c..094a217ad5bbe378416ab124515be59e73750508 100644 --- a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java +++ b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractSearchPropertyTest.java @@ -951,15 +951,22 @@ public abstract class AbstractSearchPropertyTest extends AbstractTest final ObjectPermId entity2 = createEntity(sessionToken, "Sample4", searchTest2EntityTypeId, new HashMap<>(Map.of(samplePropertyTypeId1.getPermId(), sample1.getPermId()))); - final AbstractEntitySearchCriteria<?> searchCriteria = createSearchCriteria(); - searchCriteria.withOrOperator(); - searchCriteria.withSampleProperty(searchTest1EntityTypeId.getPermId()).thatEquals(sample1.getPermId()); - try { - final List<? extends IPermIdHolder> entities = search(sessionToken, searchCriteria); - assertEquals(entities.size(), 1); - assertEquals(entities.get(0).getPermId(), entity1); + final AbstractEntitySearchCriteria<?> searchCriteria1 = createSearchCriteria(); + searchCriteria1.withOrOperator(); + searchCriteria1.withSampleProperty(searchTest1EntityTypeId.getPermId()).thatEquals(sample1.getPermId()); + + final List<? extends IPermIdHolder> entities1 = search(sessionToken, searchCriteria1); + assertEquals(entities1.size(), 1); + assertEquals(entities1.get(0).getPermId(), entity1); + + final AbstractEntitySearchCriteria<?> searchCriteria2 = createSearchCriteria(); + searchCriteria2.withOrOperator(); + searchCriteria2.withSampleProperty("WHATEVER").thatEquals(sample1.getPermId()); + + final List<? extends IPermIdHolder> entities2 = search(sessionToken, searchCriteria2); + assertEquals(entities2.size(), 0); } finally { final IDeletionId entitiesDeletion = deleteEntities(sessionToken, entity1, entity2); @@ -989,6 +996,60 @@ public abstract class AbstractSearchPropertyTest extends AbstractTest return v3api.deleteSamples(sessionToken, List.of(entityIds), deletionOptions); } + @Test + public void testSearchWithEnumProperty() + { + final String sessionToken = v3api.login(TEST_USER, PASSWORD); + + final String term1 = "TERM1"; + final String term2 = "TERM2"; + final String term3 = "TERM3"; + final VocabularyPermId vocabulary = createVocabulary(sessionToken, "TERMS", term1, term2, term3); + + final EntityTypePermId propertySampleType = createASampleType(sessionToken, false); + final PropertyTypePermId vocabularyPropertyTypeId1 = createAVocabularyPropertyType(sessionToken, + vocabulary, "Vocabulary1"); + final PropertyTypePermId vocabularyPropertyTypeId2 = createAVocabularyPropertyType(sessionToken, + vocabulary, "Vocabulary2"); + + final EntityTypePermId searchTest1EntityTypeId = createEntityType(sessionToken, vocabularyPropertyTypeId1, + vocabularyPropertyTypeId2); + + final ObjectPermId entity1 = createEntity(sessionToken, "Entity", searchTest1EntityTypeId, + new HashMap<>(Map.of(vocabularyPropertyTypeId1.getPermId(), term1, + vocabularyPropertyTypeId2.getPermId(), term2))); + + final EntityTypePermId searchTest2EntityTypeId = createEntityType(sessionToken, vocabularyPropertyTypeId1, + vocabularyPropertyTypeId2); + final ObjectPermId entity2 = createEntity(sessionToken, "Sample4", searchTest2EntityTypeId, + new HashMap<>(Map.of(vocabularyPropertyTypeId1.getPermId(), term1))); + + try + { + final AbstractEntitySearchCriteria<?> searchCriteria1 = createSearchCriteria(); + searchCriteria1.withOrOperator(); + searchCriteria1.withVocabularyProperty(searchTest1EntityTypeId.getPermId()).thatEquals(term1); + + final List<? extends IPermIdHolder> entities1 = search(sessionToken, searchCriteria1); + assertEquals(entities1.size(), 1); + assertEquals(entities1.get(0).getPermId(), entity1); + + final AbstractEntitySearchCriteria<?> searchCriteria2 = createSearchCriteria(); + searchCriteria2.withOrOperator(); + searchCriteria2.withVocabularyProperty("WHATEVER").thatEquals(term1); + + final List<? extends IPermIdHolder> entities2 = search(sessionToken, searchCriteria2); + assertEquals(entities2.size(), 0); + } finally + { + final IDeletionId entitiesDeletion = deleteEntities(sessionToken, entity1, entity2); + v3api.confirmDeletions(sessionToken, List.of(entitiesDeletion)); + deleteEntityTypes(sessionToken, searchTest1EntityTypeId, searchTest2EntityTypeId); + deletePropertyTypes(sessionToken, vocabularyPropertyTypeId1, vocabularyPropertyTypeId2); + deleteSampleTypes(sessionToken, propertySampleType); + } + } + @Test public void testSearchWithPropertyMatchingMaterialProperty() { diff --git a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java index 869d77d9eef748f5b8d26907ca20f30531234d3e..47ae164b2c9a1c8d0ff11630dfc3cbaa83515730 100644 --- a/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java +++ b/server-application-server/sourceTest/java/ch/ethz/sis/openbis/systemtest/asapi/v3/AbstractTest.java @@ -136,6 +136,9 @@ import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.Tag; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.create.TagCreation; import ch.ethz.sis.openbis.generic.asapi.v3.dto.tag.id.TagPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.VocabularyTerm; +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.IVocabularyId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.VocabularyPermId; import ch.ethz.sis.openbis.generic.asapi.v3.dto.vocabulary.id.VocabularyTermPermId; import ch.ethz.sis.openbis.generic.asapi.v3.exceptions.NotFetchedException; @@ -1502,6 +1505,18 @@ public class AbstractTest extends SystemTestCase return v3api.createPropertyTypes(sessionToken, Collections.singletonList(creation)).get(0); } + protected PropertyTypePermId createAVocabularyPropertyType(final String sessionToken, + final IVocabularyId vocabularyId, final String code) + { + final PropertyTypeCreation creation = new PropertyTypeCreation(); + creation.setCode(code); + creation.setDataType(DataType.CONTROLLEDVOCABULARY); + creation.setVocabularyId(vocabularyId); + creation.setLabel("label"); + creation.setDescription("description"); + return v3api.createPropertyTypes(sessionToken, Collections.singletonList(creation)).get(0); + } + protected void deletePropertyTypes(final String sessionToken, final IPropertyTypeId... propertyTypeIds) { final PropertyTypeDeletionOptions deletionOptions = new PropertyTypeDeletionOptions(); @@ -1538,6 +1553,22 @@ public class AbstractTest extends SystemTestCase return v3api.createSampleTypes(sessionToken, Arrays.asList(creation)).get(0); } + protected VocabularyPermId createVocabulary(final String sessionToken, final String code, final String... terms) + { + final VocabularyCreation vocabularyCreation = new VocabularyCreation(); + vocabularyCreation.setCode(code); + + final List<VocabularyTermCreation> termList = Arrays.stream(terms).map(termString -> + { + final VocabularyTermCreation creation = new VocabularyTermCreation(); + creation.setCode(termString); + return creation; + }).collect(Collectors.toList()); + vocabularyCreation.setTerms(termList); + + return v3api.createVocabularies(sessionToken, List.of(vocabularyCreation)).get(0); + } + protected void deleteSampleTypes(final String sessionToken, final IEntityTypeId... entityTypeIds) { final SampleTypeDeletionOptions deletionOptions = new SampleTypeDeletionOptions();