1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.job.history.internal

File DefaultExtensionJobHistoryTest.java

 

Code metrics

0
14
2
1
93
52
2
0.14
7
2
1

Classes

Class Line # Actions
DefaultExtensionJobHistoryTest 47 14 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.job.history.internal;
21   
22    import java.util.Arrays;
23    import java.util.Collections;
24    import java.util.Date;
25   
26    import org.apache.commons.collections4.Predicate;
27    import org.apache.commons.collections4.PredicateUtils;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.junit.rules.TemporaryFolder;
31    import org.xwiki.extension.job.InstallRequest;
32    import org.xwiki.extension.job.UninstallRequest;
33    import org.xwiki.extension.job.history.ExtensionJobHistory;
34    import org.xwiki.extension.job.history.ExtensionJobHistoryConfiguration;
35    import org.xwiki.extension.job.history.ExtensionJobHistoryRecord;
36    import org.xwiki.test.mockito.MockitoComponentMockingRule;
37   
38    import static org.junit.Assert.*;
39    import static org.mockito.Mockito.*;
40   
41    /**
42    * Unit tests for {@link DefaultExtensionJobHistory}.
43    *
44    * @version $Id: f740d4ee2588a2760080200208f3abe4f985d620 $
45    * @since 7.1RC1
46    */
 
47    public class DefaultExtensionJobHistoryTest
48    {
49    @Rule
50    public MockitoComponentMockingRule<ExtensionJobHistory> mocker =
51    new MockitoComponentMockingRule<ExtensionJobHistory>(DefaultExtensionJobHistory.class);
52   
53    @Rule
54    public TemporaryFolder testFolder = new TemporaryFolder();
55   
 
56  1 toggle @Test
57    public void addGetRecords() throws Exception
58    {
59  1 ExtensionJobHistoryConfiguration config = this.mocker.getInstance(ExtensionJobHistoryConfiguration.class);
60  1 when(config.getStorage()).thenReturn(testFolder.getRoot());
61   
62  1 long now = new Date().getTime();
63  1 ExtensionJobHistoryRecord firstRecord =
64    new ExtensionJobHistoryRecord("install", new InstallRequest(), null, null, new Date(now - 7000));
65  1 ExtensionJobHistoryRecord secondRecord =
66    new ExtensionJobHistoryRecord("uninstall", new UninstallRequest(), null, null, new Date(now + 4000));
67   
68  1 ExtensionJobHistory history = this.mocker.getComponentUnderTest();
69  1 history.addRecord(firstRecord);
70  1 history.addRecord(secondRecord);
71   
72    // Get all records.
73  1 Predicate<ExtensionJobHistoryRecord> all =
74    PredicateUtils.allPredicate(Collections.<Predicate<ExtensionJobHistoryRecord>>emptyList());
75  1 assertEquals(Arrays.asList(secondRecord, firstRecord), history.getRecords(all, null, -1));
76   
77    // Limit the number of returned records.
78  1 assertEquals(Arrays.asList(secondRecord), history.getRecords(all, null, 1));
79   
80    // Get records from offset.
81  1 assertEquals(Arrays.asList(firstRecord), history.getRecords(all, secondRecord.getId(), -1));
82   
83    // Filter the records by job type.
84  1 assertEquals(Arrays.asList(firstRecord), history.getRecords(new Predicate<ExtensionJobHistoryRecord>()
85    {
 
86  2 toggle @Override
87    public boolean evaluate(ExtensionJobHistoryRecord record)
88    {
89  2 return "install".equals(record.getJobType());
90    }
91    }, null, -1));
92    }
93    }