From f0fc8f0606188cd852a7a8449297a88345c65ef3 Mon Sep 17 00:00:00 2001 From: Kai Zimmermann Date: Fri, 9 Dec 2016 14:42:04 +0100 Subject: [PATCH] Added mising update of DS property. (#382) * Added mising update of DS property. Updated sonar plugin and make sure that test code is not covered by sonar Signed-off-by: kaizimmerm --- .../MgmtDistributionSetRequestBodyPost.java | 22 ---------- .../MgmtDistributionSetRequestBodyPut.java | 22 ++++++++++ .../resource/MgmtDistributionSetResource.java | 3 +- .../MgmtDistributionSetResourceTest.java | 42 +++++++++++++++---- .../hawkbit-repository-test/pom.xml | 41 ++++++++++-------- .../hawkbit/rest/util/JsonBuilder.java | 23 +++++----- pom.xml | 5 +++ 7 files changed, 99 insertions(+), 59 deletions(-) diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPost.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPost.java index f38c80203..906647199 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPost.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPost.java @@ -40,9 +40,6 @@ public class MgmtDistributionSetRequestBodyPost extends MgmtDistributionSetReque @JsonProperty private List modules; - @JsonProperty - private Boolean requiredMigrationStep; - @JsonProperty private String type; @@ -102,25 +99,6 @@ public class MgmtDistributionSetRequestBodyPost extends MgmtDistributionSetReque return this; } - /** - * @return the requiredMigrationStep - */ - public Boolean isRequiredMigrationStep() { - return requiredMigrationStep; - } - - /** - * @param requiredMigrationStep - * the requiredMigrationStep to set - * - * @return updated body - */ - public MgmtDistributionSetRequestBodyPost setRequiredMigrationStep(final Boolean requiredMigrationStep) { - this.requiredMigrationStep = requiredMigrationStep; - - return this; - } - /** * @return the modules */ diff --git a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPut.java b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPut.java index 4494dd8a8..8f3200cb4 100644 --- a/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPut.java +++ b/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/json/model/distributionset/MgmtDistributionSetRequestBodyPut.java @@ -30,6 +30,9 @@ public class MgmtDistributionSetRequestBodyPut { @JsonProperty private String version; + @JsonProperty + private Boolean requiredMigrationStep; + /** * @return the name */ @@ -48,6 +51,25 @@ public class MgmtDistributionSetRequestBodyPut { return this; } + /** + * @return the requiredMigrationStep + */ + public Boolean isRequiredMigrationStep() { + return requiredMigrationStep; + } + + /** + * @param requiredMigrationStep + * the requiredMigrationStep to set + * + * @return updated body + */ + public MgmtDistributionSetRequestBodyPut setRequiredMigrationStep(final Boolean requiredMigrationStep) { + this.requiredMigrationStep = requiredMigrationStep; + + return this; + } + /** * @return the description */ diff --git a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java index ccd2a7e8f..9f7baad5a 100644 --- a/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java +++ b/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResource.java @@ -152,7 +152,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi { return new ResponseEntity<>( MgmtDistributionSetMapper.toResponse(distributionSetManagement.updateDistributionSet( entityFactory.distributionSet().update(distributionSetId).name(toUpdate.getName()) - .description(toUpdate.getDescription()).version(toUpdate.getVersion()))), + .description(toUpdate.getDescription()).version(toUpdate.getVersion()) + .requiredMigrationStep(toUpdate.isRequiredMigrationStep()))), HttpStatus.OK); } diff --git a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java index e07db90e4..0f36307da 100644 --- a/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java +++ b/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtDistributionSetResourceTest.java @@ -36,6 +36,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.Target; +import org.eclipse.hawkbit.repository.model.TargetWithActionType; import org.eclipse.hawkbit.repository.test.util.TestdataFactory; import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; @@ -660,17 +661,44 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest final DistributionSet set = testdataFactory.createDistributionSet("one"); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) - .hasSize(1); + assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); - mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()).content("{\"version\":\"anotherVersion\"}") + mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()) + .content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}") .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true) - .getContent().get(0).getVersion()).isEqualTo("anotherVersion"); - assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true) - .getContent().get(0).getName()).isEqualTo(set.getName()); + final DistributionSet setupdated = distributionSetManagement.findDistributionSetById(set.getId()); + + assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(true); + assertThat(setupdated.getVersion()).isEqualTo("anotherVersion"); + assertThat(setupdated.getName()).isEqualTo(set.getName()); + } + + @Test + @Description("Ensures that DS property update on requiredMigrationStep fails if DS is assigned to a target.") + public void updateRequiredMigrationStepFailsIfDistributionSetisInUse() throws Exception { + + // prepare test data + assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) + .hasSize(0); + + final DistributionSet set = testdataFactory.createDistributionSet("one"); + deploymentManagement.assignDistributionSet(set.getId(), + Lists.newArrayList(new TargetWithActionType(testdataFactory.createTarget().getControllerId()))); + + assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1); + + mvc.perform(put("/rest/v1/distributionsets/{dsId}", set.getId()) + .content("{\"version\":\"anotherVersion\",\"requiredMigrationStep\":\"true\"}") + .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden()); + + final DistributionSet setupdated = distributionSetManagement.findDistributionSetById(set.getId()); + + assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(false); + assertThat(setupdated.getVersion()).isEqualTo(set.getVersion()); + assertThat(setupdated.getName()).isEqualTo(set.getName()); } @Test diff --git a/hawkbit-repository/hawkbit-repository-test/pom.xml b/hawkbit-repository/hawkbit-repository-test/pom.xml index c3351ca33..d75799feb 100644 --- a/hawkbit-repository/hawkbit-repository-test/pom.xml +++ b/hawkbit-repository/hawkbit-repository-test/pom.xml @@ -8,17 +8,22 @@ http://www.eclipse.org/legal/epl-v10.html --> - - 4.0.0 - - org.eclipse.hawkbit - hawkbit-repository - 0.2.0-SNAPSHOT - - hawkbit-repository-test - hawkBit :: Repository Test Utilities - - + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-repository + 0.2.0-SNAPSHOT + + hawkbit-repository-test + hawkBit :: Repository Test Utilities + + + true + + + org.eclipse.hawkbit hawkbit-repository-api @@ -29,7 +34,7 @@ hawkbit-repository-core ${project.version} - + org.eclipse.hawkbit hawkbit-artifact-repository-filesystem ${project.version} @@ -46,7 +51,7 @@ org.springframework spring-tx - + net._01001111 jlorem @@ -79,10 +84,10 @@ spring-cloud-stream-binder-test - org.springframework.cloud - spring-cloud-stream-test-support - - + org.springframework.cloud + spring-cloud-stream-test-support + + io.protostuff protostuff-core @@ -99,5 +104,5 @@ com.jayway.awaitility awaitility - + \ No newline at end of file diff --git a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java index b1c12eb53..fd5a5cab3 100644 --- a/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java +++ b/hawkbit-rest-core/src/test/java/org/eclipse/hawkbit/rest/util/JsonBuilder.java @@ -183,7 +183,7 @@ public abstract class JsonBuilder { public static String deploymentActionFeedback(final String id, final String execution, final String finished, final String message) throws JSONException { - final List messages = new ArrayList(); + final List messages = new ArrayList<>(); messages.add(message); return new JSONObject().put("id", id).put("time", "20140511T121314") @@ -344,7 +344,8 @@ public abstract class JsonBuilder { }).collect(Collectors.toList()); return new JSONObject().put("name", set.getName()).put("description", set.getDescription()) - .put("version", set.getVersion()).toString(); + .put("version", set.getVersion()).put("requiredMigrationStep", set.isRequiredMigrationStep()) + .toString(); } @@ -399,13 +400,13 @@ public abstract class JsonBuilder { } public static String rollout(final String name, final String description, final int groupSize, - final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions) { + final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions) { return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null); } public static String rollout(final String name, final String description, final Integer groupSize, final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions, - final List groups) { + final List groups) { final JSONObject json = new JSONObject(); json.put("name", name); json.put("description", description); @@ -435,35 +436,35 @@ public abstract class JsonBuilder { errorAction.put("expression", conditions.getErrorActionExp()); } - if(groups != null) { + if (groups != null) { final JSONArray jsonGroups = new JSONArray(); - for (RolloutGroup group : groups) { + for (final RolloutGroup group : groups) { final JSONObject jsonGroup = new JSONObject(); jsonGroup.put("name", group.getName()); jsonGroup.put("description", group.getDescription()); jsonGroup.put("targetFilterQuery", group.getTargetFilterQuery()); jsonGroup.put("targetPercentage", group.getTargetPercentage()); - if(group.getSuccessCondition() != null) { + if (group.getSuccessCondition() != null) { final JSONObject successCondition = new JSONObject(); jsonGroup.put("successCondition", successCondition); successCondition.put("condition", group.getSuccessCondition().toString()); successCondition.put("expression", group.getSuccessConditionExp()); } - if(group.getSuccessAction() != null) { + if (group.getSuccessAction() != null) { final JSONObject successAction = new JSONObject(); jsonGroup.put("successAction", successAction); successAction.put("action", group.getSuccessAction().toString()); successAction.put("expression", group.getSuccessActionExp()); } - if(group.getErrorCondition() != null) { + if (group.getErrorCondition() != null) { final JSONObject errorCondition = new JSONObject(); jsonGroup.put("errorCondition", errorCondition); errorCondition.put("condition", group.getErrorCondition().toString()); errorCondition.put("expression", group.getErrorConditionExp()); } - if(group.getErrorAction() != null) { + if (group.getErrorAction() != null) { final JSONObject errorAction = new JSONObject(); jsonGroup.put("errorAction", errorAction); errorAction.put("action", group.getErrorAction().toString()); @@ -487,7 +488,7 @@ public abstract class JsonBuilder { public static String cancelActionFeedback(final String id, final String execution, final String message) throws JSONException { - final List messages = new ArrayList(); + final List messages = new ArrayList<>(); messages.add(message); return new JSONObject().put("id", id).put("time", "20140511T121314") .put("status", diff --git a/pom.xml b/pom.xml index 0a5b6a8b9..b48eb334f 100644 --- a/pom.xml +++ b/pom.xml @@ -297,6 +297,11 @@ + + org.sonarsource.scanner.maven + sonar-maven-plugin + 3.1.1 + org.eclipse.m2e lifecycle-mapping