6
6
package com .liferay .portal .workflow .kaleo .internal .runtime .integration .test ;
7
7
8
8
import com .liferay .arquillian .extension .junit .bridge .junit .Arquillian ;
9
+ import com .liferay .blogs .model .BlogsEntry ;
9
10
import com .liferay .petra .lang .SafeCloseable ;
11
+ import com .liferay .petra .string .StringPool ;
12
+ import com .liferay .portal .kernel .service .ServiceContext ;
10
13
import com .liferay .portal .kernel .test .AssertUtils ;
11
14
import com .liferay .portal .kernel .test .rule .AggregateTestRule ;
12
15
import com .liferay .portal .kernel .test .util .PropsValuesTestUtil ;
13
16
import com .liferay .portal .kernel .test .util .RandomTestUtil ;
17
+ import com .liferay .portal .kernel .test .util .ServiceContextTestUtil ;
18
+ import com .liferay .portal .kernel .util .HashMapBuilder ;
19
+ import com .liferay .portal .kernel .workflow .WorkflowConstants ;
14
20
import com .liferay .portal .test .rule .Inject ;
15
21
import com .liferay .portal .test .rule .LiferayIntegrationTestRule ;
16
22
import com .liferay .portal .test .rule .PermissionCheckerMethodTestRule ;
23
+ import com .liferay .portal .workflow .kaleo .definition .Task ;
24
+ import com .liferay .portal .workflow .kaleo .model .KaleoInstance ;
25
+ import com .liferay .portal .workflow .kaleo .model .KaleoInstanceToken ;
17
26
import com .liferay .portal .workflow .kaleo .model .KaleoNode ;
18
27
import com .liferay .portal .workflow .kaleo .runtime .ExecutionContext ;
19
28
import com .liferay .portal .workflow .kaleo .runtime .notification .NotificationMessageGenerationException ;
20
29
import com .liferay .portal .workflow .kaleo .runtime .notification .NotificationMessageGenerator ;
30
+ import com .liferay .portal .workflow .kaleo .runtime .util .WorkflowContextUtil ;
31
+ import com .liferay .portal .workflow .kaleo .service .KaleoInstanceLocalService ;
32
+ import com .liferay .portal .workflow .kaleo .service .KaleoInstanceTokenLocalService ;
33
+ import com .liferay .portal .workflow .kaleo .service .KaleoNodeLocalService ;
34
+ import com .liferay .portal .workflow .kaleo .service .KaleoTaskInstanceTokenLocalService ;
21
35
22
- import java .util . HashMap ;
36
+ import java .io . Serializable ;
23
37
24
38
import org .junit .Assert ;
39
+ import org .junit .Before ;
25
40
import org .junit .ClassRule ;
26
41
import org .junit .Rule ;
27
42
import org .junit .Test ;
@@ -40,10 +55,40 @@ public class TemplateNotificationMessageGeneratorTest {
40
55
new LiferayIntegrationTestRule (),
41
56
PermissionCheckerMethodTestRule .INSTANCE );
42
57
43
- @ Test
44
- public void testGenerateMessage ()
45
- throws NotificationMessageGenerationException {
58
+ @ Before
59
+ public void setUp () throws Exception {
60
+ ServiceContext serviceContext =
61
+ ServiceContextTestUtil .getServiceContext ();
62
+
63
+ _kaleoInstance = _kaleoInstanceLocalService .addKaleoInstance (
64
+ 1 , 1 , RandomTestUtil .randomString (), 1 ,
65
+ HashMapBuilder .<String , Serializable >put (
66
+ WorkflowConstants .CONTEXT_ENTRY_CLASS_NAME ,
67
+ BlogsEntry .class .getName ()
68
+ ).put (
69
+ WorkflowConstants .CONTEXT_SERVICE_CONTEXT , serviceContext
70
+ ).build (),
71
+ serviceContext );
72
+
73
+ KaleoNode kaleoNode = _kaleoNodeLocalService .addKaleoNode (
74
+ _kaleoInstance .getKaleoDefinitionId (),
75
+ _kaleoInstance .getKaleoDefinitionVersionId (),
76
+ new Task (RandomTestUtil .randomString (), StringPool .BLANK ),
77
+ serviceContext );
46
78
79
+ _kaleoInstanceToken =
80
+ _kaleoInstanceTokenLocalService .addKaleoInstanceToken (
81
+ kaleoNode .getKaleoNodeId (),
82
+ _kaleoInstance .getKaleoDefinitionId (),
83
+ _kaleoInstance .getKaleoDefinitionVersionId (),
84
+ _kaleoInstance .getKaleoInstanceId (), 0 ,
85
+ WorkflowContextUtil .convert (
86
+ _kaleoInstance .getWorkflowContext ()),
87
+ serviceContext );
88
+ }
89
+
90
+ @ Test
91
+ public void testGenerateMessage () throws Exception {
47
92
try (SafeCloseable safeCloseable =
48
93
PropsValuesTestUtil .swapWithSafeCloseable (
49
94
"NOTIFICATION_EMAIL_TEMPLATE_ENABLED" , true )) {
@@ -52,7 +97,11 @@ public void testGenerateMessage()
52
97
KaleoNode .class .getName (), RandomTestUtil .randomLong (),
53
98
RandomTestUtil .randomString (), "freemarker" ,
54
99
"Hello ${serviceLocator}!" ,
55
- new ExecutionContext (null , new HashMap <>(), null ));
100
+ new ExecutionContext (
101
+ _kaleoInstanceToken ,
102
+ WorkflowContextUtil .convert (
103
+ _kaleoInstance .getWorkflowContext ()),
104
+ ServiceContextTestUtil .getServiceContext ()));
56
105
57
106
Assert .assertTrue (message .contains ("ServiceLocator" ));
58
107
}
@@ -68,10 +117,31 @@ public void testGenerateMessage()
68
117
KaleoNode .class .getName (), RandomTestUtil .randomLong (),
69
118
RandomTestUtil .randomString (), "freemarker" ,
70
119
"Hello ${serviceLocator}!" ,
71
- new ExecutionContext (null , new HashMap <>(), null )));
120
+ new ExecutionContext (
121
+ _kaleoInstanceToken ,
122
+ WorkflowContextUtil .convert (
123
+ _kaleoInstance .getWorkflowContext ()),
124
+ ServiceContextTestUtil .getServiceContext ())));
72
125
}
73
126
}
74
127
128
+ private KaleoInstance _kaleoInstance ;
129
+
130
+ @ Inject
131
+ private KaleoInstanceLocalService _kaleoInstanceLocalService ;
132
+
133
+ private KaleoInstanceToken _kaleoInstanceToken ;
134
+
135
+ @ Inject
136
+ private KaleoInstanceTokenLocalService _kaleoInstanceTokenLocalService ;
137
+
138
+ @ Inject
139
+ private KaleoNodeLocalService _kaleoNodeLocalService ;
140
+
141
+ @ Inject
142
+ private KaleoTaskInstanceTokenLocalService
143
+ _kaleoTaskInstanceTokenLocalService ;
144
+
75
145
@ Inject (
76
146
filter = "component.name=com.liferay.portal.workflow.kaleo.runtime.internal.notification.TemplateNotificationMessageGenerator"
77
147
)
0 commit comments