Skip to content

Commit ce85fa0

Browse files
test sort by order
1 parent 49a2410 commit ce85fa0

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

opensilex-core/src/test/java/org/opensilex/core/experiment/factors/api/FactorsAPITest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.fasterxml.jackson.databind.JsonNode;
1111
import com.fasterxml.jackson.databind.ObjectMapper;
1212
import org.junit.Test;
13+
import org.opensilex.core.device.api.DeviceGetDTO;
1314
import org.opensilex.core.experiment.api.ExperimentAPITest;
1415
import org.opensilex.core.experiment.factor.api.*;
1516
import org.opensilex.core.experiment.factor.dal.FactorLevelModel;
@@ -61,6 +62,11 @@ public class FactorsAPITest extends AbstractSecurityIntegrationTest {
6162
"/core/experiments/factors/{uri}/levels"
6263
);
6364

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+
6470
private static int factorCount = 0;
6571

6672
public FactorsAPITest() throws NoSuchMethodException {
@@ -263,7 +269,49 @@ public void testSearch() throws Exception {
263269
// System.out.println(list2.toString());
264270

265271
assertTrue(!list2.isEmpty());
272+
}
266273

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());
267315
}
268316

269317

0 commit comments

Comments
 (0)