Clover icon

Magnolia Imaging Module 3.4.2-SUPPORT-10161

  1. Project Clover database Tue Jul 16 2019 23:33:19 EEST
  2. Package info.magnolia.imaging

File AbstractRepositoryTestCase.java

 

Coverage histogram

../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

0
19
7
1
120
71
7
0.37
2.71
7
1

Classes

Class Line # Actions
AbstractRepositoryTestCase 63 19 0% 7 10
0.6153846461.5%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2009-2018 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.imaging;
35   
36    import static org.mockito.Mockito.*;
37    import info.magnolia.audit.AuditLoggingManager;
38    import info.magnolia.context.SystemContext;
39    import info.magnolia.imaging.operations.load.DefaultImageIOImageDecoder;
40    import info.magnolia.imaging.operations.load.ImageDecoder;
41    import info.magnolia.module.ModuleManagementException;
42    import info.magnolia.module.ModuleManager;
43    import info.magnolia.module.ModuleManagerImpl;
44    import info.magnolia.module.ModuleRegistry;
45    import info.magnolia.module.model.ModuleDefinition;
46    import info.magnolia.module.model.reader.ModuleDefinitionReader;
47    import info.magnolia.repository.RepositoryManager;
48    import info.magnolia.test.ComponentsTestUtil;
49    import info.magnolia.test.RepositoryTestCase;
50    import info.magnolia.test.mock.MockContext;
51    import info.magnolia.test.mock.MockRepositoryManager;
52   
53    import java.io.IOException;
54    import java.io.Reader;
55    import java.util.ArrayList;
56    import java.util.HashMap;
57    import java.util.List;
58    import java.util.Map;
59   
60    import org.junit.After;
61    import org.junit.Before;
62   
 
63    public abstract class AbstractRepositoryTestCase extends RepositoryTestCase {
64   
 
65  20 toggle @Override
66    @Before
67    public void setUp() throws Exception {
68  20 super.setUp();
69  20 ComponentsTestUtil.setInstance(AuditLoggingManager.class, new AuditLoggingManager());
70    // this is set via the module descriptor (imaging.xml)
71  20 ComponentsTestUtil.setImplementation(ImageDecoder.class, DefaultImageIOImageDecoder.class);
72   
73    }
74   
 
75  20 toggle @Override
76    @After
77    public void tearDown() throws Exception {
78    // super tearDown needs a Ctx so we have to call it prior to resetting MgnlContext instance
79  20 super.tearDown();
80  20 ComponentsTestUtil.clear();
81    }
82   
83    // TODO - this is an ugly hack to workaround MAGNOLIA-2593 - we should review RepositoryTestCase
 
84  20 toggle @Override
85    protected void initDefaultImplementations() throws IOException, ModuleManagementException {
86    //MgnlTestCase clears factory before running this method, so we have to instrument factory here rather then in setUp() before calling super.setUp()
87  20 ComponentsTestUtil.setImplementation(SystemContext.class, MockContext.class);
88  20 ComponentsTestUtil.setImplementation(RepositoryManager.class, MockRepositoryManager.class);
89  20 ModuleRegistry registry = mock(ModuleRegistry.class);
90  20 ComponentsTestUtil.setInstance(ModuleRegistry.class, registry);
91   
92  20 final ModuleDefinitionReader fakeReader = new ModuleDefinitionReader() {
 
93  0 toggle @Override
94    public ModuleDefinition read(Reader in) throws ModuleManagementException {
95  0 return null;
96    }
97   
 
98  0 toggle @Override
99    public Map readAll() throws ModuleManagementException {
100  0 Map m = new HashMap();
101  0 m.put("moduleDef", "dummy");
102  0 return m;
103    }
104   
 
105  0 toggle @Override
106    public ModuleDefinition readFromResource(String resourcePath) throws ModuleManagementException {
107  0 return null;
108    }
109    };
110  20 final ModuleManagerImpl fakeModuleManager = new ModuleManagerImpl(null, fakeReader, null, null, null, null) {
 
111  0 toggle @Override
112    public List loadDefinitions() throws ModuleManagementException {
113    // TODO Auto-generated method stub
114  0 return new ArrayList();
115    }
116    };
117  20 ComponentsTestUtil.setInstance(ModuleManager.class, fakeModuleManager);
118  20 super.initDefaultImplementations();
119    }
120    }