diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java index 89fa7a9f9..35f1277dc 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtTargetRestApi.java @@ -724,7 +724,6 @@ public interface MgmtTargetRestApi { @Operation(summary = "Return tags for specific target", description = "Get a paged list of tags for a target. Required permission: READ_REPOSITORY") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Successfully retrieved"), - @ApiResponse(responseCode = "204", description = "No tags"), @ApiResponse(responseCode = "401", description = "The request requires user authentication.", content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))), @ApiResponse(responseCode = "403", diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java index c0602f50e..ffa81d5b4 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResource.java @@ -11,6 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource; import java.util.AbstractMap.SimpleEntry; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -397,11 +398,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi { @Override public ResponseEntity> getTags(@PathVariable("targetId") String targetId) { final Set tags = targetManagement.getTagsByControllerId(targetId); - if (tags.isEmpty()) { - return ResponseEntity.noContent().build(); - } else { - return ResponseEntity.ok(MgmtTagMapper.toResponse(tags.stream().toList())); - } + return ResponseEntity.ok( + MgmtTagMapper.toResponse(tags == null ? Collections.emptyList() : tags.stream().toList())); } @Override diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java index 2703ee3c8..ea42bfbfa 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtTargetResourceTest.java @@ -1898,22 +1898,17 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest { } @Test - void getControllerTagReturnsTagWithNoContent() throws Exception { - // create target with attributes - final String knownTargetId = "targetIdWithNoTags"; - final Target target = testdataFactory.createTarget(knownTargetId); - - // test query target over rest resource - mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/tags")) - .andDo(MockMvcResultPrinter.print()) - .andExpect(status().isNoContent()); - } - - @Test - void getControllerTagReturnsTagWithOk() throws Exception { + void getControllerTagReturnsTagsWithOk() throws Exception { // create target with attributes final String knownTargetId = "targetIdWithTags"; final Target target = testdataFactory.createTarget(knownTargetId); + + // test query target over rest resource with no tags - expect OK with empty list + mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/tags")) + .andDo(MockMvcResultPrinter.print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", Matchers.hasSize(0))); + final List targetTags = testdataFactory.createTargetTags(2, "tag_getControllerTagReturnsTagWithOk"); final List tagNames = new ArrayList<>(); for (final TargetTag targetTag : targetTags) { @@ -1921,7 +1916,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest { tagNames.add(targetTag.getName()); } - // test query target over rest resource + // test query target over rest resource with 2 tags - expect OK with 2 tags the target is tagged with mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/tags")) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk())