1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.xar.internal.handler

File WikiCopiedEventListenerTest.java

 

Code metrics

0
18
4
1
114
75
4
0.22
4.5
4
1

Classes

Class Line # Actions
WikiCopiedEventListenerTest 46 18 0% 4 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.xar.internal.handler;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.bridge.event.WikiCopiedEvent;
27    import org.xwiki.extension.DefaultExtensionDependency;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.InstallException;
30    import org.xwiki.extension.InstalledExtension;
31    import org.xwiki.extension.LocalExtension;
32    import org.xwiki.extension.repository.InstalledExtensionRepository;
33    import org.xwiki.extension.repository.LocalExtensionRepository;
34    import org.xwiki.extension.repository.internal.local.DefaultLocalExtensionRepository;
35    import org.xwiki.extension.test.EmptyExtension;
36    import org.xwiki.extension.test.MockitoRepositoryUtilsRule;
37    import org.xwiki.extension.version.internal.DefaultVersionConstraint;
38    import org.xwiki.observation.ObservationManager;
39    import org.xwiki.security.authorization.AuthorizationManager;
40    import org.xwiki.security.authorization.ContextualAuthorizationManager;
41    import org.xwiki.test.annotation.AfterComponent;
42    import org.xwiki.test.annotation.AllComponents;
43    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
44   
45    @AllComponents
 
46    public class WikiCopiedEventListenerTest
47    {
48    @Rule
49    public MockitoRepositoryUtilsRule repositoryUtil = new MockitoRepositoryUtilsRule();
50   
51    private DefaultLocalExtensionRepository localExtensionRepository;
52   
53    private InstalledExtensionRepository installedExtensionRepository;
54   
55    private WikiDescriptorManager wikiDescriptorManager;
56   
57    private ObservationManager observation;
58   
59    private LocalExtension localExtension1;
60   
61    private LocalExtension localExtensionDependency1;
62   
 
63  1 toggle @AfterComponent
64    public void afterComponent() throws Exception
65    {
66  1 this.wikiDescriptorManager =
67    this.repositoryUtil.getComponentManager().registerMockComponent(WikiDescriptorManager.class);
68    }
69   
 
70  1 toggle @Before
71    public void setUp() throws Exception
72    {
73  1 this.localExtensionRepository =
74    this.repositoryUtil.getComponentManager().getInstance(LocalExtensionRepository.class);
75  1 this.installedExtensionRepository =
76    this.repositoryUtil.getComponentManager().getInstance(InstalledExtensionRepository.class);
77   
78  1 this.observation = this.repositoryUtil.getComponentManager().getInstance(ObservationManager.class);
79   
80    // Extensions
81   
82  1 EmptyExtension extension = new EmptyExtension(new ExtensionId("id", "version"), "xar");
83  1 EmptyExtension extensionDependency = new EmptyExtension(new ExtensionId("dependency", "version"), "xar");
84  1 extension.addDependency(new DefaultExtensionDependency(extensionDependency.getId().getId(),
85    new DefaultVersionConstraint(null, extensionDependency.getId().getVersion())));
86   
87  1 this.localExtensionDependency1 = this.localExtensionRepository.storeExtension(extensionDependency);
88  1 this.localExtension1 = this.localExtensionRepository.storeExtension(extension);
89    }
90   
 
91  1 toggle @AfterComponent
92    public void addContextualAuthorizationManagerComponent() throws Exception
93    {
94  1 this.repositoryUtil.getComponentManager().registerMockComponent(ContextualAuthorizationManager.class);
95  1 this.repositoryUtil.getComponentManager().registerMockComponent(AuthorizationManager.class);
96    }
97   
 
98  1 toggle @Test
99    public void testCopyOneExtension() throws InstallException
100    {
101  1 InstalledExtension extensionDependency1 =
102    this.installedExtensionRepository.installExtension(this.localExtensionDependency1, "wiki:source", false);
103  1 InstalledExtension extension1 =
104    this.installedExtensionRepository.installExtension(this.localExtension1, "wiki:source", false);
105   
106  1 Assert.assertFalse(extension1.isInstalled("wiki:target"));
107  1 Assert.assertFalse(extensionDependency1.isInstalled("wiki:target"));
108   
109  1 this.observation.notify(new WikiCopiedEvent("source", "target"), null, null);
110   
111  1 Assert.assertTrue(extension1.isInstalled("wiki:target"));
112  1 Assert.assertTrue(extensionDependency1.isInstalled("wiki:target"));
113    }
114    }