31
31
32
32
import java .util .UUID ;
33
33
34
+ import org .json .JSONObject ;
34
35
import org .junit .jupiter .api .Test ;
35
36
import org .junit .jupiter .api .extension .ExtendWith ;
36
37
import org .mockito .ArgumentCaptor ;
43
44
import software .amazon .awssdk .services .cloudformation .model .RecordHandlerProgressResponse ;
44
45
import software .amazon .cloudformation .TestModel ;
45
46
import software .amazon .cloudformation .injection .CloudFormationProvider ;
47
+ import software .amazon .cloudformation .resource .ResourceTypeSchema ;
46
48
import software .amazon .cloudformation .resource .Serializer ;
47
49
48
50
@ ExtendWith (MockitoExtension .class )
@@ -57,12 +59,15 @@ public class CloudFormationCallbackAdapterTest {
57
59
@ Mock
58
60
private Serializer serializer ;
59
61
62
+ @ Mock
63
+ private ResourceTypeSchema resourceTypeSchema ;
64
+
60
65
@ Test
61
66
public void testReportProgress_withoutRefreshingClient () {
62
- final CloudFormationClient client = mock (CloudFormationClient .class );
63
67
64
68
final CloudFormationCallbackAdapter <
65
- TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer );
69
+ TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer ,
70
+ resourceTypeSchema );
66
71
final AssertionError expectedException = assertThrows (AssertionError .class , () -> adapter .reportProgress ("bearer-token" ,
67
72
HandlerErrorCode .InvalidRequest , OperationStatus .FAILED , OperationStatus .IN_PROGRESS , null , "some error" ),
68
73
"Expected assertion exception" );
@@ -84,7 +89,8 @@ public void testReportProgress_Failed() {
84
89
when (client .recordHandlerProgress (any (RecordHandlerProgressRequest .class ))).thenReturn (response );
85
90
86
91
final CloudFormationCallbackAdapter <
87
- TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer );
92
+ TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer ,
93
+ resourceTypeSchema );
88
94
adapter .refreshClient ();
89
95
90
96
adapter .reportProgress ("bearer-token" , HandlerErrorCode .InvalidRequest , OperationStatus .FAILED ,
@@ -111,12 +117,13 @@ public void testReportProgress_IN_PROGRESS() throws JsonProcessingException {
111
117
when (response .responseMetadata ()).thenReturn (responseMetadata );
112
118
113
119
when (cloudFormationProvider .get ()).thenReturn (client );
114
- when (serializer .serialize (any ())).thenReturn ("" );
120
+ when (serializer .serialize (any ())).thenReturn ("{} " );
115
121
116
122
when (client .recordHandlerProgress (any (RecordHandlerProgressRequest .class ))).thenReturn (response );
117
123
118
124
final CloudFormationCallbackAdapter <
119
- TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer );
125
+ TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer ,
126
+ resourceTypeSchema );
120
127
121
128
adapter .refreshClient ();
122
129
@@ -131,6 +138,8 @@ public void testReportProgress_IN_PROGRESS() throws JsonProcessingException {
131
138
assertThat (argument .getValue ().operationStatus ()).isEqualTo (IN_PROGRESS );
132
139
assertThat (argument .getValue ().currentOperationStatus ()).isEqualTo (PENDING );
133
140
assertThat (argument .getValue ().statusMessage ()).isEqualTo ("doing it" );
141
+
142
+ verify (resourceTypeSchema ).removeWriteOnlyProperties (any (JSONObject .class ));
134
143
}
135
144
136
145
@ Test
@@ -147,7 +156,8 @@ public void testReportProgress_SUCCESS() {
147
156
when (client .recordHandlerProgress (any (RecordHandlerProgressRequest .class ))).thenReturn (response );
148
157
149
158
final CloudFormationCallbackAdapter <
150
- TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer );
159
+ TestModel > adapter = new CloudFormationCallbackAdapter <TestModel >(cloudFormationProvider , loggerProxy , serializer ,
160
+ resourceTypeSchema );
151
161
adapter .refreshClient ();
152
162
153
163
adapter .reportProgress ("bearer-token" , null , OperationStatus .SUCCESS , OperationStatus .IN_PROGRESS , null , "Succeeded" );
0 commit comments