1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
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.hamcrest.Matchers.hasSize; |
39 |
|
import static org.mockito.BDDMockito.given; |
40 |
|
import static org.mockito.Matchers.*; |
41 |
|
import static org.mockito.Mockito.*; |
42 |
|
|
43 |
|
import info.magnolia.cms.security.User; |
44 |
|
import info.magnolia.commands.CommandsManager; |
45 |
|
import info.magnolia.commands.chain.Command; |
46 |
|
import info.magnolia.context.Context; |
47 |
|
import info.magnolia.context.MgnlContext; |
48 |
|
import info.magnolia.event.EventBus; |
49 |
|
import info.magnolia.i18nsystem.SimpleTranslator; |
50 |
|
import info.magnolia.jcr.util.NodeTypes; |
51 |
|
import info.magnolia.resourceloader.jcr.JcrResourceOrigin; |
52 |
|
import info.magnolia.resources.app.workbench.ResourcesContainer; |
53 |
|
import info.magnolia.test.ComponentsTestUtil; |
54 |
|
import info.magnolia.test.MgnlTestCase; |
55 |
|
import info.magnolia.test.mock.MockContext; |
56 |
|
import info.magnolia.test.mock.jcr.SessionTestUtil; |
57 |
|
import info.magnolia.ui.api.event.ContentChangedEvent; |
58 |
|
import info.magnolia.ui.framework.action.AbstractCommandActionTest; |
59 |
|
import info.magnolia.ui.framework.action.async.AsyncActionExecutor; |
60 |
|
import info.magnolia.ui.framework.app.SubAppContextImpl; |
61 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrItemAdapter; |
62 |
|
|
63 |
|
import java.util.List; |
64 |
|
|
65 |
|
import javax.jcr.Node; |
66 |
|
import javax.jcr.Session; |
67 |
|
|
68 |
|
import org.junit.Before; |
69 |
|
import org.junit.Test; |
70 |
|
import org.mockito.ArgumentCaptor; |
71 |
|
|
72 |
|
import com.vaadin.data.Item; |
73 |
|
import com.vaadin.data.Property; |
74 |
|
import com.vaadin.data.util.AbstractProperty; |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (84) |
Complexity: 7 |
Complexity Density: 0.09 |
|
76 |
|
public class ResourceActivationActionTest extends MgnlTestCase { |
77 |
|
|
78 |
|
private ResourceActivationActionDefinition definition; |
79 |
|
private Context context; |
80 |
|
private ResourceActivationAction action; |
81 |
|
private Session session; |
82 |
|
private EventBus eventBus; |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
|
84 |
6 |
@Override... |
85 |
|
@Before |
86 |
|
public void setUp() throws Exception { |
87 |
6 |
super.setUp(); |
88 |
6 |
String website = "/foo.uuid=1\n" + |
89 |
|
"/foo/bar.uuid=2\n" + |
90 |
|
"/foo/bar/test.uuid=3"; |
91 |
6 |
session = SessionTestUtil.createSession(JcrResourceOrigin.RESOURCES_WORKSPACE, website); |
92 |
6 |
ComponentsTestUtil.setImplementation(AsyncActionExecutor.class, AbstractCommandActionTest.DummyAsyncExecutor.class); |
93 |
|
|
94 |
6 |
CommandsManager commandsManager = mock(CommandsManager.class); |
95 |
6 |
Command activationCommand = mock(Command.class); |
96 |
6 |
eventBus = mock(EventBus.class); |
97 |
6 |
SubAppContextImpl uiContext = mock(SubAppContextImpl.class); |
98 |
6 |
SimpleTranslator i18n = mock(SimpleTranslator.class); |
99 |
6 |
given(commandsManager.getCommand(eq(CommandsManager.DEFAULT_CATALOG), anyString())).willReturn(activationCommand); |
100 |
6 |
given(commandsManager.getCommand(eq("workflow"), anyString())).willReturn(activationCommand); |
101 |
6 |
given(commandsManager.getCommand(anyString())).willReturn(activationCommand); |
102 |
|
|
103 |
6 |
MockContext mockContext = (MockContext) MgnlContext.getInstance(); |
104 |
6 |
mockContext.addSession(JcrResourceOrigin.RESOURCES_WORKSPACE, session); |
105 |
|
|
106 |
6 |
User user = mock(User.class); |
107 |
6 |
given(user.getName()).willReturn("ilgun"); |
108 |
6 |
mockContext.setUser(user); |
109 |
|
|
110 |
6 |
Item resourceItem = mock(Item.class); |
111 |
6 |
Property property = mock(AbstractProperty.class); |
112 |
|
|
113 |
6 |
given(resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH)).willReturn(property); |
114 |
6 |
given(property.getValue()).willReturn("/foo/bar/test"); |
115 |
|
|
116 |
6 |
context = mockContext; |
117 |
6 |
definition = new ResourceActivationActionDefinition(); |
118 |
6 |
action = new ResourceActivationAction(definition, resourceItem, commandsManager, eventBus, uiContext, i18n, context); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
121 |
1 |
@Test... |
122 |
|
public void unPublishSucceeds() throws Exception { |
123 |
|
|
124 |
1 |
definition.setCommand("deactivate"); |
125 |
|
|
126 |
|
|
127 |
1 |
action.execute(); |
128 |
|
|
129 |
|
|
130 |
1 |
assertThat(!(Boolean) context.getAttribute("command_result"), is(true)); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void publishActionSucceeds() throws Exception { |
135 |
|
|
136 |
1 |
definition.setCommand("activate"); |
137 |
|
|
138 |
|
|
139 |
1 |
action.execute(); |
140 |
|
|
141 |
|
|
142 |
1 |
assertThat(!(Boolean) context.getAttribute("command_result"), is(true)); |
143 |
|
} |
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
145 |
1 |
@Test... |
146 |
|
public void buildParamsSetsRecursiveParameter() throws Exception { |
147 |
|
|
148 |
1 |
definition.setRecursive(true); |
149 |
|
|
150 |
|
|
151 |
1 |
action.execute(); |
152 |
|
|
153 |
|
|
154 |
1 |
assertThat((Boolean) action.getParams().get("recursive"), is(true)); |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
157 |
1 |
@Test... |
158 |
|
public void publishMarkedAsDeletedResourceSucceeds() throws Exception { |
159 |
|
|
160 |
1 |
definition.setCommand("activate"); |
161 |
1 |
definition.setDeletionActivation(true); |
162 |
1 |
Node foo = session.getRootNode().getNode("foo"); |
163 |
1 |
Node bar = foo.getNode("bar"); |
164 |
1 |
Node test = bar.getNode("test"); |
165 |
|
|
166 |
1 |
foo.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
167 |
1 |
foo.addMixin(NodeTypes.Deleted.NAME); |
168 |
|
|
169 |
1 |
bar.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
170 |
1 |
bar.addMixin(NodeTypes.Deleted.NAME); |
171 |
|
|
172 |
1 |
test.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
173 |
1 |
test.addMixin(NodeTypes.Deleted.NAME); |
174 |
|
|
175 |
|
|
176 |
1 |
action.execute(); |
177 |
1 |
List<JcrItemAdapter> items = action.getItems(); |
178 |
|
|
179 |
|
|
180 |
1 |
assertThat(!(Boolean) context.getAttribute("command_result"), is(true)); |
181 |
1 |
assertThat(items, hasSize(3)); |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
184 |
1 |
@Test... |
185 |
|
public void publishMarkedAsDeletedResourceWillNotPublishAncestorsIfTheyAreNotDeleted() throws Exception { |
186 |
|
|
187 |
1 |
definition.setCommand("activate"); |
188 |
1 |
definition.setDeletionActivation(true); |
189 |
1 |
Node foo = session.getRootNode().getNode("foo"); |
190 |
1 |
Node bar = foo.getNode("bar"); |
191 |
1 |
Node test = bar.getNode("test"); |
192 |
|
|
193 |
1 |
foo.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
194 |
|
|
195 |
1 |
bar.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
196 |
|
|
197 |
1 |
test.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
198 |
1 |
test.addMixin(NodeTypes.Deleted.NAME); |
199 |
|
|
200 |
|
|
201 |
1 |
action.execute(); |
202 |
1 |
List<JcrItemAdapter> items = action.getItems(); |
203 |
|
|
204 |
|
|
205 |
1 |
assertThat(!(Boolean) context.getAttribute("command_result"), is(true)); |
206 |
1 |
assertThat(items, hasSize(1)); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
209 |
1 |
@Test... |
210 |
|
@SuppressWarnings("unchecked") |
211 |
|
public void eventWithCorrectPathIsFiredAfterPublication() throws Exception { |
212 |
|
|
213 |
1 |
definition.setCommand("activate"); |
214 |
1 |
definition.setDeletionActivation(true); |
215 |
1 |
Node foo = session.getRootNode().getNode("foo"); |
216 |
1 |
Node bar = foo.getNode("bar"); |
217 |
1 |
Node test = bar.getNode("test"); |
218 |
|
|
219 |
1 |
foo.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
220 |
1 |
foo.addMixin(NodeTypes.Deleted.NAME); |
221 |
|
|
222 |
1 |
bar.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
223 |
1 |
bar.addMixin(NodeTypes.Deleted.NAME); |
224 |
|
|
225 |
1 |
test.setProperty(NodeTypes.Activatable.ACTIVATION_STATUS, true); |
226 |
1 |
test.addMixin(NodeTypes.Deleted.NAME); |
227 |
|
|
228 |
|
|
229 |
1 |
action.execute(); |
230 |
|
|
231 |
|
|
232 |
1 |
ArgumentCaptor<ContentChangedEvent> argumentCaptor = ArgumentCaptor.forClass(ContentChangedEvent.class); |
233 |
1 |
verify(eventBus, atLeastOnce()).fireEvent(argumentCaptor.capture()); |
234 |
1 |
String result = ((List<String>) argumentCaptor.getValue().getItemId()).get(0); |
235 |
1 |
assertThat(result, is("/foo/bar/test")); |
236 |
|
} |
237 |
|
} |