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 AddResourceFolderActionTest.java

 

Code metrics

0
32
5
1
130
67
5
0.16
6.4
5
1

Classes

Class Line # Actions
AddResourceFolderActionTest 56 32 0% 5 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.junit.Assert.assertThat;
38    import static org.mockito.BDDMockito.given;
39    import static org.mockito.Mockito.*;
40   
41    import info.magnolia.i18nsystem.SimpleTranslator;
42    import info.magnolia.jcr.util.NodeTypes;
43    import info.magnolia.resources.app.workbench.ResourcesContainer;
44    import info.magnolia.ui.api.app.AppContext;
45    import info.magnolia.ui.api.context.UiContext;
46    import info.magnolia.ui.api.event.ContentChangedEvent;
47    import info.magnolia.ui.vaadin.integration.jcr.DefaultProperty;
48   
49    import javax.jcr.Node;
50    import javax.jcr.RepositoryException;
51   
52    import org.junit.Before;
53    import org.junit.Test;
54    import org.mockito.ArgumentCaptor;
55   
 
56    public class AddResourceFolderActionTest extends AbstractAddResourceActionTest {
57   
58    private AddResourceFolderAction action;
59    private AddResourceFolderActionDefinition definition;
60   
 
61  3 toggle @Override
62    @Before
63    public void setUp() throws Exception {
64  3 super.setUp();
65   
66  3 definition = new AddResourceFolderActionDefinition();
67  3 definition.setDialogName("addResource");
68   
69  3 action = new AddResourceFolderAction(definition, resourceItem, formDialogPresenterFactory, mock(AppContext.class), mock(UiContext.class), contentConnector, mock(SimpleTranslator.class), locationController, origin, eventBus);
70    }
71   
 
72  1 toggle @Test
73    public void canAddFolderToRootNode() throws Exception {
74    // GIVEN
75  1 definition.setNodeType(NodeTypes.Folder.NAME);
76  1 Node root = session.getRootNode();
77  1 given(resource.getPath()).willReturn(root.getPath());
78  1 given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>(root.getPath()));
79  1 long nodeCountBefore = root.getNodes().getSize();
80   
81    // WHEN
82  1 action.execute();
83   
84    // THEN
85  1 assertAddedNewNode(root, nodeCountBefore + 1);
86    }
87   
 
88  1 toggle @Test
89    public void canAddFolderToAnotherFolder() throws Exception {
90    // GIVEN
91  1 definition.setNodeType(NodeTypes.Folder.NAME);
92  1 Node node = session.getRootNode().addNode("foo", NodeTypes.Folder.NAME);
93  1 given(resource.getPath()).willReturn(node.getPath());
94  1 given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>(node.getPath()));
95  1 long nodeCountBefore = node.getNodes().getSize();
96   
97    // WHEN
98  1 action.execute();
99   
100    // THEN
101  1 assertAddedNewNode(node, nodeCountBefore + 1);
102    }
103   
 
104  1 toggle @Test
105    public void eventIsFiredWithPathOfNewFolder() throws Exception {
106    // GIVEN
107  1 definition.setNodeType(NodeTypes.Folder.NAME);
108  1 Node root = session.getRootNode();
109  1 given(resource.getPath()).willReturn(root.getPath());
110  1 given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(new DefaultProperty<>(root.getPath()));
111   
112    // WHEN
113  1 action.execute();
114   
115    // THEN
116  1 ArgumentCaptor<ContentChangedEvent> argumentCaptor = ArgumentCaptor.forClass(ContentChangedEvent.class);
117  1 verify(eventBus, atLeastOnce()).fireEvent(argumentCaptor.capture());
118  1 String result = (String) argumentCaptor.getValue().getItemId();
119  1 assertThat("/test", is(result));
120    }
121   
 
122  2 toggle private void assertAddedNewNode(Node parentNode, long expectedNumberOfChildNodes) throws RepositoryException {
123  2 assertThat(parentNode.getNodes().getSize(), is(expectedNumberOfChildNodes));
124  2 assertThat(parentNode.hasNode("test"), is(true));
125  2 assertThat(eventBus.isEmpty(), is(false));
126   
127  2 Node newNode = parentNode.getNode("test");
128  2 assertThat(NodeTypes.Folder.NAME, is(newNode.getPrimaryNodeType().getName()));
129    }
130    }