Introduced deleted flag in REST API (#665)

* — refactored distribution set update test, changed rollout test steps to check if deleted flag is set to false
— added deleted json property for soft deletion of rollout, distribution set, distribution set type, software module, software module type, covered relevant get and put requests with tests

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>

* Changed deleted flag json property to primitive boolean type, tests refactoring

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>

* Deleted flag getters renaming

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>
This commit is contained in:
Bondar Bogdan
2018-03-26 18:11:16 +02:00
committed by Dominic Schabel
parent 607cf92a9e
commit d9fc3c0e31
16 changed files with 212 additions and 158 deletions

View File

@@ -108,6 +108,7 @@ public final class MgmtDistributionSetMapper {
response.setVersion(distributionSet.getVersion());
response.setComplete(distributionSet.isComplete());
response.setType(distributionSet.getType().getKey());
response.setDeleted(distributionSet.isDeleted());
distributionSet.getModules()
.forEach(module -> response.getModules().add(MgmtSoftwareModuleMapper.toResponse(module)));

View File

@@ -88,6 +88,7 @@ final class MgmtDistributionSetTypeMapper {
MgmtRestModelMapper.mapNamedToNamed(result, type);
result.setKey(type.getKey());
result.setModuleId(type.getId());
result.setDeleted(type.isDeleted());
result.add(linkTo(methodOn(MgmtDistributionSetTypeRestApi.class).getDistributionSetType(result.getModuleId()))
.withSelfRel());

View File

@@ -77,6 +77,7 @@ final class MgmtRolloutMapper {
body.setDistributionSetId(rollout.getDistributionSet().getId());
body.setStatus(rollout.getStatus().toString().toLowerCase());
body.setTotalTargets(rollout.getTotalTargets());
body.setDeleted(rollout.isDeleted());
if (withDetails) {
for (final TotalTargetCountStatus.Status status : TotalTargetCountStatus.Status.values()) {

View File

@@ -79,8 +79,7 @@ public final class MgmtSoftwareModuleMapper {
softwareModules.stream().map(MgmtSoftwareModuleMapper::toResponse).collect(Collectors.toList()));
}
static List<MgmtSoftwareModuleMetadata> toResponseSwMetadata(
final Collection<SoftwareModuleMetadata> metadata) {
static List<MgmtSoftwareModuleMetadata> toResponseSwMetadata(final Collection<SoftwareModuleMetadata> metadata) {
if (metadata == null) {
return Collections.emptyList();
}
@@ -107,6 +106,7 @@ public final class MgmtSoftwareModuleMapper {
response.setVersion(softwareModule.getVersion());
response.setType(softwareModule.getType().getKey());
response.setVendor(softwareModule.getVendor());
response.setDeleted(softwareModule.isDeleted());
response.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class).getSoftwareModule(response.getModuleId()))
.withSelfRel());

View File

@@ -68,6 +68,7 @@ final class MgmtSoftwareModuleTypeMapper {
result.setKey(type.getKey());
result.setMaxAssignments(type.getMaxAssignments());
result.setModuleId(type.getId());
result.setDeleted(type.isDeleted());
result.add(linkTo(methodOn(MgmtSoftwareModuleTypeRestApi.class).getSoftwareModuleType(result.getModuleId()))
.withSelfRel());

View File

@@ -609,6 +609,7 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
.andExpect(jsonPath("$.requiredMigrationStep", equalTo(set.isRequiredMigrationStep())))
.andExpect(jsonPath("$.createdBy", equalTo(set.getCreatedBy())))
.andExpect(jsonPath("$.complete", equalTo(Boolean.TRUE)))
.andExpect(jsonPath("$.deleted", equalTo(set.isDeleted())))
.andExpect(jsonPath("$.createdAt", equalTo(set.getCreatedAt())))
.andExpect(jsonPath("$.lastModifiedBy", equalTo(set.getLastModifiedBy())))
.andExpect(jsonPath("$.lastModifiedAt", equalTo(set.getLastModifiedAt())))
@@ -771,10 +772,15 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(1);
// perform request
mvc.perform(delete("/rest/v1/distributionsets/{smId}", set.getId())).andDo(MockMvcResultPrinter.print())
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(delete("/rest/v1/distributionsets/{dsId}", set.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/distributionsets/{dsId}", set.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
// check repository content
assertThat(distributionSetManagement.findByCompleted(PAGE, true)).hasSize(0);
}
@@ -790,16 +796,22 @@ public class MgmtDistributionSetResourceTest extends AbstractManagementApiIntegr
assertThat(distributionSetManagement.count()).isEqualTo(1);
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId())
.content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}")
final String body = new JSONObject().put("version", "anotherVersion").put("requiredMigrationStep", true)
.put("deleted", true).toString();
mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.version", equalTo("anotherVersion")))
.andExpect(jsonPath("$.requiredMigrationStep", equalTo(true)))
.andExpect(jsonPath("$.deleted", equalTo(false)));
final DistributionSet setupdated = distributionSetManagement.get(set.getId()).get();
assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(true);
assertThat(setupdated.getVersion()).isEqualTo("anotherVersion");
assertThat(setupdated.getName()).isEqualTo(set.getName());
assertThat(setupdated.isDeleted()).isEqualTo(false);
}
@Test

View File

@@ -363,7 +363,8 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
.andExpect(jsonPath("$.description", equalTo("Desc1234")))
.andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt())))
.andExpect(jsonPath("$.lastModifiedBy", equalTo("uploadTester")));
.andExpect(jsonPath("$.lastModifiedBy", equalTo("uploadTester")))
.andExpect(jsonPath("$.deleted", equalTo(testType.isDeleted())));
}
@Test
@@ -401,9 +402,15 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES + 1);
assertThat(distributionSetManagement.count()).isEqualTo(1);
mvc.perform(delete("/rest/v1/distributionsettypes/{smId}", testType.getId()))
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(delete("/rest/v1/distributionsettypes/{dstId}", testType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
mvc.perform(get("/rest/v1/distributionsettypes/{dstId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(distributionSetManagement.count()).isEqualTo(1);
assertThat(distributionSetTypeManagement.count()).isEqualTo(DEFAULT_DS_TYPES);
}
@@ -424,6 +431,20 @@ public class MgmtDistributionSetTypeResourceTest extends AbstractManagementApiIn
.andExpect(jsonPath("$.name", equalTo("TestName123"))).andReturn();
}
@Test
@Description("Tests the update of the deletion flag. It is verfied that the distribution set type can't be marked as deleted through update operation.")
public void updateDistributionSetTypeDeletedFlag() throws Exception {
final DistributionSetType testType = distributionSetTypeManagement
.create(entityFactory.distributionSetType().create().key("test123").name("TestName123").colour("col"));
final String body = new JSONObject().put("id", testType.getId()).put("deleted", true).toString();
mvc.perform(put("/rest/v1/distributionsettypes/{dstId}", testType.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
}
@Test
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes GET requests with paging.")
public void getDistributionSetTypesWithoutAddtionalRequestParameters() throws Exception {

View File

@@ -249,7 +249,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.totalTargetsPerStatus.scheduled", equalTo(15)))
.andExpect(jsonPath("$.totalTargetsPerStatus.cancelled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.finished", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)));
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(jsonPath("$.deleted", equalTo(false)));
}
@Step
@@ -266,7 +267,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.totalTargetsPerStatus.scheduled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.cancelled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.finished", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)));
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(jsonPath("$.deleted", equalTo(false)));
}
@Step
@@ -285,7 +287,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(jsonPath("$.totalTargetsPerStatus.scheduled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.cancelled", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.finished", equalTo(0)))
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)));
.andExpect(jsonPath("$.totalTargetsPerStatus.error", equalTo(0)))
.andExpect(jsonPath("$.deleted", equalTo(false)));
}
@Step
@@ -314,7 +317,8 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
.andExpect(
jsonPath("$._links.resume.href", allOf(startsWith(HREF_ROLLOUT_PREFIX), endsWith("/resume"))))
.andExpect(jsonPath("$._links.groups.href",
allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))));
allOf(startsWith(HREF_ROLLOUT_PREFIX), containsString("/deploygroups"))))
.andExpect(jsonPath("$.deleted", equalTo(false)));
}
@Test
@@ -782,6 +786,16 @@ public class MgmtRolloutResourceTest extends AbstractManagementApiIntegrationTes
assertThat(getRollout(rollout.getId()).getStatus()).isEqualTo(RolloutStatus.DELETING);
}
@Test
@Description("Soft deletion of a rollout: soft deletion appears when already running rollout is being deleted")
public void deleteRunningRollout() throws Exception {
final Rollout rollout = testdataFactory.createSoftDeletedRollout("softDeletedRollout");
mvc.perform(get("/rest/v1/rollouts/{rolloutid}", rollout.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(getRollout(rollout.getId()).getStatus()).isEqualTo(RolloutStatus.DELETED);
}
@Test
@Description("Testing that rollout paged list with rsql parameter")
public void getRolloutWithRSQLParam() throws Exception {

View File

@@ -114,6 +114,38 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
}
@Test
@Description("Tests the update of the deletion flag. It is verfied that the software module can't be marked as deleted through update operation.")
@WithUser(principal = "smUpdateTester", allSpPermissions = true)
public void updateSoftwareModuleDeletedFlag() throws Exception {
final String knownSWName = "name1";
final String knownSWVersion = "version1";
SoftwareModule sm = softwareModuleManagement
.create(entityFactory.softwareModule().create().type(osType).name(knownSWName).version(knownSWVersion));
assertThat(sm.isDeleted()).as("Created software module should not be deleted").isEqualTo(false);
final String body = new JSONObject().put("deleted", true).toString();
// ensures that we are not to fast so that last modified is not set
// correctly
Thread.sleep(1);
mvc.perform(put("/rest/v1/softwaremodules/{smId}", sm.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(sm.getId().intValue())))
.andExpect(jsonPath("$.lastModifiedBy", equalTo("smUpdateTester")))
.andExpect(jsonPath("$.lastModifiedAt", equalTo(sm.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
sm = softwareModuleManagement.get(sm.getId()).get();
assertThat(sm.getLastModifiedBy()).isEqualTo("smUpdateTester");
assertThat(sm.getLastModifiedAt()).isEqualTo(sm.getLastModifiedAt());
assertThat(sm.isDeleted()).isEqualTo(false);
}
@Test
@Description("Tests the uppload of an artifact binary. The upload is executed and the content checked in the repository for completenes.")
public void uploadArtifact() throws Exception {
@@ -614,6 +646,7 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
.andExpect(jsonPath("$.description", equalTo(os.getDescription())))
.andExpect(jsonPath("$.vendor", equalTo(os.getVendor())))
.andExpect(jsonPath("$.type", equalTo(os.getType().getKey())))
.andExpect(jsonPath("$.deleted", equalTo(os.isDeleted())))
.andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("$.createdAt", equalTo(os.getCreatedAt())))
.andExpect(jsonPath("$._links.metadata.href",
@@ -706,28 +739,29 @@ public class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegra
}
@Test
@Description("Verifies successfull deletion of software modules that are in use, i.e. assigned to a DS which should result in movinf the module to the archive.")
@Description("Verifies successfull deletion of a software module that is in use, i.e. assigned to a DS which should result in movinf the module to the archive.")
public void deleteAssignedSoftwareModule() throws Exception {
final DistributionSet ds1 = testdataFactory.createDistributionSet("a");
final byte random[] = RandomStringUtils.random(5 * 1024).getBytes();
artifactManagement.create(new ByteArrayInputStream(random), ds1.findFirstModuleByType(appType).get().getId(),
"file1", false);
final Long appTypeSmId = ds1.findFirstModuleByType(appType).get().getId();
assertThat(softwareModuleManagement.findAll(PAGE)).hasSize(3);
artifactManagement.create(new ByteArrayInputStream(random), appTypeSmId, "file1", false);
assertThat(softwareModuleManagement.count()).isEqualTo(3);
assertThat(artifactManagement.count()).isEqualTo(1);
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(appType).get().getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(runtimeType).get().getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", ds1.findFirstModuleByType(osType).get().getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
// all 3 are now marked as deleted
assertThat(softwareModuleManagement.findAll(PAGE).getNumber())
.as("After delete no softwarmodule should be available").isEqualTo(0);
mvc.perform(delete("/rest/v1/softwaremodules/{smId}", appTypeSmId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/softwaremodules/{smId}", appTypeSmId)).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(softwareModuleManagement.count()).isEqualTo(2);
assertThat(artifactManagement.count()).isEqualTo(1);
}

View File

@@ -221,7 +221,8 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
.andExpect(jsonPath("$.createdBy", equalTo("uploadTester")))
.andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt())))
.andExpect(jsonPath("$.lastModifiedBy", equalTo("uploadTester")))
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())));
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted", equalTo(testType.isDeleted())));
}
@Test
@@ -255,8 +256,14 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
assertThat(softwareModuleTypeManagement.count()).isEqualTo(4);
mvc.perform(delete("/rest/v1/softwaremoduletypes/{smId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk());
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(false)));
mvc.perform(delete("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
mvc.perform(get("/rest/v1/softwaremoduletypes/{smtId}", testType.getId())).andDo(MockMvcResultPrinter.print())
.andExpect(status().isOk()).andExpect(jsonPath("$.deleted", equalTo(true)));
assertThat(softwareModuleTypeManagement.count()).isEqualTo(3);
}
@@ -277,6 +284,24 @@ public class MgmtSoftwareModuleTypeResourceTest extends AbstractManagementApiInt
}
@Test
@Description("Tests the update of the deletion flag. It is verfied that the software module type can't be marked as deleted through update operation.")
public void updateSoftwareModuleTypeDeletedFlag() throws Exception {
SoftwareModuleType testType = createTestType();
final String body = new JSONObject().put("id", testType.getId()).put("deleted", true).toString();
mvc.perform(put("/rest/v1/softwaremoduletypes/{smtId}", testType.getId()).content(body)
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
.andExpect(jsonPath("$.deleted", equalTo(false)));
testType = softwareModuleTypeManagement.get(testType.getId()).get();
assertThat(testType.getLastModifiedAt()).isEqualTo(testType.getLastModifiedAt());
assertThat(testType.isDeleted()).isEqualTo(false);
}
@Test
@Description("Checks the correct behaviour of /rest/v1/softwaremoduletypes GET requests with paging.")
public void getSoftwareModuleTypesWithoutAddtionalRequestParameters() throws Exception {