Refactor @ApiResponses annotations (#2879)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2026-01-22 09:10:10 +02:00
committed by GitHub
parent ad9a690f0e
commit d55f1ffa10
57 changed files with 783 additions and 3622 deletions

View File

@@ -71,7 +71,7 @@ public class MgmtActionResource implements MgmtActionRestApi {
}
@Override
@AuditLog(entity = "Actions",type = AuditLog.Type.DELETE, description = "Delete Action", logResponse = true)
@AuditLog(entity = "Actions", type = AuditLog.Type.DELETE, description = "Delete Action", logResponse = true)
public ResponseEntity<Void> deleteAction(Long actionId) {
deploymentManagement.deleteAction(actionId);
return ResponseEntity.noContent().build();

View File

@@ -159,7 +159,7 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
dsTypeKey));
}
return dsType;
}).orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, dsTypeKey))));
}).orElseThrow(() -> new EntityNotFoundException(DistributionSetType.class, dsTypeKey))));
final Collection<? extends DistributionSet> createdDSets =
distributionSetManagement.create(mgmtDistributionSetMapper.fromRequest(sets, defaultDsKey, dsTypeKeyToDsType));

View File

@@ -85,7 +85,8 @@ class MgmtDistributionSetTagResource implements MgmtDistributionSetTagRestApi {
public ResponseEntity<List<MgmtTag>> createDistributionSetTags(final List<MgmtTagRequestBodyPut> tags) {
log.debug("creating {} ds tags", tags.size());
final List<? extends DistributionSetTag> createdTags = distributionSetTagManagement.create(MgmtDistributionSetMapper.mapTagFromRequest(tags));
final List<? extends DistributionSetTag> createdTags = distributionSetTagManagement
.create(MgmtDistributionSetMapper.mapTagFromRequest(tags));
return new ResponseEntity<>(MgmtTagMapper.toResponseDistributionSetTag(createdTags), HttpStatus.CREATED);
}

View File

@@ -60,7 +60,8 @@ public class MgmtDistributionSetTypeResource implements MgmtDistributionSetTypeR
@Override
public ResponseEntity<PagedList<MgmtDistributionSetType>> getDistributionSetTypes(
final String rsqlParam, final int pagingOffsetParam, final int pagingLimitParam, final String sortParam) {
final Pageable pageable = PagingUtility.toPageable(pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetTypeSortParam(sortParam));
final Pageable pageable = PagingUtility.toPageable(
pagingOffsetParam, pagingLimitParam, sanitizeDistributionSetTypeSortParam(sortParam));
final Slice<? extends DistributionSetType> findModuleTypesAll;
long countModulesAll;
if (rsqlParam != null) {

View File

@@ -263,7 +263,8 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi {
}
@Override
public ResponseEntity<Void> updateMetadata(final Long softwareModuleId, final String metadataKey, final MgmtSoftwareModuleMetadataBodyPut metadata) {
public ResponseEntity<Void> updateMetadata(
final Long softwareModuleId, final String metadataKey, final MgmtSoftwareModuleMetadataBodyPut metadata) {
softwareModuleManagement.createMetadata(
softwareModuleId, metadataKey, new MetadataValueCreate(metadata.getValue(), metadata.getTargetVisible()));
return ResponseEntity.noContent().build();

View File

@@ -249,16 +249,6 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
.orElseGet(() -> ResponseEntity.notFound().build());
}
private Optional<Action> getValidatedAction(final String targetId, final Long actionId) {
final Action action = deploymentManagement.findAction(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.getTarget().getControllerId().equals(targetId)) {
log.warn(ACTION_TARGET_MISSING_ASSIGN_WARN, action.getId(), targetId);
return Optional.empty();
}
return Optional.of(action);
}
@Override
@AuditLog(entity = "Target", type = AuditLog.Type.UPDATE, description = "Cancel Target Action")
public ResponseEntity<Void> cancelAction(final String targetId, final Long actionId, final boolean force) {
@@ -479,6 +469,16 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
return ResponseEntity.noContent().build();
}
private Optional<Action> getValidatedAction(final String targetId, final Long actionId) {
final Action action = deploymentManagement.findAction(actionId)
.orElseThrow(() -> new EntityNotFoundException(Action.class, actionId));
if (!action.getTarget().getControllerId().equals(targetId)) {
log.warn(ACTION_TARGET_MISSING_ASSIGN_WARN, action.getId(), targetId);
return Optional.empty();
}
return Optional.of(action);
}
private <T, R> R getNullIfEmpty(final T object, final Function<T, R> extractMethod) {
return ObjectUtils.isEmpty(object) ? null : extractMethod.apply(object);
}

View File

@@ -62,7 +62,7 @@ public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
findTargetTypes = targetTypeManagement.findAll(pageable);
}
return ResponseEntity.ok(
new PagedList<>(MgmtTargetTypeMapper.toListResponse(findTargetTypes.getContent()), findTargetTypes.getTotalElements()));
new PagedList<>(MgmtTargetTypeMapper.toListResponse(findTargetTypes.getContent()), findTargetTypes.getTotalElements()));
}
@Override

View File

@@ -76,10 +76,10 @@ public final class MgmtDistributionSetTypeMapper {
public static void addLinks(final MgmtDistributionSetType result) {
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getMandatoryModules(result.getId()))
.withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_MANDATORY_MODULES).expand());
.withRel(MgmtRestConstants.MANDATORYMODULES).expand());
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getOptionalModules(result.getId()))
.withRel(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_OPTIONAL_MODULES).expand());
.withRel(MgmtRestConstants.OPTIONALMODULES).expand());
}
private DistributionSetTypeManagement.Create fromRequest(final MgmtDistributionSetTypeRequestBodyPost smsRest) {

View File

@@ -74,7 +74,7 @@ public final class MgmtTargetTypeMapper {
public static void addLinks(final MgmtTargetType result) {
result.add(linkTo(methodOn(MgmtTargetTypeRestApi.class).getCompatibleDistributionSets(result.getId()))
.withRel(MgmtRestConstants.TARGETTYPE_V1_DS_TYPES).expand());
.withRel(MgmtRestConstants.COMPATIBLEDISTRIBUTIONSETTYPES).expand());
}
private TargetTypeManagement.Create fromRequest(final MgmtTargetTypeRequestBodyPost targetTypesRest) {

View File

@@ -282,7 +282,7 @@ class JsonBuilder {
private static RolloutGroupConditions getConditions(final RolloutGroup rolloutGroup) {
if (rolloutGroup == null) {
return new RolloutGroupConditionBuilder().withDefaults().build();
return new RolloutGroupConditionBuilder().withDefaults().build();
} else {
return new RolloutGroupConditionBuilder()
.errorCondition(rolloutGroup.getErrorCondition(), rolloutGroup.getErrorConditionExp())

View File

@@ -543,7 +543,7 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
actionIdsToDelete.add(deletedActionId2);
mvc.perform(delete(MgmtRestConstants.ACTION_V1_REQUEST_MAPPING)
.content(toJson(actionIdsToDelete)).contentType(APPLICATION_JSON))
.content(toJson(actionIdsToDelete)).contentType(APPLICATION_JSON))
.andExpect(status().isNoContent());
mvc.perform(get(ACTION_V1_REQUEST_MAPPING + "/" + deletedActionId1))
@@ -581,6 +581,19 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(status().isBadRequest());
}
private static String generateActionLink(final String targetId, final Long actionId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING +
"/" + targetId + "/" + MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId;
}
private static String generateTargetLink(final String targetId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId;
}
private static String generateDistributionSetLink(final Action action) {
return "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + action.getDistributionSet().getId();
}
private List<DistributionSetAssignmentResult> createTargetsAndPerformAssignment(int n) {
final List<Target> targets = new ArrayList<>();
for (int i = 0; i < n; i++) {
@@ -595,19 +608,6 @@ class MgmtActionResourceTest extends AbstractManagementApiIntegrationTest {
return results;
}
private static String generateActionLink(final String targetId, final Long actionId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING +
"/" + targetId + "/" + MgmtRestConstants.TARGET_V1_ACTIONS + "/" + actionId;
}
private static String generateTargetLink(final String targetId) {
return "http://localhost" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId;
}
private static String generateDistributionSetLink(final Action action) {
return "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + action.getDistributionSet().getId();
}
private void verifyResultsByTargetPropertyFilter(final Target target, final DistributionSet ds, final String rsqlTargetFilter)
throws Exception {
// pending status one result

View File

@@ -71,19 +71,18 @@ import org.springframework.web.context.WebApplicationContext;
classes = { MgmtApiConfiguration.class, RestConfiguration.class, JpaRepositoryConfiguration.class, TestConfiguration.class })
class MgmtBasicAuthResourceTest {
private static final String DEFAULT_TENANT = "DEFAULT";
private static final String TEST_USER = "testUser";
@Autowired
protected WebApplicationContext webApplicationContext;
@Autowired
MockMvc defaultMock;
private static final String DEFAULT_TENANT = "DEFAULT";
private static final String TEST_USER = "testUser";
/**
* Test of userinfo api with basic authentication validation
*/
@Test
@WithUser(principal = TEST_USER, authorities = {"READ", "WRITE", "DELETE"})
@WithUser(principal = TEST_USER, authorities = { "READ", "WRITE", "DELETE" })
void validateBasicAuthWithUserDetails() throws Exception {
withSecurityMock().perform(get(MgmtRestConstants.AUTH_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print())

View File

@@ -1831,6 +1831,22 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
Arguments.of(false, false), Arguments.of(true, null), Arguments.of(false, null));
}
private static List<MgmtDistributionSetRequestBodyPut> toMgmtDistributionSetPost(final List<DistributionSetManagement.Create> creates) {
return creates.stream()
.map(create ->
new MgmtDistributionSetRequestBodyPost()
.setType(create.getType().getKey())
.setModules(create.getModules().stream()
.map(module -> new MgmtSoftwareModuleAssignment().setId(module.getId()))
.map(MgmtSoftwareModuleAssignment.class::cast)
.toList())
.setName(create.getName())
.setDescription(create.getDescription())
.setVersion(create.getVersion())
.setRequiredMigrationStep(create.getRequiredMigrationStep()))
.toList();
}
private JSONArray createTargetAndJsonArray(final String schedule, final String duration, final String timezone,
final String type, final Boolean confirmationRequired, final String... targetIds) throws Exception {
final JSONArray result = new JSONArray();
@@ -1927,22 +1943,6 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andReturn();
}
private static List<MgmtDistributionSetRequestBodyPut> toMgmtDistributionSetPost(final List<DistributionSetManagement.Create> creates) {
return creates.stream()
.map(create ->
new MgmtDistributionSetRequestBodyPost()
.setType(create.getType().getKey())
.setModules(create.getModules().stream()
.map(module -> new MgmtSoftwareModuleAssignment().setId(module.getId()))
.map(MgmtSoftwareModuleAssignment.class::cast)
.toList())
.setName(create.getName())
.setDescription(create.getDescription())
.setVersion(create.getVersion())
.setRequiredMigrationStep(create.getRequiredMigrationStep()))
.toList();
}
private Set<DistributionSet> createDistributionSetsAlphabetical(final int amount) {
char character = 'a';
final Set<DistributionSet> created = new HashSet<>(amount);

View File

@@ -469,7 +469,7 @@ class MgmtDistributionSetTagResourceTest extends AbstractManagementApiIntegratio
final Map<String, Object> info = exceptionInfo.getInfo();
assertThat(info).isNotNull();
assertThat(info.get(EntityNotFoundException.TYPE)).isEqualTo(DistributionSet.class.getSimpleName());
final List<String> notFound = (List<String>)info.get(EntityNotFoundException.ENTITY_ID);
final List<String> notFound = (List<String>) info.get(EntityNotFoundException.ENTITY_ID);
Collections.sort(notFound);
assertThat(notFound).isEqualTo(missing);
});

View File

@@ -25,10 +25,8 @@ import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegrationTest {
@Test
void shouldRetrieveDistinctTargetGroups() throws Exception {
@@ -38,7 +36,7 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
targetManagement.create(builder().controllerId("target3").group("Europe").build());
mvc.perform(get(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING)
.contentType(MediaType.APPLICATION_JSON))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.[0]", Matchers.in(expectedGroups)))
.andExpect(jsonPath("$.[1]", Matchers.in(expectedGroups)));
@@ -51,8 +49,8 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
targetManagement.create(builder().controllerId("target3").group("Europe").build());
mvc.perform(get(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/assigned")
.param("group", "Europe/East")
.param("subgroups", "false"))
.param("group", "Europe/East")
.param("subgroups", "false"))
.andExpect(status().isOk())
.andExpect(jsonPath("content", Matchers.hasSize(1)))
.andExpect(jsonPath("content.[0].controllerId", Matchers.equalTo("target2")));
@@ -93,7 +91,6 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
.content(toJson(Arrays.asList("target1", "target2", "target3"))))
.andExpect(status().isNoContent());
mvc.perform(get(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/newGroup/assigned")
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "ID:ASC")
.contentType(MediaType.APPLICATION_JSON))
@@ -169,8 +166,8 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
targetManagement.create(builder().controllerId("target2").group("Europe").build());
mvc.perform(delete(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/assigned")
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(Arrays.asList("target1", "target2"))))
.contentType(MediaType.APPLICATION_JSON)
.content(toJson(Arrays.asList("target1", "target2"))))
.andExpect(status().isNoContent());
mvc.perform(get(MgmtRestConstants.TARGET_GROUP_V1_REQUEST_MAPPING + "/assigned")
@@ -230,7 +227,5 @@ public class MgmtTargetGroupResourceTest extends AbstractManagementApiIntegratio
.andExpect(jsonPath("content.[0].controllerId", Matchers.equalTo("target1")))
.andExpect(jsonPath("content.[1].controllerId", Matchers.equalTo("target2")))
.andExpect(jsonPath("content.[2].controllerId", Matchers.equalTo("target3")));
}
}

View File

@@ -2571,32 +2571,32 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
testdataFactory.createTargetType("targettype", Set.of());
// GET is not allowed
mvc.perform(get(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING, knownTargetId))
mvc.perform(get(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_ID_TARGETTYPE, knownTargetId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
// PUT is not allowed
mvc.perform(put(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING, knownTargetId))
mvc.perform(put(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_ID_TARGETTYPE, knownTargetId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isMethodNotAllowed());
// POST does not exist with path parameter targettype
mvc.perform(post(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING + "/123", knownTargetId))
mvc.perform(post(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_ID_TARGETTYPE + "/123", knownTargetId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// DELETE does not exist with path parameter targettype
mvc.perform(delete(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING + "/123", knownTargetId))
mvc.perform(delete(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_ID_TARGETTYPE + "/123", knownTargetId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
// Invalid content
mvc.perform(post(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING, knownTargetId))
mvc.perform(post(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_ID_TARGETTYPE, knownTargetId))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isUnsupportedMediaType());
// Bad request if id field is missing
mvc.perform(post(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING, knownTargetId)
mvc.perform(post(TARGET_V1_REQUEST_MAPPING + MgmtRestConstants.TARGET_TARGET_ID_TARGETTYPE, knownTargetId)
.content("{\"unknownfield\":123}").contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest());

View File

@@ -59,7 +59,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
private static final String TARGETTYPES_ENDPOINT = MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING;
private static final String TARGETTYPE_SINGLE_ENDPOINT = MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING + "/{typeid}";
private static final String TARGETTYPE_DSTYPES_ENDPOINT = TARGETTYPE_SINGLE_ENDPOINT + "/" + MgmtRestConstants.TARGETTYPE_V1_DS_TYPES;
private static final String TARGETTYPE_DSTYPES_ENDPOINT = TARGETTYPE_SINGLE_ENDPOINT + "/" + MgmtRestConstants.COMPATIBLEDISTRIBUTIONSETTYPES;
private static final String TARGETTYPE_DSTYPE_SINGLE_ENDPOINT = TARGETTYPE_DSTYPES_ENDPOINT + "/{dstypeid}";
private static final String TEST_USER = "targetTypeTester";

View File

@@ -63,7 +63,7 @@ class SortUtilityTest {
}
/**
* Sorting based on name with case sensitive is possible.
* Sorting based on name with case-sensitive is possible.
*/
@Test
@SuppressWarnings("squid:S2699") // assert no error