Clover icon

magnolia-module-groovy 2.4.7

  1. Project Clover database Thu Dec 1 2016 10:48:40 CET
  2. Package info.magnolia.module.groovy.rescue

File MgnlGroovyRescueAppTest.java

 

Code metrics

0
27
3
1
112
62
3
0.11
9
3
1

Classes

Class Line # Actions
MgnlGroovyRescueAppTest 65 27 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /**
2    * This file Copyright (c) 2011-2016 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.module.groovy.rescue;
35   
36    import static org.junit.Assert.assertEquals;
37    import static org.mockito.BDDMockito.given;
38    import static org.mockito.Mockito.mock;
39   
40    import info.magnolia.cms.core.SystemProperty;
41    import info.magnolia.cms.i18n.MessagesManager;
42    import info.magnolia.context.MgnlContext;
43    import info.magnolia.event.EventBus;
44    import info.magnolia.i18nsystem.LocaleProvider;
45    import info.magnolia.i18nsystem.SimpleTranslator;
46    import info.magnolia.i18nsystem.TranslationService;
47    import info.magnolia.i18nsystem.TranslationServiceImpl;
48    import info.magnolia.i18nsystem.module.I18nModule;
49    import info.magnolia.objectfactory.Components;
50    import info.magnolia.repository.RepositoryManager;
51    import info.magnolia.resourceloader.ResourceOrigin;
52    import info.magnolia.test.ComponentsTestUtil;
53    import info.magnolia.test.mock.MockComponentProvider;
54   
55    import java.util.Locale;
56   
57    import javax.inject.Provider;
58   
59    import org.junit.After;
60    import org.junit.Before;
61    import org.junit.Test;
62   
63    import com.vaadin.server.VaadinRequest;
64   
 
65    public class MgnlGroovyRescueAppTest {
66   
 
67  1 toggle @Before
68    public void setUp() {
69  1 SystemProperty.clear();
70  1 RepositoryManager repositoryManager = mock(RepositoryManager.class);
71  1 LocaleProvider localeProvider = mock(LocaleProvider.class);
72  1 given(localeProvider.getLocale()).willReturn(Locale.ENGLISH);
73  1 given(localeProvider.get()).willReturn(Locale.ENGLISH);
74   
75  1 MockComponentProvider componentProvider = new MockComponentProvider();
76  1 Provider<I18nModule> provider = mock(Provider.class);
77  1 ResourceOrigin resourceOrigin = mock(ResourceOrigin.class);
78  1 EventBus eventBus = mock(EventBus.class);
79  1 TranslationService translationService = new TranslationServiceImpl(provider, componentProvider, resourceOrigin, eventBus);
80  1 SimpleTranslator simpleTranslator = new SimpleTranslator(translationService, localeProvider);
81   
82  1 MessagesManager messagesManager = mock(MessagesManager.class);
83  1 componentProvider.setInstance(TranslationService.class, translationService);
84  1 componentProvider.setInstance(SimpleTranslator.class, simpleTranslator);
85  1 componentProvider.setInstance(LocaleProvider.class, localeProvider);
86  1 componentProvider.setInstance(RepositoryManager.class, repositoryManager);
87  1 componentProvider.setInstance(MessagesManager.class, messagesManager);
88  1 componentProvider.setInstance(info.magnolia.ui.framework.message.MessagesManager.class, mock(info.magnolia.ui.framework.message.MessagesManager.class));
89  1 Components.setComponentProvider(componentProvider);
90    }
91   
 
92  1 toggle @After
93    public void tearDown() {
94  1 SystemProperty.clear();
95  1 Components.setComponentProvider(null);
96  1 ComponentsTestUtil.clear();
97  1 MgnlContext.setInstance(null);
98    }
99   
 
100  1 toggle @Test
101    public void initMethodSetRescueSecuritySupport() throws Exception {
102    // GIVEN
103  1 MgnlGroovyRescueApp rescueServlet = new MgnlGroovyRescueApp();
104  1 rescueServlet.init(mock(VaadinRequest.class));
105   
106    // WHEN
107  1 String securitySupportClass = SystemProperty.getProperty("info.magnolia.cms.security.SecuritySupport");
108   
109    // THEN
110  1 assertEquals("info.magnolia.cms.security.RescueSecuritySupport", securitySupportClass);
111    }
112    }