Switch completely to locked for checking if DS could be functionally modified (#2766)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-10-22 11:46:36 +03:00
committed by GitHub
parent e154e1b18a
commit 3caa9d9eda
9 changed files with 191 additions and 243 deletions

View File

@@ -11,11 +11,13 @@ package org.eclipse.hawkbit.mgmt.rest.resource;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@@ -46,6 +48,7 @@ import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModuleAssi
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility; import org.eclipse.hawkbit.mgmt.rest.resource.util.ResourceUtility;
import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.DistributionSetManagement.Update;
import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.Create; import org.eclipse.hawkbit.repository.TargetFilterQueryManagement.Create;
import org.eclipse.hawkbit.repository.TargetManagement; import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException; import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
@@ -96,7 +99,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
void getSoftwareModules() throws Exception { void getSoftwareModules() throws Exception {
// Create DistributionSet with three software modules // Create DistributionSet with three software modules
final DistributionSet set = testdataFactory.createDistributionSet("SMTest"); final DistributionSet set = testdataFactory.createDistributionSet("SMTest");
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(set.getModules().size()))); .andExpect(jsonPath("$.size", equalTo(set.getModules().size())));
@@ -110,19 +113,19 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final DistributionSet set = testdataFactory.createUpdatedDistributionSet(); final DistributionSet set = testdataFactory.createUpdatedDistributionSet();
// post assignment // post assignment
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM") mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")
.param("offset", "1").param("limit", "2").param("sort", "version:DESC").param("q", "name==one*") .param("offset", "1").param("limit", "2").param("sort", "version:DESC").param("q", "name==one*")
.accept(MediaType.APPLICATION_JSON)) .accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); .andExpect(content().contentType(APPLICATION_JSON));
} }
/** /**
* This test verifies the deletion of a assigned Software Module of a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target. * This test verifies the deletion of a assigned Software Module of a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.
*/ */
@Test @Test
void deleteFailureWhenDistributionSetInUse() throws Exception { void failToDeleteWhenDistributionSetInUse() throws Exception {
// create DisSet // create DisSet
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Eris", "560a"); final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Eris", "560a");
final List<Long> smIDs = new ArrayList<>(); final List<Long> smIDs = new ArrayList<>();
@@ -133,8 +136,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
smList.put(new JSONObject().put("id", smID)); smList.put(new JSONObject().put("id", smID));
} }
// post assignment // post assignment
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())) .contentType(APPLICATION_JSON).content(smList.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
@@ -146,29 +149,27 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
list.put(new JSONObject().put("id", Long.valueOf(targetId))); list.put(new JSONObject().put("id", Long.valueOf(targetId)));
} }
assignDistributionSet(disSet.getId(), knownTargetIds[0]); assignDistributionSet(disSet.getId(), knownTargetIds[0]);
mvc.perform( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1))) .andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.total", equalTo(knownTargetIds.length))); .andExpect(jsonPath("$.total", equalTo(knownTargetIds.length)));
// try to delete the Software Module from DistSet that has been assigned // try to delete the Software Module from DistSet that has been assigned to the target - hence locked.
// to the target. mvc.perform(delete(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/" + smIDs.get(0))
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM/" .contentType(APPLICATION_JSON))
+ smIDs.get(0)).contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden()) .andExpect(status().isLocked())
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_REPO_ENTITY_READ_ONLY.getKey()))); .andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_LOCKED.getKey())));
} }
/** /**
* This test verifies that the assignment of a Software Module to a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target. * This test verifies that the assignment of a Software Module to a Distribution Set can not be achieved when that Distribution Set has been assigned or installed to a target.
*/ */
@Test @Test
void assignmentFailureWhenAssigningToUsedDistributionSet() throws Exception { void failToAssignWhenAssigningToUsedDistributionSet() throws Exception {
// create DisSet // create DisSet
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Mars", "686,980"); final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Mars", "686,980");
final List<Long> smIDs = new ArrayList<>(); final List<Long> smIDs = new ArrayList<>();
@@ -179,8 +180,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
smList.put(new JSONObject().put("id", smID)); smList.put(new JSONObject().put("id", smID));
} }
// post assignment // post assignment
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(smList.toString())) .contentType(APPLICATION_JSON).content(smList.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
@@ -189,8 +190,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final JSONArray list = createTargetAndJsonArray(null, null, null, null, null, knownTargetIds); final JSONArray list = createTargetAndJsonArray(null, null, null, null, null, knownTargetIds);
// assign DisSet to target and test assignment // assign DisSet to target and test assignment
assignDistributionSet(disSet.getId(), knownTargetIds[0]); assignDistributionSet(disSet.getId(), knownTargetIds[0]);
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(list.toString())) .contentType(APPLICATION_JSON).content(list.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1))) .andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
@@ -202,11 +203,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final JSONArray smList2 = new JSONArray(); final JSONArray smList2 = new JSONArray();
smList2.put(new JSONObject().put("id", sm2.getId())); smList2.put(new JSONObject().put("id", sm2.getId()));
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM") // fail because locked
.contentType(MediaType.APPLICATION_JSON).content(smList2.toString())) mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(APPLICATION_JSON).content(smList2.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden()) .andExpect(status().isLocked())
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_REPO_ENTITY_READ_ONLY.getKey()))); .andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_LOCKED.getKey())));
} }
/** /**
@@ -217,7 +219,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// create DisSet // create DisSet
final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Jupiter", "398,88"); final DistributionSet disSet = testdataFactory.createDistributionSetWithNoSoftwareModules("Jupiter", "398,88");
// Test if size is 0 // Test if size is 0
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(disSet.getModules().size()))); .andExpect(jsonPath("$.size", equalTo(disSet.getModules().size())));
@@ -226,12 +228,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
testdataFactory.createSoftwareModuleApp().getId()); testdataFactory.createSoftwareModuleApp().getId());
// post assignment // post assignment
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(toJson(smIDs.stream().map(MgmtId::new).toList()))) .contentType(APPLICATION_JSON).content(toJson(smIDs.stream().map(MgmtId::new).toList())))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
// Test if size is 3 // Test if size is 3
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(smIDs.size()))); .andExpect(jsonPath("$.size", equalTo(smIDs.size())));
@@ -245,20 +247,19 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// post assignment // post assignment
final String jsonIDs = toJson(moduleIDs.subList(0, maxSoftwareModules - smIDs.size()).stream().map(MgmtId::new).toList()); final String jsonIDs = toJson(moduleIDs.subList(0, maxSoftwareModules - smIDs.size()).stream().map(MgmtId::new).toList());
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(jsonIDs)) .contentType(APPLICATION_JSON).content(jsonIDs))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
// test if size corresponds with quota // test if size corresponds with quota
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM?limit={limit}", maxSoftwareModules * 2))
+ "/assignedSM?limit={limit}", maxSoftwareModules * 2))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(maxSoftwareModules))); .andExpect(jsonPath("$.size", equalTo(maxSoftwareModules)));
// post one more to cause the quota to be exceeded // post one more to cause the quota to be exceeded
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON) .contentType(APPLICATION_JSON)
.content(toJson(Stream.of(moduleIDs.get(moduleIDs.size() - 1)).map(MgmtId::new).toList()))) .content(toJson(Stream.of(moduleIDs.get(moduleIDs.size() - 1)).map(MgmtId::new).toList())))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden()) .andExpect(status().isForbidden())
@@ -267,19 +268,18 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// verify quota is also enforced for bulk uploads // verify quota is also enforced for bulk uploads
final DistributionSet disSet2 = testdataFactory.createDistributionSetWithNoSoftwareModules("Saturn", "4.0"); final DistributionSet disSet2 = testdataFactory.createDistributionSetWithNoSoftwareModules("Saturn", "4.0");
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet2.getId() + "/assignedSM") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet2.getId() + "/assignedSM")
.contentType(MediaType.APPLICATION_JSON).content(toJson(moduleIDs.stream().map(MgmtId::new).toList()))) .contentType(APPLICATION_JSON).content(toJson(moduleIDs.stream().map(MgmtId::new).toList())))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden()) .andExpect(status().isForbidden())
.andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName()))) .andExpect(jsonPath("$.exceptionClass", equalTo(AssignmentQuotaExceededException.class.getName())))
.andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey()))); .andExpect(jsonPath("$.errorCode", equalTo(SpServerError.SP_QUOTA_EXCEEDED.getKey())));
// verify size is still 0 // verify size is still 0
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet2.getId() + "/assignedSM")) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + disSet2.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(0))); .andExpect(jsonPath("$.size", equalTo(0)));
} }
/** /**
@@ -290,16 +290,16 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// Create DistributionSet with three software modules // Create DistributionSet with three software modules
final DistributionSet set = testdataFactory.createDistributionSet("Venus"); final DistributionSet set = testdataFactory.createDistributionSet("Venus");
int amountOfSM = set.getModules().size(); int amountOfSM = set.getModules().size();
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(amountOfSM))); .andExpect(jsonPath("$.size", equalTo(amountOfSM)));
// test the removal of all software modules one by one // test the removal of all software modules one by one
for (final SoftwareModule softwareModule : set.getModules()) { for (final SoftwareModule softwareModule : set.getModules()) {
final Long smId = softwareModule.getId(); final Long smId = softwareModule.getId();
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM/" + smId)) mvc.perform(delete(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM/" + smId))
.andExpect(status().isOk()); .andExpect(status().isOk());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM")) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedSM"))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(--amountOfSM))); .andExpect(jsonPath("$.size", equalTo(--amountOfSM)));
@@ -319,9 +319,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign already one target to DS // assign already one target to DS
assignDistributionSet(createdDs.getId(), knownTargetIds[0]); assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1))) .andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
@@ -349,9 +348,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
list.put(new JSONObject().put("id", targetId).put("type", "forced")); list.put(new JSONObject().put("id", targetId).put("type", "forced"));
} }
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()); .andExpect(status().isOk());
// we just need to make sure that no error 500 is returned // we just need to make sure that no error 500 is returned
} }
@@ -386,8 +384,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final MvcResult mvcResult = mvc final MvcResult mvcResult = mvc
.perform(post("/rest/v1/distributionsets") .perform(post("/rest/v1/distributionsets")
.content(toJson(toMgmtDistributionSetPost(List.of(generated)))) .content(toJson(toMgmtDistributionSetPost(List.of(generated))))
.contentType(MediaType.APPLICATION_JSON) .contentType(APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)) .accept(APPLICATION_JSON))
.andExpect(status().isBadRequest()) .andExpect(status().isBadRequest())
.andReturn(); .andReturn();
@@ -414,8 +412,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
} }
}); });
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + ds.getId() + "/assignedTargets") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + ds.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(payload.toString())) .contentType(APPLICATION_JSON).content(payload.toString()))
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
assertThat(targetManagement.findByAssignedDistributionSet(ds.getId(), PAGE).getContent()).isEmpty(); assertThat(targetManagement.findByAssignedDistributionSet(ds.getId(), PAGE).getContent()).isEmpty();
@@ -426,7 +424,6 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
*/ */
@Test @Test
void changeDistributionSetAssignmentForTargetUntilQuotaIsExceeded() throws Exception { void changeDistributionSetAssignmentForTargetUntilQuotaIsExceeded() throws Exception {
// create one target // create one target
final Target testTarget = testdataFactory.createTarget("trg1"); final Target testTarget = testdataFactory.createTarget("trg1");
final int maxActions = quotaManagement.getMaxActionsPerTarget(); final int maxActions = quotaManagement.getMaxActionsPerTarget();
@@ -444,8 +441,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign our test target to another distribution set and verify that // assign our test target to another distribution set and verify that
// the 'max actions per target' quota is exceeded // the 'max actions per target' quota is exceeded
final String json = new JSONArray().put(new JSONObject().put("id", testTarget.getControllerId())).toString(); final String json = new JSONArray().put(new JSONObject().put("id", testTarget.getControllerId())).toString();
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + ds3.getId() + "/assignedTargets") mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + ds3.getId() + "/assignedTargets")
.contentType(MediaType.APPLICATION_JSON).content(json)) .contentType(APPLICATION_JSON).content(json))
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
} }
@@ -468,8 +465,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign already one target to DS // assign already one target to DS
assignDistributionSet(createdDs.getId(), targets.get(0).getControllerId()); assignDistributionSet(createdDs.getId(), targets.get(0).getControllerId());
mvc.perform(post(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId()
+ "/assignedTargets?offline=true").contentType(MediaType.APPLICATION_JSON).content(list.toString())) + "/assignedTargets?offline=true").contentType(APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(targets.size() - 1))) .andExpect(jsonPath("$.assigned", equalTo(targets.size() - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
@@ -494,9 +491,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign already one target to DS // assign already one target to DS
assignDistributionSet(createdDs.getId(), knownTargetIds[0]); assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
} }
@@ -513,9 +509,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign already one target to DS // assign already one target to DS
assignDistributionSet(createdDs.getId(), knownTargetIds[0]); assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
} }
@@ -533,9 +528,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign already one target to DS // assign already one target to DS
assignDistributionSet(createdDs.getId(), knownTargetIds[0]); assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
@@ -553,9 +547,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign already one target to DS // assign already one target to DS
assignDistributionSet(createdDs.getId(), knownTargetIds[0]); assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
} }
@@ -582,9 +575,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// assign already one target to DS // assign already one target to DS
assignDistributionSet(createdDs.getId(), knownTargetIds[0]); assignDistributionSet(createdDs.getId(), knownTargetIds[0]);
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(list.toString()))
.contentType(MediaType.APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
@@ -601,9 +593,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
assignTargetJson.put(new JSONObject().put("id", "notexistingtarget").put("type", "forced")); assignTargetJson.put(new JSONObject().put("id", "notexistingtarget").put("type", "forced"));
mvc.perform(post( mvc.perform(post(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets") .contentType(APPLICATION_JSON).content(assignTargetJson.toString()))
.contentType(MediaType.APPLICATION_JSON).content(assignTargetJson.toString()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
.andExpect(jsonPath("$.assigned", equalTo(2))) .andExpect(jsonPath("$.assigned", equalTo(2)))
@@ -621,7 +612,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
testdataFactory.createTarget(knownTargetId); testdataFactory.createTarget(knownTargetId);
assignDistributionSet(createdDs.getId(), knownTargetId); assignDistributionSet(createdDs.getId(), knownTargetId);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets")) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(1))) .andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId))); .andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId)));
@@ -637,12 +628,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
assignDistributionSet(set, testdataFactory.createTargets(5, "targetMisc", "Test targets for query")) assignDistributionSet(set, testdataFactory.createTargets(5, "targetMisc", "Test targets for query"))
.getAssignedEntity(); .getAssignedEntity();
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedTargets") mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/assignedTargets")
.param("offset", "1").param("limit", "2").param("sort", "name:DESC") .param("offset", "1").param("limit", "2").param("sort", "name:DESC")
.param("q", "controllerId==target*").accept(MediaType.APPLICATION_JSON)) .param("q", "controllerId==target*").accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); .andExpect(content().contentType(APPLICATION_JSON));
} }
@@ -652,8 +643,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
@Test @Test
void getAssignedTargetsOfDistributionSetIsEmpty() throws Exception { void getAssignedTargetsOfDistributionSetIsEmpty() throws Exception {
final DistributionSet createdDs = testdataFactory.createDistributionSet(); final DistributionSet createdDs = testdataFactory.createDistributionSet();
mvc.perform(get( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(0))) .andExpect(jsonPath("$.size", equalTo(0)))
.andExpect(jsonPath("$.total", equalTo(0))); .andExpect(jsonPath("$.total", equalTo(0)));
@@ -677,8 +667,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
testdataFactory.sendUpdateActionStatusToTargets(Collections.singletonList(createTarget), Status.FINISHED, testdataFactory.sendUpdateActionStatusToTargets(Collections.singletonList(createTarget), Status.FINISHED,
Collections.singletonList("some message")); Collections.singletonList("some message"));
mvc.perform(get( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets"))
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/installedTargets"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(1))) .andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId))); .andExpect(jsonPath("$.content[0].controllerId", equalTo(knownTargetId)));
@@ -696,12 +685,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.map(Action::getTarget).toList(); .map(Action::getTarget).toList();
testdataFactory.sendUpdateActionStatusToTargets(targets, Status.FINISHED, "some message"); testdataFactory.sendUpdateActionStatusToTargets(targets, Status.FINISHED, "some message");
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/installedTargets") mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/installedTargets")
.param("offset", "1").param("limit", "2").param("sort", "name:DESC") .param("offset", "1").param("limit", "2").param("sort", "name:DESC")
.param("q", "controllerId==target*").accept(MediaType.APPLICATION_JSON)) .param("q", "controllerId==target*").accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); .andExpect(content().contentType(APPLICATION_JSON));
} }
/** /**
@@ -713,15 +702,14 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final String knownFilterName = "a"; final String knownFilterName = "a";
final DistributionSet createdDs = testdataFactory.createDistributionSet(); final DistributionSet createdDs = testdataFactory.createDistributionSet();
targetFilterQueryManagement.create(Create.builder().name(knownFilterName) targetFilterQueryManagement.create(
.query("name==y").autoAssignDistributionSet(createdDs).build()); Create.builder().name(knownFilterName).query("name==y").autoAssignDistributionSet(createdDs).build());
// create some dummy target filter queries // create some dummy target filter queries
targetFilterQueryManagement.create(Create.builder().name("b").query("name==y").build()); targetFilterQueryManagement.create(Create.builder().name("b").query("name==y").build());
targetFilterQueryManagement.create(Create.builder().name("c").query("name==y").build()); targetFilterQueryManagement.create(Create.builder().name("c").query("name==y").build());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/autoAssignTargetFilters"))
+ "/autoAssignTargetFilters"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(1))) .andExpect(jsonPath("$.size", equalTo(1)))
.andExpect(jsonPath("$.content[0].name", equalTo(knownFilterName))); .andExpect(jsonPath("$.content[0].name", equalTo(knownFilterName)));
@@ -735,13 +723,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final DistributionSet set = testdataFactory.createUpdatedDistributionSet(); final DistributionSet set = testdataFactory.createUpdatedDistributionSet();
targetFilterQueryManagement.create(Create.builder().name("filter1").query("name==a").autoAssignDistributionSet(set).build()); targetFilterQueryManagement.create(Create.builder().name("filter1").query("name==a").autoAssignDistributionSet(set).build());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/autoAssignTargetFilters") mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + set.getId() + "/autoAssignTargetFilters")
.param("offset", "1").param("limit", "2").param("sort", "name:DESC").param("q", "name==*1") .param("offset", "1").param("limit", "2").param("sort", "name:DESC").param("q", "name==*1")
.accept(MediaType.APPLICATION_JSON)) .accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)); .andExpect(content().contentType(APPLICATION_JSON));
} }
/** /**
@@ -753,8 +740,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final DistributionSet createdDs = testdataFactory.createDistributionSet(); final DistributionSet createdDs = testdataFactory.createDistributionSet();
final String invalidQuery = "unknownField=le=42"; final String invalidQuery = "unknownField=le=42";
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/autoAssignTargetFilters")
+ "/autoAssignTargetFilters").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, invalidQuery)) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, invalidQuery))
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
} }
@@ -769,8 +756,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
prepareTestFilters(filterNamePrefix, createdDs); prepareTestFilters(filterNamePrefix, createdDs);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/autoAssignTargetFilters")
+ "/autoAssignTargetFilters").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, query)) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, query))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(2))) .andExpect(jsonPath("$.size", equalTo(2)))
.andExpect(jsonPath("$.content[0].name", equalTo(filterNamePrefix + "1"))) .andExpect(jsonPath("$.content[0].name", equalTo(filterNamePrefix + "1")))
@@ -788,8 +775,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
prepareTestFilters(filterNamePrefix, createdDs); prepareTestFilters(filterNamePrefix, createdDs);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/autoAssignTargetFilters")
+ "/autoAssignTargetFilters").param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, query)) .param(MgmtRestConstants.REQUEST_PARAMETER_SEARCH, query))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.size", equalTo(0))); .andExpect(jsonPath("$.size", equalTo(0)));
} }
@@ -801,7 +788,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
void getDistributionSetsWithoutAdditionalRequestParameters() throws Exception { void getDistributionSetsWithoutAdditionalRequestParameters() throws Exception {
final int sets = 5; final int sets = 5;
createDistributionSetsAlphabetical(sets); createDistributionSetsAlphabetical(sets);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(sets))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(sets)))
@@ -817,8 +804,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final int sets = 5; final int sets = 5;
final int limitSize = 1; final int limitSize = 1;
createDistributionSetsAlphabetical(sets); createDistributionSetsAlphabetical(sets);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING).param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(limitSize)))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(sets))) .andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(sets)))
@@ -835,7 +821,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final int offsetParam = 2; final int offsetParam = 2;
final int expectedSize = sets - offsetParam; final int expectedSize = sets - offsetParam;
createDistributionSetsAlphabetical(sets); createDistributionSetsAlphabetical(sets);
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING)
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam)) .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offsetParam))
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(sets))) .param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(sets)))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
@@ -855,8 +841,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
assertThat(distributionSetManagement.findAll(PAGE)).isEmpty(); assertThat(distributionSetManagement.findAll(PAGE)).isEmpty();
DistributionSet set = testdataFactory.createDistributionSet("one"); DistributionSet set = testdataFactory.createDistributionSet("one");
set = distributionSetManagement.update(DistributionSetManagement.Update.builder().id(set.getId()) set = distributionSetManagement.update(Update.builder().id(set.getId()).version("anotherVersion").requiredMigrationStep(true).build());
.version("anotherVersion").requiredMigrationStep(true).build());
// load also lazy stuff // load also lazy stuff
set = distributionSetManagement.getWithDetails(set.getId()); set = distributionSetManagement.getWithDetails(set.getId());
@@ -864,7 +849,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
assertThat(distributionSetManagement.findAll(PAGE)).hasSize(1); assertThat(distributionSetManagement.findAll(PAGE)).hasSize(1);
// perform request // perform request
mvc.perform(get("/rest/v1/distributionsets").accept(MediaType.APPLICATION_JSON)) mvc.perform(get("/rest/v1/distributionsets").accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
@@ -882,9 +867,9 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt()))) .andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(set.getLastModifiedAt())))
.andExpect(jsonPath("$.content.[0].version", equalTo(set.getVersion()))) .andExpect(jsonPath("$.content.[0].version", equalTo(set.getVersion())))
.andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + runtimeType.getKey() + "')].id", .andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
contains(findFirstModuleByType(set, runtimeType).get().getId().intValue()))) contains(findFirstModuleByType(set, runtimeType).orElseThrow().getId().intValue())))
.andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + appType.getKey() + "')].id", .andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + appType.getKey() + "')].id",
contains(findFirstModuleByType(set, appType).get().getId().intValue()))) contains(findFirstModuleByType(set, appType).orElseThrow().getId().intValue())))
.andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + osType.getKey() + "')].id", .andExpect(jsonPath("$.content.[0].modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(getOsModule(set).intValue()))); contains(getOsModule(set).intValue())));
} }
@@ -898,7 +883,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final DistributionSet set = testdataFactory.createUpdatedDistributionSet(); final DistributionSet set = testdataFactory.createUpdatedDistributionSet();
// perform request // perform request
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(MediaType.APPLICATION_JSON)) mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId()).accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
@@ -917,16 +902,16 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("$.lastModifiedAt", equalTo(set.getLastModifiedAt()))) .andExpect(jsonPath("$.lastModifiedAt", equalTo(set.getLastModifiedAt())))
.andExpect(jsonPath("$.version", equalTo(set.getVersion()))) .andExpect(jsonPath("$.version", equalTo(set.getVersion())))
.andExpect(jsonPath("$.modules.[?(@.type=='" + runtimeType.getKey() + "')].id", .andExpect(jsonPath("$.modules.[?(@.type=='" + runtimeType.getKey() + "')].id",
contains(findFirstModuleByType(set, runtimeType).get().getId().intValue()))) contains(findFirstModuleByType(set, runtimeType).orElseThrow().getId().intValue())))
.andExpect(jsonPath("$.modules.[?(@.type=='" + appType.getKey() + "')].id", .andExpect(jsonPath("$.modules.[?(@.type=='" + appType.getKey() + "')].id",
contains(findFirstModuleByType(set, appType).get().getId().intValue()))) contains(findFirstModuleByType(set, appType).orElseThrow().getId().intValue())))
.andExpect(jsonPath("$.modules.[?(@.type=='" + osType.getKey() + "')].id", .andExpect(jsonPath("$.modules.[?(@.type=='" + osType.getKey() + "')].id",
contains(getOsModule(set).intValue()))); contains(getOsModule(set).intValue())));
} }
/** /**
* Ensures that multipe DS posted to API are created in the repository. * Ensures that multiple DS posted to API are created in the repository.
*/ */
@Test @Test
@WithUser(principal = "uploadTester", allSpPermissions = true) @WithUser(principal = "uploadTester", allSpPermissions = true)
@@ -984,9 +969,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
void deleteUnassignedistributionSet() throws Exception { void deleteUnassignedistributionSet() throws Exception {
// prepare test data // prepare test data
assertThat(distributionSetManagement.findAll(PAGE)).isEmpty(); assertThat(distributionSetManagement.findAll(PAGE)).isEmpty();
final DistributionSet set = testdataFactory.createDistributionSet("one"); final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.findAll(PAGE)).hasSize(1); assertThat(distributionSetManagement.findAll(PAGE)).hasSize(1);
// perform request // perform request
@@ -1059,7 +1042,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.toString(); .toString();
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body) mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON).accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.version", equalTo("anotherVersion"))) .andExpect(jsonPath("$.version", equalTo("anotherVersion")))
@@ -1090,15 +1073,15 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()) mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId())
.content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}") .content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}")
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON).accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden()); .andExpect(status().isLocked());
final DistributionSet setupdated = distributionSetManagement.find(set.getId()).get(); final DistributionSet setUpdated = distributionSetManagement.find(set.getId()).get();
assertThat(setupdated.isRequiredMigrationStep()).isFalse(); assertThat(setUpdated.isRequiredMigrationStep()).isFalse();
assertThat(setupdated.getVersion()).isEqualTo(set.getVersion()); assertThat(setUpdated.getVersion()).isEqualTo(set.getVersion());
assertThat(setupdated.getName()).isEqualTo(set.getName()); assertThat(setUpdated.getName()).isEqualTo(set.getName());
} }
/** /**
@@ -1125,26 +1108,26 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(status().isNotFound()); .andExpect(status().isNotFound());
// bad request - no content // bad request - no content
mvc.perform(post("/rest/v1/distributionsets").contentType(MediaType.APPLICATION_JSON)) mvc.perform(post("/rest/v1/distributionsets").contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
// bad request - bad content // bad request - bad content
mvc.perform(post("/rest/v1/distributionsets").content("sdfjsdlkjfskdjf".getBytes()) mvc.perform(post("/rest/v1/distributionsets").content("sdfjsdlkjfskdjf".getBytes())
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
final DistributionSetManagement.Create missingName = DistributionSetManagement.Create.builder().build(); final DistributionSetManagement.Create missingName = DistributionSetManagement.Create.builder().build();
mvc.perform(post("/rest/v1/distributionsets").content(toJson(List.of(missingName))) mvc.perform(post("/rest/v1/distributionsets").content(toJson(List.of(missingName)))
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
final DistributionSetManagement.Create toLongName = final DistributionSetManagement.Create toLongName =
testdataFactory.generateDistributionSet(randomString(NamedEntity.NAME_MAX_SIZE + 1)); testdataFactory.generateDistributionSet(randomString(NamedEntity.NAME_MAX_SIZE + 1));
mvc.perform(post("/rest/v1/distributionsets").content(toJson(List.of(toLongName))) mvc.perform(post("/rest/v1/distributionsets").content(toJson(List.of(toLongName)))
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
@@ -1186,7 +1169,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
metaData1.put(new JSONObject().put("key", knownKey2).put("value", knownValue2)); metaData1.put(new JSONObject().put("key", knownKey2).put("value", knownValue2));
mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()) mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId())
.contentType(MediaType.APPLICATION_JSON) .contentType(APPLICATION_JSON)
.content(metaData1.toString())) .content(metaData1.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated()); .andExpect(status().isCreated());
@@ -1203,7 +1186,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
} }
mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId()) mvc.perform(post("/rest/v1/distributionsets/{dsId}/metadata", testDS.getId())
.contentType(MediaType.APPLICATION_JSON) .contentType(APPLICATION_JSON)
.content(metaData2.toString())) .content(metaData2.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isForbidden()); .andExpect(status().isForbidden());
@@ -1227,7 +1210,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue); final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey) mvc.perform(put("/rest/v1/distributionsets/{dsId}/metadata/{key}", testDS.getId(), knownKey)
.contentType(MediaType.APPLICATION_JSON) .contentType(APPLICATION_JSON)
.content(jsonObject.toString())) .content(jsonObject.toString()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
@@ -1312,7 +1295,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
distributionSetManagement.createMetadata(testDS.getId(), Map.of(knownKeyPrefix + index, knownValuePrefix + index)); distributionSetManagement.createMetadata(testDS.getId(), Map.of(knownKeyPrefix + index, knownValuePrefix + index));
} }
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata", testDS.getId())) mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata", testDS.getId()))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaTypes.HAL_JSON)); .andExpect(content().contentType(MediaTypes.HAL_JSON));
@@ -1338,7 +1321,6 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("total", equalTo(2))) .andExpect(jsonPath("total", equalTo(2)))
.andExpect(jsonPath("content[0].name", equalTo("DS1test"))) .andExpect(jsonPath("content[0].name", equalTo("DS1test")))
.andExpect(jsonPath("content[1].name", equalTo("DS2test"))); .andExpect(jsonPath("content[1].name", equalTo("DS2test")));
} }
/** /**
@@ -1381,8 +1363,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final String rsqlFindTargetId1 = "controllerId==1"; final String rsqlFindTargetId1 = "controllerId==1";
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/" + createdDs.getId() + "/assignedTargets?q=" + rsqlFindTargetId1)
+ "/assignedTargets?q=" + rsqlFindTargetId1).contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1))) .andExpect(jsonPath("total", equalTo(1)))
.andExpect(jsonPath("size", equalTo(1))) .andExpect(jsonPath("size", equalTo(1)))
@@ -1403,7 +1385,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
assignDistributionSet(createdDs.getId(), knownTargetIds[0], Action.ActionType.DOWNLOAD_ONLY); assignDistributionSet(createdDs.getId(), knownTargetIds[0], Action.ActionType.DOWNLOAD_ONLY);
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", createdDs.getId()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", createdDs.getId())
.contentType(MediaType.APPLICATION_JSON).content(list.toString())) .contentType(APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1))) .andExpect(jsonPath("$.assigned", equalTo(knownTargetIds.length - 1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(1))) .andExpect(jsonPath("$.alreadyAssigned", equalTo(1)))
@@ -1418,8 +1400,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
*/ */
@ParameterizedTest @ParameterizedTest
@MethodSource("confirmationOptions") @MethodSource("confirmationOptions")
void assignTargetsToDistributionSetWithConfirmationOptions(final boolean confirmationFlowActive, void assignTargetsToDistributionSetWithConfirmationOptions(final boolean confirmationFlowActive, final Boolean confirmationRequired)
final Boolean confirmationRequired) throws Exception { throws Exception {
final DistributionSet createdDs = testdataFactory.createDistributionSet(); final DistributionSet createdDs = testdataFactory.createDistributionSet();
if (confirmationFlowActive) { if (confirmationFlowActive) {
@@ -1431,7 +1413,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final JSONArray list = createTargetAndJsonArray(null, null, null, null, confirmationRequired, targetId); final JSONArray list = createTargetAndJsonArray(null, null, null, null, confirmationRequired, targetId);
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", createdDs.getId()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", createdDs.getId())
.contentType(MediaType.APPLICATION_JSON).content(list.toString())) .contentType(APPLICATION_JSON).content(list.toString()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.assigned", equalTo(1))) .andExpect(jsonPath("$.assigned", equalTo(1)))
.andExpect(jsonPath("$.alreadyAssigned", equalTo(0))) .andExpect(jsonPath("$.alreadyAssigned", equalTo(0)))
@@ -1445,7 +1427,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
if (!confirmationFlowActive) { if (!confirmationFlowActive) {
return !action.isWaitingConfirmation(); return !action.isWaitingConfirmation();
} }
return confirmationRequired == null ? action.isWaitingConfirmation() return confirmationRequired == null
? action.isWaitingConfirmation()
: confirmationRequired == action.isWaitingConfirmation(); : confirmationRequired == action.isWaitingConfirmation();
}); });
} }
@@ -1463,7 +1446,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
body.put(getAssignmentObject(targetId, MgmtActionType.FORCED)); body.put(getAssignmentObject(targetId, MgmtActionType.FORCED));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString())
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()); .andExpect(status().isBadRequest());
} }
@@ -1481,19 +1464,18 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
body.put(getAssignmentObject(targetId, MgmtActionType.FORCED)); body.put(getAssignmentObject(targetId, MgmtActionType.FORCED));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString())
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(1))); .andExpect(jsonPath("total", equalTo(1)));
} }
/** /**
* Assigning targets multiple times to a DS in one request works in multiassignment mode. * Assigning targets multiple times to a DS in one request works in multi-assignment mode.
*/ */
@Test @Test
void multiAssignment() throws Exception { void multiAssignment() throws Exception {
final List<String> targetIds = testdataFactory.createTargets(2).stream().map(Target::getControllerId) final List<String> targetIds = testdataFactory.createTargets(2).stream().map(Target::getControllerId).toList();
.toList();
final Long dsId = testdataFactory.createDistributionSet().getId(); final Long dsId = testdataFactory.createDistributionSet().getId();
final JSONArray body = new JSONArray(); final JSONArray body = new JSONArray();
@@ -1504,7 +1486,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
enableMultiAssignments(); enableMultiAssignments();
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(body.toString())
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("total", equalTo(body.length()))); .andExpect(jsonPath("total", equalTo(body.length())));
@@ -1524,17 +1506,17 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.put(getAssignmentObject(targetId, MgmtActionType.FORCED, Action.WEIGHT_MIN - 1)); .put(getAssignmentObject(targetId, MgmtActionType.FORCED, Action.WEIGHT_MIN - 1));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString())
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
enableMultiAssignments(); enableMultiAssignments();
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyInvalide.toString()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyInvalide.toString())
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isBadRequest()) .andExpect(status().isBadRequest())
.andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation"))); .andExpect(jsonPath("$.errorCode", equalTo("hawkbit.server.error.repo.constraintViolation")));
mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString()) mvc.perform(post("/rest/v1/distributionsets/{ds}/assignedTargets", dsId).content(bodyValide.toString())
.contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()); .andExpect(status().isOk());
@@ -1552,15 +1534,13 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
DistributionSet ds1 = testdataFactory.createDistributionSet("DS1"); DistributionSet ds1 = testdataFactory.createDistributionSet("DS1");
DistributionSet ds2 = testdataFactory.createDistributionSet("DS2"); DistributionSet ds2 = testdataFactory.createDistributionSet("DS2");
testdataFactory.createRolloutByVariables("rollout1", "description", testdataFactory.createRolloutByVariables("rollout1", "description", 1, "name==targets*", ds1, "50", "5", false);
1, "name==targets*", ds1, "50", "5", false); Rollout rollout = testdataFactory.createRolloutByVariables("rollout2", "description", 1, "name==targets*", ds1, "50", "5", false);
Rollout rollout = testdataFactory.createRolloutByVariables("rollout2", "description",
1, "name==targets*", ds1, "50", "5", false);
rolloutManagement.start(rollout.getId()); rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll(); rolloutHandler.handleAll();
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/rollouts", ds1.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/rollouts", ds1.getId()).contentType(
MediaType.APPLICATION_JSON)) APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("rollouts.READY", equalTo(1))) .andExpect(jsonPath("rollouts.READY", equalTo(1)))
@@ -1569,8 +1549,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("actions").doesNotExist()) .andExpect(jsonPath("actions").doesNotExist())
.andExpect(jsonPath("totalAutoAssignments").doesNotExist()); .andExpect(jsonPath("totalAutoAssignments").doesNotExist());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/rollouts", ds2.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/rollouts", ds2.getId())
MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("rollouts").doesNotExist()) .andExpect(jsonPath("rollouts").doesNotExist())
@@ -1593,8 +1573,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
rolloutManagement.start(rollout.getId()); rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll(); rolloutHandler.handleAll();
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/actions", ds1.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/actions", ds1.getId())
MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("actions.RUNNING", equalTo(4))) .andExpect(jsonPath("actions.RUNNING", equalTo(4)))
@@ -1602,8 +1582,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("rollouts").doesNotExist()) .andExpect(jsonPath("rollouts").doesNotExist())
.andExpect(jsonPath("totalAutoAssignments").doesNotExist()); .andExpect(jsonPath("totalAutoAssignments").doesNotExist());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/actions", ds2.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/actions", ds2.getId())
MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("rollouts").doesNotExist()) .andExpect(jsonPath("rollouts").doesNotExist())
@@ -1626,16 +1606,16 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
targetFilterQueryManagement.create( targetFilterQueryManagement.create(
Create.builder().name("test filter 2").autoAssignDistributionSet(ds1).query("name==targets*").build()); Create.builder().name("test filter 2").autoAssignDistributionSet(ds1).query("name==targets*").build());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds1.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds1.getId()).contentType(
MediaType.APPLICATION_JSON)) APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("totalAutoAssignments", equalTo(2))) .andExpect(jsonPath("totalAutoAssignments", equalTo(2)))
.andExpect(jsonPath("rollouts").doesNotExist()) .andExpect(jsonPath("rollouts").doesNotExist())
.andExpect(jsonPath("actions").doesNotExist()); .andExpect(jsonPath("actions").doesNotExist());
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds2.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds2.getId()).contentType(
MediaType.APPLICATION_JSON)) APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("rollouts").doesNotExist()) .andExpect(jsonPath("rollouts").doesNotExist())
@@ -1656,13 +1636,12 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
targetFilterQueryManagement.create( targetFilterQueryManagement.create(
Create.builder().name("test filter 1").autoAssignDistributionSet(ds1).query("name==autoAssignments*").build()); Create.builder().name("test filter 1").autoAssignDistributionSet(ds1).query("name==autoAssignments*").build());
Rollout rollout = testdataFactory.createRolloutByVariables("rollout", "description", Rollout rollout = testdataFactory.createRolloutByVariables("rollout", "description", 1, "name==targets*", ds1, "50", "5", false);
1, "name==targets*", ds1, "50", "5", false);
rolloutManagement.start(rollout.getId()); rolloutManagement.start(rollout.getId());
rolloutHandler.handleAll(); rolloutHandler.handleAll();
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics", ds1.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics", ds1.getId())
MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("totalAutoAssignments", equalTo(1))) .andExpect(jsonPath("totalAutoAssignments", equalTo(1)))
@@ -1671,8 +1650,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
.andExpect(jsonPath("rollouts.RUNNING", equalTo(1))) .andExpect(jsonPath("rollouts.RUNNING", equalTo(1)))
.andExpect(jsonPath("rollouts.total", equalTo(1))); .andExpect(jsonPath("rollouts.total", equalTo(1)));
mvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds2.getId()).contentType( mvc.perform(get(DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{ds}/statistics/autoassignments", ds2.getId())
MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("rollouts").doesNotExist()) .andExpect(jsonPath("rollouts").doesNotExist())
@@ -1698,7 +1677,8 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
jsonObject.put("actionCancelationType", "soft"); jsonObject.put("actionCancelationType", "soft");
mvc.perform(post("/rest/v1/distributionsets/{ds}/invalidate", distributionSet.getId()) mvc.perform(post("/rest/v1/distributionsets/{ds}/invalidate", distributionSet.getId())
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON)
.content(jsonObject.toString()))
.andExpect(status().isOk()); .andExpect(status().isOk());
assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet()) assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet())
@@ -1733,7 +1713,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
jsonObject.put("actionCancelationType", "force"); jsonObject.put("actionCancelationType", "force");
mvc.perform(post("/rest/v1/distributionsets/{ds}/invalidate", distributionSet.getId()) mvc.perform(post("/rest/v1/distributionsets/{ds}/invalidate", distributionSet.getId())
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON)) .content(jsonObject.toString()).contentType(APPLICATION_JSON))
.andExpect(status().isOk()); .andExpect(status().isOk());
assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet()).isNull(); assertThat(targetFilterQueryManagement.find(targetFilterQuery.getId()).get().getAutoAssignDistributionSet()).isNull();
@@ -1766,7 +1746,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
jsonObject.put("actionCancelationType", "none"); jsonObject.put("actionCancelationType", "none");
mvc.perform(post("/rest/v1/distributionsets/{ds}/invalidate", distributionSet.getId()) mvc.perform(post("/rest/v1/distributionsets/{ds}/invalidate", distributionSet.getId())
.content(jsonObject.toString()).contentType(MediaType.APPLICATION_JSON)) .content(jsonObject.toString()).contentType(APPLICATION_JSON))
.andExpect(status().isOk()); .andExpect(status().isOk());
assertThat(rolloutManagement.get(rollout.getId()).getStatus()).isIn(RolloutStatus.RUNNING); assertThat(rolloutManagement.get(rollout.getId()).getStatus()).isIn(RolloutStatus.RUNNING);
@@ -1795,7 +1775,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// lock // lock
final String body = new JSONObject().put("locked", true).toString(); final String body = new JSONObject().put("locked", true).toString();
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body) mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON).accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.locked", equalTo(true))); .andExpect(jsonPath("$.locked", equalTo(true)));
@@ -1823,7 +1803,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
// unlock // unlock
final String body = new JSONObject().put("locked", false).toString(); final String body = new JSONObject().put("locked", false).toString();
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body) mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON).accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(jsonPath("$.locked", equalTo(false))); .andExpect(jsonPath("$.locked", equalTo(false)));
@@ -1887,7 +1867,7 @@ class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegrationTe
final DistributionSetManagement.Create three) throws Exception { final DistributionSetManagement.Create three) throws Exception {
return mvc return mvc
.perform(post("/rest/v1/distributionsets").content(toJson(toMgmtDistributionSetPost(List.of(one, two, three)))) .perform(post("/rest/v1/distributionsets").content(toJson(toMgmtDistributionSetPost(List.of(one, two, three))))
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .contentType(APPLICATION_JSON).accept(APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()) .andDo(MockMvcResultPrinter.print())
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))

View File

@@ -28,18 +28,6 @@ public class EntityReadOnlyException extends AbstractServerRtException {
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_READ_ONLY; private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_ENTITY_READ_ONLY;
public EntityReadOnlyException() {
super(THIS_ERROR);
}
public EntityReadOnlyException(final Throwable cause) {
super(THIS_ERROR, cause);
}
public EntityReadOnlyException(final String message, final Throwable cause) {
super(THIS_ERROR, message, cause);
}
public EntityReadOnlyException(final String message) { public EntityReadOnlyException(final String message) {
super(THIS_ERROR, message); super(THIS_ERROR, message);
} }

View File

@@ -194,7 +194,6 @@ abstract class AbstractJpaRepositoryManagement<T extends AbstractJpaBaseEntity,
@SuppressWarnings("java:S1066") // javaS1066 - better readable that way @SuppressWarnings("java:S1066") // javaS1066 - better readable that way
public T update(final U update) { public T update(final U update) {
final T entity = getValid(update.getId()); final T entity = getValid(update.getId());
checkUpdate(update, entity);
// update getId has no setter in target JPA entity but shall have getter and the value shall be the same // update getId has no setter in target JPA entity but shall have getter and the value shall be the same
// otherwise the Utils will throw an exception that there is no counterpart setter for getId // otherwise the Utils will throw an exception that there is no counterpart setter for getId
if (ObjectCopyUtil.copy(update, entity, false, this::attach)) { if (ObjectCopyUtil.copy(update, entity, false, this::attach)) {
@@ -222,7 +221,6 @@ abstract class AbstractJpaRepositoryManagement<T extends AbstractJpaBaseEntity,
final List<T> toSave = new ArrayList<>(toUpdate.values()); final List<T> toSave = new ArrayList<>(toUpdate.values());
for (final U u : update) { for (final U u : update) {
final T entity = toUpdate.get(u.getId()); final T entity = toUpdate.get(u.getId());
checkUpdate(u, entity);
// update getId has no setter in target JPA entity but shall have getter and the value shall be the same // update getId has no setter in target JPA entity but shall have getter and the value shall be the same
// otherwise the Utils will throw an exception that there is no counterpart setter for getId // otherwise the Utils will throw an exception that there is no counterpart setter for getId
if (ObjectCopyUtil.copy(u, entity, false, this::attach)) { if (ObjectCopyUtil.copy(u, entity, false, this::attach)) {
@@ -262,8 +260,6 @@ abstract class AbstractJpaRepositoryManagement<T extends AbstractJpaBaseEntity,
.orElseGet(() -> List.of(QLSupport.getInstance().buildSpec(rsql, fieldsClass()))); .orElseGet(() -> List.of(QLSupport.getInstance().buildSpec(rsql, fieldsClass())));
} }
protected void checkUpdate(final U update, final T distributionSet) {}
// return which are for soft deletion // return which are for soft deletion
@SuppressWarnings("java:S1172") // java:S1172 - it is intended to be used by subclasses @SuppressWarnings("java:S1172") // java:S1172 - it is intended to be used by subclasses
protected Collection<T> softDelete(final Collection<T> toDelete) { protected Collection<T> softDelete(final Collection<T> toDelete) {

View File

@@ -32,6 +32,7 @@ import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.InvalidMd5HashException; import org.eclipse.hawkbit.repository.exception.InvalidMd5HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSha1HashException; import org.eclipse.hawkbit.repository.exception.InvalidSha1HashException;
import org.eclipse.hawkbit.repository.exception.InvalidSha256HashException; import org.eclipse.hawkbit.repository.exception.InvalidSha256HashException;
import org.eclipse.hawkbit.repository.exception.LockedException;
import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper; import org.eclipse.hawkbit.repository.jpa.JpaManagementHelper;
import org.eclipse.hawkbit.repository.jpa.acm.AccessController; import org.eclipse.hawkbit.repository.jpa.acm.AccessController;
import org.eclipse.hawkbit.repository.jpa.configuration.Constants; import org.eclipse.hawkbit.repository.jpa.configuration.Constants;
@@ -109,6 +110,12 @@ public class JpaArtifactManagement implements ArtifactManagement {
softwareModuleId -> artifactRepository.count(null, ArtifactSpecifications.bySoftwareModuleId(softwareModuleId))); softwareModuleId -> artifactRepository.count(null, ArtifactSpecifications.bySoftwareModuleId(softwareModuleId)));
final JpaSoftwareModule softwareModule = softwareModuleRepository.getById(moduleId); final JpaSoftwareModule softwareModule = softwareModuleRepository.getById(moduleId);
if (softwareModule.isLocked()) {
// check in order to:
// - on non-existing artifact - skip binary storing before, eventual, failing in new JpaSoftwareModule.addArtifact
// - if existing and overriding - no check will be made in new JpaSoftwareModule.addArtifact, so we sh to fail here
throw new LockedException(JpaSoftwareModule.class, softwareModule.getId(), "ADD_ARTIFACT");
}
final String filename = artifactUpload.filename(); final String filename = artifactUpload.filename();
final Artifact existing = softwareModule.getArtifactByFilename(filename).orElse(null); final Artifact existing = softwareModule.getArtifactByFilename(filename).orElse(null);
@@ -243,12 +250,13 @@ public class JpaArtifactManagement implements ArtifactManagement {
} }
private Artifact storeArtifactMetadata( private Artifact storeArtifactMetadata(
final SoftwareModule softwareModule, final String providedFilename, final JpaSoftwareModule softwareModule, final String providedFilename,
final ArtifactHashes hash, final long fileSize, final ArtifactHashes hash, final long fileSize,
final Artifact existing) { final Artifact existing) {
final JpaArtifact artifact; final JpaArtifact artifact;
if (existing == null) { if (existing == null) {
artifact = new JpaArtifact(hash.sha1(), providedFilename, softwareModule); artifact = new JpaArtifact(hash.sha1(), providedFilename, softwareModule);
softwareModule.addArtifact(artifact);
} else { } else {
artifact = (JpaArtifact) existing; artifact = (JpaArtifact) existing;
artifact.setSha1Hash(hash.sha1()); artifact.setSha1Hash(hash.sha1());

View File

@@ -36,7 +36,6 @@ import org.eclipse.hawkbit.repository.RepositoryProperties;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.exception.DeletedException; import org.eclipse.hawkbit.repository.exception.DeletedException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException; import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException; import org.eclipse.hawkbit.repository.exception.RSQLParameterSyntaxException;
@@ -47,7 +46,6 @@ import org.eclipse.hawkbit.repository.jpa.model.JpaDistributionSet_;
import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule; import org.eclipse.hawkbit.repository.jpa.model.JpaSoftwareModule;
import org.eclipse.hawkbit.repository.jpa.ql.Node; import org.eclipse.hawkbit.repository.jpa.ql.Node;
import org.eclipse.hawkbit.repository.jpa.ql.QLSupport; import org.eclipse.hawkbit.repository.jpa.ql.QLSupport;
import org.eclipse.hawkbit.repository.jpa.repository.ActionRepository;
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetRepository;
import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetTagRepository; import org.eclipse.hawkbit.repository.jpa.repository.DistributionSetTagRepository;
import org.eclipse.hawkbit.repository.jpa.repository.SoftwareModuleRepository; import org.eclipse.hawkbit.repository.jpa.repository.SoftwareModuleRepository;
@@ -85,7 +83,6 @@ public class JpaDistributionSetManagement
private final SoftwareModuleRepository softwareModuleRepository; private final SoftwareModuleRepository softwareModuleRepository;
private final DistributionSetTagRepository distributionSetTagRepository; private final DistributionSetTagRepository distributionSetTagRepository;
private final TargetFilterQueryRepository targetFilterQueryRepository; private final TargetFilterQueryRepository targetFilterQueryRepository;
private final ActionRepository actionRepository;
private final QuotaManagement quotaManagement; private final QuotaManagement quotaManagement;
private final TenantConfigHelper tenantConfigHelper; private final TenantConfigHelper tenantConfigHelper;
private final RepositoryProperties repositoryProperties; private final RepositoryProperties repositoryProperties;
@@ -98,7 +95,6 @@ public class JpaDistributionSetManagement
final SoftwareModuleRepository softwareModuleRepository, final SoftwareModuleRepository softwareModuleRepository,
final DistributionSetTagRepository distributionSetTagRepository, final DistributionSetTagRepository distributionSetTagRepository,
final TargetFilterQueryRepository targetFilterQueryRepository, final TargetFilterQueryRepository targetFilterQueryRepository,
final ActionRepository actionRepository,
final QuotaManagement quotaManagement, final QuotaManagement quotaManagement,
final SystemSecurityContext systemSecurityContext, final SystemSecurityContext systemSecurityContext,
final TenantConfigurationManagement tenantConfigurationManagement, final TenantConfigurationManagement tenantConfigurationManagement,
@@ -108,7 +104,6 @@ public class JpaDistributionSetManagement
this.softwareModuleRepository = softwareModuleRepository; this.softwareModuleRepository = softwareModuleRepository;
this.distributionSetTagRepository = distributionSetTagRepository; this.distributionSetTagRepository = distributionSetTagRepository;
this.targetFilterQueryRepository = targetFilterQueryRepository; this.targetFilterQueryRepository = targetFilterQueryRepository;
this.actionRepository = actionRepository;
this.quotaManagement = quotaManagement; this.quotaManagement = quotaManagement;
this.tenantConfigHelper = TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement); this.tenantConfigHelper = TenantConfigHelper.usingContext(systemSecurityContext, tenantConfigurationManagement);
this.repositoryProperties = repositoryProperties; this.repositoryProperties = repositoryProperties;
@@ -175,13 +170,6 @@ public class JpaDistributionSetManagement
return updated; return updated;
} }
@Override
protected void checkUpdate(final Update update, final JpaDistributionSet distributionSet) {
if (update.getRequiredMigrationStep() != null && !update.getRequiredMigrationStep().equals(distributionSet.isRequiredMigrationStep())) {
assertDistributionSetIsNotAssignedToTargets(update.getId());
}
}
@Override @Override
protected Collection<JpaDistributionSet> softDelete(final Collection<JpaDistributionSet> toDelete) { protected Collection<JpaDistributionSet> softDelete(final Collection<JpaDistributionSet> toDelete) {
// soft delete assigned // soft delete assigned
@@ -284,7 +272,6 @@ public class JpaDistributionSetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY)) @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
public JpaDistributionSet assignSoftwareModules(final long id, final Collection<Long> softwareModuleId) { public JpaDistributionSet assignSoftwareModules(final long id, final Collection<Long> softwareModuleId) {
final JpaDistributionSet set = getValid0(id); final JpaDistributionSet set = getValid0(id);
assertDistributionSetIsNotAssignedToTargets(id);
assertSoftwareModuleQuota(id, softwareModuleId.size()); assertSoftwareModuleQuota(id, softwareModuleId.size());
final Collection<JpaSoftwareModule> modules = softwareModuleRepository.findAllById(softwareModuleId); final Collection<JpaSoftwareModule> modules = softwareModuleRepository.findAllById(softwareModuleId);
@@ -303,7 +290,6 @@ public class JpaDistributionSetManagement
@Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY)) @Retryable(retryFor = { ConcurrencyFailureException.class }, maxAttempts = TX_RT_MAX, backoff = @Backoff(delay = TX_RT_DELAY))
public JpaDistributionSet unassignSoftwareModule(final long id, final long moduleId) { public JpaDistributionSet unassignSoftwareModule(final long id, final long moduleId) {
final JpaDistributionSet set = getValid0(id); final JpaDistributionSet set = getValid0(id);
assertDistributionSetIsNotAssignedToTargets(id);
final JpaSoftwareModule module = softwareModuleRepository.getById(moduleId); final JpaSoftwareModule module = softwareModuleRepository.getById(moduleId);
set.removeModule(module); set.removeModule(module);
@@ -464,13 +450,6 @@ public class JpaDistributionSetManagement
SoftwareModule.class, DistributionSet.class, softwareModuleRepository::countByAssignedToId); SoftwareModule.class, DistributionSet.class, softwareModuleRepository::countByAssignedToId);
} }
private void assertDistributionSetIsNotAssignedToTargets(final Long distributionSet) {
if (actionRepository.countByDistributionSetId(distributionSet) > 0) {
throw new EntityReadOnlyException(String.format(
"Distribution set %s is already assigned to targets and cannot be changed", distributionSet));
}
}
private void lockSoftwareModules(final JpaDistributionSet distributionSet) { private void lockSoftwareModules(final JpaDistributionSet distributionSet) {
distributionSet.getModules().forEach(module -> { distributionSet.getModules().forEach(module -> {
if (!module.isLocked()) { if (!module.isLocked()) {

View File

@@ -61,7 +61,7 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
@NotNull @NotNull
private String filename; private String filename;
@Column(name = "md5_hash", length = 32, updatable = false, nullable = true) @Column(name = "md5_hash", length = 32, updatable = false)
private String md5Hash; private String md5Hash;
@Column(name = "sha1_hash", length = 40, nullable = false, updatable = false) @Column(name = "sha1_hash", length = 40, nullable = false, updatable = false)
@@ -69,7 +69,7 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
@NotNull @NotNull
private String sha1Hash; private String sha1Hash;
@Column(name = "sha256_hash", length = 64, updatable = false, nullable = true) @Column(name = "sha256_hash", length = 64, updatable = false)
private String sha256Hash; private String sha256Hash;
@Column(name = "file_size", updatable = false) @Column(name = "file_size", updatable = false)
@@ -79,7 +79,6 @@ public class JpaArtifact extends AbstractJpaTenantAwareBaseEntity implements Art
this.sha1Hash = sha1Hash; this.sha1Hash = sha1Hash;
this.filename = filename; this.filename = filename;
this.softwareModule = (JpaSoftwareModule) softwareModule; this.softwareModule = (JpaSoftwareModule) softwareModule;
this.softwareModule.addArtifact(this);
} }
@Override @Override

View File

@@ -134,7 +134,6 @@ public class JpaDistributionSet
@Column(name = "valid") @Column(name = "valid")
private boolean valid; private boolean valid;
@Setter
@Column(name = "required_migration_step") @Column(name = "required_migration_step")
private boolean requiredMigrationStep; private boolean requiredMigrationStep;
@@ -159,6 +158,17 @@ public class JpaDistributionSet
return this; return this;
} }
@SuppressWarnings("java:S1144") // used via reflection copy utils
private void setRequiredMigrationStep(final boolean requiredMigrationStep) {
if (this.requiredMigrationStep != requiredMigrationStep) {
if (isLocked()) {
throw new LockedException(JpaDistributionSet.class, getId(), "CHANGE_REQUIRED_MIGRATION_STEP");
}
this.requiredMigrationStep = requiredMigrationStep;
}
}
@Override @Override
public boolean isComplete() { public boolean isComplete() {
return Optional.ofNullable(type).map(dsType -> { return Optional.ofNullable(type).map(dsType -> {

View File

@@ -79,7 +79,6 @@ public class JpaSoftwareModule
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Setter
@ManyToOne @ManyToOne
@JoinColumn(name = "sm_type", nullable = false, updatable = false, @JoinColumn(name = "sm_type", nullable = false, updatable = false,
foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_software_module_sm_type")) foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_software_module_sm_type"))
@@ -91,17 +90,14 @@ public class JpaSoftwareModule
targetEntity = JpaArtifact.class, orphanRemoval = true) targetEntity = JpaArtifact.class, orphanRemoval = true)
private List<JpaArtifact> artifacts; private List<JpaArtifact> artifacts;
@Setter
@Column(name = "vendor", length = SoftwareModule.VENDOR_MAX_SIZE) @Column(name = "vendor", length = SoftwareModule.VENDOR_MAX_SIZE)
@Size(max = SoftwareModule.VENDOR_MAX_SIZE) @Size(max = SoftwareModule.VENDOR_MAX_SIZE)
private String vendor; private String vendor;
@Setter
@Column(name = "encrypted") @Column(name = "encrypted")
private boolean encrypted; private boolean encrypted;
// no cascade option on an ElementCollection, the target objects are always persisted, merged, removed with their parent. // no cascade option on an ElementCollection, the target objects are always persisted, merged, removed with their parent.
@Getter
@ElementCollection @ElementCollection
@CollectionTable( @CollectionTable(
name = "sp_sm_metadata", name = "sp_sm_metadata",
@@ -130,23 +126,6 @@ public class JpaSoftwareModule
return artifacts == null ? Collections.emptyList() : Collections.unmodifiableList(artifacts); return artifacts == null ? Collections.emptyList() : Collections.unmodifiableList(artifacts);
} }
public void addArtifact(final Artifact artifact) {
if (isLocked()) {
throw new LockedException(JpaSoftwareModule.class, getId(), "ADD_ARTIFACT");
}
if (artifact instanceof JpaArtifact jpaArtifact) {
if (artifacts == null) {
artifacts = new ArrayList<>(4);
artifacts.add(jpaArtifact);
} else if (!artifacts.contains(jpaArtifact)) {
artifacts.add(jpaArtifact);
}
} else {
throw new UnsupportedOperationException("Only JpaArtifact is supported");
}
}
@Override @Override
public boolean isComplete() { public boolean isComplete() {
return Optional.ofNullable(type).map(smType -> { return Optional.ofNullable(type).map(smType -> {
@@ -158,6 +137,18 @@ public class JpaSoftwareModule
}).orElse(true); }).orElse(true);
} }
public void addArtifact(final JpaArtifact artifact) {
if (isLocked()) {
throw new LockedException(JpaSoftwareModule.class, getId(), "ADD_ARTIFACT");
}
if (artifacts == null) {
artifacts = new ArrayList<>(4);
artifacts.add(artifact);
} else if (!artifacts.contains(artifact)) {
artifacts.add(artifact);
}
}
public void removeArtifact(final Artifact artifact) { public void removeArtifact(final Artifact artifact) {
if (isLocked()) { if (isLocked()) {
throw new LockedException(JpaSoftwareModule.class, getId(), "REMOVE_ARTIFACT"); throw new LockedException(JpaSoftwareModule.class, getId(), "REMOVE_ARTIFACT");

View File

@@ -43,7 +43,6 @@ import org.eclipse.hawkbit.repository.event.remote.entity.SoftwareModuleCreatedE
import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException; import org.eclipse.hawkbit.repository.exception.AssignmentQuotaExceededException;
import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException; import org.eclipse.hawkbit.repository.exception.EntityAlreadyExistsException;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
import org.eclipse.hawkbit.repository.exception.EntityReadOnlyException;
import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException; import org.eclipse.hawkbit.repository.exception.IncompleteDistributionSetException;
import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException; import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetException;
import org.eclipse.hawkbit.repository.exception.LockedException; import org.eclipse.hawkbit.repository.exception.LockedException;
@@ -288,13 +287,11 @@ class DistributionSetManagementTest extends AbstractRepositoryManagementWithMeta
final Long dsId = ds.getId(); final Long dsId = ds.getId();
// not allowed as it is assigned now // not allowed as it is assigned now
assertThatThrownBy(() -> distributionSetManagement.assignSoftwareModules(dsId, os2Id)) assertThatThrownBy(() -> distributionSetManagement.assignSoftwareModules(dsId, os2Id)).isInstanceOf(LockedException.class);
.isInstanceOf(EntityReadOnlyException.class);
// not allowed as it is assigned now // not allowed as it is assigned now
final Long appId = findFirstModuleByType(ds, appType).map(Identifiable::getId).orElseThrow(); final Long appId = findFirstModuleByType(ds, appType).map(Identifiable::getId).orElseThrow();
assertThatThrownBy(() -> distributionSetManagement.unassignSoftwareModule(dsId, appId)) assertThatThrownBy(() -> distributionSetManagement.unassignSoftwareModule(dsId, appId)).isInstanceOf(LockedException.class);
.isInstanceOf(EntityReadOnlyException.class);
} }
/** /**