Revision: 3494
http://openutils.svn.sourceforge.net/openutils/?rev=3494&view=rev
Author: carlocolombo
Date: 2011-05-24 12:25:14 +0000 (Tue, 24 May 2011)
Log Message:
-----------
failing test for offset with maxResult different from pagesize
Added Paths:
-----------
trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/CorrectElementsWithoutMaxResults.java
Added: trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/CorrectElementsWithoutMaxResults.java
===================================================================
--- trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/CorrectElementsWithoutMaxResults.java (rev 0)
+++ trunk/openutils-mgnlcriteria/src/test/java/net/sourceforge/openutils/mgnlcriteria/advanced/impl/CorrectElementsWithoutMaxResults.java 2011-05-24 12:25:14 UTC (rev 3494)
@@ -0,0 +1,156 @@
+/**
+ *
+ */
+package net.sourceforge.openutils.mgnlcriteria.advanced.impl;
+
+import info.magnolia.cms.beans.config.ContentRepository;
+import info.magnolia.cms.core.ItemType;
+import info.magnolia.context.MgnlContext;
+import it.openutils.mgnlutils.test.RepositoryTestConfiguration;
+import it.openutils.mgnlutils.test.TestNgRepositoryTestcase;
+import net.sourceforge.openutils.mgnlcriteria.jcr.query.Criteria;
+import net.sourceforge.openutils.mgnlcriteria.jcr.query.JCRCriteriaFactory;
+import net.sourceforge.openutils.mgnlcriteria.jcr.query.criterion.Restrictions;
+import net.sourceforge.openutils.mgnlcriteria.tests.CriteriaTestUtils;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+/**
+ * @author carlo
+ */
+@RepositoryTestConfiguration(jackrabbitRepositoryConfig = "/crit-repository/jackrabbit-test-configuration.xml", repositoryConfig = "/crit-repository/test-repositories.xml", bootstrapFiles = "/crit-bootstrap/website.pets.xml")
+public class CorrectElementsWithoutMaxResults extends TestNgRepositoryTestcase
+{
+
+ @Override
+ @BeforeClass
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ // Nodes in this workspace:
+ // - pets (title=Pets)
+ // --- cats (title=Cats)
+ // ----- 1 (title=Leo, petType=cat, birthDate=2000-09-07)
+ // ----- 7 (title=Samantha, petType=cat, birthDate=1995-09-04)
+ // ----- 8 (title=Max, petType=cat, birthDate=1995-09-04)
+ // ----- 13 (title=Sly, petType=cat, birthDate=2002-06-08)
+ // --- dogs (title=Dogs)
+ // ----- 3 (title=Rosy, petType=dog, birthDate=2001-04-17)
+ // ----- 4 (title=Jewel, petType=dog, birthDate=2000-03-07)
+ // ----- 10 (title=Mulligan, petType=dog, birthDate=1997-02-24)
+ // ----- 12 (title=Lucky, petType=dog, birthDate=2000-06-24)
+ // --- lizards (title=Lizards)
+ // ----- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30)
+ // --- snakes (title=Snakes)
+ // ----- 6 (title=George, petType=snake, birthDate=2000-01-20)
+ // --- birds (title=Birds)
+ // ----- 9 (title=Lucky, petType=bird, birthDate=1999-08-06)
+ // ----- 11 (title=Freddy, petType=bird, birthDate=2000-03-09)
+ // --- hamsters (title=Hamsters)
+ // ----- 2 (title=Basil, petType=hamster, birthDate=2002-08-06)
+ // ************************************************************
+ // total 13 pets
+ MgnlContext.getHierarchyManager(ContentRepository.WEBSITE).save();
+ }
+
+ @Test
+ public void otherResultWithMaxResultAsMaxInt() throws Exception
+ {
+ Criteria criteria = getAllPetWithDocumentOrder();
+
+ criteria.setFirstResult(9);
+ criteria.setMaxResults(Integer.MAX_VALUE);
+
+ CriteriaTestUtils.assertNumOfResults(
+ 4,
+ CriteriaTestUtils.collectCollectionFromResult(criteria.execute()),
+ "all pets, offset:9");
+ assertMissing4MissingPets(criteria);
+ }
+
+ @Test
+ public void otherResultWithMaxResultAsOffset() throws Exception
+ {
+ Criteria criteria = getAllPetWithDocumentOrder();
+
+ criteria.setFirstResult(9);
+ criteria.setMaxResults(9);
+
+ CriteriaTestUtils.assertNumOfResults(
+ 4,
+ CriteriaTestUtils.collectCollectionFromResult(criteria.execute()),
+ "all pets, offset:9");
+ assertMissing4MissingPets(criteria);
+ }
+
+ @Test
+ public void otherResultWithMaxResultAsLesserThanOffset() throws Exception
+ {
+ Criteria criteria = getAllPetWithDocumentOrder();
+
+ criteria.setFirstResult(9);
+ criteria.setMaxResults(8);
+
+ CriteriaTestUtils.assertNumOfResults(
+ 4,
+ CriteriaTestUtils.collectCollectionFromResult(criteria.execute()),
+ "all pets, offset:9, maxResult: 8");
+ assertMissing4MissingPets(criteria);
+ }
+
+ @Test
+ public void otherResultWithMaxResultAsGreaterThanOffset() throws Exception
+ {
+ Criteria criteria = getAllPetWithDocumentOrder();
+
+ criteria.setFirstResult(9);
+ criteria.setMaxResults(10);
+
+ CriteriaTestUtils.assertNumOfResults(
+ 4,
+ CriteriaTestUtils.collectCollectionFromResult(criteria.execute()),
+ "all pets, offset:9, maxResult: 10");
+ assertMissing4MissingPets(criteria);
+ }
+
+ /**
+ * Control test
+ * @throws Exception
+ */
+ @Test
+ public void otherResultWithPagination() throws Exception
+ {
+ Criteria criteria = getAllPetWithDocumentOrder();
+ criteria.setPaging(9, 2);
+ CriteriaTestUtils.assertNumOfResults(
+ 4,
+ CriteriaTestUtils.collectCollectionFromResult(criteria.execute()),
+ "all pets, 2nd page, pagesize: 9");
+ assertMissing4MissingPets(criteria);
+ }
+
+ /**
+ * @param criteria
+ */
+ private void assertMissing4MissingPets(Criteria criteria)
+ {
+ CriteriaTestUtils.assertSortedResults(new String[]{"George", "Lucky", "Freddy", "Basil" }, CriteriaTestUtils
+ .collectCollectionFromResult(criteria.execute()), "all missing pets, sorted");
+ }
+
+ /**
+ * @return
+ */
+ private Criteria getAllPetWithDocumentOrder()
+ {
+ return JCRCriteriaFactory
+ .createCriteria()
+ .setWorkspace(ContentRepository.WEBSITE)
+ .setBasePath("/jcr:root/pets/*/*")
+ .add(Restrictions.eq("@jcr:primaryType", ItemType.CONTENT.getSystemName()))
+ .setForcePagingWithDocumentOrder(true);
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|