Refactor management api style (#2445)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-06-10 17:09:03 +03:00
committed by GitHub
parent 85ef8652fc
commit 2992f5c211
88 changed files with 671 additions and 736 deletions

View File

@@ -311,7 +311,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
assertThat(targetManagement.findByAssignedDistributionSet(PAGE, createdDs.getId()).getContent())
assertThat(targetManagement.findByAssignedDistributionSet(createdDs.getId(), PAGE).getContent())
.as("Five targets in repository have DS assigned").hasSize(5);
}
@@ -398,7 +398,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.contentType(MediaType.APPLICATION_JSON).content(payload.toString()))
.andExpect(status().isForbidden());
assertThat(targetManagement.findByAssignedDistributionSet(PAGE, ds.getId()).getContent()).isEmpty();
assertThat(targetManagement.findByAssignedDistributionSet(ds.getId(), PAGE).getContent()).isEmpty();
}
@Test
@@ -451,10 +451,10 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(targets.size())));
assertThat(targetManagement.findByAssignedDistributionSet(PAGE, createdDs.getId()).getContent())
assertThat(targetManagement.findByAssignedDistributionSet(createdDs.getId(), PAGE).getContent())
.as("Five targets in repository have DS assigned").hasSize(5);
assertThat(targetManagement.findByInstalledDistributionSet(PAGE, createdDs.getId()).getContent()).hasSize(4);
assertThat(targetManagement.findByInstalledDistributionSet(createdDs.getId(), PAGE).getContent()).hasSize(4);
}
@Test
@@ -789,7 +789,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
@Description("Ensures that multiple DS requested are listed with expected payload.")
void getDistributionSets() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
DistributionSet set = testdataFactory.createDistributionSet("one");
set = distributionSetManagement.update(entityFactory.distributionSet().update(set.getId())
@@ -798,7 +798,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// load also lazy stuff
set = distributionSetManagement.getWithDetails(set.getId()).get();
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(1);
// perform request
mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON))
@@ -864,7 +864,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
@WithUser(principal = "uploadTester", allSpPermissions = true)
@Description("Ensures that multipe DS posted to API are created in the repository.")
void createDistributionSets() throws Exception {
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
final SoftwareModule ah = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_APP);
final SoftwareModule jvm = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_RT);
final SoftwareModule os = testdataFactory.createSoftwareModule(TestdataFactory.SM_TYPE_OS);
@@ -907,7 +907,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.hasToString(String.valueOf(three.getId()));
// check in database
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(3);
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(3);
assertThat(one.isRequiredMigrationStep()).isFalse();
assertThat(two.isRequiredMigrationStep()).isFalse();
assertThat(three.isRequiredMigrationStep()).isTrue();
@@ -921,11 +921,11 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
@Description("Ensures that DS deletion request to API is reflected by the repository.")
void deleteUnassignedistributionSet() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(1);
// perform request
mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId()))
@@ -933,7 +933,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(status().isOk());
// check repository content
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
assertThat(distributionSetManagement.count()).isZero();
}
@@ -949,13 +949,13 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
@Description("Ensures that assigned DS deletion request to API is reflected by the repository by means of deleted flag set.")
void deleteAssignedDistributionSet() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
final DistributionSet set = testdataFactory.createDistributionSet("one");
testdataFactory.createTarget("test");
assignDistributionSet(set.getId(), "test");
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).hasSize(1);
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()))
.andDo(MockMvcResultPrinter.print())
@@ -972,14 +972,14 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.deleted", equalTo(true)));
// check repository content
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
}
@Test
@Description("Ensures that DS property update request to API is reflected by the repository.")
void updateDistributionSet() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.count()).isEqualTo(1);
@@ -1009,7 +1009,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
void updateRequiredMigrationStepFailsIfDistributionSetisInUse() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
final DistributionSet set = testdataFactory.createDistributionSet("one");
assignDistributionSet(set.getId(), testdataFactory.createTarget().getControllerId());
@@ -1310,7 +1310,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
assertThat(targetManagement.findByAssignedDistributionSet(PAGE, createdDs.getId()).getContent())
assertThat(targetManagement.findByAssignedDistributionSet(createdDs.getId(), PAGE).getContent())
.as("Five targets in repository have DS assigned").hasSize(5);
}
@@ -1604,7 +1604,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
@Description("Tests the lock. It is verified that the distribution set can be marked as locked through update operation.")
void lockDistributionSet() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.count()).isEqualTo(1);
@@ -1626,7 +1626,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
@Description("Tests the unlock.")
void unlockDistributionSet() throws Exception {
// prepare test data
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).isEmpty();
assertThat(distributionSetManagement.findByCompleted(true, PAGE)).isEmpty();
final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.count()).isEqualTo(1);

View File

@@ -459,7 +459,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
rolloutHandler.handleAll();
final Rollout rollout = rolloutManagement.findByRsql(PAGE, "name==rollout1", false).getContent().get(0);
final Rollout rollout = rolloutManagement.findByRsql("name==rollout1", false, PAGE).getContent().get(0);
rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll();
@@ -766,7 +766,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
final DistributionSet dsA = testdataFactory.createDistributionSet("");
postRollout("rollout1", 5, dsA.getId(), "id==target*", 20, Action.ActionType.FORCED);
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
final List<Rollout> content = rolloutManagement.findAll(false, PAGE).getContent();
assertThat(content).hasSizeGreaterThan(0).allSatisfy(rollout -> {
assertThat(rolloutGroupManagement.findByRollout(rollout.getId(), PAGE))
.describedAs("Confirmation required flag depends on feature active.")
@@ -803,7 +803,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(status().isCreated())
.andReturn();
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
final List<Rollout> content = rolloutManagement.findAll(false, PAGE).getContent();
assertThat(content).hasSize(1).allSatisfy(rollout -> {
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getContent();
assertThat(groups).hasSize(2).allMatch(group -> {
@@ -846,7 +846,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andExpect(status().isCreated())
.andReturn();
final List<Rollout> content = rolloutManagement.findAll(PAGE, false).getContent();
final List<Rollout> content = rolloutManagement.findAll(false, PAGE).getContent();
assertThat(content).hasSize(1).allSatisfy(rollout -> {
final List<RolloutGroup> groups = rolloutGroupManagement.findByRollout(rollout.getId(), PAGE).getContent();
assertThat(groups).hasSize(2).allMatch(group -> {
@@ -1552,7 +1552,7 @@ class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTest {
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated());
final List<Rollout> rollouts = rolloutManagement.findAll(PAGE, false).getContent();
final List<Rollout> rollouts = rolloutManagement.findAll(false, PAGE).getContent();
assertThat(rollouts).hasSize(2);
assertThat(rollouts.get(0).getWeight()).get().isEqualTo(weight);
}

View File

@@ -275,8 +275,7 @@ public class MgmtTargetFilterQueryResourceTest extends AbstractManagementApiInte
+ filterQuery.getId();
final String distributionsetHrefPrefix = "http://localhost" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING;
final String dsQuery = "?offset=0&limit=50&q=name==" + set.getName() + ";" + "version==" + set.getVersion();
final String dsQuery = "?q=name==" + set.getName() + ";" + "version==" + set.getVersion() + "&offset=0&limit=50";
mvc.perform(
post(MgmtRestConstants.TARGET_FILTER_V1_REQUEST_MAPPING + "/" + filterQuery.getId() + "/autoAssignDS")
.content("{\"id\":" + set.getId() + "}").contentType(MediaType.APPLICATION_JSON))

View File

@@ -376,7 +376,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
final PageRequest pageRequest = PageRequest.of(0, 1000, Direction.ASC, ActionFields.ID.getJpaEntityFieldName());
final Action action = deploymentManagement.findActionsByTarget(knownTargetId, pageRequest).getContent().get(0);
final ActionStatus status = deploymentManagement.findActionStatusByAction(PAGE, action.getId()).getContent()
final ActionStatus status = deploymentManagement.findActionStatusByAction(action.getId(), PAGE).getContent()
.stream().sorted((e1, e2) -> Long.compare(e2.getId(), e1.getId())).toList().get(0);
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId + "/"
@@ -1337,7 +1337,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
final String knownTargetId = "targetId";
final Action action = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId).get(0);
// retrieve list in default descending order for actionstaus entries
final List<ActionStatus> actionStatus = deploymentManagement.findActionStatusByAction(PAGE, action.getId())
final List<ActionStatus> actionStatus = deploymentManagement.findActionStatusByAction(action.getId(), PAGE)
.getContent().stream().sorted((e1, e2) -> Long.compare(e2.getId(), e1.getId()))
.toList();
@@ -1365,7 +1365,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
void getActionsStatusSortedByReportedAt() throws Exception {
final String knownTargetId = "targetId";
final Action action = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId).get(0);
final List<ActionStatus> actionStatus = deploymentManagement.findActionStatusByAction(PAGE, action.getId())
final List<ActionStatus> actionStatus = deploymentManagement.findActionStatusByAction(action.getId(), PAGE)
.getContent().stream().sorted(Comparator.comparingLong(Identifiable::getId))
.toList();
@@ -1414,7 +1414,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
final String knownTargetId = "targetId";
final Action action = generateTargetWithTwoUpdatesWithOneOverride(knownTargetId).get(0);
final List<ActionStatus> actionStatus = deploymentManagement.findActionStatusByAction(PAGE, action.getId())
final List<ActionStatus> actionStatus = deploymentManagement.findActionStatusByAction(action.getId(), PAGE)
.getContent().stream().sorted((e1, e2) -> Long.compare(e1.getId(), e2.getId()))
.toList();
@@ -1668,7 +1668,7 @@ class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest {
implicitLock(set);
final List<Action> findActiveActionsByTarget = deploymentManagement
.findActiveActionsByTarget(PAGE, target.getControllerId()).getContent();
.findActiveActionsByTarget(target.getControllerId(), PAGE).getContent();
assertThat(findActiveActionsByTarget).hasSize(1);
assertThat(findActiveActionsByTarget.get(0).getActionType()).isEqualTo(ActionType.TIMEFORCED);
assertThat(findActiveActionsByTarget.get(0).getForcedTime()).isEqualTo(forceTime);

View File

@@ -22,12 +22,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
import io.qameta.allure.Description;
import io.qameta.allure.Feature;
@@ -49,9 +47,6 @@ import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
import org.eclipse.hawkbit.rest.util.JsonBuilder;
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.ResultActions;
@@ -163,11 +158,11 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag createdOne = targetTagManagement.findByRsql(PAGE, "name==thetest1").getContent().get(0);
final Tag createdOne = targetTagManagement.findByRsql("name==thetest1", PAGE).getContent().get(0);
assertThat(createdOne.getName()).isEqualTo(tagOne.getName());
assertThat(createdOne.getDescription()).isEqualTo(tagOne.getDescription());
assertThat(createdOne.getColour()).isEqualTo(tagOne.getColour());
final Tag createdTwo = targetTagManagement.findByRsql(PAGE, "name==thetest2").getContent().get(0);
final Tag createdTwo = targetTagManagement.findByRsql("name==thetest2", PAGE).getContent().get(0);
assertThat(createdTwo.getName()).isEqualTo(tagTwo.getName());
assertThat(createdTwo.getDescription()).isEqualTo(tagTwo.getDescription());
assertThat(createdTwo.getColour()).isEqualTo(tagTwo.getColour());
@@ -196,7 +191,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag updated = targetTagManagement.findByRsql(PAGE, "name==updatedName").getContent().get(0);
final Tag updated = targetTagManagement.findByRsql("name==updatedName", PAGE).getContent().get(0);
assertThat(updated.getName()).isEqualTo(update.getName());
assertThat(updated.getDescription()).isEqualTo(update.getDescription());
assertThat(updated.getColour()).isEqualTo(update.getColour());
@@ -303,7 +298,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<Target> updated = targetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(Target::getControllerId).toList()).containsOnly(assigned.getControllerId());
}
@@ -325,7 +320,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<Target> updated = targetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(Target::getControllerId).toList())
.containsOnly(assigned0.getControllerId(), assigned1.getControllerId());
}
@@ -366,7 +361,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
Collections.sort(notFound);
assertThat(notFound).isEqualTo(missing);
});
assertThat(targetManagement.findByTag(PAGE, tag.getId()).getContent()).isEmpty();
assertThat(targetManagement.findByTag(tag.getId(), PAGE).getContent()).isEmpty();
}
@Test
@@ -407,7 +402,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
Collections.sort(notFound);
assertThat(notFound).isEqualTo(missing);
});
assertThat(targetManagement.findByTag(PAGE, tag.getId()).getContent().stream().map(Target::getControllerId).sorted().toList())
assertThat(targetManagement.findByTag(tag.getId(), PAGE).getContent().stream().map(Target::getControllerId).sorted().toList())
.isEqualTo(targets.stream().sorted().toList());
}
@@ -440,7 +435,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(targetManagement.findByTag(PAGE, tag.getId()).getContent().stream().map(Target::getControllerId).sorted().toList())
assertThat(targetManagement.findByTag(tag.getId(), PAGE).getContent().stream().map(Target::getControllerId).sorted().toList())
.isEqualTo(targets.stream().sorted().toList());
}
@@ -463,7 +458,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<Target> updated = targetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(Target::getControllerId).toList())
.containsOnly(assigned.getControllerId());
}
@@ -489,7 +484,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<Target> updated = targetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(Target::getControllerId).toList())
.containsOnly(assigned.getControllerId());
}
@@ -533,7 +528,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
Collections.sort(notFound);
assertThat(notFound).isEqualTo(missing);
});
assertThat(targetManagement.findByTag(PAGE, tag.getId()).getContent().stream().map(Target::getControllerId).sorted().toList())
assertThat(targetManagement.findByTag(tag.getId(), PAGE).getContent().stream().map(Target::getControllerId).sorted().toList())
.isEqualTo(targets.stream().sorted().toList());
}
@@ -577,7 +572,7 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
Collections.sort(notFound);
assertThat(notFound).isEqualTo(missing);
});
assertThat(targetManagement.findByTag(PAGE, tag.getId()).getContent()).isEmpty();
assertThat(targetManagement.findByTag(tag.getId(), PAGE).getContent()).isEmpty();
}
@Test
@@ -611,6 +606,6 @@ public class MgmtTargetTagResourceTest extends AbstractManagementApiIntegrationT
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(targetManagement.findByTag(PAGE, tag.getId()).getContent()).isEmpty();
assertThat(targetManagement.findByTag(tag.getId(), PAGE).getContent()).isEmpty();
}
}