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,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