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

@@ -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