11package de .inoxio .spring .cloudwatchmetrics ;
22
3+ import static de .inoxio .spring .cloudwatchmetrics .AnnotationDTO .AnnotationBuilder .annotionBuilder ;
4+ import static de .inoxio .spring .cloudwatchmetrics .AnnotationsDTO .AnnotationsBuilder .annotationsBuilder ;
5+ import static de .inoxio .spring .cloudwatchmetrics .DimensionKeyPair .DimensionKeyPairBuilder .dimensionKeyPairBuilder ;
6+ import static de .inoxio .spring .cloudwatchmetrics .MetricDTO .MetricBuilder .metricBuilder ;
7+ import static de .inoxio .spring .cloudwatchmetrics .MetricKeyPair .MetricKeyPairBuilder .metricKeyPairBuilder ;
8+ import static de .inoxio .spring .cloudwatchmetrics .PropertyDTO .PropertyBuilder .propertyBuilder ;
9+ import static de .inoxio .spring .cloudwatchmetrics .WidgetDTO .WidgetBuilder .widgetBuilder ;
310import static org .assertj .core .api .Assertions .assertThat ;
411import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
12+ import static org .assertj .core .api .Assertions .tuple ;
513import static org .mockito .ArgumentMatchers .any ;
614import static org .mockito .BDDMockito .given ;
715import static org .mockito .BDDMockito .then ;
1220import static org .mockito .Mockito .spy ;
1321import static org .mockito .Mockito .times ;
1422
15- import static de .inoxio .spring .cloudwatchmetrics .AnnotationDTO .AnnotationBuilder .annotionBuilder ;
16- import static de .inoxio .spring .cloudwatchmetrics .AnnotationsDTO .AnnotationsBuilder .annotationsBuilder ;
17- import static de .inoxio .spring .cloudwatchmetrics .DimensionKeyPair .DimensionKeyPairBuilder .dimensionKeyPairBuilder ;
18- import static de .inoxio .spring .cloudwatchmetrics .MetricDTO .MetricBuilder .metricBuilder ;
19- import static de .inoxio .spring .cloudwatchmetrics .MetricKeyPair .MetricKeyPairBuilder .metricKeyPairBuilder ;
20- import static de .inoxio .spring .cloudwatchmetrics .PropertyDTO .PropertyBuilder .propertyBuilder ;
21- import static de .inoxio .spring .cloudwatchmetrics .WidgetDTO .WidgetBuilder .widgetBuilder ;
22-
2323import java .io .IOException ;
2424import java .time .ZonedDateTime ;
2525import java .util .ArrayList ;
26- import java .util .Collections ;
2726import java .util .List ;
2827import java .util .concurrent .CompletableFuture ;
2928import java .util .concurrent .CompletionException ;
30-
29+ import com . fasterxml . jackson . databind . ObjectMapper ;
3130import org .assertj .core .api .ThrowableAssert ;
3231import org .junit .jupiter .api .Test ;
3332import org .mockito .ArgumentCaptor ;
34-
35- import com .fasterxml .jackson .databind .ObjectMapper ;
36-
3733import software .amazon .awssdk .awscore .exception .AwsErrorDetails ;
3834import software .amazon .awssdk .services .cloudwatch .CloudWatchAsyncClient ;
3935import software .amazon .awssdk .services .cloudwatch .model .DashboardValidationMessage ;
36+ import software .amazon .awssdk .services .cloudwatch .model .Dimension ;
4037import software .amazon .awssdk .services .cloudwatch .model .GetDashboardRequest ;
4138import software .amazon .awssdk .services .cloudwatch .model .GetDashboardResponse ;
39+ import software .amazon .awssdk .services .cloudwatch .model .MetricDatum ;
4240import software .amazon .awssdk .services .cloudwatch .model .PutDashboardRequest ;
4341import software .amazon .awssdk .services .cloudwatch .model .PutDashboardResponse ;
4442import software .amazon .awssdk .services .cloudwatch .model .PutMetricDataRequest ;
@@ -52,8 +50,8 @@ void shouldPutMetricsToCloudwatch() {
5250
5351 // given
5452 final var cloudWatchClient = mock (CloudWatchAsyncClient .class );
55- given (cloudWatchClient .putMetricData (anyPutMetricDataRequest ())). willReturn ( CompletableFuture . completedFuture (
56- null ));
53+ given (cloudWatchClient .putMetricData (anyPutMetricDataRequest ()))
54+ . willReturn ( CompletableFuture . completedFuture ( null ));
5755 final var cloudwatchRestDAO = new CloudwatchRestDAO (cloudWatchClient , mock (ObjectMapper .class ));
5856 cloudwatchRestDAO .setMetricPrefix ("somePrefix" );
5957 cloudwatchRestDAO .setNamespace ("someNamespace" );
@@ -70,12 +68,14 @@ void shouldPutMetricsToCloudwatch() {
7068
7169 final var metricData = request .metricData ();
7270 assertThat (metricData ).as ("Size of metric is not one." ).hasSize (1 );
73- assertThat (metricData .get (0 ).metricName ()).as ("Metric name is not correct" ).isEqualTo ("somePrefixsomeMetric" );
74- assertThat (metricData .get (0 ).value ()).as ("Metric has incorrect value." ).isEqualTo (10.0d );
75- assertThat (metricData .get (0 ).unit ()).as ("Unit type of metric is incorrect." ).isEqualTo (StandardUnit .COUNT );
76-
77- final var dimensions = metricData .get (0 ).dimensions ();
78- assertThat (dimensions ).as ("Size of metric dimensions is incorrect." ).hasSize (0 );
71+ assertThat (metricData ).as ("Metric name is not correct" )
72+ .extracting (MetricDatum ::metricName ).containsExactly ("somePrefixsomeMetric" );
73+ assertThat (metricData ).as ("Metric has incorrect value." )
74+ .extracting (MetricDatum ::value ).containsExactly (10.0d );
75+ assertThat (metricData ).as ("Unit type of metric is incorrect." )
76+ .extracting (MetricDatum ::unit ).containsExactly (StandardUnit .COUNT );
77+ assertThat (metricData ).as ("Size of metric dimensions is incorrect." )
78+ .flatExtracting (MetricDatum ::dimensions ).hasSize (0 );
7979 }
8080
8181 @ Test
@@ -102,14 +102,16 @@ void shouldPutMetricsToCloudwatchWithDimension() {
102102
103103 final var metricData = request .metricData ();
104104 assertThat (metricData ).as ("Size of metric is not one." ).hasSize (1 );
105- assertThat (metricData .get (0 ).metricName ()).as ("Metric name is not correct" ).isEqualTo ("somePrefixsomeMetric" );
106- assertThat (metricData .get (0 ).value ()).as ("Metric has incorrect value." ).isEqualTo (10.0d );
107- assertThat (metricData .get (0 ).unit ()).as ("Unit type of metric is incorrect." ).isEqualTo (StandardUnit .COUNT );
108-
109- final var dimensions = metricData .get (0 ).dimensions ();
110- assertThat (dimensions ).as ("Size of metric dimensions is incorrect." ).hasSize (1 );
111- assertThat (dimensions .get (0 ).name ()).as ("Dimension name of metric is incorrect." ).isEqualTo ("someDimension" );
112- assertThat (dimensions .get (0 ).value ()).as ("Dimension value of metric is incorrect." ).isEqualTo ("dimensionValue" );
105+ assertThat (metricData ).as ("Metric name is not correct" )
106+ .extracting (MetricDatum ::metricName ).containsExactly ("somePrefixsomeMetric" );
107+ assertThat (metricData ).as ("Metric has incorrect value." )
108+ .extracting (MetricDatum ::value ).containsExactly (10.0d );
109+ assertThat (metricData ).as ("Unit type of metric is incorrect." )
110+ .extracting (MetricDatum ::unit ).containsExactly (StandardUnit .COUNT );
111+ assertThat (metricData ).as ("Dimonsion name and value is incorrect." )
112+ .flatExtracting (MetricDatum ::dimensions )
113+ .extracting (Dimension ::name , Dimension ::value )
114+ .containsExactly (tuple ("someDimension" , "dimensionValue" ));
113115 }
114116
115117 @ Test
@@ -321,45 +323,6 @@ void shouldThrowExceptionOnPutDashboardIfError() {
321323 .isThrownBy (callable );
322324 }
323325
324- @ Test
325- void shouldLogMessageOnPutDashboard () {
326-
327- // given
328- final var cloudwatchRestDAO = spy (new CloudwatchRestDAO (mock (CloudWatchAsyncClient .class ),
329- mock (ObjectMapper .class )));
330- willDoNothing ().given (cloudwatchRestDAO ).logInfoMessage (any ());
331-
332- // when
333- cloudwatchRestDAO .handlePutDashboard (Collections .emptyList (), null );
334-
335- // then
336- final var captor = ArgumentCaptor .forClass (String .class );
337- then (cloudwatchRestDAO ).should ().logInfoMessage (captor .capture ());
338- assertThat (captor .getValue ()).as ("Log message was not created." ).isEqualTo ("Dashboard annotated" );
339-
340- }
341-
342- @ Test
343- void shouldAlsoLogValidationWarningsOnPutDashboard () {
344-
345- // given
346- final var cloudwatchRestDAO = spy (new CloudwatchRestDAO (mock (CloudWatchAsyncClient .class ),
347- mock (ObjectMapper .class )));
348- willDoNothing ().given (cloudwatchRestDAO ).logInfoMessage (any ());
349-
350- // when
351- cloudwatchRestDAO .handlePutDashboard (List .of (DashboardValidationMessage .builder ()
352- .message ("some validation" )
353- .build ()), null );
354-
355- // then
356- final var captor = ArgumentCaptor .forClass (String .class );
357- then (cloudwatchRestDAO ).should (times (2 )).logInfoMessage (captor .capture ());
358- assertThat (captor .getAllValues ()).as ("Incorrect validation warnings." )
359- .contains ("Dashboard annotated" , "BUT: some validation" );
360-
361- }
362-
363326 @ Test
364327 void shouldAddNewAnnotation () {
365328
@@ -375,9 +338,10 @@ void shouldAddNewAnnotation() {
375338
376339 // then
377340 final var verticalAnnotations = widget .getProperties ().getAnnotations ().getVertical ();
378- assertThat (verticalAnnotations ).as ("Size of vertical annotations is incorrect." ).hasSize (1 );
379- assertThat (verticalAnnotations .get (0 ).getLabel ()).as ("Vertival annotations label is incorrect." )
380- .isEqualTo ("somePrefix Start" );
341+ assertThat (verticalAnnotations )
342+ .as ("Vertival annotations label is incorrect." )
343+ .extracting (AnnotationDTO ::getLabel )
344+ .containsExactly ("somePrefix Start" );
381345 }
382346
383347 @ Test
0 commit comments