From 7c036915a8c4f70b64a9e5130ead32effd4dc3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20T=C3=A1rraga=20Gim=C3=A9nez?= Date: Fri, 28 Feb 2025 13:09:19 +0100 Subject: [PATCH] test: add JUnit test, #TASK-7439 --- .../variant/search/VariantSearchTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/search/VariantSearchTest.java b/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/search/VariantSearchTest.java index 17d7d073c5..923d2e2460 100644 --- a/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/search/VariantSearchTest.java +++ b/opencga-storage/opencga-storage-core/src/test/java/org/opencb/opencga/storage/core/variant/search/VariantSearchTest.java @@ -4,6 +4,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -224,6 +225,48 @@ public void testSpecialCharacter() throws Exception { } } + @Test + public void testTypeFacet() throws Exception { + int limit = 500; + + VariantStorageMetadataManager scm = variantStorageEngine.getMetadataManager(); + + solr.configure(variantStorageEngine); + VariantSearchManager variantSearchManager = variantStorageEngine.getVariantSearchManager(); + + System.out.println(smallInputUri.getPath()); + + List variants = getVariants(limit); + List annotatedVariants = annotatedVariants(variants); + + metadataManager.createStudy("s1"); + + String collection = solr.coreName; + variantSearchManager.create(collection); + + variantSearchManager.insert(collection, annotatedVariants); + + QueryOptions queryOptions = new QueryOptions(); + String facet = "type[INDEL,SNV]"; + queryOptions.put(QueryOptions.FACET, facet); + DataResult facetQueryResult = variantSearchManager.facetedQuery(collection, new Query(), queryOptions); + String s = JacksonUtils.getDefaultObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(facetQueryResult); + System.out.println(s); + + FacetField facetField = facetQueryResult.first(); + Assert.assertEquals(499, facetField.getCount()); + Assert.assertEquals(2, facetField.getBuckets().size()); + Assert.assertTrue(facetField.getBuckets().stream().map(FacetField.Bucket::getValue).collect(Collectors.toList()).contains("SNV")); + Assert.assertTrue(facetField.getBuckets().stream().map(FacetField.Bucket::getValue).collect(Collectors.toList()).contains("INDEL")); + for (FacetField.Bucket bucket : facetField.getBuckets()) { + if (bucket.getValue().equals("SNV")) { + Assert.assertEquals(490, bucket.getCount()); + } else if (bucket.getValue().equals("INDEL")) { + Assert.assertEquals(9, bucket.getCount()); + } + } + } + @Test public void testGeneFacet() throws Exception { int limit = 500;