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

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
24
2
1
126
75
2
0.08
12
2
1

Classes

Class Line # Actions
AbstractAddResourceActionTest 71 24 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 5 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 info.magnolia.resourceloader.dummy.DummyResourceOrigin.Differentiator.qux;
37    import static org.mockito.BDDMockito.given;
38    import static org.mockito.Matchers.any;
39    import static org.mockito.Matchers.anyString;
40    import static org.mockito.Mockito.*;
41   
42    import info.magnolia.context.MgnlContext;
43    import info.magnolia.context.SystemContext;
44    import info.magnolia.event.RecordingEventBus;
45    import info.magnolia.resourceloader.Resource;
46    import info.magnolia.resourceloader.ResourceOrigin;
47    import info.magnolia.resourceloader.dummy.DummyResourceOrigin;
48    import info.magnolia.resourceloader.jcr.JcrResourceOrigin;
49    import info.magnolia.resourceloader.jcr.JcrResourceOriginFactory;
50    import info.magnolia.resourceloader.layered.LayeredResourceOrigin;
51    import info.magnolia.resourceloader.layered.LayeredResourceOriginFactory;
52    import info.magnolia.resources.app.ResourcesContentConnector;
53    import info.magnolia.test.MgnlTestCase;
54    import info.magnolia.test.mock.MockContext;
55    import info.magnolia.test.mock.jcr.MockSession;
56    import info.magnolia.ui.api.context.UiContext;
57    import info.magnolia.ui.api.location.LocationController;
58    import info.magnolia.ui.api.shell.Shell;
59    import info.magnolia.ui.dialog.formdialog.FormDialogPresenter;
60    import info.magnolia.ui.dialog.formdialog.FormDialogPresenterFactory;
61    import info.magnolia.ui.form.EditorCallback;
62   
63    import org.junit.Before;
64    import org.mockito.invocation.InvocationOnMock;
65    import org.mockito.stubbing.Answer;
66   
67    import com.google.inject.util.Providers;
68    import com.vaadin.data.Item;
69    import com.vaadin.data.util.ObjectProperty;
70   
 
71    public class AbstractAddResourceActionTest extends MgnlTestCase {
72   
73    private final static String WORKSPACE = "resources";
74   
75    protected MockSession session;
76    protected Item resourceItem;
77    protected LocationController locationController;
78    protected Resource resource;
79    protected RecordingEventBus eventBus;
80    protected ResourcesContentConnector contentConnector;
81    protected LayeredResourceOrigin origin;
82    protected FormDialogPresenterFactory formDialogPresenterFactory;
83   
 
84  5 toggle @Override
85    @Before
86    public void setUp() throws Exception {
87  5 super.setUp();
88   
89  5 MockContext context = (MockContext) MgnlContext.getInstance();
90  5 session = new MockSession(WORKSPACE);
91  5 context.addSession(WORKSPACE, session);
92   
93  5 DummyResourceOrigin dummyOrigin = new DummyResourceOrigin(qux, null, null, new String[]{"/x", "/x/y"});
94  5 JcrResourceOrigin jcrResourceOrigin = new JcrResourceOriginFactory(Providers.<SystemContext>of(context)).create("jcr");
95  5 this.origin = new LayeredResourceOriginFactory().create("layeredOrigin", new ResourceOrigin[]{jcrResourceOrigin, dummyOrigin});
96   
97  5 resourceItem = mock(Item.class);
98   
99  5 contentConnector = new ResourcesContentConnector(origin, context);
100   
101  5 FormDialogPresenter formDialogPresenter = mock(FormDialogPresenter.class);
102  5 doAnswer(new Answer() {
 
103  5 toggle @Override
104    public Object answer(InvocationOnMock inv) throws Throwable {
105    // On dialog start - simply set the new resource name to 'test' and invoke a callback success method
106  5 final Object[] args = inv.getArguments();
107  5 final EditorCallback callback = (EditorCallback) args[3];
108  5 final Item item = (Item) args[0];
109  5 item.addItemProperty("name", new ObjectProperty<>("test"));
110  5 callback.onSuccess("commit");
111  5 return null;
112    }
113    }).when(formDialogPresenter).start(any(Item.class), any(String.class), any(UiContext.class), any(EditorCallback.class));
114   
115  5 formDialogPresenterFactory = mock(FormDialogPresenterFactory.class);
116  5 given(formDialogPresenterFactory.createFormDialogPresenter(anyString())).willReturn(formDialogPresenter);
117   
118  5 ResourceOrigin resourceOrigin = mock(ResourceOrigin.class);
119  5 resource = mock(Resource.class);
120  5 given(resourceOrigin.getByPath(anyString())).willReturn(resource);
121   
122  5 eventBus = mock(RecordingEventBus.class);
123  5 locationController = new LocationController(eventBus, mock(Shell.class));
124    }
125   
126    }