List of usage examples for org.springframework.data.domain Page getNumberOfElements
int getNumberOfElements();
From source file:com.netflix.genie.core.jpa.services.JpaClusterServiceImplIntegrationTests.java
/** * Test the get clusters method.// www.ja va 2s . c o m */ @Test public void testGetClustersByMinUpdateTime() { final Calendar time = Calendar.getInstance(); time.clear(); time.set(2014, Calendar.JULY, 9, 2, 58, 59); final Page<Cluster> clusters = this.service.getClusters(null, null, null, time.getTime(), null, PAGE); Assert.assertEquals(1, clusters.getNumberOfElements()); Assert.assertEquals(CLUSTER_2_ID, clusters.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaClusterServiceImplIntegrationTests.java
/** * Test the get clusters method.//from w w w . j a va2 s.c o m */ @Test public void testGetClustersByMaxUpdateTime() { final Calendar time = Calendar.getInstance(); time.clear(); time.set(2014, Calendar.JULY, 8, 3, 0, 0); final Page<Cluster> clusters = this.service.getClusters(null, null, null, null, time.getTime(), PAGE); Assert.assertEquals(1, clusters.getNumberOfElements()); Assert.assertEquals(CLUSTER_1_ID, clusters.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaClusterServiceImplIntegrationTests.java
/** * Test the get clusters method with ascending sort. *///from w w w .ja v a 2s . com @Test public void testGetClustersAscending() { final Pageable ascendingPage = new PageRequest(0, 10, Sort.Direction.ASC, "updated"); //Default to order by Updated final Page<Cluster> clusters = this.service.getClusters(null, null, null, null, null, ascendingPage); Assert.assertEquals(2, clusters.getNumberOfElements()); Assert.assertEquals(CLUSTER_1_ID, clusters.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(CLUSTER_2_ID, clusters.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaClusterServiceImplIntegrationTests.java
/** * Test the get clusters method.//w ww. j a v a 2 s . com */ @Test public void testGetClustersByTags() { final Set<String> tags = Sets.newHashSet("prod"); Page<Cluster> clusters = this.service.getClusters(null, null, tags, null, null, PAGE); Assert.assertEquals(1, clusters.getNumberOfElements()); Assert.assertEquals(CLUSTER_1_ID, clusters.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); tags.clear(); tags.add("hive"); clusters = this.service.getClusters(null, null, tags, null, null, PAGE); Assert.assertEquals(2, clusters.getNumberOfElements()); Assert.assertEquals(CLUSTER_2_ID, clusters.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(CLUSTER_1_ID, clusters.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); tags.add("somethingThatWouldNeverReallyExist"); clusters = this.service.getClusters(null, null, tags, null, null, PAGE); Assert.assertTrue(clusters.getContent().isEmpty()); tags.clear(); clusters = this.service.getClusters(null, null, tags, null, null, PAGE); Assert.assertEquals(2, clusters.getNumberOfElements()); Assert.assertEquals(CLUSTER_2_ID, clusters.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(CLUSTER_1_ID, clusters.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaApplicationServiceImplIntegrationTests.java
/** * Test the get applications method order by a collection field should return the order by default value (updated). *///from w ww .j a v a2s . c o m @Test @Ignore public void testGetClustersOrderBysCollectionField() { final Pageable orderByTagsPage = new PageRequest(0, 10, Sort.Direction.DESC, "tags"); final Page<Application> applications = this.appService.getApplications(null, null, null, null, null, orderByTagsPage); Assert.assertThat(applications.getContent().toString(), Matchers.is("blahs")); Assert.assertEquals(3, applications.getNumberOfElements()); Assert.assertEquals(APP_3_ID, applications.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_2_ID, applications.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(APP_1_ID, applications.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java
/** * Test the get commands method with descending sort. *//*from www . j ava 2 s. co m*/ @Test public void testGetClustersDescending() { //Default to order by Updated final Page<Command> commands = this.service.getCommands(null, null, null, null, PAGE); Assert.assertEquals(3, commands.getNumberOfElements()); Assert.assertEquals(COMMAND_2_ID, commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(COMMAND_3_ID, commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(COMMAND_1_ID, commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java
/** * Test the get commands method order by name. *//*from www.j a v a 2 s . c o m*/ @Test public void testGetClustersOrderBysName() { final Pageable name = new PageRequest(0, 10, Sort.Direction.DESC, "name"); final Page<Command> commands = this.service.getCommands(null, null, null, null, name); Assert.assertEquals(3, commands.getNumberOfElements()); Assert.assertEquals(COMMAND_1_ID, commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(COMMAND_3_ID, commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(COMMAND_2_ID, commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java
/** * Test the get commands method order by a collection field should return the order by default value (updated). *///from w w w. j a va 2 s. c om @Ignore @Test public void testGetClustersOrderBysCollectionField() { final Pageable tags = new PageRequest(0, 10, Sort.Direction.DESC, "tags"); final Page<Command> commands = this.service.getCommands(null, null, null, null, tags); Assert.assertEquals(3, commands.getNumberOfElements()); Assert.assertEquals(COMMAND_2_ID, commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(COMMAND_3_ID, commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(COMMAND_1_ID, commands.getContent().get(2).getId().orElseThrow(IllegalArgumentException::new)); }
From source file:de.hska.ld.content.controller.DocumentController.java
/** * Fetches a tags page for a specifc document. * <p>//from ww w. jav a 2 s . co m * <pre> * <b>Required roles:</b> ROLE_USER * <b>Path:</b> GET /api/documents/{documentId}/tags?page-number=0&page-size=10&sort-direction=DESC&sort-property=createdAt * </pre> * * @param documentId the document id of the document the tag shall be fetched for. * @return <b>200 OK</b> the requested tags page * <b>404 NOT FOUND</b> if there is no tag present */ @Secured(Core.ROLE_USER) @RequestMapping(method = RequestMethod.GET, value = "/{documentId}/tags") @Transactional(readOnly = true) public Callable getTagsPage(@PathVariable Long documentId, @RequestParam(value = "page-number", defaultValue = "0") Integer pageNumber, @RequestParam(value = "page-size", defaultValue = "10") Integer pageSize, @RequestParam(value = "sort-direction", defaultValue = "DESC") String sortDirection, @RequestParam(value = "sort-property", defaultValue = "createdAt") String sortProperty) { return () -> { Page<Tag> tagsPage = documentService.getDocumentTagsPage(documentId, pageNumber, pageSize, sortDirection, sortProperty); if (tagsPage != null && tagsPage.getNumberOfElements() > 0) { return new ResponseEntity<>(tagsPage, HttpStatus.OK); } else { throw new NotFoundException(); } }; }
From source file:com.netflix.genie.core.jpa.services.JpaCommandServiceImplIntegrationTests.java
/** * Test the get commands method./*w w w. j a va 2s . co m*/ */ @Test public void testGetCommandsByStatuses() { final Set<CommandStatus> statuses = Sets.newHashSet(CommandStatus.INACTIVE, CommandStatus.DEPRECATED); final Page<Command> commands = this.service.getCommands(null, null, statuses, null, PAGE); Assert.assertEquals(2, commands.getNumberOfElements()); Assert.assertEquals(COMMAND_2_ID, commands.getContent().get(0).getId().orElseThrow(IllegalArgumentException::new)); Assert.assertEquals(COMMAND_3_ID, commands.getContent().get(1).getId().orElseThrow(IllegalArgumentException::new)); }