introduced open actionIds in MgmtTargetAssignmentResponseBody (#864)
* introduced open actionIds in MgmtTargetAssignmentResponseBody Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed SonarQube issues Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * removed unused method parameter Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * updated documentation tests Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * added limit to the alreadyAssignedActions in the AssignmentResult Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * moved alreadyAssignedActions limitation to MgmtDistributionSetMapper Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * removed alreadyAssignedActions Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed sonarQube issues Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed compilation error Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed PR review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed PR review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * Renamed AssignmentResult to AbstractAssignmentResult Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed review findings Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * fixed formatting Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com> * reverted method visibility Signed-off-by: Ahmed Sayed <ahmed.sayed@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
973f1952c7
commit
d40b11d2ab
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.json.model.distributionset;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Representation of an Action Id as a Json Object with link to the Action resource
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtActionId extends ResourceSupport {
|
||||
|
||||
private long actionId;
|
||||
|
||||
public MgmtActionId() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param actionId
|
||||
* the actionId
|
||||
* @param controllerId
|
||||
* the controller Id
|
||||
*/
|
||||
public MgmtActionId(final String controllerId, final long actionId) {
|
||||
this.actionId = actionId;
|
||||
add(linkTo(methodOn(MgmtTargetRestApi.class).getAction(controllerId, actionId)).withSelfRel());
|
||||
}
|
||||
|
||||
@JsonProperty("id")
|
||||
public long getActionId() {
|
||||
return actionId;
|
||||
}
|
||||
|
||||
public void setActionId(final long actionId) {
|
||||
this.actionId = actionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return super.equals(obj) && this.getClass().isInstance(obj) && actionId == ((MgmtActionId) obj).getActionId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), actionId);
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,14 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.json.model.distributionset;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.springframework.hateoas.ResourceSupport;
|
||||
|
||||
/**
|
||||
* Response Body of Target for assignment operations.
|
||||
@@ -20,25 +25,17 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
*/
|
||||
@JsonInclude(Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtTargetAssignmentResponseBody {
|
||||
public class MgmtTargetAssignmentResponseBody extends ResourceSupport {
|
||||
|
||||
private int assigned;
|
||||
private int alreadyAssigned;
|
||||
private int total;
|
||||
private List<MgmtActionId> assignedActions;
|
||||
|
||||
/**
|
||||
* @return the assigned
|
||||
* @return the count of assigned targets
|
||||
*/
|
||||
@JsonProperty("assigned")
|
||||
public int getAssigned() {
|
||||
return assigned;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param assigned
|
||||
* the assigned to set
|
||||
*/
|
||||
public void setAssigned(final int assigned) {
|
||||
this.assigned = assigned;
|
||||
return assignedActions == null ? 0 : assignedActions.size();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,15 +56,35 @@ public class MgmtTargetAssignmentResponseBody {
|
||||
/**
|
||||
* @return the total
|
||||
*/
|
||||
@JsonProperty("total")
|
||||
public int getTotal() {
|
||||
return total;
|
||||
return getAssigned() + alreadyAssigned;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param total
|
||||
* the total to set
|
||||
* @return the assignedActions
|
||||
*/
|
||||
public void setTotal(final int total) {
|
||||
this.total = total;
|
||||
public List<MgmtActionId> getAssignedActions() {
|
||||
return assignedActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param assignedActions
|
||||
* the assigned actions to set
|
||||
*/
|
||||
public void setAssignedActions(final List<MgmtActionId> assignedActions) {
|
||||
this.assignedActions = assignedActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
return super.equals(obj) && this.getClass().isInstance(obj)
|
||||
&& ((MgmtTargetAssignmentResponseBody) obj).getAlreadyAssigned() == alreadyAssigned
|
||||
&& Objects.equals(((MgmtTargetAssignmentResponseBody) obj).getAssignedActions(), assignedActions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), alreadyAssigned, assignedActions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2019 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.mgmt.json.model.distributionset;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.qameta.allure.Story;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Description;
|
||||
|
||||
@Story("Retrieve all open action ids")
|
||||
@Description("Tests for the MgmtTargetAssignmentResponseBody")
|
||||
public class MgmtTargetAssignmentResponseBodyTest {
|
||||
|
||||
private static final List<Long> ASSIGNED_ACTIONS = Arrays.asList(4L, 5L, 6L);
|
||||
private static final int ALREADY_ASSIGNED_COUNT = 3;
|
||||
private static final String CONTROLLER_ID = "target";
|
||||
|
||||
@Test
|
||||
@Description("Tests that the ActionIds are serialized correctly in MgmtTargetAssignmentResponseBody")
|
||||
public void testActionIdsSerialization() throws IOException {
|
||||
final MgmtTargetAssignmentResponseBody responseBody = generateResponseBody();
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
final String responseBodyAsString = objectMapper.writeValueAsString(responseBody);
|
||||
final JsonNode jsonNode = objectMapper.readTree(responseBodyAsString);
|
||||
|
||||
assertThat(jsonNode.has("assigned")).as("the assigned targets count").isTrue();
|
||||
assertThat(jsonNode.get("assigned").isNumber()).as("the assigned targets count").isTrue();
|
||||
assertThat(jsonNode.get("assigned").asLong()).as("the assigned targets count")
|
||||
.isEqualTo(ASSIGNED_ACTIONS.size());
|
||||
|
||||
assertThat(jsonNode.has("alreadyAssigned")).as("the already assigned targets count").isTrue();
|
||||
assertThat(jsonNode.get("alreadyAssigned").isNumber()).as("the already assigned targets count").isTrue();
|
||||
assertThat(jsonNode.get("alreadyAssigned").asLong()).as("the already assigned targets count")
|
||||
.isEqualTo(ALREADY_ASSIGNED_COUNT);
|
||||
|
||||
assertThat(jsonNode.has("total")).as("the total targets count").isTrue();
|
||||
assertThat(jsonNode.get("total").isNumber()).as("the total targets count").isTrue();
|
||||
assertThat(jsonNode.get("total").asLong()).as("the total targets count")
|
||||
.isEqualTo(ALREADY_ASSIGNED_COUNT + ASSIGNED_ACTIONS.size());
|
||||
|
||||
assertThat(jsonNode.has("assignedActions")).as("The created actions in result of this assignment").isTrue();
|
||||
assertThat(jsonNode.get("assignedActions").isArray()).as("The created actions in result of this assignment")
|
||||
.isTrue();
|
||||
assertThat(jsonNode.get("assignedActions").size()).as("The created actions in result of this assignment")
|
||||
.isEqualTo(3);
|
||||
|
||||
assertThat(jsonNode.get("assignedActions").get(0).isObject())
|
||||
.as("A created action in result of this assignment").isTrue();
|
||||
assertThat(jsonNode.get("assignedActions").get(0).has("id")).as("A created action in result of this assignment")
|
||||
.isTrue();
|
||||
assertThat(jsonNode.get("assignedActions").get(0).get("id").isNumber())
|
||||
.as("A created action in result of this assignment").isTrue();
|
||||
assertThat(ASSIGNED_ACTIONS).as("The expected action ids")
|
||||
.contains(jsonNode.get("assignedActions").get(0).get("id").asLong());
|
||||
}
|
||||
|
||||
private static MgmtTargetAssignmentResponseBody generateResponseBody() {
|
||||
MgmtTargetAssignmentResponseBody response = new MgmtTargetAssignmentResponseBody();
|
||||
response.setAssignedActions(
|
||||
ASSIGNED_ACTIONS.stream().map(id -> new MgmtActionId(CONTROLLER_ID, id)).collect(Collectors.toList()));
|
||||
response.setAlreadyAssigned(ALREADY_ASSIGNED_COUNT);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user