1818
1919import java .net .URI ;
2020
21- import org .json .JSONObject ;
2221import org .junit .jupiter .api .BeforeEach ;
2322import org .junit .jupiter .api .Test ;
2423import org .mockito .ArgumentCaptor ;
24+ import org .skyscreamer .jsonassert .JSONAssert ;
25+ import org .skyscreamer .jsonassert .JSONCompareMode ;
2526import org .springframework .http .HttpEntity ;
2627import org .springframework .http .MediaType ;
2728import org .springframework .web .client .RestTemplate ;
2829import reactor .core .publisher .Mono ;
2930import reactor .test .StepVerifier ;
31+ import tools .jackson .databind .json .JsonMapper ;
3032
3133import de .codecentric .boot .admin .server .domain .entities .Instance ;
3234import de .codecentric .boot .admin .server .domain .entities .InstanceRepository ;
4648
4749class MicrosoftTeamsNotifierTest {
4850
49- private static final String ACCENT = "Accent " ;
51+ private static final String ACCENT = "accent " ;
5052
51- private static final String ATTENTION = "Attention " ;
53+ private static final String ATTENTION = "attention " ;
5254
53- private static final String GOOD = "Good " ;
55+ private static final String GOOD = "good " ;
5456
5557 private static final String APP_NAME = "Test App" ;
5658
@@ -230,13 +232,15 @@ void test_messageSerializesToExpectedJsonStructure() throws Exception {
230232 Message message = notifier .getStatusChangedMessage (upInstance , notifier .createEvaluationContext (
231233 new InstanceStatusChangedEvent (upInstance .getId (), 1L , StatusInfo .ofUp ()), upInstance ));
232234
233- // Build expected JSON structure using JSONObject with actual values
234- JSONObject expectedJson = new JSONObject ("""
235+ JsonMapper mapper = JsonMapper .builder ().build ();
236+ String actual = mapper .writeValueAsString (message );
237+
238+ // Build expected JSON structure
239+ String expectedJson = """
235240 {
236241 "type": "message",
237242 "attachments": [{
238243 "contentType": "application/vnd.microsoft.card.adaptive",
239- "contentUrl": null,
240244 "content": {
241245 "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
242246 "type": "AdaptiveCard",
@@ -247,7 +251,7 @@ void test_messageSerializesToExpectedJsonStructure() throws Exception {
247251 "text": "Status Changed",
248252 "size": "Large",
249253 "weight": "Bolder",
250- "color": "Good "
254+ "color": "good "
251255 },
252256 {
253257 "type": "TextBlock",
@@ -273,57 +277,9 @@ void test_messageSerializesToExpectedJsonStructure() throws Exception {
273277 }
274278 }]
275279 }
276- """ );
277-
278- // Verify message structure matches expected format
279- assertThat (message .getType ()).isEqualTo (expectedJson .getString ("type" ));
280-
281- assertThat (message .getAttachments ()).hasSize (1 );
282- var attachment = message .getAttachments ().get (0 );
283- assertThat (attachment .getContentType ())
284- .isEqualTo (expectedJson .getJSONArray ("attachments" ).getJSONObject (0 ).getString ("contentType" ));
280+ """ ;
285281
286- var content = attachment .getContent ();
287- var expectedContent = expectedJson .getJSONArray ("attachments" ).getJSONObject (0 ).getJSONObject ("content" );
288- assertThat (content .getSchema ()).isEqualTo (expectedContent .getString ("$schema" ));
289- assertThat (content .getType ()).isEqualTo (expectedContent .getString ("type" ));
290- assertThat (content .getVersion ()).isEqualTo (expectedContent .getString ("version" ));
291-
292- // Verify body structure and content
293- var body = content .getBody ();
294- var expectedBody = expectedContent .getJSONArray ("body" );
295- assertThat (body ).hasSize (expectedBody .length ());
296-
297- // Verify Title TextBlock
298- assertThat (body .get (0 ).getType ()).isEqualTo ("TextBlock" );
299- assertThat (body .get (0 ).getText ()).isEqualTo ("Status Changed" );
300- assertThat (body .get (0 ).getSize ()).isEqualTo ("Large" );
301- assertThat (body .get (0 ).getWeight ()).isEqualTo ("Bolder" );
302- assertThat (body .get (0 ).getColor ()).isEqualTo ("Good" );
303-
304- // Verify Service Name TextBlock
305- assertThat (body .get (1 ).getType ()).isEqualTo ("TextBlock" );
306- assertThat (body .get (1 ).getText ()).isEqualTo (APP_NAME );
307- assertThat (body .get (1 ).getSize ()).isEqualTo ("Medium" );
308- assertThat (body .get (1 ).getWeight ()).isEqualTo ("Bolder" );
309-
310- // Verify Activity Subtitle TextBlock
311- assertThat (body .get (2 ).getType ()).isEqualTo ("TextBlock" );
312- assertThat (body .get (2 ).getText ()).isEqualTo ("Test App with id TestAppId changed status from UNKNOWN to UP" );
313- assertThat (body .get (2 ).getWrap ()).isTrue ();
314-
315- // Verify FactSet
316- assertThat (body .get (3 ).getType ()).isEqualTo ("FactSet" );
317- assertThat (body .get (3 ).getFacts ()).hasSize (4 ); // Source is omitted because it's
318- // null
319- assertThat (body .get (3 ).getFacts ().get (0 ).title ()).isEqualTo ("Status" );
320- assertThat (body .get (3 ).getFacts ().get (0 ).value ()).isEqualTo ("UP" );
321- assertThat (body .get (3 ).getFacts ().get (1 ).title ()).isEqualTo ("Service URL" );
322- assertThat (body .get (3 ).getFacts ().get (1 ).value ()).isEqualTo (SERVICE_URL );
323- assertThat (body .get (3 ).getFacts ().get (2 ).title ()).isEqualTo ("Health URL" );
324- assertThat (body .get (3 ).getFacts ().get (2 ).value ()).isEqualTo (HEALTH_URL );
325- assertThat (body .get (3 ).getFacts ().get (3 ).title ()).isEqualTo ("Management URL" );
326- assertThat (body .get (3 ).getFacts ().get (3 ).value ()).isEqualTo (MANAGEMENT_URL );
282+ JSONAssert .assertEquals (expectedJson , actual , JSONCompareMode .NON_EXTENSIBLE );
327283 }
328284
329285 private String getActivitySubtitleFromMessage (Message message ) {
0 commit comments