Refactoring of RepostioryManagement and extending classes (#2174)

* createMetaData renamed to putMetaData
* getXXX methods returing Optional are renamed to findXXX
* unified method order (code cosmetics)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-08 14:03:04 +02:00
committed by GitHub
parent cad18fe04b
commit 6504bc26d9
55 changed files with 942 additions and 986 deletions

View File

@@ -357,7 +357,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
distributionSetTypeManagement.delete(type.getId());
// check if the ds type is marked as deleted
final Optional<DistributionSetType> opt = distributionSetTypeManagement.getByKey(type.getKey());
final Optional<DistributionSetType> opt = distributionSetTypeManagement.findByKey(type.getKey());
if (opt.isEmpty()) {
throw new AssertionError("The Optional object of distribution set type should not be empty!");
}
@@ -883,13 +883,13 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final MvcResult mvcResult = executeMgmtTargetPost(one, two, three);
one = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql(PAGE, "name==one").getContent().get(0).getId())
.getWithDetails(distributionSetManagement.findByRsql("name==one", PAGE).getContent().get(0).getId())
.get();
two = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql(PAGE, "name==two").getContent().get(0).getId())
.getWithDetails(distributionSetManagement.findByRsql("name==two", PAGE).getContent().get(0).getId())
.get();
three = distributionSetManagement
.getWithDetails(distributionSetManagement.findByRsql(PAGE, "name==three").getContent().get(0).getId())
.getWithDetails(distributionSetManagement.findByRsql("name==three", PAGE).getContent().get(0).getId())
.get();
assertThat(
@@ -1122,9 +1122,9 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.andExpect(jsonPath("[1]value", equalTo(knownValue2)));
final DistributionSetMetadata metaKey1 = distributionSetManagement
.getMetaDataByDistributionSetId(testDS.getId(), knownKey1).get();
.findMetaDataByDistributionSetId(testDS.getId(), knownKey1).get();
final DistributionSetMetadata metaKey2 = distributionSetManagement
.getMetaDataByDistributionSetId(testDS.getId(), knownKey2).get();
.findMetaDataByDistributionSetId(testDS.getId(), knownKey2).get();
assertThat(metaKey1.getValue()).isEqualTo(knownValue1);
assertThat(metaKey2.getValue()).isEqualTo(knownValue2);
@@ -1145,7 +1145,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
// verify that the number of meta data entries has not changed
// (we cannot use the PAGE constant here as it tries to sort by ID)
assertThat(distributionSetManagement
.findMetaDataByDistributionSetId(PageRequest.of(0, Integer.MAX_VALUE), testDS.getId())
.findMetaDataByDistributionSetId(testDS.getId(), PageRequest.of(0, Integer.MAX_VALUE))
.getTotalElements()).isEqualTo(metaData1.length());
}
@@ -1173,7 +1173,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.andExpect(jsonPath("value", equalTo(updateValue)));
final DistributionSetMetadata assertDS = distributionSetManagement
.getMetaDataByDistributionSetId(testDS.getId(), knownKey).get();
.findMetaDataByDistributionSetId(testDS.getId(), knownKey).get();
assertThat(assertDS.getValue()).isEqualTo(updateValue);
}
@@ -1192,7 +1192,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(distributionSetManagement.getMetaDataByDistributionSetId(testDS.getId(), knownKey)).isNotPresent();
assertThat(distributionSetManagement.findMetaDataByDistributionSetId(testDS.getId(), knownKey)).isNotPresent();
}
@Test
@@ -1213,7 +1213,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
assertThat(distributionSetManagement.getMetaDataByDistributionSetId(testDS.getId(), knownKey)).isPresent();
assertThat(distributionSetManagement.findMetaDataByDistributionSetId(testDS.getId(), knownKey)).isPresent();
}
@Test
@@ -1240,7 +1240,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
final String knownValuePrefix = "knownValue";
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
for (int index = 0; index < totalMetadata; index++) {
distributionSetManagement.createMetaData(testDS.getId(),
distributionSetManagement.putMetaData(testDS.getId(),
List.of(entityFactory.generateDsMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
}

View File

@@ -194,11 +194,11 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag createdOne = distributionSetTagManagement.findByRsql(PAGE, "name==thetest1").getContent().get(0);
final Tag createdOne = distributionSetTagManagement.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 = distributionSetTagManagement.findByRsql(PAGE, "name==thetest2").getContent().get(0);
final Tag createdTwo = distributionSetTagManagement.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());
@@ -227,7 +227,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final Tag updated = distributionSetTagManagement.findByRsql(PAGE, "name==updatedName").getContent().get(0);
final Tag updated = distributionSetTagManagement.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());
@@ -333,7 +333,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
// 2 DistributionSetUpdateEvent
ResultActions result = toggle(tag, sets);
List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
.containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()));
@@ -349,7 +349,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
result.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(0), "unassignedDistributionSets"))
.andExpect(applyBaseEntityMatcherOnArrayResult(updated.get(1), "unassignedDistributionSets"));
assertThat(distributionSetManagement.findByTag(PAGE, tag.getId())).isEmpty();
assertThat(distributionSetManagement.findByTag(tag.getId(), PAGE)).isEmpty();
}
@Test
@@ -367,7 +367,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
.containsOnly(set.getId());
}
@@ -389,7 +389,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
.containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()));
}
@@ -414,7 +414,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
.containsOnly(assigned.getId());
}
@@ -440,7 +440,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
.containsOnly(assigned.getId());
}
@@ -505,7 +505,7 @@ public class MgmtDistributionSetTagResourceTest extends AbstractManagementApiInt
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE));
final List<DistributionSet> updated = distributionSetManagement.findByTag(PAGE, tag.getId()).getContent();
final List<DistributionSet> updated = distributionSetManagement.findByTag(tag.getId(), PAGE).getContent();
assertThat(updated.stream().map(DistributionSet::getId).collect(Collectors.toList()))
.containsAll(sets.stream().map(DistributionSet::getId).collect(Collectors.toList()));

View File

@@ -675,9 +675,9 @@ class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIntegrati
@Step
private void verifyCreatedDistributionSetTypes(final MvcResult mvcResult) throws UnsupportedEncodingException {
final DistributionSetType created1 = distributionSetTypeManagement.getByKey("testKey1").get();
final DistributionSetType created2 = distributionSetTypeManagement.getByKey("testKey2").get();
final DistributionSetType created3 = distributionSetTypeManagement.getByKey("testKey3").get();
final DistributionSetType created1 = distributionSetTypeManagement.findByKey("testKey1").get();
final DistributionSetType created2 = distributionSetTypeManagement.findByKey("testKey2").get();
final DistributionSetType created3 = distributionSetTypeManagement.findByKey("testKey3").get();
assertThat(created1.getMandatoryModuleTypes()).containsOnly(osType);
assertThat(created1.getOptionalModuleTypes()).containsOnly(runtimeType);

View File

@@ -117,7 +117,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
softwareModuleTypeManagement.delete(sm.getType().getId());
//check if it is marked as deleted
final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.getByKey(SM_TYPE);
final Optional<SoftwareModuleType> opt = softwareModuleTypeManagement.findByKey(SM_TYPE);
if (opt.isEmpty()) {
throw new AssertionError("The Optional object of software module type should not be empty!");
}
@@ -164,7 +164,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
for (int index = 0; index < totalMetadata; index++) {
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
.key(knownKeyPrefix + index).value(knownValuePrefix + index));
}
@@ -184,7 +184,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
for (int index = 0; index < totalMetadata; index++) {
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata().create(module.getId())
.key(knownKeyPrefix + index).value(knownValuePrefix + index));
}
@@ -204,7 +204,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String knownKey = "knownKey";
final String knownValue = "knownValue";
final SoftwareModule module = testdataFactory.createDistributionSet("one").findFirstModuleByType(osType).get();
softwareModuleManagement.createMetaData(
softwareModuleManagement.updateMetaData(
entityFactory.softwareModuleMetadata().create(module.getId()).key(knownKey).value(knownValue));
mvc.perform(
@@ -1265,9 +1265,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("[1].createdAt", not(equalTo(0))))
.andReturn();
final SoftwareModule osCreated = softwareModuleManagement.getByNameAndVersionAndType("name1", "version1",
final SoftwareModule osCreated = softwareModuleManagement.findByNameAndVersionAndType("name1", "version1",
osType.getId()).get();
final SoftwareModule appCreated = softwareModuleManagement.getByNameAndVersionAndType("name3", "version3",
final SoftwareModule appCreated = softwareModuleManagement.findByNameAndVersionAndType("name3", "version3",
appType.getId()).get();
assertThat(JsonPath.compile("[0]._links.self.href")
@@ -1281,13 +1281,13 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.isEqualTo("http://localhost/rest/v1/softwaremodules/" + appCreated.getId());
assertThat(softwareModuleManagement.findAll(PAGE)).as("Wrong softwaremodule size").hasSize(2);
assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0).getName()).as(
assertThat(softwareModuleManagement.findByType(osType.getId(), PAGE).getContent().get(0).getName()).as(
"Softwaremoudle name is wrong").isEqualTo(os.getName());
assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0).getCreatedBy()).as(
assertThat(softwareModuleManagement.findByType(osType.getId(), PAGE).getContent().get(0).getCreatedBy()).as(
"Softwaremoudle created by is wrong").isEqualTo("uploadTester");
assertThat(softwareModuleManagement.findByType(PAGE, osType.getId()).getContent().get(0).getCreatedAt()).as(
assertThat(softwareModuleManagement.findByType(osType.getId(), PAGE).getContent().get(0).getCreatedAt()).as(
"Softwaremoudle created at is wrong").isGreaterThanOrEqualTo(current);
assertThat(softwareModuleManagement.findByType(PAGE, appType.getId()).getContent().get(0).getName()).as(
assertThat(softwareModuleManagement.findByType(appType.getId(), PAGE).getContent().get(0).getName()).as(
"Softwaremoudle name is wrong").isEqualTo(ah.getName());
}
@@ -1376,9 +1376,9 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("[1].value", equalTo(knownValue2)))
.andExpect(jsonPath("[1].targetVisible", equalTo(true)));
assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(), knownKey1))
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey1))
.as("Metadata key is wrong").get().extracting(SoftwareModuleMetadata::getValue).isEqualTo(knownValue1);
assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(), knownKey2))
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey2))
.as("Metadata key is wrong").get().extracting(SoftwareModuleMetadata::getValue).isEqualTo(knownValue2);
// verify quota enforcement
@@ -1411,7 +1411,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String updateValue = "valueForUpdate";
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
softwareModuleManagement.createMetaData(
softwareModuleManagement.updateMetaData(
entityFactory.softwareModuleMetadata().create(sm.getId()).key(knownKey).value(knownValue));
final JSONObject jsonObject = new JSONObject().put("key", knownKey)
@@ -1426,7 +1426,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("key", equalTo(knownKey)))
.andExpect(jsonPath("value", equalTo(updateValue)));
final SoftwareModuleMetadata assertDS = softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(),
final SoftwareModuleMetadata assertDS = softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(),
knownKey).get();
assertThat(assertDS.getValue()).as("Metadata is wrong").isEqualTo(updateValue);
assertThat(assertDS.isTargetVisible()).as("target visible is wrong").isTrue();
@@ -1440,14 +1440,14 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String knownValue = "knownValue";
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
softwareModuleManagement.createMetaData(
softwareModuleManagement.updateMetaData(
entityFactory.softwareModuleMetadata().create(sm.getId()).key(knownKey).value(knownValue));
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/{key}", sm.getId(), knownKey))
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isNotPresent();
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isNotPresent();
}
@Test
@@ -1458,7 +1458,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final String knownValue = "knownValue";
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
softwareModuleManagement.createMetaData(
softwareModuleManagement.updateMetaData(
entityFactory.softwareModuleMetadata().create(sm.getId()).key(knownKey).value(knownValue));
mvc.perform(delete("/rest/v1/softwaremodules/{swId}/metadata/XXX", sm.getId(), knownKey))
@@ -1469,7 +1469,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
.andDo(MockMvcResultPrinter.print())
.andExpect(status().isNotFound());
assertThat(softwareModuleManagement.getMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isPresent();
assertThat(softwareModuleManagement.findMetaDataBySoftwareModuleId(sm.getId(), knownKey)).isPresent();
}
@Test
@@ -1489,7 +1489,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes
final SoftwareModule sm = testdataFactory.createSoftwareModuleOs();
for (int index = 0; index < totalMetadata; index++) {
softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata()
softwareModuleManagement.updateMetaData(entityFactory.softwareModuleMetadata()
.create(sm.getId())
.key(knownKeyPrefix + index)
.value(knownValuePrefix + index));

View File

@@ -210,9 +210,9 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
.andExpect(jsonPath("[2].maxAssignments", equalTo(3)))
.andReturn();
final SoftwareModuleType created1 = softwareModuleTypeManagement.getByKey("test1").get();
final SoftwareModuleType created2 = softwareModuleTypeManagement.getByKey("test2").get();
final SoftwareModuleType created3 = softwareModuleTypeManagement.getByKey("test3").get();
final SoftwareModuleType created1 = softwareModuleTypeManagement.findByKey("test1").get();
final SoftwareModuleType created2 = softwareModuleTypeManagement.findByKey("test2").get();
final SoftwareModuleType created3 = softwareModuleTypeManagement.findByKey("test3").get();
assertThat(
JsonPath.compile("[0]_links.self.href").read(mvcResult.getResponse().getContentAsString()).toString())

View File

@@ -390,7 +390,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
void deletingDsTypeRemovesAssignmentFromTargetType() throws Exception {
TargetType testType = createTestTargetTypeInDB("TestTypeRemoveDs", Collections.singletonList(standardDsType));
assertThat(testType.getCompatibleDistributionSetTypes()).hasSize(1);
assertThat(distributionSetTypeManagement.getByKey(standardDsType.getKey())).isNotEmpty();
assertThat(distributionSetTypeManagement.findByKey(standardDsType.getKey())).isNotEmpty();
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/" + standardDsType.getId()))
.andDo(MockMvcResultPrinter.print())
@@ -400,7 +400,7 @@ class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
assertThat(testType.getOptLockRevision()).isEqualTo(2);
assertThat(testType.getCompatibleDistributionSetTypes()).isEmpty();
assertThat(distributionSetTypeManagement.getByKey(standardDsType.getKey())).isEmpty();
assertThat(distributionSetTypeManagement.findByKey(standardDsType.getKey())).isEmpty();
}
@Test