|
20 | 20 | import org.apache.commons.lang3.RandomStringUtils;
|
21 | 21 | import org.apache.commons.lang3.StringUtils;
|
22 | 22 | import org.apache.commons.lang3.time.StopWatch;
|
| 23 | +import org.junit.Assert; |
23 | 24 | import org.junit.Test;
|
24 | 25 | import org.junit.experimental.categories.Category;
|
25 | 26 | import org.opencb.biodata.models.common.Status;
|
26 | 27 | import org.opencb.biodata.models.pedigree.IndividualProperty;
|
27 |
| -import org.opencb.commons.datastore.core.DataResult; |
28 |
| -import org.opencb.commons.datastore.core.ObjectMap; |
29 |
| -import org.opencb.commons.datastore.core.Query; |
30 |
| -import org.opencb.commons.datastore.core.QueryOptions; |
| 28 | +import org.opencb.commons.datastore.core.*; |
31 | 29 | import org.opencb.opencga.TestParamConstants;
|
32 | 30 | import org.opencb.opencga.catalog.auth.authorization.AuthorizationManager;
|
33 | 31 | import org.opencb.opencga.catalog.db.api.*;
|
@@ -970,6 +968,49 @@ public void visitJob() throws CatalogException {
|
970 | 968 | assertEquals(1, catalogManager.getJobManager().count(studyFqn, query, ownerToken).getNumMatches());
|
971 | 969 | }
|
972 | 970 |
|
| 971 | + @Test |
| 972 | + public void testJobsFacet() throws CatalogException { |
| 973 | + Query query = new Query(); |
| 974 | + String studyId = catalogManager.getStudyManager().searchInOrganization(organizationId, query, null, ownerToken).first().getId(); |
| 975 | + |
| 976 | +// catalogManager.getJobManager().create(studyId, new Job().setId("myErrorJob"), null, ownerToken); |
| 977 | +// |
| 978 | +// QueryOptions options = new QueryOptions(QueryOptions.COUNT, true); |
| 979 | +// DataResult<Job> allJobs = catalogManager.getJobManager().search(studyId, null, options, ownerToken); |
| 980 | + |
| 981 | + int numJobs = 88; |
| 982 | + for (int i = numJobs; i > 0; i--) { |
| 983 | + ToolInfo toolInfo = new ToolInfo(); |
| 984 | + toolInfo.setId("tool-" + (i % 5) + Integer.valueOf(RandomStringUtils.randomNumeric(1))); |
| 985 | + Job job = new Job().setId("myJob-" + i).setTool(toolInfo); |
| 986 | + catalogManager.getJobManager().create(studyId, job, null, ownerToken); |
| 987 | + } |
| 988 | + |
| 989 | + Map<String, Integer> toolIdCounter = new HashMap<>(); |
| 990 | + QueryOptions options = new QueryOptions(QueryOptions.COUNT, true); |
| 991 | + DataResult<Job> allJobs = catalogManager.getJobManager().search(studyId, null, options, ownerToken); |
| 992 | + for (Job job : allJobs.getResults()) { |
| 993 | + String toolId = job.getTool().getId(); |
| 994 | + if (!toolIdCounter.containsKey(toolId)) { |
| 995 | + toolIdCounter.put(toolId, 0); |
| 996 | + } |
| 997 | + toolIdCounter.put(toolId, 1 + toolIdCounter.get(toolId)); |
| 998 | + } |
| 999 | + |
| 1000 | + for (Map.Entry<String, Integer> entry : toolIdCounter.entrySet()) { |
| 1001 | + System.out.println(entry.getKey() + " --> " + entry.getValue()); |
| 1002 | + } |
| 1003 | + |
| 1004 | + String field = "tool.id"; |
| 1005 | + FacetField facetField = catalogManager.getJobManager().facet(studyId, new Query(), field, ownerToken).first(); |
| 1006 | + Assert.assertEquals(field, facetField.getName()); |
| 1007 | + Assert.assertEquals(numJobs, facetField.getCount(), 0.001); |
| 1008 | + for (FacetField.Bucket bucket : facetField.getBuckets()) { |
| 1009 | + Assert.assertTrue(toolIdCounter.containsKey(bucket.getValue())); |
| 1010 | + Assert.assertEquals(toolIdCounter.get(bucket.getValue()), bucket.getCount(), 0.001); |
| 1011 | + } |
| 1012 | + } |
| 1013 | + |
973 | 1014 | /**
|
974 | 1015 | * VariableSet methods ***************************
|
975 | 1016 | */
|
|
0 commit comments