Index: xwiki-platform-core/xwiki-core/src/test/java/com/xpn/xwiki/criteria/impl/PeriodFactoryTest.java =================================================================== --- xwiki-platform-core/xwiki-core/src/test/java/com/xpn/xwiki/criteria/impl/PeriodFactoryTest.java (revision 0) +++ xwiki-platform-core/xwiki-core/src/test/java/com/xpn/xwiki/criteria/impl/PeriodFactoryTest.java (revision 0) @@ -0,0 +1,69 @@ +/* + * See the NOTICE file distributed with this work for additional + * information regarding copyright ownership. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package com.xpn.xwiki.criteria.impl; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import junit.framework.TestCase; + +import com.xpn.xwiki.stats.impl.xwiki.XWikiStatsReader; + +/** + * Unit tests for {@link PeriodFactory}. + */ +public class PeriodFactoryTest extends TestCase +{ + /** + * Tests if the start code of a day period is strictly less than its end code. This is needed + * because the {@link XWikiStatsReader} retrieves the statistics that have been recorded between + * the start code, including it, and the end code, excluding it. + */ + public void testDayPeriodStartEndCode() + { + Period day = PeriodFactory.createDayPeriod(System.currentTimeMillis()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + try { + long start = sdf.parse(String.valueOf(day.getStartCode())).getTime(); + long end = sdf.parse(String.valueOf(day.getEndCode())).getTime(); + assertTrue("Start code must be less than end code", start < end); + } catch (ParseException e) { + assertTrue(e.getMessage(), false); + } + } + + /** + * Tests if the start code of a month period is strictly less than its end code. This is needed + * because the {@link XWikiStatsReader} retrieves the statistics that have been recorded between + * the start code, including it, and the end code, excluding it. + */ + public void testMonthPeriodStartEndCode() + { + Period month = PeriodFactory.createMonthPeriod(System.currentTimeMillis()); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); + try { + long start = sdf.parse(String.valueOf(month.getStartCode())).getTime(); + long end = sdf.parse(String.valueOf(month.getEndCode())).getTime(); + assertTrue("Start code must be less than end code", start < end); + } catch (ParseException e) { + assertTrue(e.getMessage(), false); + } + } +} Index: xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/stats/impl/xwiki/XWikiStatsReader.java =================================================================== --- xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/stats/impl/xwiki/XWikiStatsReader.java (revision 9580) +++ xwiki-platform-core/xwiki-core/src/main/java/com/xpn/xwiki/stats/impl/xwiki/XWikiStatsReader.java (working copy) @@ -142,7 +142,7 @@ * * @param action the action for which to retrieve statistics. * @param scope the set of documents to consider. - * @param period the period of time. + * @param period the period of time, including its start date but excluding its end date. * @param step the step used for sampling the period. * @param context the XWiki context. * @return a map of (date, actionCount) pairs. @@ -183,7 +183,7 @@ * or "download". If the action is "view" then the documents are ordered by the * number of times they have been viewed so far. * @param scope the set of documents for which to retrieve statistics. - * @param period the period of time. + * @param period the period of time, including its start date but excluding its end date. * @param range the sub-range to return from the entire result set. Use this parameter for * pagination. * @param context the XWiki context. @@ -205,7 +205,7 @@ try { String query = MessageFormat.format( "select name, sum(pageViews) from DocumentStats" - + " where {0} and action=? and ? <= period and period <= ? group by name order" + + " where {0} and action=? and ? <= period and period < ? group by name order" + " by sum(pageViews) {1}", nameFilter, sortOrder); paramList.add(action); @@ -260,7 +260,7 @@ * * @param domain the domain used for filtering the results. * @param scope the scope of referred documents for which to retrieve statistics. - * @param period the period of time. + * @param period the period of time, including its start date but excluding its end date. * @param range the sub-range to return from the entire result set. Use this parameter for * pagination. * @param context the XWiki context. @@ -281,7 +281,7 @@ try { String query = MessageFormat.format( "select name, sum(pageViews) from RefererStats" - + " where {0} and referer like ? and ? <= period and period <= ? group by name" + + " where {0} and referer like ? and ? <= period and period < ? group by name" + " order by sum(pageViews) {1}", nameFilter, sortOrder); paramList.add(getHqlValidDomain(domain)); @@ -309,7 +309,7 @@ * @param domain the domain for which to retrieve statistics. To retrieve statistics for all * domains use the empty string. * @param scope the scope of referred documents to use for filtering the results. - * @param period the period of time. + * @param period the period of time, including its start date but excluding its end date. * @param range the sub-range to return from the entire result set. Use this parameter for * pagination. * @param context the XWiki context. @@ -330,7 +330,7 @@ try { String query = MessageFormat.format("select referer, sum(pageViews) from RefererStats" - + " where {0} and referer like ? and ? <= period and period <= ?" + + " where {0} and referer like ? and ? <= period and period < ?" + " group by referer order by sum(pageViews) {1}", nameFilter, sortOrder); paramList.add(getHqlValidDomain(domain)); @@ -384,7 +384,7 @@ * @param action the action the results should be ordered by. It can be one of: "view", "save" * or "download". If the action is "view" then the visitors are ordered by the number * of pages they have viewed so far. - * @param period the period of time. + * @param period the period of time, including its start date but excluding its end date. * @param range the sub-range to return from the entire result set. Use this parameter for * pagination. * @param context the XWiki context.