Clover icon

Magnolia Resources App Module 2.4.7

  1. Project Clover database Fri Sep 9 2016 16:27:56 CEST
  2. Package info.magnolia.resources.app.action

File HotfixActivationActionTest.java

 

Code metrics

0
33
4
1
149
80
4
0.12
8.25
4
1

Classes

Class Line # Actions
HotfixActivationActionTest 70 33 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /**
2    * This file Copyright (c) 2015-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.resources.app.action;
35   
36    import static org.hamcrest.CoreMatchers.is;
37    import static org.hamcrest.MatcherAssert.assertThat;
38    import static org.mockito.BDDMockito.given;
39    import static org.mockito.Matchers.*;
40    import static org.mockito.Mockito.mock;
41   
42    import info.magnolia.cms.security.User;
43    import info.magnolia.commands.CommandsManager;
44    import info.magnolia.commands.chain.Command;
45    import info.magnolia.context.Context;
46    import info.magnolia.context.MgnlContext;
47    import info.magnolia.event.EventBus;
48    import info.magnolia.i18nsystem.SimpleTranslator;
49    import info.magnolia.resourceloader.jcr.JcrResourceOrigin;
50    import info.magnolia.resources.app.workbench.ResourcesContainer;
51    import info.magnolia.test.ComponentsTestUtil;
52    import info.magnolia.test.MgnlTestCase;
53    import info.magnolia.test.mock.MockContext;
54    import info.magnolia.test.mock.jcr.MockSession;
55    import info.magnolia.test.mock.jcr.SessionTestUtil;
56    import info.magnolia.ui.framework.action.AbstractCommandActionTest;
57    import info.magnolia.ui.framework.action.async.AsyncActionExecutor;
58    import info.magnolia.ui.framework.app.SubAppContextImpl;
59   
60    import org.junit.Before;
61    import org.junit.Test;
62   
63    import com.vaadin.data.Item;
64    import com.vaadin.data.Property;
65    import com.vaadin.data.util.AbstractProperty;
66   
67    /**
68    * @deprecated {@link HotfixActivationAction} is deprecated since 2.4.2. {@link ResourceActivationAction} should be used instead.
69    */
 
70    public class HotfixActivationActionTest extends MgnlTestCase {
71   
72    private HotfixActivationActionDefinition definition;
73    private Context context;
74    private HotfixActivationAction action;
75   
 
76  3 toggle @Override
77    @Before
78    public void setUp() throws Exception {
79  3 super.setUp();
80  3 String website = "/foo.uuid=1\n" +
81    "/foo/bar.uuid=2\n" +
82    "/foo/bar/test.uuid=3";
83  3 MockSession session = SessionTestUtil.createSession(JcrResourceOrigin.RESOURCES_WORKSPACE, website);
84   
85  3 ComponentsTestUtil.setImplementation(AsyncActionExecutor.class, AbstractCommandActionTest.DummyAsyncExecutor.class);
86   
87  3 CommandsManager commandsManager = mock(CommandsManager.class);
88  3 Command activationCommand = mock(Command.class);
89  3 EventBus eventBus = mock(EventBus.class);
90  3 SubAppContextImpl uiContext = mock(SubAppContextImpl.class);
91  3 SimpleTranslator i18n = mock(SimpleTranslator.class);
92  3 given(commandsManager.getCommand(eq(CommandsManager.DEFAULT_CATALOG), anyString())).willReturn(activationCommand);
93  3 given(commandsManager.getCommand(eq("workflow"), anyString())).willReturn(activationCommand);
94  3 given(commandsManager.getCommand(anyString())).willReturn(activationCommand);
95   
96  3 MockContext mockContext = (MockContext) MgnlContext.getInstance();
97  3 mockContext.addSession(JcrResourceOrigin.RESOURCES_WORKSPACE, session);
98   
99  3 User user = mock(User.class);
100  3 given(user.getName()).willReturn("ilgun");
101  3 mockContext.setUser(user);
102   
103  3 Item resourceItem = mock(Item.class);
104  3 Property property = mock(AbstractProperty.class);
105   
106  3 given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(property);
107  3 given(property.getValue()).willReturn("/foo/bar/test");
108   
109  3 context = mockContext;
110  3 definition = new HotfixActivationActionDefinition();
111  3 action = new HotfixActivationAction(definition, resourceItem, commandsManager, eventBus, uiContext, i18n, context);
112    }
113   
 
114  1 toggle @Test
115    public void unPublishSucceeds() throws Exception {
116    // GIVEN
117  1 definition.setCommand("deactivate");
118   
119    // WHEN
120  1 action.execute();
121   
122    // THEN
123  1 assertThat(!(Boolean) context.getAttribute("command_result"), is(true));
124    }
125   
 
126  1 toggle @Test
127    public void publishActionSucceeds() throws Exception {
128    // GIVEN
129  1 definition.setCommand("activate");
130   
131    // WHEN
132  1 action.execute();
133   
134    // THEN
135  1 assertThat(!(Boolean) context.getAttribute("command_result"), is(true));
136    }
137   
 
138  1 toggle @Test
139    public void buildParamsSetsRecursiveParameter() throws Exception {
140    // GIVEN
141  1 definition.setRecursive(true);
142   
143    // WHEN
144  1 action.execute();
145   
146    // THEN
147  1 assertThat((Boolean) action.getParams().get("recursive"), is(true));
148    }
149    }