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.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@link |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (37) |
Complexity: 4 |
Complexity Density: 0.12 |
|
70 |
|
public class HotfixActivationActionTest extends MgnlTestCase { |
71 |
|
|
72 |
|
private HotfixActivationActionDefinition definition; |
73 |
|
private Context context; |
74 |
|
private HotfixActivationAction action; |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
|
76 |
3 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
114 |
1 |
@Test... |
115 |
|
public void unPublishSucceeds() throws Exception { |
116 |
|
|
117 |
1 |
definition.setCommand("deactivate"); |
118 |
|
|
119 |
|
|
120 |
1 |
action.execute(); |
121 |
|
|
122 |
|
|
123 |
1 |
assertThat(!(Boolean) context.getAttribute("command_result"), is(true)); |
124 |
|
} |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
126 |
1 |
@Test... |
127 |
|
public void publishActionSucceeds() throws Exception { |
128 |
|
|
129 |
1 |
definition.setCommand("activate"); |
130 |
|
|
131 |
|
|
132 |
1 |
action.execute(); |
133 |
|
|
134 |
|
|
135 |
1 |
assertThat(!(Boolean) context.getAttribute("command_result"), is(true)); |
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
138 |
1 |
@Test... |
139 |
|
public void buildParamsSetsRecursiveParameter() throws Exception { |
140 |
|
|
141 |
1 |
definition.setRecursive(true); |
142 |
|
|
143 |
|
|
144 |
1 |
action.execute(); |
145 |
|
|
146 |
|
|
147 |
1 |
assertThat((Boolean) action.getParams().get("recursive"), is(true)); |
148 |
|
} |
149 |
|
} |