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

File WikiCopiedEventListenerTest.java

 

Code metrics

0
17
3
1
104
67
3
0.18
5.67
3
1

Classes

Class Line # Actions
WikiCopiedEventListenerTest 45 17 0% 3 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   
44    @AllComponents
 
45    public class WikiCopiedEventListenerTest
46    {
47    @Rule
48    public MockitoRepositoryUtilsRule repositoryUtil = new MockitoRepositoryUtilsRule();
49   
50    private DefaultLocalExtensionRepository localExtensionRepository;
51   
52    private InstalledExtensionRepository installedExtensionRepository;
53   
54    private ObservationManager observation;
55   
56    private LocalExtension localExtension1;
57   
58    private LocalExtension localExtensionDependency1;
59   
 
60  1 toggle @Before
61    public void setUp() throws Exception
62    {
63  1 this.localExtensionRepository =
64    this.repositoryUtil.getComponentManager().getInstance(LocalExtensionRepository.class);
65  1 this.installedExtensionRepository =
66    this.repositoryUtil.getComponentManager().getInstance(InstalledExtensionRepository.class);
67   
68  1 this.observation = this.repositoryUtil.getComponentManager().getInstance(ObservationManager.class);
69   
70    // Extensions
71   
72  1 EmptyExtension extension = new EmptyExtension(new ExtensionId("id", "version"), "xar");
73  1 EmptyExtension extensionDependency = new EmptyExtension(new ExtensionId("dependency", "version"), "xar");
74  1 extension.addDependency(new DefaultExtensionDependency(extensionDependency.getId().getId(),
75    new DefaultVersionConstraint(null, extensionDependency.getId().getVersion())));
76   
77  1 this.localExtensionDependency1 = this.localExtensionRepository.storeExtension(extensionDependency);
78  1 this.localExtension1 = this.localExtensionRepository.storeExtension(extension);
79    }
80   
 
81  1 toggle @AfterComponent
82    public void addContextualAuthorizationManagerComponent() throws Exception
83    {
84  1 this.repositoryUtil.getComponentManager().registerMockComponent(ContextualAuthorizationManager.class);
85  1 this.repositoryUtil.getComponentManager().registerMockComponent(AuthorizationManager.class);
86    }
87   
 
88  1 toggle @Test
89    public void testCopyOneExtension() throws InstallException
90    {
91  1 InstalledExtension extensionDependency1 =
92    this.installedExtensionRepository.installExtension(this.localExtensionDependency1, "wiki:source", false);
93  1 InstalledExtension extension1 =
94    this.installedExtensionRepository.installExtension(this.localExtension1, "wiki:source", false);
95   
96  1 Assert.assertFalse(extension1.isInstalled("wiki:target"));
97  1 Assert.assertFalse(extensionDependency1.isInstalled("wiki:target"));
98   
99  1 this.observation.notify(new WikiCopiedEvent("source", "target"), null, null);
100   
101  1 Assert.assertTrue(extension1.isInstalled("wiki:target"));
102  1 Assert.assertTrue(extensionDependency1.isInstalled("wiki:target"));
103    }
104    }