Skip to content

Commit d4769eb

Browse files
authored
test: Add integration test for pulse agent (#1230)
1 parent 041be8d commit d4769eb

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

hivemq-edge/src/main/java/com/hivemq/api/resources/impl/PulseApiImpl.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.hivemq.api.errors.pulse.MissingEntityTypePulseAgentForAssetMapperError;
3636
import com.hivemq.api.errors.pulse.PulseAgentDeactivatedError;
3737
import com.hivemq.api.errors.pulse.PulseAgentNotConnectedError;
38-
import com.hivemq.api.model.ItemsResponse;
3938
import com.hivemq.combining.model.DataCombiner;
4039
import com.hivemq.combining.model.EntityType;
4140
import com.hivemq.configuration.entity.pulse.PulseAssetEntity;
@@ -354,7 +353,7 @@ public PulseApiImpl(
354353
.flatMap(dataCombining -> dataCombining.instructions().stream())
355354
.map(com.hivemq.persistence.mappings.fieldmapping.Instruction::toModel)
356355
.toList();
357-
return Response.ok().entity(new InstructionList(instructions)).build();
356+
return Response.ok().entity(instructions).build();
358357
}
359358
}
360359

@@ -679,10 +678,4 @@ private void notifyAssetMapper(final @NotNull PulseAgentAsset asset) {
679678
.anyMatch(dataCombining -> Objects.equals(asset.getMapping().getId(), dataCombining.id())))
680679
.forEach(assetMappingExtractor::updateDataCombiner);
681680
}
682-
683-
public static class InstructionList extends ItemsResponse<Instruction> {
684-
public InstructionList(final @NotNull List<com.hivemq.edge.api.model.Instruction> items) {
685-
super(items);
686-
}
687-
}
688681
}

hivemq-edge/src/test/java/com/hivemq/api/resources/impl/pulse/PulseApiImplGetAssetMapperInstructionsTest.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package com.hivemq.api.resources.impl.pulse;
1818

1919
import com.hivemq.api.errors.pulse.AssetMapperNotFoundError;
20-
import com.hivemq.api.resources.impl.PulseApiImpl;
2120
import com.hivemq.combining.model.DataCombiner;
2221
import com.hivemq.edge.api.model.Combiner;
2322
import com.hivemq.edge.api.model.DataIdentifierReference;
2423
import com.hivemq.edge.api.model.EntityType;
2524
import jakarta.ws.rs.core.Response;
25+
import org.assertj.core.api.InstanceOfAssertFactories;
2626
import org.junit.jupiter.api.Test;
2727

28+
import java.util.List;
2829
import java.util.Optional;
2930
import java.util.UUID;
3031

@@ -34,11 +35,18 @@
3435

3536
public 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

Comments
 (0)