1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.platform.wiki.creationjob.internal

File ExtensionInstallerTest.java

 

Code metrics

0
20
3
1
103
66
4
0.2
6.67
3
1.33

Classes

Class Line # Actions
ExtensionInstallerTest 49 20 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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.platform.wiki.creationjob.internal;
21   
22    import java.util.Arrays;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.mockito.invocation.InvocationOnMock;
27    import org.mockito.stubbing.Answer;
28    import org.xwiki.component.manager.ComponentLookupException;
29    import org.xwiki.extension.ExtensionId;
30    import org.xwiki.extension.job.InstallRequest;
31    import org.xwiki.extension.job.internal.InstallJob;
32    import org.xwiki.job.Job;
33    import org.xwiki.job.Request;
34    import org.xwiki.model.reference.DocumentReference;
35    import org.xwiki.platform.wiki.creationjob.WikiCreationException;
36    import org.xwiki.test.mockito.MockitoComponentMockingRule;
37   
38    import static org.junit.Assert.assertEquals;
39    import static org.junit.Assert.assertNotNull;
40    import static org.junit.Assert.assertTrue;
41    import static org.mockito.ArgumentMatchers.any;
42    import static org.mockito.Mockito.doAnswer;
43    import static org.mockito.Mockito.mock;
44    import static org.mockito.Mockito.verify;
45   
46    /**
47    * @version $Id: 04fac726c086f5873ec017763db161db33e962ac $
48    */
 
49    public class ExtensionInstallerTest
50    {
51    @Rule
52    public MockitoComponentMockingRule<ExtensionInstaller> mocker =
53    new MockitoComponentMockingRule<>(ExtensionInstaller.class);
54   
 
55  1 toggle @Test
56    public void installExtension() throws Exception
57    {
58    // Mocks
59  1 InstallJob installJob = mock(InstallJob.class);
60  1 mocker.registerComponent(Job.class, InstallJob.JOBTYPE, installJob);
61  1 final InstallRequest[] installRequest = {null};
62   
63  1 doAnswer(new Answer()
64    {
 
65  1 toggle @Override
66    public Object answer(InvocationOnMock invocation) throws Throwable
67    {
68  1 installRequest[0] = (InstallRequest) invocation.getArguments()[0];
69  1 return null;
70    }
71    }).when(installJob).initialize(any(Request.class));
72   
73    // Test
74  1 mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
75   
76    // Verify
77  1 assertNotNull(installRequest[0]);
78  1 assertEquals(Arrays.asList("wiki:wikiId"), installRequest[0].getNamespaces());
79  1 assertEquals(Arrays.asList("wikicreation", "install", "wikiId"), installRequest[0].getId());
80  1 assertEquals(Arrays.asList(new ExtensionId("extensionId", "version")), installRequest[0].getExtensions());
81  1 assertEquals(new DocumentReference("xwiki", "XWiki", "superadmin"),
82    installRequest[0].getProperty("user.reference"));
83  1 verify(installJob).run();
84    }
85   
 
86  1 toggle @Test
87    public void installExtensionWithException() throws Exception
88    {
89    // Test
90  1 WikiCreationException caughtException = null;
91  1 try {
92  1 mocker.getComponentUnderTest().installExtension("wikiId", new ExtensionId("extensionId", "version"));
93    } catch (WikiCreationException e) {
94  1 caughtException = e;
95    }
96   
97    // Verify
98  1 assertNotNull(caughtException);
99  1 assertEquals("Failed to install the extension [extensionId-version] on the wiki [wikiId].",
100    caughtException.getMessage());
101  1 assertTrue(caughtException.getCause() instanceof ComponentLookupException);
102    }
103    }