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 <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-12-09 14:42:04 +01:00
committed by GitHub
parent edbadc4002
commit f0fc8f0606
7 changed files with 99 additions and 59 deletions

View File

@@ -40,9 +40,6 @@ public class MgmtDistributionSetRequestBodyPost extends MgmtDistributionSetReque
@JsonProperty @JsonProperty
private List<MgmtSoftwareModuleAssigment> modules; private List<MgmtSoftwareModuleAssigment> modules;
@JsonProperty
private Boolean requiredMigrationStep;
@JsonProperty @JsonProperty
private String type; private String type;
@@ -102,25 +99,6 @@ public class MgmtDistributionSetRequestBodyPost extends MgmtDistributionSetReque
return this; 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 * @return the modules
*/ */

View File

@@ -30,6 +30,9 @@ public class MgmtDistributionSetRequestBodyPut {
@JsonProperty @JsonProperty
private String version; private String version;
@JsonProperty
private Boolean requiredMigrationStep;
/** /**
* @return the name * @return the name
*/ */
@@ -48,6 +51,25 @@ public class MgmtDistributionSetRequestBodyPut {
return this; 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 * @return the description
*/ */

View File

@@ -152,7 +152,8 @@ public class MgmtDistributionSetResource implements MgmtDistributionSetRestApi {
return new ResponseEntity<>( return new ResponseEntity<>(
MgmtDistributionSetMapper.toResponse(distributionSetManagement.updateDistributionSet( MgmtDistributionSetMapper.toResponse(distributionSetManagement.updateDistributionSet(
entityFactory.distributionSet().update(distributionSetId).name(toUpdate.getName()) entityFactory.distributionSet().update(distributionSetId).name(toUpdate.getName())
.description(toUpdate.getDescription()).version(toUpdate.getVersion()))), .description(toUpdate.getDescription()).version(toUpdate.getVersion())
.requiredMigrationStep(toUpdate.isRequiredMigrationStep()))),
HttpStatus.OK); HttpStatus.OK);
} }

View File

@@ -36,6 +36,7 @@ import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.DistributionSetMetadata; import org.eclipse.hawkbit.repository.model.DistributionSetMetadata;
import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target; 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.TestdataFactory;
import org.eclipse.hawkbit.repository.test.util.WithUser; import org.eclipse.hawkbit.repository.test.util.WithUser;
import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest; import org.eclipse.hawkbit.rest.AbstractRestIntegrationTest;
@@ -660,17 +661,44 @@ public class MgmtDistributionSetResourceTest extends AbstractRestIntegrationTest
final DistributionSet set = testdataFactory.createDistributionSet("one"); final DistributionSet set = testdataFactory.createDistributionSet("one");
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true)) assertThat(distributionSetManagement.countDistributionSetsAll()).isEqualTo(1);
.hasSize(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)) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()); .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true) final DistributionSet setupdated = distributionSetManagement.findDistributionSetById(set.getId());
.getContent().get(0).getVersion()).isEqualTo("anotherVersion");
assertThat(distributionSetManagement.findDistributionSetsByDeletedAndOrCompleted(pageReq, false, true) assertThat(setupdated.isRequiredMigrationStep()).isEqualTo(true);
.getContent().get(0).getName()).isEqualTo(set.getName()); 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 @Test

View File

@@ -8,17 +8,22 @@
http://www.eclipse.org/legal/epl-v10.html http://www.eclipse.org/legal/epl-v10.html
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.hawkbit</groupId> <parent>
<artifactId>hawkbit-repository</artifactId> <groupId>org.eclipse.hawkbit</groupId>
<version>0.2.0-SNAPSHOT</version> <artifactId>hawkbit-repository</artifactId>
</parent> <version>0.2.0-SNAPSHOT</version>
<artifactId>hawkbit-repository-test</artifactId> </parent>
<name>hawkBit :: Repository Test Utilities</name> <artifactId>hawkbit-repository-test</artifactId>
<name>hawkBit :: Repository Test Utilities</name>
<dependencies>
<properties>
<sonar.skip>true</sonar.skip>
</properties>
<dependencies>
<dependency> <dependency>
<groupId>org.eclipse.hawkbit</groupId> <groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-repository-api</artifactId> <artifactId>hawkbit-repository-api</artifactId>
@@ -29,7 +34,7 @@
<artifactId>hawkbit-repository-core</artifactId> <artifactId>hawkbit-repository-core</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.eclipse.hawkbit</groupId> <groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-artifact-repository-filesystem</artifactId> <artifactId>hawkbit-artifact-repository-filesystem</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
@@ -46,7 +51,7 @@
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId> <artifactId>spring-tx</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net._01001111</groupId> <groupId>net._01001111</groupId>
<artifactId>jlorem</artifactId> <artifactId>jlorem</artifactId>
</dependency> </dependency>
@@ -79,10 +84,10 @@
<artifactId>spring-cloud-stream-binder-test</artifactId> <artifactId>spring-cloud-stream-binder-test</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId> <artifactId>spring-cloud-stream-test-support</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.protostuff</groupId> <groupId>io.protostuff</groupId>
<artifactId>protostuff-core</artifactId> <artifactId>protostuff-core</artifactId>
</dependency> </dependency>
@@ -99,5 +104,5 @@
<groupId>com.jayway.awaitility</groupId> <groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId> <artifactId>awaitility</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -183,7 +183,7 @@ public abstract class JsonBuilder {
public static String deploymentActionFeedback(final String id, final String execution, final String finished, public static String deploymentActionFeedback(final String id, final String execution, final String finished,
final String message) throws JSONException { final String message) throws JSONException {
final List<String> messages = new ArrayList<String>(); final List<String> messages = new ArrayList<>();
messages.add(message); messages.add(message);
return new JSONObject().put("id", id).put("time", "20140511T121314") return new JSONObject().put("id", id).put("time", "20140511T121314")
@@ -344,7 +344,8 @@ public abstract class JsonBuilder {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return new JSONObject().put("name", set.getName()).put("description", set.getDescription()) 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, 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); return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null);
} }
public static String rollout(final String name, final String description, final Integer groupSize, public static String rollout(final String name, final String description, final Integer groupSize,
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions, final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions,
final List<RolloutGroup> groups) { final List<RolloutGroup> groups) {
final JSONObject json = new JSONObject(); final JSONObject json = new JSONObject();
json.put("name", name); json.put("name", name);
json.put("description", description); json.put("description", description);
@@ -435,35 +436,35 @@ public abstract class JsonBuilder {
errorAction.put("expression", conditions.getErrorActionExp()); errorAction.put("expression", conditions.getErrorActionExp());
} }
if(groups != null) { if (groups != null) {
final JSONArray jsonGroups = new JSONArray(); final JSONArray jsonGroups = new JSONArray();
for (RolloutGroup group : groups) { for (final RolloutGroup group : groups) {
final JSONObject jsonGroup = new JSONObject(); final JSONObject jsonGroup = new JSONObject();
jsonGroup.put("name", group.getName()); jsonGroup.put("name", group.getName());
jsonGroup.put("description", group.getDescription()); jsonGroup.put("description", group.getDescription());
jsonGroup.put("targetFilterQuery", group.getTargetFilterQuery()); jsonGroup.put("targetFilterQuery", group.getTargetFilterQuery());
jsonGroup.put("targetPercentage", group.getTargetPercentage()); jsonGroup.put("targetPercentage", group.getTargetPercentage());
if(group.getSuccessCondition() != null) { if (group.getSuccessCondition() != null) {
final JSONObject successCondition = new JSONObject(); final JSONObject successCondition = new JSONObject();
jsonGroup.put("successCondition", successCondition); jsonGroup.put("successCondition", successCondition);
successCondition.put("condition", group.getSuccessCondition().toString()); successCondition.put("condition", group.getSuccessCondition().toString());
successCondition.put("expression", group.getSuccessConditionExp()); successCondition.put("expression", group.getSuccessConditionExp());
} }
if(group.getSuccessAction() != null) { if (group.getSuccessAction() != null) {
final JSONObject successAction = new JSONObject(); final JSONObject successAction = new JSONObject();
jsonGroup.put("successAction", successAction); jsonGroup.put("successAction", successAction);
successAction.put("action", group.getSuccessAction().toString()); successAction.put("action", group.getSuccessAction().toString());
successAction.put("expression", group.getSuccessActionExp()); successAction.put("expression", group.getSuccessActionExp());
} }
if(group.getErrorCondition() != null) { if (group.getErrorCondition() != null) {
final JSONObject errorCondition = new JSONObject(); final JSONObject errorCondition = new JSONObject();
jsonGroup.put("errorCondition", errorCondition); jsonGroup.put("errorCondition", errorCondition);
errorCondition.put("condition", group.getErrorCondition().toString()); errorCondition.put("condition", group.getErrorCondition().toString());
errorCondition.put("expression", group.getErrorConditionExp()); errorCondition.put("expression", group.getErrorConditionExp());
} }
if(group.getErrorAction() != null) { if (group.getErrorAction() != null) {
final JSONObject errorAction = new JSONObject(); final JSONObject errorAction = new JSONObject();
jsonGroup.put("errorAction", errorAction); jsonGroup.put("errorAction", errorAction);
errorAction.put("action", group.getErrorAction().toString()); 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) public static String cancelActionFeedback(final String id, final String execution, final String message)
throws JSONException { throws JSONException {
final List<String> messages = new ArrayList<String>(); final List<String> messages = new ArrayList<>();
messages.add(message); messages.add(message);
return new JSONObject().put("id", id).put("time", "20140511T121314") return new JSONObject().put("id", id).put("time", "20140511T121314")
.put("status", .put("status",

View File

@@ -297,6 +297,11 @@
<pluginManagement> <pluginManagement>
<plugins> <plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.1.1</version>
</plugin>
<plugin> <plugin>
<groupId>org.eclipse.m2e</groupId> <groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId> <artifactId>lifecycle-mapping</artifactId>