Target REST API returns OK with empty list when no tags (#1786)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com
This commit is contained in:
@@ -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")
|
@Operation(summary = "Return tags for specific target", description = "Get a paged list of tags for a target. Required permission: READ_REPOSITORY")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "Successfully retrieved"),
|
@ApiResponse(responseCode = "200", description = "Successfully retrieved"),
|
||||||
@ApiResponse(responseCode = "204", description = "No tags"),
|
|
||||||
@ApiResponse(responseCode = "401", description = "The request requires user authentication.",
|
@ApiResponse(responseCode = "401", description = "The request requires user authentication.",
|
||||||
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
content = @Content(mediaType = "application/json", schema = @Schema(hidden = true))),
|
||||||
@ApiResponse(responseCode = "403",
|
@ApiResponse(responseCode = "403",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
|
|||||||
|
|
||||||
import java.util.AbstractMap.SimpleEntry;
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@@ -397,11 +398,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
|||||||
@Override
|
@Override
|
||||||
public ResponseEntity<List<MgmtTag>> getTags(@PathVariable("targetId") String targetId) {
|
public ResponseEntity<List<MgmtTag>> getTags(@PathVariable("targetId") String targetId) {
|
||||||
final Set<TargetTag> tags = targetManagement.getTagsByControllerId(targetId);
|
final Set<TargetTag> tags = targetManagement.getTagsByControllerId(targetId);
|
||||||
if (tags.isEmpty()) {
|
return ResponseEntity.ok(
|
||||||
return ResponseEntity.noContent().build();
|
MgmtTagMapper.toResponse(tags == null ? Collections.emptyList() : tags.stream().toList()));
|
||||||
} else {
|
|
||||||
return ResponseEntity.ok(MgmtTagMapper.toResponse(tags.stream().toList()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1898,22 +1898,17 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getControllerTagReturnsTagWithNoContent() throws Exception {
|
void getControllerTagReturnsTagsWithOk() 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 {
|
|
||||||
// create target with attributes
|
// create target with attributes
|
||||||
final String knownTargetId = "targetIdWithTags";
|
final String knownTargetId = "targetIdWithTags";
|
||||||
final Target target = testdataFactory.createTarget(knownTargetId);
|
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<TargetTag> targetTags = testdataFactory.createTargetTags(2, "tag_getControllerTagReturnsTagWithOk");
|
final List<TargetTag> targetTags = testdataFactory.createTargetTags(2, "tag_getControllerTagReturnsTagWithOk");
|
||||||
final List<String> tagNames = new ArrayList<>();
|
final List<String> tagNames = new ArrayList<>();
|
||||||
for (final TargetTag targetTag : targetTags) {
|
for (final TargetTag targetTag : targetTags) {
|
||||||
@@ -1921,7 +1916,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
|
|||||||
tagNames.add(targetTag.getName());
|
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"))
|
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/tags"))
|
||||||
.andDo(MockMvcResultPrinter.print())
|
.andDo(MockMvcResultPrinter.print())
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
|
|||||||
Reference in New Issue
Block a user