1717package com .hivemq .api .resources .impl .pulse ;
1818
1919import com .hivemq .api .errors .pulse .AssetMapperNotFoundError ;
20- import com .hivemq .api .resources .impl .PulseApiImpl ;
2120import com .hivemq .combining .model .DataCombiner ;
2221import com .hivemq .edge .api .model .Combiner ;
2322import com .hivemq .edge .api .model .DataIdentifierReference ;
2423import com .hivemq .edge .api .model .EntityType ;
2524import jakarta .ws .rs .core .Response ;
25+ import org .assertj .core .api .InstanceOfAssertFactories ;
2626import org .junit .jupiter .api .Test ;
2727
28+ import java .util .List ;
2829import java .util .Optional ;
2930import java .util .UUID ;
3031
3435
3536public class PulseApiImplGetAssetMapperInstructionsTest extends AbstractPulseApiImplTest {
3637 @ Test
37- public void whenCombinerNotFound_thenReturnsAssetMapperNotFoundError () {
38- when (assetMappingExtractor .getCombinerById (any ())).thenReturn (Optional .empty ());
39- try (final Response response = pulseApi .getAssetMapperInstructions (UUID .randomUUID (), UUID .randomUUID ())) {
40- assertThat (response .getStatus ()).isEqualTo (404 );
41- assertThat (response .getEntity ()).isInstanceOf (AssetMapperNotFoundError .class );
38+ public void whenCombinerAndMappingIdExist_thenReturnsOK () {
39+ final Combiner combiner = createCombiner (EntityType .PULSE_AGENT , DataIdentifierReference .TypeEnum .PULSE_ASSET );
40+ when (assetMappingExtractor .getCombinerById (any ())).thenReturn (Optional .of (DataCombiner .fromModel (combiner )));
41+ try (final Response response = pulseApi .getAssetMapperInstructions (combiner .getId (),
42+ combiner .getMappings ().getItems ().getFirst ().getId ())) {
43+ assertThat (response .getStatus ()).isEqualTo (200 );
44+ assertThat (response .getEntity ()).isInstanceOf (List .class )
45+ .isEqualTo (combiner .getMappings ()
46+ .getItems ()
47+ .stream ()
48+ .flatMap (mappings -> mappings .getInstructions ().stream ())
49+ .toList ());
4250 }
4351 }
4452
@@ -48,26 +56,18 @@ public void whenCombinerExistsButMappingIdDoesNotExist_thenReturnsOK() {
4856 when (assetMappingExtractor .getCombinerById (any ())).thenReturn (Optional .of (DataCombiner .fromModel (combiner )));
4957 try (final Response response = pulseApi .getAssetMapperInstructions (combiner .getId (), UUID .randomUUID ())) {
5058 assertThat (response .getStatus ()).isEqualTo (200 );
51- assertThat (response .getEntity ()).isInstanceOf (PulseApiImpl . InstructionList . class );
52- final PulseApiImpl . InstructionList instructionList = ( PulseApiImpl . InstructionList ) response . getEntity ();
53- assertThat ( instructionList . getItems ()) .isEmpty ();
59+ assertThat (response .getEntity ()).isInstanceOf (List . class )
60+ . asInstanceOf ( InstanceOfAssertFactories . LIST )
61+ .isEmpty ();
5462 }
5563 }
5664
5765 @ Test
58- public void whenCombinerAndMappingIdExist_thenReturnsOK () {
59- final Combiner combiner = createCombiner (EntityType .PULSE_AGENT , DataIdentifierReference .TypeEnum .PULSE_ASSET );
60- when (assetMappingExtractor .getCombinerById (any ())).thenReturn (Optional .of (DataCombiner .fromModel (combiner )));
61- try (final Response response = pulseApi .getAssetMapperInstructions (combiner .getId (),
62- combiner .getMappings ().getItems ().getFirst ().getId ())) {
63- assertThat (response .getStatus ()).isEqualTo (200 );
64- assertThat (response .getEntity ()).isInstanceOf (PulseApiImpl .InstructionList .class );
65- final PulseApiImpl .InstructionList instructionList = (PulseApiImpl .InstructionList ) response .getEntity ();
66- assertThat (instructionList .getItems ()).isEqualTo (combiner .getMappings ()
67- .getItems ()
68- .stream ()
69- .flatMap (mappings -> mappings .getInstructions ().stream ())
70- .toList ());
66+ public void whenCombinerNotFound_thenReturnsAssetMapperNotFoundError () {
67+ when (assetMappingExtractor .getCombinerById (any ())).thenReturn (Optional .empty ());
68+ try (final Response response = pulseApi .getAssetMapperInstructions (UUID .randomUUID (), UUID .randomUUID ())) {
69+ assertThat (response .getStatus ()).isEqualTo (404 );
70+ assertThat (response .getEntity ()).isInstanceOf (AssetMapperNotFoundError .class );
7171 }
7272 }
7373}
0 commit comments