|
10 | 10 | import com.fasterxml.jackson.databind.JsonNode; |
11 | 11 | import com.fasterxml.jackson.databind.ObjectMapper; |
12 | 12 | import org.junit.Test; |
| 13 | +import org.opensilex.core.device.api.DeviceGetDTO; |
13 | 14 | import org.opensilex.core.experiment.api.ExperimentAPITest; |
14 | 15 | import org.opensilex.core.experiment.factor.api.*; |
15 | 16 | import org.opensilex.core.experiment.factor.dal.FactorLevelModel; |
@@ -61,6 +62,11 @@ public class FactorsAPITest extends AbstractSecurityIntegrationTest { |
61 | 62 | "/core/experiments/factors/{uri}/levels" |
62 | 63 | ); |
63 | 64 |
|
| 65 | + public final ServiceDescription search = new ServiceDescription( |
| 66 | + FactorAPI.class.getMethod("searchFactors", String.class, String.class, URI.class, URI.class, List.class, int.class, int.class), |
| 67 | + searchPath |
| 68 | + ); |
| 69 | + |
64 | 70 | private static int factorCount = 0; |
65 | 71 |
|
66 | 72 | public FactorsAPITest() throws NoSuchMethodException { |
@@ -263,7 +269,49 @@ public void testSearch() throws Exception { |
263 | 269 | // System.out.println(list2.toString()); |
264 | 270 |
|
265 | 271 | assertTrue(!list2.isEmpty()); |
| 272 | + } |
266 | 273 |
|
| 274 | + @Test |
| 275 | + public void searchSortedByCategorie() throws Exception { |
| 276 | + URI experimentURI = new UserCallBuilder(ExperimentAPITest.create) |
| 277 | + .setBody(ExperimentAPITest.getCreationDTO()) |
| 278 | + .buildAdmin() |
| 279 | + .executeCallAndReturnURI(); |
| 280 | + |
| 281 | + FactorCreationDTO dto1WithCatB = getCreationDTO(experimentURI); |
| 282 | + dto1WithCatB.setUri(URI.create("http://opensilex.org/factor1")); |
| 283 | + dto1WithCatB.setCategory(URI.create("http://opensilex.org/categoryB")); |
| 284 | + |
| 285 | + FactorCreationDTO dto2WithCatA = getCreationDTO(experimentURI); |
| 286 | + dto2WithCatA.setUri(URI.create("http://opensilex.org/factor2")); |
| 287 | + dto2WithCatA.setCategory(URI.create("http://opensilex.org/categoryA")); |
| 288 | + |
| 289 | + new UserCallBuilder(create) |
| 290 | + .setBody(dto1WithCatB) |
| 291 | + .buildAdmin() |
| 292 | + .executeCallAndAssertStatus(Status.CREATED); |
| 293 | + new UserCallBuilder(create) |
| 294 | + .setBody(dto2WithCatA) |
| 295 | + .buildAdmin() |
| 296 | + .executeCallAndAssertStatus(Status.CREATED); |
| 297 | + |
| 298 | + List<FactorDetailsGetDTO> factorsSortedByCategoryAsc = new UserCallBuilder(search) |
| 299 | + .addParam("order_by", "category=asc") |
| 300 | + .buildAdmin() |
| 301 | + .executeCallAndDeserialize(new TypeReference<PaginatedListResponse<FactorDetailsGetDTO>>() {}) |
| 302 | + .getDeserializedResponse() |
| 303 | + .getResult(); |
| 304 | + |
| 305 | + List<FactorDetailsGetDTO> factorsSortedByCategoryDesc = new UserCallBuilder(search) |
| 306 | + .addParam("order_by", "category=desc") |
| 307 | + .buildAdmin() |
| 308 | + .executeCallAndDeserialize(new TypeReference<PaginatedListResponse<FactorDetailsGetDTO>>() {}) |
| 309 | + .getDeserializedResponse() |
| 310 | + .getResult(); |
| 311 | + |
| 312 | + assertEquals("search should have retrieved all factors", 2, factorsSortedByCategoryAsc.size()); |
| 313 | + assertEquals("first factor should be the one with category A when category sort with asc", "http://opensilex.org/categoryA", factorsSortedByCategoryAsc.get(0).getCategory().toString()); |
| 314 | + assertEquals("first factor should be the one with category B when category sort with desc", "http://opensilex.org/categoryB", factorsSortedByCategoryDesc.get(0).getCategory().toString()); |
267 | 315 | } |
268 | 316 |
|
269 | 317 |
|
|
0 commit comments