Feature target type entity (#1162)
* Added Target Type model Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added Target Type JPA model Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added Target Type repository model classes Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Removed the name entity from Target Type Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Refactored the Target Type models Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added the DB migration script and updated the Target Type models Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added target type in target Mapper Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Changed the target type ID to Long Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added MYSQL DB migration script and removed the deleted column for target type Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Updated the DB migration script for target table Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added manyToMany reltation between target type and Ds type Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added POSTGRESQL DB migration script Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added MSSQL SERVER DB migration script Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added DB2 DB migration script Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added missing license header and java docs Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added on delete cascade in DB migration script Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added Target Type specification Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Removed the delete cascade and Added type API Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * fixed API doc build Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added target type management test Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added target type events test Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added target type update and unassign to target Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added API tests for assigning target type to target Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added missing license header Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added missing docs Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Fixed sonar issues Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Fixed license header build issue Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Updated the attribute name to target type Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Fixed the review comments Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Removed unused error status variable Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added target API to assign target type Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Added the tests for assigning target type to target Signed-off-by: Anand kumar <anand.kumar@bosch-si.com> * Fixed the review comments for null check Signed-off-by: Anand kumar <anand.kumar@bosch-si.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.distributionsettype;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
|
||||
/**
|
||||
* Request Body of DistributionSetType for assignment operations (ID only).
|
||||
*
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtDistributionSetTypeAssignment extends MgmtId {
|
||||
}
|
||||
@@ -49,6 +49,24 @@ public class MgmtTarget extends MgmtNamedEntity {
|
||||
@JsonProperty
|
||||
private boolean requestAttributes;
|
||||
|
||||
@JsonProperty
|
||||
private Long targetType;
|
||||
|
||||
/**
|
||||
* @return Target type ID
|
||||
*/
|
||||
public Long getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetType
|
||||
* Target type ID
|
||||
*/
|
||||
public void setTargetType(Long targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the controllerId
|
||||
*/
|
||||
@@ -150,6 +168,9 @@ public class MgmtTarget extends MgmtNamedEntity {
|
||||
return securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Address
|
||||
*/
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
@@ -171,6 +192,9 @@ public class MgmtTarget extends MgmtNamedEntity {
|
||||
this.securityToken = securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean true or false
|
||||
*/
|
||||
public boolean isRequestAttributes() {
|
||||
return requestAttributes;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,34 @@ public class MgmtTargetRequestBody {
|
||||
@JsonProperty
|
||||
private Boolean requestAttributes;
|
||||
|
||||
@JsonProperty
|
||||
private Long targetType;
|
||||
|
||||
/**
|
||||
* @return Target type ID
|
||||
*/
|
||||
public Long getTargetType() {
|
||||
return targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param targetType
|
||||
* Target type ID
|
||||
*/
|
||||
public void setTargetType(Long targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return token
|
||||
*/
|
||||
public String getSecurityToken() {
|
||||
return securityToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param securityToken Token
|
||||
*/
|
||||
public void setSecurityToken(final String securityToken) {
|
||||
this.securityToken = securityToken;
|
||||
}
|
||||
@@ -83,18 +107,32 @@ public class MgmtTargetRequestBody {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return address
|
||||
*/
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param address
|
||||
* Address
|
||||
*/
|
||||
public void setAddress(final String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean true or false
|
||||
*/
|
||||
public Boolean isRequestAttributes() {
|
||||
return requestAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param requestAttributes
|
||||
* Attributes
|
||||
*/
|
||||
public void setRequestAttributes(final Boolean requestAttributes) {
|
||||
this.requestAttributes = requestAttributes;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.targettype;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtNamedEntity;
|
||||
|
||||
/**
|
||||
* A json annotated rest model for TargetType to RESTful API
|
||||
* representation.
|
||||
*
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MgmtTargetType extends MgmtNamedEntity {
|
||||
|
||||
@JsonProperty(value = "id", required = true)
|
||||
private Long typeId;
|
||||
|
||||
@JsonProperty
|
||||
private String colour;
|
||||
|
||||
/**
|
||||
* @return target type ID
|
||||
*/
|
||||
public Long getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param typeId
|
||||
* Target type ID
|
||||
*/
|
||||
public void setTypeId(final Long typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the color in format #000000
|
||||
*/
|
||||
public String getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param colour
|
||||
* in format #000000
|
||||
*/
|
||||
public void setColour(String colour) {
|
||||
this.colour = colour;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.targettype;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.softwaremoduletype.MgmtSoftwareModuleTypeAssigment;
|
||||
|
||||
/**
|
||||
* Request Body for TargetType POST.
|
||||
*
|
||||
*/
|
||||
public class MgmtTargetTypeRequestBodyPost extends MgmtTargetTypeRequestBodyPut{
|
||||
|
||||
@JsonProperty
|
||||
private List<MgmtDistributionSetTypeAssignment> compatibledistributionsettypes;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
* @return post request body
|
||||
*/
|
||||
@Override
|
||||
public MgmtTargetTypeRequestBodyPost setName(final String name) {
|
||||
super.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MgmtTargetTypeRequestBodyPost setDescription(final String description) {
|
||||
super.setDescription(description);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MgmtTargetTypeRequestBodyPost setColour(final String colour) {
|
||||
super.setColour(colour);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the compatible ds types
|
||||
*/
|
||||
public List<MgmtDistributionSetTypeAssignment> getCompatibleDsTypes() {
|
||||
return compatibledistributionsettypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param compatibleDsTypes
|
||||
* the compatible ds types to set
|
||||
*
|
||||
* @return updated body
|
||||
*/
|
||||
public MgmtTargetTypeRequestBodyPost setCompatibleDsTypes(
|
||||
final List<MgmtDistributionSetTypeAssignment> compatibleDsTypes) {
|
||||
this.compatibledistributionsettypes = compatibleDsTypes;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.targettype;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Request Body for TargetType PUT.
|
||||
*
|
||||
*/
|
||||
public class MgmtTargetTypeRequestBodyPut {
|
||||
|
||||
@JsonProperty(required = true)
|
||||
private String name;
|
||||
|
||||
@JsonProperty
|
||||
private String description;
|
||||
|
||||
@JsonProperty
|
||||
private String colour;
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* the name to set
|
||||
*
|
||||
* @return updated body
|
||||
*/
|
||||
public MgmtTargetTypeRequestBodyPut setName(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description
|
||||
* Description
|
||||
* @return Updated body
|
||||
*/
|
||||
public MgmtTargetTypeRequestBodyPut setDescription(final String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Colour
|
||||
*/
|
||||
public String getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param colour
|
||||
* Colour
|
||||
* @return Updated body
|
||||
*/
|
||||
public MgmtTargetTypeRequestBodyPut setColour(final String colour) {
|
||||
this.colour = colour;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,11 @@ public final class MgmtRestConstants {
|
||||
|
||||
public static final String SYSTEM_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + BASE_SYSTEM_MAPPING;
|
||||
|
||||
/**
|
||||
* The target URL mapping, href link for assigned target type.
|
||||
*/
|
||||
public static final String TARGET_V1_ASSIGNED_TARGET_TYPE= "targetType";
|
||||
|
||||
/**
|
||||
* The target URL mapping, href link for assigned distribution set.
|
||||
*/
|
||||
@@ -99,6 +104,21 @@ public final class MgmtRestConstants {
|
||||
*/
|
||||
public static final String TARGET_TAG_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targettags";
|
||||
|
||||
/**
|
||||
* The target URL mapping rest resource.
|
||||
*/
|
||||
public static final String TARGET_TARGET_TYPE_V1_REQUEST_MAPPING = "/{targetId}/targettype";
|
||||
|
||||
/**
|
||||
* The target type URL mapping rest resource.
|
||||
*/
|
||||
public static final String TARGETTYPE_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/targettypes";
|
||||
|
||||
/**
|
||||
* The target type URL mapping rest resource.
|
||||
*/
|
||||
public static final String TARGETTYPE_V1_DS_TYPES = "compatibledistributionsettypes";
|
||||
|
||||
/**
|
||||
* The tag URL mapping rest resource.
|
||||
*
|
||||
|
||||
@@ -10,6 +10,7 @@ package org.eclipse.hawkbit.mgmt.rest.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadataBodyPut;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
||||
@@ -123,6 +124,31 @@ public interface MgmtTargetRestApi {
|
||||
@DeleteMapping(value = "/{targetId}")
|
||||
ResponseEntity<Void> deleteTarget(@PathVariable("targetId") String targetId);
|
||||
|
||||
/**
|
||||
* Handles the DELETE (unassign) request of a target type.
|
||||
*
|
||||
* @param targetId
|
||||
* the ID of the target
|
||||
* @return If the given targetId could exists and could be unassign Http OK.
|
||||
* In any failure the JsonResponseExceptionHandler is handling the
|
||||
* response.
|
||||
*/
|
||||
@DeleteMapping(value = MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING)
|
||||
ResponseEntity<Void> unassignTargetType(@PathVariable("targetId") String targetId);
|
||||
|
||||
/**
|
||||
* Handles the POST (assign) request of a target type.
|
||||
*
|
||||
* @param targetId
|
||||
* the ID of the target
|
||||
* @return If the given targetId could exists and could be assign Http OK.
|
||||
* In any failure the JsonResponseExceptionHandler is handling the
|
||||
* response.
|
||||
*/
|
||||
@PostMapping(value = MgmtRestConstants.TARGET_TARGET_TYPE_V1_REQUEST_MAPPING, consumes = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<Void> assignTargetType(@PathVariable("targetId") String targetId, MgmtId targetTypeId);
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving the attributes of a specific
|
||||
* target.
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.rest.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPut;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* REST Resource handling for TargetType CRUD operations.
|
||||
*
|
||||
*/
|
||||
@RequestMapping(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING)
|
||||
public interface MgmtTargetTypeRestApi {
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving all TargetTypes.
|
||||
*
|
||||
* @param pagingOffsetParam
|
||||
* the offset of list of target types for pagination, might not be
|
||||
* present in the rest request then default value will be applied
|
||||
* @param pagingLimitParam
|
||||
* the limit of the paged request, might not be present in the rest
|
||||
* request then default value will be applied
|
||||
* @param sortParam
|
||||
* the sorting parameter in the request URL, syntax
|
||||
* {@code field:direction, field:direction}
|
||||
* @param rsqlParam
|
||||
* the search parameter in the request URL, syntax
|
||||
* {@code q=name==abc}
|
||||
*
|
||||
* @return a list of all TargetTypes for a defined or default page request with
|
||||
* status OK. The response is always paged. In any failure the
|
||||
* JsonResponseExceptionHandler is handling the response.
|
||||
*/
|
||||
@GetMapping(produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<PagedList<MgmtTargetType>> getTargetTypes(
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) int pagingOffsetParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) int pagingLimitParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) String sortParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) String rsqlParam);
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving a single TargetType.
|
||||
*
|
||||
* @param targetTypeId
|
||||
* the ID of the target type to retrieve
|
||||
*
|
||||
* @return a single target type with status OK.
|
||||
*/
|
||||
@GetMapping(value = "/{targetTypeId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<MgmtTargetType> getTargetType(@PathVariable("targetTypeId") Long targetTypeId);
|
||||
|
||||
/**
|
||||
* Handles the DELETE request for a single Target Type.
|
||||
*
|
||||
* @param targetTypeId
|
||||
* the ID of the target type to retrieve
|
||||
* @return status OK if delete is successful.
|
||||
*
|
||||
*/
|
||||
@DeleteMapping(value = "/{targetTypeId}")
|
||||
ResponseEntity<Void> deleteTargetType(@PathVariable("targetTypeId") Long targetTypeId);
|
||||
|
||||
/**
|
||||
* Handles the PUT request of updating a Target Type.
|
||||
*
|
||||
* @param targetTypeId
|
||||
* the ID of the target type in the URL
|
||||
* @param restTargetType
|
||||
* the target type to be updated.
|
||||
* @return status OK if update is successful
|
||||
*/
|
||||
@PutMapping(value = "/{targetTypeId}", consumes = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaTypes.HAL_JSON_VALUE,
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<MgmtTargetType> updateTargetType(@PathVariable("targetTypeId") Long targetTypeId,
|
||||
MgmtTargetTypeRequestBodyPut restTargetType);
|
||||
|
||||
/**
|
||||
* Handles the POST request of creating new Target Types. The request body must
|
||||
* always be a list of types.
|
||||
*
|
||||
* @param targetTypes
|
||||
* the target types to be created.
|
||||
* @return In case all target types could be successfully created the
|
||||
* ResponseEntity with status code 201 - Created but without
|
||||
* ResponseBody. In any failure the JsonResponseExceptionHandler is
|
||||
* handling the response.
|
||||
*/
|
||||
@PostMapping(consumes = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }, produces = {
|
||||
MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<List<MgmtTargetType>> createTargetTypes(List<MgmtTargetTypeRequestBodyPost> targetTypes);
|
||||
|
||||
/**
|
||||
* Handles the GET request of retrieving the list of compatible distribution set
|
||||
* types in that target type.
|
||||
*
|
||||
* @param targetTypeId
|
||||
* of the TargetType.
|
||||
* @return Unpaged list of distribution set types and OK in case of success.
|
||||
*/
|
||||
@GetMapping(value = "/{targetTypeId}/" + MgmtRestConstants.TARGETTYPE_V1_DS_TYPES, produces = {
|
||||
MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<List<MgmtDistributionSetType>> getCompatibleDistributionSets(
|
||||
@PathVariable("targetTypeId") Long targetTypeId);
|
||||
|
||||
/**
|
||||
* Handles DELETE request for removing the compatibility of a distribution set
|
||||
* type from the target type.
|
||||
*
|
||||
* @param targetTypeId
|
||||
* of the TargetType.
|
||||
* @param distributionSetTypeId
|
||||
* of the DistributionSetType.
|
||||
*
|
||||
* @return OK if the request was successful
|
||||
*/
|
||||
@DeleteMapping(value = "/{targetTypeId}/" + MgmtRestConstants.TARGETTYPE_V1_DS_TYPES + "/{distributionSetTypeId}")
|
||||
ResponseEntity<Void> removeCompatibleDistributionSet(@PathVariable("targetTypeId") Long targetTypeId,
|
||||
@PathVariable("distributionSetTypeId") Long distributionSetTypeId);
|
||||
|
||||
/**
|
||||
* Handles the POST request for adding the compatibility of a distribution set
|
||||
* type to a target type.
|
||||
*
|
||||
* @param targetTypeId
|
||||
* of the TargetType.
|
||||
* @param distributionSetTypeIds
|
||||
* of the DistributionSetTypes as a List.
|
||||
*
|
||||
* @return OK if the request was successful
|
||||
*/
|
||||
@PostMapping(value = "/{targetTypeId}/" + MgmtRestConstants.TARGETTYPE_V1_DS_TYPES, consumes = {
|
||||
MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE })
|
||||
ResponseEntity<Void> addCompatibleDistributionSets(@PathVariable("targetTypeId") final Long targetTypeId,
|
||||
final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ final class MgmtDistributionSetTypeMapper {
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
static List<MgmtDistributionSetType> toListResponse(final List<DistributionSetType> types) {
|
||||
static List<MgmtDistributionSetType> toListResponse(final Collection<DistributionSetType> types) {
|
||||
if (types == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMaintenanceWindow;
|
||||
@@ -30,6 +31,7 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.ActionFields;
|
||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
@@ -79,6 +81,10 @@ public final class MgmtTargetMapper {
|
||||
response.add(linkTo(methodOn(MgmtTargetRestApi.class).getMetadata(response.getControllerId(),
|
||||
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET_VALUE,
|
||||
MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT_VALUE, null, null)).withRel("metadata"));
|
||||
if (response.getTargetType() != null) {
|
||||
response.add(linkTo(methodOn(MgmtTargetTypeRestApi.class)
|
||||
.getTargetType(response.getTargetType())).withRel(MgmtRestConstants.TARGET_V1_ASSIGNED_TARGET_TYPE));
|
||||
}
|
||||
}
|
||||
|
||||
static void addPollStatus(final Target target, final MgmtTarget targetRest) {
|
||||
@@ -153,6 +159,9 @@ public final class MgmtTargetMapper {
|
||||
if (installationDate != null) {
|
||||
targetRest.setInstalledAt(installationDate);
|
||||
}
|
||||
if (target.getTargetType() != null){
|
||||
targetRest.setTargetType(target.getTargetType().getId());
|
||||
}
|
||||
|
||||
targetRest.add(linkTo(methodOn(MgmtTargetRestApi.class).getTarget(target.getControllerId())).withSelfRel());
|
||||
|
||||
@@ -172,7 +181,7 @@ public final class MgmtTargetMapper {
|
||||
private static TargetCreate fromRequest(final EntityFactory entityFactory, final MgmtTargetRequestBody targetRest) {
|
||||
return entityFactory.target().create().controllerId(targetRest.getControllerId()).name(targetRest.getName())
|
||||
.description(targetRest.getDescription()).securityToken(targetRest.getSecurityToken())
|
||||
.address(targetRest.getAddress());
|
||||
.address(targetRest.getAddress()).targetType(targetRest.getTargetType());
|
||||
}
|
||||
|
||||
static List<MetaData> fromRequestTargetMetadata(final List<MgmtMetadata> metadata,
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.ValidationException;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtId;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadata;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.MgmtMetadataBodyPut;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
||||
@@ -140,7 +141,8 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
|
||||
final Target updateTarget = this.targetManagement.update(entityFactory.target().update(targetId)
|
||||
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
|
||||
.securityToken(targetRest.getSecurityToken()).requestAttributes(targetRest.isRequestAttributes()));
|
||||
.targetType(targetRest.getTargetType()).securityToken(targetRest.getSecurityToken())
|
||||
.requestAttributes(targetRest.isRequestAttributes()));
|
||||
|
||||
final MgmtTarget response = MgmtTargetMapper.toResponse(updateTarget);
|
||||
MgmtTargetMapper.addPollStatus(updateTarget, response);
|
||||
@@ -156,6 +158,18 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> unassignTargetType(@PathVariable("targetId") final String targetId) {
|
||||
this.targetManagement.unAssignType(targetId);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> assignTargetType(@PathVariable("targetId") final String targetId, @RequestBody final MgmtId targetTypeId) {
|
||||
this.targetManagement.assignType(targetId, targetTypeId.getId());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetAttributes> getAttributes(@PathVariable("targetId") final String targetId) {
|
||||
final Map<String, String> controllerAttributes = targetManagement.getControllerAttributes(targetId);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.rest.resource;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.rest.data.ResponseList;
|
||||
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
|
||||
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
|
||||
|
||||
/**
|
||||
* A mapper which maps repository model to RESTful model representation and
|
||||
* back.
|
||||
*
|
||||
*/
|
||||
public final class MgmtTargetTypeMapper {
|
||||
|
||||
// private constructor, utility class
|
||||
private MgmtTargetTypeMapper() {
|
||||
}
|
||||
|
||||
static List<TargetTypeCreate> targetFromRequest(final EntityFactory entityFactory,
|
||||
final Collection<MgmtTargetTypeRequestBodyPost> targetTypesRest) {
|
||||
if (targetTypesRest == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return targetTypesRest.stream().map(targetRest -> fromRequest(entityFactory, targetRest)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static TargetTypeCreate fromRequest(final EntityFactory entityFactory,
|
||||
final MgmtTargetTypeRequestBodyPost targetTypesRest) {
|
||||
return entityFactory.targetType().create().name(targetTypesRest.getName()).description(targetTypesRest.getDescription())
|
||||
.colour(targetTypesRest.getColour()).compatible(getDistributionSets(targetTypesRest));
|
||||
}
|
||||
|
||||
private static Collection<Long> getDistributionSets(final MgmtTargetTypeRequestBodyPost targetTypesRest) {
|
||||
return Optional.ofNullable(targetTypesRest.getCompatibleDsTypes())
|
||||
.map(ds -> ds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()))
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
static List<MgmtTargetType> toListResponse(final List<TargetType> types) {
|
||||
if (types == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return new ResponseList<>(types.stream().map(MgmtTargetTypeMapper::toResponse).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
static MgmtTargetType toResponse(final TargetType type) {
|
||||
final MgmtTargetType result = new MgmtTargetType();
|
||||
MgmtRestModelMapper.mapNamedToNamed(result, type);
|
||||
result.setTypeId(type.getId());
|
||||
result.setColour(type.getColour());
|
||||
result.add(linkTo(methodOn(MgmtTargetTypeRestApi.class).getTargetType(result.getTypeId())).withSelfRel());
|
||||
return result;
|
||||
}
|
||||
|
||||
static void addLinks(final MgmtTargetType result) {
|
||||
result.add(linkTo(methodOn(MgmtTargetTypeRestApi.class).getCompatibleDistributionSets(result.getTypeId()))
|
||||
.withRel(MgmtRestConstants.TARGETTYPE_V1_DS_TYPES));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.rest.resource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.eclipse.hawkbit.mgmt.json.model.PagedList;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.distributionsettype.MgmtDistributionSetTypeAssignment;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetType;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPost;
|
||||
import org.eclipse.hawkbit.mgmt.json.model.targettype.MgmtTargetTypeRequestBodyPut;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTypeRestApi;
|
||||
import org.eclipse.hawkbit.repository.DistributionSetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.EntityFactory;
|
||||
import org.eclipse.hawkbit.repository.OffsetBasedPageRequest;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Slice;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* REST Resource handling for {@link TargetType} CRUD operations.
|
||||
*/
|
||||
@RestController
|
||||
public class MgmtTargetTypeResource implements MgmtTargetTypeRestApi {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MgmtTargetTypeResource.class);
|
||||
|
||||
private final TargetTypeManagement targetTypeManagement;
|
||||
private final EntityFactory entityFactory;
|
||||
|
||||
public MgmtTargetTypeResource(TargetTypeManagement targetTypeManagement, final EntityFactory entityFactory) {
|
||||
this.targetTypeManagement = targetTypeManagement;
|
||||
this.entityFactory = entityFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<PagedList<MgmtTargetType>> getTargetTypes(
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_OFFSET) final int pagingOffsetParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, defaultValue = MgmtRestConstants.REQUEST_PARAMETER_PAGING_DEFAULT_LIMIT) final int pagingLimitParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SORTING, required = false) final String sortParam,
|
||||
@RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_SEARCH, required = false) final String rsqlParam) {
|
||||
|
||||
final int sanitizedOffsetParam = PagingUtility.sanitizeOffsetParam(pagingOffsetParam);
|
||||
final int sanitizedLimitParam = PagingUtility.sanitizePageLimitParam(pagingLimitParam);
|
||||
final Sort sorting = PagingUtility.sanitizeTargetTypeSortParam(sortParam);
|
||||
final Pageable pageable = new OffsetBasedPageRequest(sanitizedOffsetParam, sanitizedLimitParam, sorting);
|
||||
|
||||
final Page<TargetType> findTargetTypesAll;
|
||||
long countTargetTypesAll;
|
||||
if (rsqlParam != null) {
|
||||
findTargetTypesAll= targetTypeManagement.findByRsql(pageable, rsqlParam);
|
||||
} else {
|
||||
findTargetTypesAll = targetTypeManagement.findAll(pageable);
|
||||
}
|
||||
countTargetTypesAll = findTargetTypesAll.getTotalElements();
|
||||
|
||||
final List<MgmtTargetType> rest = MgmtTargetTypeMapper.toListResponse(findTargetTypesAll.getContent());
|
||||
return ResponseEntity.ok(new PagedList<>(rest, countTargetTypesAll));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetType> getTargetType(@PathVariable("targetTypeId") final Long targetTypeId) {
|
||||
final TargetType foundType = findTargetTypeWithExceptionIfNotFound(targetTypeId);
|
||||
final MgmtTargetType response = MgmtTargetTypeMapper.toResponse(foundType);
|
||||
MgmtTargetTypeMapper.addLinks(response);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> deleteTargetType(@PathVariable("targetTypeId") final Long targetTypeId) {
|
||||
LOG.debug("Delete {} target type", targetTypeId);
|
||||
targetTypeManagement.delete(targetTypeId);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<MgmtTargetType> updateTargetType(@PathVariable("targetTypeId") final Long targetTypeId,
|
||||
@RequestBody final MgmtTargetTypeRequestBodyPut restTargetType) {
|
||||
|
||||
final TargetType updated = targetTypeManagement
|
||||
.update(entityFactory.targetType().update(targetTypeId).name(restTargetType.getName())
|
||||
.description(restTargetType.getDescription()).colour(restTargetType.getColour()));
|
||||
final MgmtTargetType response = MgmtTargetTypeMapper.toResponse(updated);
|
||||
MgmtTargetTypeMapper.addLinks(response);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtTargetType>> createTargetTypes(
|
||||
@RequestBody final List<MgmtTargetTypeRequestBodyPost> targetTypes) {
|
||||
|
||||
final List<TargetType> createdTargetTypes = targetTypeManagement
|
||||
.create(MgmtTargetTypeMapper.targetFromRequest(entityFactory, targetTypes));
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(MgmtTargetTypeMapper.toListResponse(createdTargetTypes));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<List<MgmtDistributionSetType>> getCompatibleDistributionSets(
|
||||
@PathVariable("targetTypeId") final Long targetTypeId) {
|
||||
|
||||
final TargetType foundType = findTargetTypeWithExceptionIfNotFound(targetTypeId);
|
||||
return ResponseEntity
|
||||
.ok(MgmtDistributionSetTypeMapper.toListResponse(foundType.getCompatibleDistributionSetTypes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> removeCompatibleDistributionSet(@PathVariable("targetTypeId") final Long targetTypeId,
|
||||
@PathVariable("distributionSetTypeId") final Long distributionSetTypeId) {
|
||||
|
||||
targetTypeManagement.unassignDistributionSetType(targetTypeId, distributionSetTypeId);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Void> addCompatibleDistributionSets(@PathVariable("targetTypeId") final Long targetTypeId,
|
||||
@RequestBody final List<MgmtDistributionSetTypeAssignment> distributionSetTypeIds) {
|
||||
|
||||
targetTypeManagement.assignCompatibleDistributionSetTypes(targetTypeId,
|
||||
distributionSetTypeIds.stream().map(MgmtDistributionSetTypeAssignment::getId).collect(Collectors.toList()));
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
private TargetType findTargetTypeWithExceptionIfNotFound(final Long targetTypeId) {
|
||||
return targetTypeManagement.get(targetTypeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException(TargetType.class, targetTypeId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import org.eclipse.hawkbit.repository.SoftwareModuleTypeFields;
|
||||
import org.eclipse.hawkbit.repository.TagFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFields;
|
||||
import org.eclipse.hawkbit.repository.TargetFilterQueryFields;
|
||||
import org.eclipse.hawkbit.repository.TargetTypeFields;
|
||||
import org.eclipse.hawkbit.rest.util.SortUtility;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
@@ -61,6 +62,14 @@ public final class PagingUtility {
|
||||
return Sort.by(SortUtility.parse(TargetFields.class, sortParam));
|
||||
}
|
||||
|
||||
static Sort sanitizeTargetTypeSortParam(final String sortParam) {
|
||||
if (sortParam == null) {
|
||||
// default
|
||||
return Sort.by(Direction.ASC, TargetTypeFields.ID.getFieldName());
|
||||
}
|
||||
return Sort.by(SortUtility.parse(TargetFields.class, sortParam));
|
||||
}
|
||||
|
||||
static Sort sanitizeTagSortParam(final String sortParam) {
|
||||
if (sortParam == null) {
|
||||
// default
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.validation.ConstraintViolationException;
|
||||
@@ -56,6 +57,7 @@ import org.eclipse.hawkbit.repository.model.Rollout;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetMetadata;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.exception.MessageNotReadableException;
|
||||
@@ -63,6 +65,7 @@ import org.eclipse.hawkbit.rest.json.model.ExceptionInfo;
|
||||
import org.eclipse.hawkbit.rest.util.JsonBuilder;
|
||||
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
|
||||
import org.eclipse.hawkbit.util.IpUtil;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -105,6 +108,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
private static final String JSON_PATH_FIELD_SIZE = ".size";
|
||||
private static final String JSON_PATH_FIELD_TOTAL = ".total";
|
||||
private static final String JSON_PATH_FIELD_LAST_REQUEST_AT = ".lastControllerRequestAt";
|
||||
private static final String JSON_PATH_FIELD_TARGET_TYPE = ".targetType";
|
||||
|
||||
// target
|
||||
// $.field
|
||||
@@ -117,6 +121,7 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
private static final String JSON_PATH_CONTROLLERID = JSON_PATH_ROOT + JSON_PATH_FIELD_CONTROLLERID;
|
||||
private static final String JSON_PATH_DESCRIPTION = JSON_PATH_ROOT + JSON_PATH_FIELD_DESCRIPTION;
|
||||
private static final String JSON_PATH_LAST_REQUEST_AT = JSON_PATH_ROOT + JSON_PATH_FIELD_LAST_REQUEST_AT;
|
||||
private static final String JSON_PATH_TYPE = JSON_PATH_ROOT + JSON_PATH_FIELD_TARGET_TYPE;
|
||||
|
||||
@Autowired
|
||||
private JpaProperties jpaProperties;
|
||||
@@ -2075,4 +2080,192 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
|
||||
"$._links.rollout.href", containsString("/rest/v1/rollouts/" + rollout.getId().intValue())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a post request for creating targets with target type works.")
|
||||
public void createTargetsWithTargetType() throws Exception {
|
||||
final TargetType type1 = testdataFactory.createTargetType("typeWithDs", Collections.singletonList(standardDsType));
|
||||
final TargetType type2 = testdataFactory.createTargetType("typeWithOutDs", Collections.singletonList(standardDsType));
|
||||
|
||||
final Target test1 = entityFactory.target().create().controllerId("id1").name("targetWithoutType")
|
||||
.securityToken("token").address("amqp://test123/foobar").description("testid1").build();
|
||||
final Target test2 = entityFactory.target().create().controllerId("id2").name("targetOfType1")
|
||||
.targetType(type1.getId()).description("testid2").build();
|
||||
final Target test3 = entityFactory.target().create().controllerId("id3").name("targetOfType2")
|
||||
.targetType(type2.getId()).description("testid3").build();
|
||||
final String hrefType1 = "http://localhost/rest/v1/targettypes/" + type1.getId();
|
||||
|
||||
final List<Target> targets = Arrays.asList(test1, test2, test3);
|
||||
|
||||
final MvcResult mvcPostResult = mvc
|
||||
.perform(post("/rest/v1/targets/").content(JsonBuilder.targets(targets, true))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("[0].name", equalTo("targetWithoutType")))
|
||||
.andExpect(jsonPath("[0].controllerId", equalTo("id1")))
|
||||
.andExpect(jsonPath("[0].description", equalTo("testid1")))
|
||||
.andExpect(jsonPath("[0].createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("[0].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("[0].securityToken", equalTo("token")))
|
||||
.andExpect(jsonPath("[0].address", equalTo("amqp://test123/foobar")))
|
||||
.andExpect(jsonPath("[0].targetType").doesNotExist())
|
||||
.andExpect(jsonPath("[1].name", equalTo("targetOfType1")))
|
||||
.andExpect(jsonPath("[1].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("[1].controllerId", equalTo("id2")))
|
||||
.andExpect(jsonPath("[1].description", equalTo("testid2")))
|
||||
.andExpect(jsonPath("[1].createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("[1].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("[1].targetType", equalTo(type1.getId().intValue())))
|
||||
.andExpect(jsonPath("[2].name", equalTo("targetOfType2")))
|
||||
.andExpect(jsonPath("[2].controllerId", equalTo("id3")))
|
||||
.andExpect(jsonPath("[2].description", equalTo("testid3")))
|
||||
.andExpect(jsonPath("[2].createdAt", not(equalTo(0))))
|
||||
.andExpect(jsonPath("[2].createdBy", equalTo("bumlux")))
|
||||
.andExpect(jsonPath("[2].targetType", equalTo(type2.getId().intValue())))
|
||||
.andReturn();
|
||||
|
||||
mvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + test2.getControllerId()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(JSON_PATH_NAME, equalTo("targetOfType1")))
|
||||
.andExpect(jsonPath(JSON_PATH_CONTROLLERID, equalTo("id2")))
|
||||
.andExpect(jsonPath(JSON_PATH_TYPE, equalTo(type1.getId().intValue())))
|
||||
.andExpect(jsonPath(JSON_PATH_DESCRIPTION, equalTo("testid2")))
|
||||
.andExpect(jsonPath("$._links.targetType.href", equalTo(hrefType1))).andReturn();
|
||||
|
||||
assertThat(targetManagement.getByControllerID("id1")).isNotNull();
|
||||
assertThat(targetManagement.getByControllerID("id1").get().getName()).isEqualTo("targetWithoutType");
|
||||
assertThat(targetManagement.getByControllerID("id1").get().getDescription()).isEqualTo("testid1");
|
||||
assertThat(targetManagement.getByControllerID("id1").get().getTargetType()).isNull();
|
||||
assertThat(targetManagement.getByControllerID("id1").get().getSecurityToken()).isEqualTo("token");
|
||||
assertThat(targetManagement.getByControllerID("id1").get().getAddress().toString())
|
||||
.isEqualTo("amqp://test123/foobar");
|
||||
assertThat(targetManagement.getByControllerID("id2")).isNotNull();
|
||||
assertThat(targetManagement.getByControllerID("id2").get().getName()).isEqualTo("targetOfType1");
|
||||
assertThat(targetManagement.getByControllerID("id2").get().getDescription()).isEqualTo("testid2");
|
||||
assertThat(targetManagement.getByControllerID("id2").get().getTargetType().getName()).isEqualTo("typeWithDs");
|
||||
assertThat(targetManagement.getByControllerID("id3")).isNotNull();
|
||||
assertThat(targetManagement.getByControllerID("id3").get().getName()).isEqualTo("targetOfType2");
|
||||
assertThat(targetManagement.getByControllerID("id3").get().getDescription()).isEqualTo("testid3");
|
||||
assertThat(targetManagement.getByControllerID("id3").get().getTargetType().getName()).isEqualTo("typeWithOutDs");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a post request for creating target with target type works.")
|
||||
public void createTargetWithExistingTargetType() throws Exception {
|
||||
// create target type
|
||||
List<TargetType> targetTypes = testdataFactory.createTargetTypes("targettype",1);
|
||||
assertThat(targetTypes).hasSize(1);
|
||||
|
||||
final Target target = entityFactory.target().create().controllerId("targetcontroller").name("testtarget").targetType(targetTypes.get(0).getId()).build();
|
||||
|
||||
final String targetList = JsonBuilder.targets(Collections.singletonList(target), false);
|
||||
|
||||
// test query target over rest resource
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content(targetList)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("[0].controllerId", equalTo("targetcontroller")))
|
||||
.andExpect(jsonPath("[0].targetType", equalTo(targetTypes.get(0).getId().intValue())));
|
||||
|
||||
assertThat(targetManagement.getByControllerID("targetcontroller").get().getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a put request for updating targets with target type works.")
|
||||
public void updateTargetTypeInTarget() throws Exception {
|
||||
// create target type
|
||||
List<TargetType> targetTypes = testdataFactory.createTargetTypes("targettype",2);
|
||||
assertThat(targetTypes).hasSize(2);
|
||||
|
||||
String controllerId = "targetcontroller";
|
||||
Target target = testdataFactory.createTarget(controllerId, "testtarget", targetTypes.get(0).getId());
|
||||
|
||||
assertThat(target).isNotNull();
|
||||
assertThat(target.getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
|
||||
|
||||
// update target over rest resource
|
||||
final String body = new JSONObject().put("targetType", targetTypes.get(1).getId().intValue()).toString();
|
||||
|
||||
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + controllerId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("controllerId", equalTo(controllerId)))
|
||||
.andExpect(jsonPath("targetType", equalTo(targetTypes.get(1).getId().intValue())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a post request for creating targets with unknown target type fails.")
|
||||
public void addingNonExistingTargetTypeInTargetShouldFail() throws Exception {
|
||||
long unknownTargetTypeId = 999;
|
||||
String errorMsg = String.format("TargetType with given identifier {%s} does not exist.", unknownTargetTypeId);
|
||||
|
||||
Optional<TargetType> targetType = targetTypeManagement.get(unknownTargetTypeId);
|
||||
assertThat(targetType).isNotPresent();
|
||||
|
||||
String controllerId = "targetcontroller";
|
||||
final Target target = entityFactory.target().create().controllerId(controllerId).name("testtarget").build();
|
||||
|
||||
final String targetList = JsonBuilder.targets(Collections.singletonList(target), false, unknownTargetTypeId);
|
||||
|
||||
// post target over rest resource
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING).content(targetList)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNotFound())
|
||||
.andExpect(jsonPath("message", Matchers.containsString(errorMsg)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a post request for assign target type to target works.")
|
||||
public void assignTargetTypeToTarget() throws Exception {
|
||||
// create target type
|
||||
TargetType targetType = testdataFactory.findOrCreateTargetType("targettype");
|
||||
assertThat(targetType).isNotNull();
|
||||
|
||||
// create target
|
||||
String targetControllerId = "targetcontroller";
|
||||
Target target = testdataFactory.createTarget(targetControllerId, "testtarget");
|
||||
assertThat(target).isNotNull();
|
||||
|
||||
// assign target type over rest resource
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetControllerId + "/targettype")
|
||||
.content("{\"id\":" + targetType.getId() + "}").contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
assertThat(targetManagement.getByControllerID(targetControllerId).get().getTargetType().getId()).isEqualTo(targetType.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a post request for assign a invalid target type to target fails.")
|
||||
public void assignInvalidTargetTypeToTargetFails() throws Exception {
|
||||
// Invalid target type ID
|
||||
long invalidTargetTypeId = 999;
|
||||
|
||||
// create target
|
||||
String targetControllerId = "targetcontroller";
|
||||
Target target = testdataFactory.createTarget(targetControllerId, "testtarget");
|
||||
assertThat(target).isNotNull();
|
||||
|
||||
// assign invalid target type over rest resource
|
||||
mvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetControllerId + "/targettype")
|
||||
.content("{\"id\":" + invalidTargetTypeId + "}").contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that a delete request for unassign target type from target works.")
|
||||
public void unassignTargetTypeFromTarget() throws Exception {
|
||||
// create target type
|
||||
List<TargetType> targetTypes = testdataFactory.createTargetTypes("targettype",1);
|
||||
assertThat(targetTypes).hasSize(1);
|
||||
|
||||
String targetControllerId = "targetcontroller";
|
||||
Target target = testdataFactory.createTarget(targetControllerId, "testtarget", targetTypes.get(0).getId());
|
||||
|
||||
assertThat(target).isNotNull();
|
||||
assertThat(target.getTargetType().getId()).isEqualTo(targetTypes.get(0).getId());
|
||||
|
||||
// unassign target type over rest resource
|
||||
mvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetControllerId + "/targettype")
|
||||
.contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
|
||||
|
||||
assertThat(targetManagement.getByControllerID(targetControllerId).get().getTargetType()).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,616 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.rest.resource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Step;
|
||||
import io.qameta.allure.Story;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.builder.TargetTypeCreate;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.NamedEntity;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.repository.test.util.WithUser;
|
||||
import org.eclipse.hawkbit.rest.util.JsonBuilder;
|
||||
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.hasToString;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
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.post;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Spring MVC Tests against the MgmtTargetTypeResource.
|
||||
*
|
||||
*/
|
||||
@Feature("Component Tests - Management API")
|
||||
@Story("Target Type Resource")
|
||||
class MgmtTargetTypeResourceTest extends AbstractManagementApiIntegrationTest {
|
||||
|
||||
private final static String TARGETTYPES_ENDPOINT = MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING;
|
||||
private final static String TARGETTYPE_SINGLE_ENDPOINT = MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING
|
||||
+ "/{typeid}";
|
||||
private final static String TARGETTYPE_DSTYPES_ENDPOINT = TARGETTYPE_SINGLE_ENDPOINT + "/"
|
||||
+ MgmtRestConstants.TARGETTYPE_V1_DS_TYPES;
|
||||
private final static String TARGETTYPE_DSTYPE_SINGLE_ENDPOINT = TARGETTYPE_DSTYPES_ENDPOINT + "/{dstypeid}";
|
||||
|
||||
private final static String TEST_USER = "targetTypeTester";
|
||||
|
||||
|
||||
@Test
|
||||
@WithUser(principal = "targetTypeTester", allSpPermissions = true, removeFromAllPermission = { SpPermission.READ_TARGET })
|
||||
@Description("GET targettypes returns Forbidden when permission is missing")
|
||||
void getTargetTypesWithoutPermission() throws Exception {
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{id} GET request.")
|
||||
void getTargetType() throws Exception {
|
||||
String typeName = "TestTypeGET";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
Long typeId = testType.getId();
|
||||
|
||||
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, typeId).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.id", is(typeId), Long.class)).andExpect(jsonPath("$.name", equalTo(typeName)))
|
||||
.andExpect(jsonPath("$.colour", is("#000000")))
|
||||
.andExpect(jsonPath("$.description", equalTo(typeName + " description")))
|
||||
.andExpect(jsonPath("$.createdBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt())))
|
||||
.andExpect(jsonPath("$.lastModifiedBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$._links.self.href", equalTo("http://localhost/rest/v1/targettypes/" + typeId)))
|
||||
.andExpect(jsonPath("$.deleted").doesNotExist())
|
||||
.andExpect(jsonPath("$.key").doesNotExist())
|
||||
.andExpect(jsonPath("$._links.compatibledistributionsettypes.href",
|
||||
equalTo("http://localhost/rest/v1/targettypes/" + typeId + "/compatibledistributionsettypes")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes GET requests.")
|
||||
void getTargetTypes() throws Exception {
|
||||
String typeName = "TestTypeGET";
|
||||
int count = 5;
|
||||
List<TargetType> testTypes = createTestTargetTypesInDB(typeName, count);
|
||||
|
||||
ResultActions resultActions = mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print());
|
||||
|
||||
for (int index = 0; index < count; index++) {
|
||||
Long typeId = testTypes.get(index).getId();
|
||||
resultActions.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].id", contains(typeId.intValue())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].name", contains(typeName + index)))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].colour", contains("#000000")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].description",
|
||||
contains(typeName + " description")))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].createdBy", contains(TEST_USER)))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].createdAt",
|
||||
contains(testTypes.get(index).getCreatedAt())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].lastModifiedBy", contains(TEST_USER)))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].lastModifiedAt",
|
||||
contains(testTypes.get(index).getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].deleted").doesNotExist())
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')].key").doesNotExist())
|
||||
.andExpect(jsonPath("$.content.[?(@.id=='" + typeId + "')]._links.self.href",
|
||||
contains("http://localhost/rest/v1/targettypes/" + typeId)))
|
||||
.andExpect(
|
||||
jsonPath("$.content.[?(@.id=='" + typeId + "')]._links.compatibledistributionsettypes.href")
|
||||
.doesNotExist())
|
||||
.andExpect(jsonPath("$.total", equalTo(count))).andExpect(jsonPath("$.size", equalTo(count)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes GET requests without prior created target types.")
|
||||
void getDefaultTargetTypes() throws Exception {
|
||||
|
||||
// 0 types overall (no default types are created)
|
||||
final int types = 0;
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(types)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(types)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(types)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes GET requests with sorting by name.")
|
||||
void getTargetTypesSortedByName() throws Exception {
|
||||
String typeNameA = "ATestTypeGETsorted";
|
||||
String typeNameB = "BTestTypeGETsorted";
|
||||
String typeNameC = "CTestTypeGETsorted";
|
||||
TargetType testTypeB = createTestTargetTypeInDB(typeNameB);
|
||||
TargetType testTypeC = createTestTargetTypeInDB(typeNameC);
|
||||
TargetType testTypeA = createTestTargetTypeInDB(typeNameA);
|
||||
|
||||
testTypeA = targetTypeManagement
|
||||
.update(entityFactory.targetType().update(testTypeA.getId()).description("Updated description"));
|
||||
|
||||
// descending
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON)
|
||||
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "name:DESC")).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.content.[0].id", equalTo(testTypeC.getId().intValue())))
|
||||
.andExpect(jsonPath("$.content.[0].name", equalTo(typeNameC)))
|
||||
.andExpect(jsonPath("$.content.[0].colour", equalTo("#000000")))
|
||||
.andExpect(jsonPath("$.content.[0].description", equalTo(typeNameC + " description")))
|
||||
.andExpect(jsonPath("$.content.[0].createdBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.content.[0].createdAt", equalTo(testTypeC.getCreatedAt())))
|
||||
.andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(testTypeC.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$.content.[0].deleted").doesNotExist())
|
||||
.andExpect(jsonPath("$.content.[0].key").doesNotExist())
|
||||
.andExpect(jsonPath("$.content.[0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/targettypes/" + testTypeC.getId())))
|
||||
.andExpect(jsonPath("$.content.[0]._links.compatibledistributionsettypes.href").doesNotExist())
|
||||
.andExpect(jsonPath("$.total", equalTo(3))).andExpect(jsonPath("$.size", equalTo(3)))
|
||||
.andExpect(jsonPath("$.content.[1].name", equalTo(typeNameB)))
|
||||
.andExpect(jsonPath("$.content.[2].name", equalTo(typeNameA)));
|
||||
|
||||
// ascending
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT).accept(MediaType.APPLICATION_JSON)
|
||||
.param(MgmtRestConstants.REQUEST_PARAMETER_SORTING, "name:ASC")).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.content.[0].id", equalTo(testTypeA.getId().intValue())))
|
||||
.andExpect(jsonPath("$.content.[0].name", equalTo(typeNameA)))
|
||||
.andExpect(jsonPath("$.content.[0].description", equalTo("Updated description")))
|
||||
.andExpect(jsonPath("$.content.[0].colour", equalTo("#000000")))
|
||||
.andExpect(jsonPath("$.content.[0].createdBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.content.[0].createdAt", equalTo(testTypeA.getCreatedAt())))
|
||||
.andExpect(jsonPath("$.content.[0].lastModifiedBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.content.[0].lastModifiedAt", equalTo(testTypeA.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$.content.[0].deleted").doesNotExist())
|
||||
.andExpect(jsonPath("$.content.[0].key").doesNotExist())
|
||||
.andExpect(jsonPath("$.content.[0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/targettypes/" + testTypeA.getId())))
|
||||
.andExpect(jsonPath("$.content.[0]._links.compatibledistributionsettypes.href").doesNotExist())
|
||||
.andExpect(jsonPath("$.total", equalTo(3))).andExpect(jsonPath("$.size", equalTo(3)))
|
||||
.andExpect(jsonPath("$.content.[1].name", equalTo(typeNameB)))
|
||||
.andExpect(jsonPath("$.content.[2].name", equalTo(typeNameC)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes GET requests with paging.")
|
||||
void getTargetTypesWithPagingLimitRequestParameter() throws Exception {
|
||||
final String typePrefix = "TestTypeGETPaging";
|
||||
final int count = 10;
|
||||
final int limit = 3;
|
||||
createTestTargetTypesInDB(typePrefix, count);
|
||||
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT).param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT,
|
||||
String.valueOf(limit))).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(count)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(limit)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(limit)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes GET requests with paging and offset.")
|
||||
void getTargetTypesWithPagingLimitAndOffsetRequestParameter() throws Exception {
|
||||
final int count = 10;
|
||||
final int offset = 2;
|
||||
final int expectedSize = count - offset;
|
||||
final String typePrefix = "TestTypeGETPaging";
|
||||
createTestTargetTypesInDB(typePrefix, count);
|
||||
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT)
|
||||
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_OFFSET, String.valueOf(offset))
|
||||
.param(MgmtRestConstants.REQUEST_PARAMETER_PAGING_LIMIT, String.valueOf(count)))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_TOTAL, equalTo(count)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_SIZE, equalTo(expectedSize)))
|
||||
.andExpect(jsonPath(MgmtTargetResourceTest.JSON_PATH_PAGED_LIST_CONTENT, hasSize(expectedSize)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{ID} PUT requests.")
|
||||
void updateTargetType() throws Exception {
|
||||
String typeName = "TestTypePUT";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
final String body = new JSONObject().put("id", testType.getId()).put("description", "updated description")
|
||||
.put("name", "TestTypePUTupdated").put("colour", "#ffffff").toString();
|
||||
|
||||
mvc.perform(
|
||||
put(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).content(body).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
|
||||
.andExpect(jsonPath("$.description", equalTo("updated description")))
|
||||
.andExpect(jsonPath("$.name", equalTo("TestTypePUTupdated")))
|
||||
.andExpect(jsonPath("$.colour", equalTo("#ffffff"))).andReturn();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{id} GET requests.")
|
||||
void getUpdatedTargetType() throws Exception {
|
||||
TargetType testType = createTestTargetTypeInDB("TestTypeGET");
|
||||
String typeNameUpdated = "TestTypeGETupdated";
|
||||
testType = targetTypeManagement.update(entityFactory.targetType().update(testType.getId()).name(typeNameUpdated)
|
||||
.description("Updated Description").colour("#ffffff"));
|
||||
|
||||
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$.name", equalTo(typeNameUpdated)))
|
||||
.andExpect(jsonPath("$.description", equalTo("Updated Description")))
|
||||
.andExpect(jsonPath("$.colour", equalTo("#ffffff")))
|
||||
.andExpect(jsonPath("$.createdBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.createdAt", equalTo(testType.getCreatedAt())))
|
||||
.andExpect(jsonPath("$.lastModifiedBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$.lastModifiedAt", equalTo(testType.getLastModifiedAt())))
|
||||
.andExpect(jsonPath("$.deleted").doesNotExist())
|
||||
.andExpect(jsonPath("$.key").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes POST requests.")
|
||||
void createTargetTypes() throws Exception {
|
||||
String typeName = "TestTypePOST";
|
||||
final List<TargetType> types = buildTestTargetTypesWithoutDsTypes(typeName, 5);
|
||||
|
||||
runPostTargetTypeAndVerify(types);
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes POST requests.")
|
||||
void addDistributionSetTypeToTargetType() throws Exception {
|
||||
String typeName = "TestTypeAddDs";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(1);
|
||||
|
||||
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())
|
||||
.content("[{\"id\":" + standardDsType.getId() + "}]").contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
testType = targetTypeManagement.get(testType.getId()).get();
|
||||
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).containsExactly(standardDsType);
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes GET requests.")
|
||||
void getDistributionSetsOfTargetType() throws Exception {
|
||||
String typeName = "TestTypeGetDs";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
|
||||
|
||||
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$[0].name", equalTo(standardDsType.getName())))
|
||||
.andExpect(jsonPath("$[0].description", equalTo(standardDsType.getDescription())))
|
||||
.andExpect(jsonPath("$[0].key", equalTo("test_default_ds_type")))
|
||||
.andExpect(jsonPath("$[0]._links.self.href",
|
||||
equalTo("http://localhost/rest/v1/distributionsettypes/" + standardDsType.getId())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes/{ID} GET requests.")
|
||||
void getDistributionSetOfTargetTypeReturnsNotAllowed() throws Exception {
|
||||
String typeName = "TestTypeAddDs";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
|
||||
mvc.perform(get(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), standardDsType.getId())
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{ID}/compatibledistributionsettypes/{ID} DELETE requests.")
|
||||
void removeDsTypeFromTargetType() throws Exception {
|
||||
String typeName = "TestTypeRemoveDs";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
|
||||
|
||||
mvc.perform(delete(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), standardDsType.getId())
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
testType = targetTypeManagement.get(testType.getId()).get();
|
||||
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/distributionsettypes/{ID} DELETE requests.")
|
||||
void deletingDsTypeRemovesAssignmentFromTargetType() throws Exception {
|
||||
String typeName = "TestTypeRemoveDs";
|
||||
TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).hasSize(1);
|
||||
assertThat(distributionSetTypeManagement.getByKey(standardDsType.getKey())).isNotEmpty();
|
||||
|
||||
mvc.perform(delete(MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING + "/" + standardDsType.getId()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
|
||||
|
||||
testType = targetTypeManagement.get(testType.getId()).get();
|
||||
assertThat(testType.getLastModifiedBy()).isEqualTo(TEST_USER);
|
||||
assertThat(testType.getOptLockRevision()).isEqualTo(2);
|
||||
assertThat(testType.getCompatibleDistributionSetTypes()).isEmpty();
|
||||
assertThat(distributionSetTypeManagement.getByKey(standardDsType.getKey())).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{ID} DELETE requests - Deletion when not in use.")
|
||||
void deleteTargetTypeUnused() throws Exception {
|
||||
String typeName = "TestTypeUnusedDelete";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
|
||||
assertThat(targetTypeManagement.count()).isEqualTo(1);
|
||||
|
||||
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
assertThat(targetTypeManagement.count()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Checks the correct behaviour of /rest/v1/targettypes/{ID} DELETE requests - Deletion not possible when in use.")
|
||||
void deleteTargetTypeUsed() throws Exception {
|
||||
String typeName = "TestTypeUsedDelete";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
|
||||
targetManagement.create(entityFactory.target().create().controllerId("target").name("TargetOfTestType")
|
||||
.description("target description").targetType(testType.getId()));
|
||||
|
||||
assertThat(targetTypeManagement.count()).isEqualTo(1);
|
||||
assertThat(targetManagement.count()).isEqualTo(1);
|
||||
|
||||
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isConflict());
|
||||
|
||||
assertThat(targetManagement.count()).isEqualTo(1);
|
||||
assertThat(targetTypeManagement.count()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Ensures that target type deletion request to API on an entity that does not exist results in NOT_FOUND.")
|
||||
void deleteTargetTypeThatDoesNotExistLeadsToNotFound() throws Exception {
|
||||
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, 1234)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUser(principal = TEST_USER, allSpPermissions = true)
|
||||
@Description("Tests the update of the deletion flag. It is verified that the target type can't be marked as deleted through update operation.")
|
||||
void updateTargetTypeDeletedFlag() throws Exception {
|
||||
String typeName = "TestTypePUT";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName);
|
||||
|
||||
final String body = new JSONObject().put("id", testType.getId()).put("deleted", true).toString();
|
||||
|
||||
mvc.perform(
|
||||
put(TARGETTYPE_SINGLE_ENDPOINT, testType.getId()).content(body).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.id", equalTo(testType.getId().intValue())))
|
||||
.andExpect(jsonPath("$.deleted").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Ensures that the server is behaving as expected on invalid requests (wrong media type, wrong ID etc.).")
|
||||
void invalidRequestsOnTargetTypesResource() throws Exception {
|
||||
String typeName = "TestTypeInvalidReq";
|
||||
final TargetType testType = createTestTargetTypeInDB(typeName, Collections.singletonList(standardDsType));
|
||||
|
||||
// target type does not exist
|
||||
mvc.perform(get(TARGETTYPE_SINGLE_ENDPOINT, 12345678)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, 123456789)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
mvc.perform(delete(TARGETTYPE_SINGLE_ENDPOINT, 123456789)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
// target types at creation time invalid
|
||||
final TargetType testNewType = createTestTargetTypeInDB(typeName + "Another",
|
||||
Collections.singletonList(standardDsType));
|
||||
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(Collections.singletonList(testNewType)))
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isUnsupportedMediaType());
|
||||
|
||||
// bad request - no content
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
|
||||
|
||||
// bad request - bad content
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content("sdfjsdlkjfskdjf".getBytes())
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// Missing mandatory field name
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content("[{\"description\":\"Desc123\"}]")
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
final TargetType tooLongName = entityFactory.targetType().create()
|
||||
.name(RandomStringUtils.randomAlphanumeric(NamedEntity.NAME_MAX_SIZE + 1)).build();
|
||||
mvc.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(Collections.singletonList(tooLongName)))
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
// ds types
|
||||
mvc.perform(get(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk());
|
||||
|
||||
mvc.perform(delete(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isNotFound());
|
||||
|
||||
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()).content("{\"id\":1}")
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
mvc.perform(post(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId()).content("[{\"id\":44456}]")
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
// not allowed methods
|
||||
mvc.perform(put(TARGETTYPES_ENDPOINT)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
|
||||
mvc.perform(delete(TARGETTYPES_ENDPOINT)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
|
||||
mvc.perform(put(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId())).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
|
||||
mvc.perform(delete(TARGETTYPE_DSTYPES_ENDPOINT, testType.getId(), 565765)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
|
||||
mvc.perform(put(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed());
|
||||
|
||||
mvc.perform(post(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765)
|
||||
.contentType(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isMethodNotAllowed());
|
||||
|
||||
mvc.perform(get(TARGETTYPE_DSTYPE_SINGLE_ENDPOINT, testType.getId(), 565765))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isMethodNotAllowed());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Search request of target types.")
|
||||
void searchTargetTypeRsql() throws Exception {
|
||||
targetTypeManagement.create(entityFactory.targetType().create().name("TestName123"));
|
||||
targetTypeManagement.create(entityFactory.targetType().create().name("TestName1234"));
|
||||
|
||||
final String rsqlFindLikeDs1OrDs2 = "name==TestName123,name==TestName1234";
|
||||
|
||||
mvc.perform(get(TARGETTYPES_ENDPOINT + "?q=" + rsqlFindLikeDs1OrDs2)).andDo(MockMvcResultPrinter.print())
|
||||
.andExpect(status().isOk()).andExpect(jsonPath("size", equalTo(2)))
|
||||
.andExpect(jsonPath("total", equalTo(2))).andExpect(jsonPath("content[0].name", equalTo("TestName123")))
|
||||
.andExpect(jsonPath("content[1].name", equalTo("TestName1234")));
|
||||
}
|
||||
|
||||
@Step
|
||||
private TargetType buildTestTargetTypeBody(String name) {
|
||||
return prepareTestTargetType(name, null).build();
|
||||
}
|
||||
|
||||
private TargetTypeCreate prepareTestTargetType(String name, Collection<DistributionSetType> dsTypes) {
|
||||
TargetTypeCreate create = entityFactory.targetType().create().name(name)
|
||||
.description("Description of the test type").colour("#aaaaaa");
|
||||
if (dsTypes != null && !dsTypes.isEmpty()) {
|
||||
create.compatible(Collections.singletonList(standardDsType.getId()));
|
||||
}
|
||||
return create;
|
||||
}
|
||||
|
||||
@Step
|
||||
private List<TargetType> createTestTargetTypesInDB(String namePrefix, int count) {
|
||||
return testdataFactory.createTargetTypes(namePrefix, count);
|
||||
}
|
||||
|
||||
@Step
|
||||
private TargetType createTestTargetTypeInDB(String name) {
|
||||
return testdataFactory.findOrCreateTargetType(name);
|
||||
}
|
||||
|
||||
@Step
|
||||
private TargetType createTestTargetTypeInDB(String name, List<DistributionSetType> dsTypes) {
|
||||
TargetType targetType = testdataFactory.createTargetType(name, dsTypes);
|
||||
assertThat(targetType.getOptLockRevision()).isEqualTo(1);
|
||||
return targetType;
|
||||
}
|
||||
|
||||
@Step
|
||||
private List<TargetType> buildTestTargetTypesWithoutDsTypes(String namePrefix, int count) {
|
||||
final List<TargetType> types = new ArrayList<>();
|
||||
for (int index = 0; index < count; index++) {
|
||||
types.add(buildTestTargetTypeBody(namePrefix + index));
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
@Step
|
||||
private void runPostTargetTypeAndVerify(final List<TargetType> types) throws Exception {
|
||||
int size = types.size();
|
||||
ResultActions resultActions = mvc
|
||||
.perform(post(TARGETTYPES_ENDPOINT).content(JsonBuilder.targetTypes(types))
|
||||
.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print());
|
||||
|
||||
for (int index = 0; index < size; index++) {
|
||||
resultActions.andExpect(status().isCreated()).andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||
.andExpect(jsonPath("$[" + index + "].id").exists())
|
||||
.andExpect(jsonPath("$[" + index + "].name", startsWith("TestTypePOST")))
|
||||
.andExpect(jsonPath("$[" + index + "].colour", hasToString("#aaaaaa")))
|
||||
.andExpect(jsonPath("$[" + index + "].description",
|
||||
equalTo("Description of the test type")))
|
||||
.andExpect(jsonPath("$[" + index + "].createdBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$[" + index + "].createdAt").exists())
|
||||
.andExpect(jsonPath("$[" + index + "].lastModifiedBy", equalTo(TEST_USER)))
|
||||
.andExpect(jsonPath("$[" + index + "].lastModifiedAt").exists())
|
||||
.andExpect(jsonPath("$[" + index + "].key").doesNotExist())
|
||||
.andExpect(jsonPath("$[" + index + "].deleted").doesNotExist())
|
||||
.andExpect(jsonPath("$[" + index + "]._links.self.href",
|
||||
startsWith("http://localhost/rest/v1/targettypes/")))
|
||||
.andExpect(
|
||||
jsonPath("$[" + index + "]._links.compatibledistributionsettypes.href")
|
||||
.doesNotExist());
|
||||
}
|
||||
MvcResult mvcResult = resultActions.andReturn();
|
||||
|
||||
for (int index = 0; index < size; index++) {
|
||||
String name = "TestTypePOST" + index;
|
||||
final TargetType created = targetTypeManagement.getByName(name).get();
|
||||
|
||||
assertThat(JsonPath.compile("$[ ?(@.name=='" + name + "') ].id")
|
||||
.read(mvcResult.getResponse().getContentAsString()).toString()).contains(String.valueOf(created.getId()));
|
||||
assertThat(JsonPath.compile("$[ ?(@.name=='" + name + "') ]._links.self.href")
|
||||
.read(mvcResult.getResponse().getContentAsString()).toString()).contains("/"+created.getId());
|
||||
}
|
||||
|
||||
assertThat(targetTypeManagement.count()).isEqualTo(size);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,6 +87,7 @@ public class ResponseExceptionHandler {
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_CONFIGURATION_VALUE_CHANGE_NOT_ALLOWED, HttpStatus.FORBIDDEN);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_MULTIASSIGNMENT_NOT_ENABLED, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_NO_WEIGHT_PROVIDED_IN_MULTIASSIGNMENT_MODE, HttpStatus.BAD_REQUEST);
|
||||
ERROR_TO_HTTP_STATUS.put(SpServerError.SP_TARGET_TYPE_IN_USE, HttpStatus.CONFLICT);
|
||||
}
|
||||
|
||||
private static HttpStatus getStatusOrDefault(final SpServerError error) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
|
||||
import org.eclipse.hawkbit.repository.model.Tag;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -426,13 +427,13 @@ public abstract class JsonBuilder {
|
||||
int i = 0;
|
||||
for (final Target target : targets) {
|
||||
final String address = target.getAddress() != null ? target.getAddress().toString() : null;
|
||||
|
||||
final String targetType = target.getTargetType() != null ? target.getTargetType().getId().toString() : null;
|
||||
final String token = withToken ? target.getSecurityToken() : null;
|
||||
|
||||
builder.append(new JSONObject().put("controllerId", target.getControllerId())
|
||||
.put("description", target.getDescription()).put("name", target.getName()).put("createdAt", "0")
|
||||
.put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh")
|
||||
.put("address", address).put("securityToken", token).toString());
|
||||
.put("updatedAt", "0").put("createdBy", "systemtest").put("updatedBy", "systemtest")
|
||||
.put("address", address).put("securityToken", token).put("targetType", targetType).toString());
|
||||
|
||||
if (++i < targets.size()) {
|
||||
builder.append(",");
|
||||
@@ -444,6 +445,83 @@ public abstract class JsonBuilder {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String targets(final List<Target> targets, final boolean withToken, final long targetTypeId) throws JSONException {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("[");
|
||||
int i = 0;
|
||||
for (final Target target : targets) {
|
||||
final String address = target.getAddress() != null ? target.getAddress().toString() : null;
|
||||
final String type = target.getTargetType() != null ? target.getTargetType().getId().toString() : null;
|
||||
final String token = withToken ? target.getSecurityToken() : null;
|
||||
|
||||
builder.append(new JSONObject().put("controllerId", target.getControllerId())
|
||||
.put("description", target.getDescription()).put("name", target.getName()).put("createdAt", "0")
|
||||
.put("updatedAt", "0").put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh")
|
||||
.put("address", address).put("securityToken", token).put("targetType", targetTypeId).toString());
|
||||
|
||||
if (++i < targets.size()) {
|
||||
builder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String targetTypes(final List<TargetType> types) throws JSONException {
|
||||
final JSONArray result = new JSONArray();
|
||||
|
||||
for (final TargetType type : types) {
|
||||
|
||||
final JSONArray dsTypes = new JSONArray();
|
||||
type.getCompatibleDistributionSetTypes().forEach(dsType -> {
|
||||
try {
|
||||
dsTypes.put(new JSONObject().put("id", dsType.getId()));
|
||||
} catch (final JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
result.put(new JSONObject().put("name", type.getName()).put("description", type.getDescription())
|
||||
.put("id", Long.MAX_VALUE).put("colour", type.getColour()).put("createdAt", "0").put("updatedAt", "0")
|
||||
.put("createdBy", "fghdfkjghdfkjh").put("updatedBy", "fghdfkjghdfkjh")
|
||||
.put("distributionsets", dsTypes));
|
||||
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String targetTypesCreatableFieldsOnly(final List<TargetType> types) throws JSONException {
|
||||
final JSONArray result = new JSONArray();
|
||||
|
||||
for (final TargetType type : types) {
|
||||
|
||||
final JSONArray dsTypes = new JSONArray();
|
||||
type.getCompatibleDistributionSetTypes().forEach(dsType -> {
|
||||
try {
|
||||
dsTypes.put(new JSONObject().put("id", dsType.getId()));
|
||||
} catch (final JSONException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
JSONObject json = new JSONObject().put("name", type.getName()).put("description", type.getDescription())
|
||||
.put("colour", type.getColour());
|
||||
|
||||
if(dsTypes.length() != 0)
|
||||
{
|
||||
json.put("compatibledistributionsettypes", dsTypes);
|
||||
}
|
||||
|
||||
result.put(json);
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String rollout(final String name, final String description, final int groupSize,
|
||||
final long distributionSetId, final String targetFilterQuery, final RolloutGroupConditions conditions) {
|
||||
return rollout(name, description, groupSize, distributionSetId, targetFilterQuery, conditions, null, null,
|
||||
|
||||
@@ -0,0 +1,396 @@
|
||||
:doctype: book
|
||||
:icons: font
|
||||
:source-highlighter: highlightjs
|
||||
:toc: macro
|
||||
:toclevels: 1
|
||||
:sectlinks:
|
||||
:linkattrs:
|
||||
|
||||
[[target-types]]
|
||||
= Target Types
|
||||
|
||||
toc::[]
|
||||
|
||||
|
||||
== GET /rest/v1/targettypes
|
||||
|
||||
=== Implementation notes
|
||||
|
||||
Handles the GET request of retrieving all target types within Hawkbit. Required Permission: READ_TARGET
|
||||
|
||||
=== Get target types
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/get-target-types/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/get-target-types/http-request.adoc[]
|
||||
|
||||
==== Request query parameter
|
||||
|
||||
include::{snippets}/targettypes/get-target-types-with-parameters/request-parameters.adoc[]
|
||||
|
||||
==== Request parameter example
|
||||
|
||||
include::{snippets}/targettypes/get-target-types-with-parameters/http-request.adoc[]
|
||||
|
||||
=== Response (Status 200)
|
||||
|
||||
==== Response fields
|
||||
|
||||
include::{snippets}/targettypes/get-target-types/response-fields.adoc[]
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/get-target-types/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
|
||||
== POST /rest/v1/targettypes
|
||||
|
||||
=== Implementation notes
|
||||
|
||||
Handles the POST request for creating new target types within Hawkbit. The request body must always be a list of types. Required Permission: CREATE_TARGET
|
||||
|
||||
=== Create target types
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/post-target-types/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/post-target-types/http-request.adoc[]
|
||||
|
||||
==== Request fields
|
||||
|
||||
include::{snippets}/targettypes/post-target-types/request-fields.adoc[]
|
||||
|
||||
=== Response (Status 201)
|
||||
|
||||
==== Response fields
|
||||
|
||||
include::{snippets}/targettypes/post-target-types/response-fields.adoc[]
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/post-target-types/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
| `404 Not Found`
|
||||
| Target type was not found.
|
||||
| See <<error-body>>
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
| `409 Conflict`
|
||||
| Target type already exists
|
||||
| See <<error-body>>
|
||||
include::../errors/415.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
|
||||
== DELETE /rest/v1/targettypes/{targetTypeId}
|
||||
|
||||
=== Implementation Notes
|
||||
|
||||
Handles the DELETE request for a single target type within Hawkbit. Required Permission: DELETE_TARGET
|
||||
|
||||
=== Delete target type
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/delete-target-type/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/delete-target-type/http-request.adoc[]
|
||||
|
||||
==== Request path parameter
|
||||
|
||||
include::{snippets}/targettypes/delete-target-type/path-parameters.adoc[]
|
||||
|
||||
=== Response (Status 200)
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/delete-target-type/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
| `404 Not Found`
|
||||
| Target type was not found.
|
||||
| See <<error-body>>
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
|
||||
== GET /rest/v1/targettypes/{targetTypeId}
|
||||
|
||||
=== Implementation notes
|
||||
|
||||
Handles the GET request of retrieving a single target type within Hawkbit. Required Permission: READ_TARGET
|
||||
|
||||
=== Get target type
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/get-target-type/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/get-target-type/http-request.adoc[]
|
||||
|
||||
==== Request path parameter
|
||||
|
||||
include::{snippets}/targettypes/get-target-type/path-parameters.adoc[]
|
||||
|
||||
=== Response (Status 200)
|
||||
|
||||
==== Response fields
|
||||
|
||||
include::{snippets}/targettypes/get-target-type/response-fields.adoc[]
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/get-target-type/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
| `404 Not Found`
|
||||
| Target type was not found.
|
||||
| See <<error-body>>
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
|
||||
== PUT /rest/v1/targettypes/{targetTypeId}
|
||||
|
||||
=== Implementation notes
|
||||
|
||||
Handles the PUT request for a single target type within Hawkbit. Required Permission: UPDATE_TARGET
|
||||
|
||||
=== Update target type
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/put-target-type/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/put-target-type/http-request.adoc[]
|
||||
|
||||
==== Request path parameter
|
||||
|
||||
include::{snippets}/targettypes/put-target-type/path-parameters.adoc[]
|
||||
|
||||
==== Request fields
|
||||
|
||||
include::{snippets}/targettypes/put-target-type/request-fields.adoc[]
|
||||
|
||||
=== Response (Status 200)
|
||||
|
||||
==== Response fields
|
||||
|
||||
include::{snippets}/targettypes/put-target-type/response-fields.adoc[]
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/put-target-type/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
| `404 Not Found`
|
||||
| Target type was not found.
|
||||
| See <<error-body>>
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
include::../errors/409.adoc[]
|
||||
include::../errors/415.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
|
||||
== GET /rest/v1/targettypes/{targetTypeId}/compatibledistributionsettypes
|
||||
|
||||
=== Implementation notes
|
||||
|
||||
Handles the GET request of retrieving the list of compatible distribution set types in that target type. Required Permission: READ_TARGET, READ_REPOSITORY
|
||||
|
||||
=== Lists all compatible distribution set types
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/get-compatible-distribution-set-types/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/get-compatible-distribution-set-types/http-request.adoc[]
|
||||
|
||||
==== Request path parameter
|
||||
|
||||
include::{snippets}/targettypes/get-compatible-distribution-set-types/path-parameters.adoc[]
|
||||
|
||||
=== Response (Status 200)
|
||||
|
||||
==== Response fields
|
||||
|
||||
include::{snippets}/targettypes/get-compatible-distribution-set-types/response-fields.adoc[]
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/get-compatible-distribution-set-types/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
| `404 Not Found`
|
||||
| Distribution set type was not found.
|
||||
| See <<error-body>>
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
|
||||
== POST /rest/v1/targettypes/{targetTypeId}/compatibledistributionsettypes
|
||||
|
||||
=== Implementation notes
|
||||
|
||||
Handles the POST request for adding compatible distribution set types to a target type. Required Permission: UPDATE_TARGET and READ_REPOSITORY
|
||||
|
||||
=== Add compatible distribution set type
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/post-compatible-distribution-set-types/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/post-compatible-distribution-set-types/http-request.adoc[]
|
||||
|
||||
==== Request path parameter
|
||||
|
||||
include::{snippets}/targettypes/post-compatible-distribution-set-types/path-parameters.adoc[]
|
||||
|
||||
==== Request fields
|
||||
|
||||
include::{snippets}/targettypes/post-compatible-distribution-set-types/request-fields.adoc[]
|
||||
|
||||
=== Response (Status 201)
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/post-compatible-distribution-set-types/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
| `404 Not Found`
|
||||
| Distribution set type was not found.
|
||||
| See <<error-body>>
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
| `409 Conflict`
|
||||
| Distribution set type already exists
|
||||
| See <<error-body>>
|
||||
include::../errors/415.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
|
||||
== DELETE /rest/v1/targettypes/{targetTypeId}/compatibledistributionsettypes/{distributionSetTypeId}
|
||||
|
||||
=== Implementation Notes
|
||||
|
||||
Handles the DELETE request for removing a distribution set type from a single target type. Required Permission: UPDATE_TARGET and READ_REPOSITORY
|
||||
|
||||
=== Remove compatible distribution set type from target type
|
||||
|
||||
==== CURL
|
||||
|
||||
include::{snippets}/targettypes/delete-compatible-distribution-set-type/curl-request.adoc[]
|
||||
|
||||
==== Request URL
|
||||
|
||||
include::{snippets}/targettypes/delete-compatible-distribution-set-type/http-request.adoc[]
|
||||
|
||||
==== Request path parameter
|
||||
|
||||
include::{snippets}/targettypes/delete-compatible-distribution-set-type/path-parameters.adoc[]
|
||||
|
||||
=== Response (Status 200)
|
||||
|
||||
==== Response example
|
||||
|
||||
include::{snippets}/targettypes/delete-compatible-distribution-set-type/http-response.adoc[]
|
||||
|
||||
=== Error responses
|
||||
|
||||
|===
|
||||
| HTTP Status Code | Reason | Response Model
|
||||
|
||||
include::../errors/400.adoc[]
|
||||
include::../errors/401.adoc[]
|
||||
include::../errors/403.adoc[]
|
||||
| `404 Not Found`
|
||||
| Distribution set type was not found.
|
||||
| See <<error-body>>
|
||||
include::../errors/405.adoc[]
|
||||
include::../errors/406.adoc[]
|
||||
include::../errors/429.adoc[]
|
||||
|===
|
||||
|
||||
@@ -19,12 +19,12 @@ public final class ApiModelPropertiesGeneric {
|
||||
public static final String ITEM_ID = "The technical identifier " + ENDING;
|
||||
public static final String NAME = "The name" + ENDING;
|
||||
public static final String DESCRPTION = "The description" + ENDING;
|
||||
public static final String COLOUR = "The colour" + ENDING;
|
||||
public static final String COLOUR = "The colour" + ENDING + ". In HEX format, e.g. #800080";
|
||||
public static final String DELETED = "Deleted flag, used for soft deleted entities";
|
||||
|
||||
public static final String CREATED_BY = "Entity was originally created by User, AMQP-Controller, anonymous etc.)";
|
||||
public static final String CREATED_BY = "Entity was originally created by (User, AMQP-Controller, anonymous etc.)";
|
||||
public static final String CREATED_AT = "Entity was originally created at (timestamp UTC in milliseconds)";
|
||||
public static final String LAST_MODIFIED_BY = "Entity was last modified by User, AMQP-Controller, anonymous etc.)";
|
||||
public static final String LAST_MODIFIED_BY = "Entity was last modified by (User, AMQP-Controller, anonymous etc.)";
|
||||
public static final String LAST_MODIFIED_AT = "Entity was last modified at (timestamp UTC in milliseconds)";
|
||||
|
||||
// Paging elements
|
||||
|
||||
@@ -78,6 +78,10 @@ public final class MgmtApiModelProperties {
|
||||
public static final String POLL_STATUS = "Poll status of the target. In many scenarios that target will poll the update server on a regular basis to look for potential updates. If that poll does not happen it might imply that the target is offline.";
|
||||
public static final String POLL_OVERDUE = "Defines if the target poll time is overdue based on the next expected poll time plus the configured overdue poll time threshold.";
|
||||
|
||||
// Target type
|
||||
public static final String COMPATIBLE_DS_TYPES = "Array of distribution set types that are compatible to that target type";
|
||||
public static final String LINK_COMPATIBLE_DS_TYPES = "Link to the compatible distribution set types in this target type";
|
||||
|
||||
// rollout
|
||||
public static final String ROLLOUT_FILTER_QUERY = "target filter query language expression";
|
||||
public static final String ROLLOUT_GROUP_FILTER_QUERY = "target filter query language expression that selects a subset of targets which match the target filter of the Rollout";
|
||||
@@ -118,6 +122,8 @@ public final class MgmtApiModelProperties {
|
||||
|
||||
public static final String TARGET_LIST = "List of provisioning targets.";
|
||||
|
||||
public static final String TARGET_TYPE_LIST = "List of target types";
|
||||
|
||||
public static final String SM_LIST = "List of software modules.";
|
||||
|
||||
public static final String ROLLOUT_LIST = "list of rollouts";
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO 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.rest.mgmt.documentation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetType;
|
||||
import org.eclipse.hawkbit.repository.model.TargetType;
|
||||
import org.eclipse.hawkbit.rest.documentation.AbstractApiRestDocumentation;
|
||||
import org.eclipse.hawkbit.rest.documentation.ApiModelPropertiesGeneric;
|
||||
import org.eclipse.hawkbit.rest.documentation.MgmtApiModelProperties;
|
||||
import org.eclipse.hawkbit.rest.util.JsonBuilder;
|
||||
import org.eclipse.hawkbit.rest.util.MockMvcResultPrinter;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.payload.JsonFieldType;
|
||||
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
|
||||
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* Documentation generation for Management API for {@link TargetType}.
|
||||
*
|
||||
*/
|
||||
@Feature("Spring Rest Docs Tests - TargetType")
|
||||
@Story("TargetTypes Resource")
|
||||
public class TargetTypesDocumentationTest extends AbstractApiRestDocumentation {
|
||||
@Override
|
||||
public String getResourceName() {
|
||||
return "targettypes";
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving all target types within Hawkbit. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
public void getTargetTypes() throws Exception {
|
||||
testdataFactory.findOrCreateTargetType("targetType1");
|
||||
testdataFactory.createTargetType("targetType2", Collections.singletonList(standardDsType));
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(responseFields(
|
||||
fieldWithPath("size").type(JsonFieldType.NUMBER).description(ApiModelPropertiesGeneric.SIZE),
|
||||
fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS),
|
||||
fieldWithPath("content").description(MgmtApiModelProperties.TARGET_TYPE_LIST),
|
||||
fieldWithPath("content[].id").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
fieldWithPath("content[].name").description(ApiModelPropertiesGeneric.NAME),
|
||||
fieldWithPath("content[].description").description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
fieldWithPath("content[].colour").description(ApiModelPropertiesGeneric.COLOUR),
|
||||
fieldWithPath("content[].createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
|
||||
fieldWithPath("content[].createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
|
||||
fieldWithPath("content[].lastModifiedAt")
|
||||
.description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT).type("Number"),
|
||||
fieldWithPath("content[].lastModifiedBy")
|
||||
.description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY).type("String"),
|
||||
fieldWithPath("content[]._links.self").ignored())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving all target types within Hawkbit with a defined page size and "
|
||||
+ "offset, sorted by name in descending order and filtered down to all targets which name starts with 'targetType'. "
|
||||
+ "Required Permission: " + SpPermission.READ_TARGET)
|
||||
public void getTargetTypesWithParameters() throws Exception {
|
||||
testdataFactory.findOrCreateTargetType("targetType1");
|
||||
testdataFactory.createTargetType("targetType2", Collections.singletonList(standardDsType));
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING).accept(MediaType.APPLICATION_JSON)
|
||||
.param("offset", "0").param("limit", "2").param("sort", "name:ASC").param("q", "name==targetType*"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(this.document.document(getFilterRequestParamter()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request for a single target type within Hawkbit. Required Permission: "
|
||||
+ SpPermission.READ_TARGET)
|
||||
public void getTargetType() throws Exception {
|
||||
TargetType testType = testdataFactory.createTargetType("TargetType", Collections.singletonList(standardDsType));
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING + "/{targetTypeId}", testType.getId())
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("targetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(fieldWithPath("id").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
fieldWithPath("name").description(ApiModelPropertiesGeneric.NAME),
|
||||
fieldWithPath("description").description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
fieldWithPath("colour").description(ApiModelPropertiesGeneric.COLOUR),
|
||||
fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
|
||||
fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
|
||||
fieldWithPath("lastModifiedAt").description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT)
|
||||
.type("Number"),
|
||||
fieldWithPath("lastModifiedBy").description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY)
|
||||
.type("String"),
|
||||
fieldWithPath("_links.compatibledistributionsettypes.href")
|
||||
.description(MgmtApiModelProperties.LINK_COMPATIBLE_DS_TYPES),
|
||||
fieldWithPath("_links.self").ignored())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the POST request for creating new target types within Hawkbit. The request body "
|
||||
+ "must always be a list of types. Required Permission: " + SpPermission.CREATE_TARGET)
|
||||
public void postTargetTypes() throws Exception {
|
||||
final List<TargetType> types = new ArrayList<>();
|
||||
types.add(entityFactory.targetType().create().name("targetType1").description("targetType1 description")
|
||||
.colour("#ffffff").build());
|
||||
types.add(entityFactory.targetType().create().name("targetType2").description("targetType2 description")
|
||||
.colour("#000000").compatible(Collections.singletonList(standardDsType.getId())).build());
|
||||
|
||||
mockMvc.perform(post(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING)
|
||||
.content(JsonBuilder.targetTypesCreatableFieldsOnly(types)).contentType(MediaType.APPLICATION_JSON)
|
||||
.accept(MediaType.APPLICATION_JSON)).andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andDo(this.document.document(
|
||||
requestFields(requestFieldWithPath("[]name").description(ApiModelPropertiesGeneric.NAME),
|
||||
optionalRequestFieldWithPath("[]description")
|
||||
.description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
optionalRequestFieldWithPath("[]colour").description(ApiModelPropertiesGeneric.COLOUR),
|
||||
optionalRequestFieldWithPath("[]compatibledistributionsettypes")
|
||||
.description(MgmtApiModelProperties.COMPATIBLE_DS_TYPES)),
|
||||
responseFields(fieldWithPath("[]id").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
fieldWithPath("[]name").description(ApiModelPropertiesGeneric.NAME),
|
||||
fieldWithPath("[]description").description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
fieldWithPath("[]colour").description(ApiModelPropertiesGeneric.COLOUR),
|
||||
fieldWithPath("[]createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
|
||||
fieldWithPath("[]createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
|
||||
fieldWithPath("[]lastModifiedAt")
|
||||
.description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT).type("Number"),
|
||||
fieldWithPath("[]lastModifiedBy")
|
||||
.description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY).type("String"),
|
||||
fieldWithPath("[]_links.self").ignored())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the DELETE request of retrieving a single target type within Hawkbit. Required Permission: "
|
||||
+ SpPermission.DELETE_TARGET)
|
||||
public void deleteTargetType() throws Exception {
|
||||
TargetType testType = testdataFactory.createTargetType("TargetType", Collections.singletonList(standardDsType));
|
||||
|
||||
mockMvc.perform(delete(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING + "/{targetTypeId}", testType.getId()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(pathParameters(
|
||||
parameterWithName("targetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the PUT request for a single target type within Hawkbit. " + "Required Permission: "
|
||||
+ SpPermission.UPDATE_TARGET)
|
||||
public void putTargetType() throws Exception {
|
||||
TargetType testType = testdataFactory.createTargetType("targetType", Collections.singletonList(standardDsType));
|
||||
final String body = new JSONObject().put("description", "an updated description").put("name", "updatedTypeName")
|
||||
.put("colour", "#aaafff").toString();
|
||||
|
||||
this.mockMvc
|
||||
.perform(put(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING + "/{targetTypeId}", testType.getId())
|
||||
.content(body).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("targetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
requestFields(
|
||||
optionalRequestFieldWithPath("description")
|
||||
.description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
optionalRequestFieldWithPath("name").description(ApiModelPropertiesGeneric.NAME),
|
||||
optionalRequestFieldWithPath("colour").description(ApiModelPropertiesGeneric.COLOUR)),
|
||||
responseFields(fieldWithPath("id").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
fieldWithPath("name").description(ApiModelPropertiesGeneric.NAME),
|
||||
fieldWithPath("description").description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
fieldWithPath("colour").description(ApiModelPropertiesGeneric.COLOUR),
|
||||
fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
|
||||
fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
|
||||
fieldWithPath("lastModifiedAt").description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT)
|
||||
.type("Number"),
|
||||
fieldWithPath("lastModifiedBy").description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY)
|
||||
.type("String"),
|
||||
fieldWithPath("_links.compatibledistributionsettypes.href")
|
||||
.description(MgmtApiModelProperties.LINK_COMPATIBLE_DS_TYPES),
|
||||
fieldWithPath("_links.self").ignored())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving the list of compatible distribution set types in that target type. "
|
||||
+ "Required Permission: " + SpPermission.READ_TARGET + " and " + SpPermission.READ_REPOSITORY)
|
||||
public void getCompatibleDistributionSetTypes() throws Exception {
|
||||
TargetType testType = testdataFactory.createTargetType("targetType", Collections.singletonList(standardDsType));
|
||||
|
||||
mockMvc.perform(
|
||||
get(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING + "/{targetTypeId}/compatibledistributionsettypes",
|
||||
testType.getId()).accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("targetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(fieldWithPath("[]id").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
fieldWithPath("[]key").description(MgmtApiModelProperties.DS_TYPE_KEY),
|
||||
fieldWithPath("[]name").description(ApiModelPropertiesGeneric.NAME),
|
||||
fieldWithPath("[]description").description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
fieldWithPath("[]createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
|
||||
fieldWithPath("[]createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
|
||||
fieldWithPath("[]lastModifiedAt")
|
||||
.description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT).type("Number"),
|
||||
fieldWithPath("[]lastModifiedBy")
|
||||
.description(ApiModelPropertiesGeneric.LAST_MODIFIED_BY).type("String"),
|
||||
fieldWithPath("[]deleted").description(ApiModelPropertiesGeneric.DELETED),
|
||||
fieldWithPath("[]_links.self").ignored())));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the POST request for adding a compatible distribution set type to a target type."
|
||||
+ " Required Permission: " + SpPermission.UPDATE_TARGET + " and " + SpPermission.READ_REPOSITORY)
|
||||
public void postCompatibleDistributionSetTypes() throws Exception {
|
||||
final DistributionSetType dsType1 = distributionSetTypeManagement.create(
|
||||
entityFactory.distributionSetType().create().key("test1").name("TestName1").description("Desc1"));
|
||||
final DistributionSetType dsType2 = distributionSetTypeManagement.create(
|
||||
entityFactory.distributionSetType().create().key("test2").name("TestName2").description("Desc2"));
|
||||
final TargetType targetType = testdataFactory.createTargetType("targetType",
|
||||
Collections.singletonList(standardDsType));
|
||||
|
||||
mockMvc.perform(
|
||||
post(MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING + "/{targetTypeId}/compatibledistributionsettypes",
|
||||
targetType.getId())
|
||||
.content("[{\"id\":" + dsType1.getId() + "},{\"id\":" + dsType2.getId() + "}]")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("targetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
requestFields(requestFieldWithPath("[]id").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the DELETE request to unassign the list of compatible distribution set types in that target type. "
|
||||
+ SpPermission.UPDATE_TARGET + " and " + SpPermission.READ_REPOSITORY)
|
||||
public void deleteCompatibleDistributionSetType() throws Exception {
|
||||
final DistributionSetType dsType = distributionSetTypeManagement.create(
|
||||
entityFactory.distributionSetType().create().key("test1").name("TestName1").description("Desc1"));
|
||||
final TargetType targetType = testdataFactory.createTargetType("targetType", Collections.singletonList(dsType));
|
||||
|
||||
mockMvc.perform(delete(
|
||||
MgmtRestConstants.TARGETTYPE_V1_REQUEST_MAPPING
|
||||
+ "/{targetTypeId}/compatibledistributionsettypes/{distributionSetTypeId}",
|
||||
targetType.getId(), dsType.getId()).contentType(MediaType.APPLICATION_JSON))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(pathParameters(
|
||||
parameterWithName("targetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("distributionSetTypeId").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user