Feature target metadata (#757)
* Defined the model for target matadata and the corresponding repository layer/management * Added target metadata quotas incl enforcement * Extended Target Mgmt REST API to allow for metadata CRUD operations * Added migration scripts for each database * Added back reference to target metadata in JpaTarget * Added tests for target management, Mgmt REST API, target metadata RSQL, and REST documentation * Updated asciidocs for target rest documentation * Fix Allure imports and annotations * Fix review findings Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> Signed-off-by: Stefan Behl <stefan.behl@bosch-si.com>
This commit is contained in:
committed by
Stefan Behl
parent
1cbde47370
commit
0cf4f8e8b9
@@ -248,7 +248,9 @@ public abstract class AbstractApiRestDocumentation extends AbstractRestIntegrati
|
||||
fieldWithPath(fieldArrayPrefix + "_links.attributes")
|
||||
.description(MgmtApiModelProperties.LINKS_ATTRIBUTES),
|
||||
fieldWithPath(fieldArrayPrefix + "_links.actions")
|
||||
.description(MgmtApiModelProperties.LINKS_ACTIONS)));
|
||||
.description(MgmtApiModelProperties.LINKS_ACTIONS),
|
||||
fieldWithPath(fieldArrayPrefix + "_links.metadata").description(MgmtApiModelProperties.META_DATA)));
|
||||
|
||||
}
|
||||
fields.addAll(Arrays.asList(descriptors));
|
||||
|
||||
|
||||
@@ -504,7 +504,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
distributionSetManagement.createMetaData(testDS.getId(), Lists
|
||||
.newArrayList(entityFactory.generateMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
|
||||
.newArrayList(entityFactory.generateDsMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
|
||||
}
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata",
|
||||
@@ -532,7 +532,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
distributionSetManagement.createMetaData(testDS.getId(), Lists
|
||||
.newArrayList(entityFactory.generateMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
|
||||
.newArrayList(entityFactory.generateDsMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
|
||||
}
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{dsId}/metadata", testDS.getId())
|
||||
@@ -564,7 +564,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
|
||||
final String knownValue = "knownValue";
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
distributionSetManagement.createMetaData(testDS.getId(),
|
||||
Arrays.asList(entityFactory.generateMetadata(knownKey, knownValue)));
|
||||
Arrays.asList(entityFactory.generateDsMetadata(knownKey, knownValue)));
|
||||
|
||||
mockMvc.perform(get(
|
||||
MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata/{metadatakey}",
|
||||
@@ -588,7 +588,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
|
||||
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
distributionSetManagement.createMetaData(testDS.getId(),
|
||||
Arrays.asList(entityFactory.generateMetadata(knownKey, knownValue)));
|
||||
Arrays.asList(entityFactory.generateDsMetadata(knownKey, knownValue)));
|
||||
|
||||
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
|
||||
|
||||
@@ -616,7 +616,7 @@ public class DistributionSetsDocumentationTest extends AbstractApiRestDocumentat
|
||||
|
||||
final DistributionSet testDS = testdataFactory.createDistributionSet("one");
|
||||
distributionSetManagement.createMetaData(testDS.getId(),
|
||||
Arrays.asList(entityFactory.generateMetadata(knownKey, knownValue)));
|
||||
Arrays.asList(entityFactory.generateDsMetadata(knownKey, knownValue)));
|
||||
|
||||
mockMvc.perform(
|
||||
delete(MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING + "/{distributionSetId}/metadata/{key}",
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.paramete
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
|
||||
import static org.springframework.restdocs.snippet.Attributes.key;
|
||||
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;
|
||||
|
||||
@@ -28,6 +29,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.im.authentication.SpPermission;
|
||||
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
|
||||
import org.eclipse.hawkbit.repository.ActionStatusFields;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
@@ -38,6 +40,7 @@ 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.MockMvcResultPrinter;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -47,6 +50,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.payload.JsonFieldType;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
@@ -60,7 +64,7 @@ import io.qameta.allure.Story;
|
||||
@Story("Target Resource")
|
||||
public class TargetResourceDocumentationTest extends AbstractApiRestDocumentation {
|
||||
|
||||
private final String controllerId = "137";
|
||||
private final String targetId = "137";
|
||||
|
||||
@Override
|
||||
@Before
|
||||
@@ -72,7 +76,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving all targets within SP. Required Permission: READ_TARGET.")
|
||||
public void getTargets() throws Exception {
|
||||
createTargetByGivenNameWithAttributes(controllerId, createDistributionSet());
|
||||
createTargetByGivenNameWithAttributes(targetId, createDistributionSet());
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)).andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
@@ -90,7 +94,8 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
.type("enum").attributes(
|
||||
key("value").value("['error', 'in_sync', 'pending', 'registered', 'unknown']")),
|
||||
fieldWithPath("content[].securityToken").description(MgmtApiModelProperties.SECURITY_TOKEN),
|
||||
fieldWithPath("content[].requestAttributes").description(MgmtApiModelProperties.REQUEST_ATTRIBUTES),
|
||||
fieldWithPath("content[].requestAttributes")
|
||||
.description(MgmtApiModelProperties.REQUEST_ATTRIBUTES),
|
||||
fieldWithPath("content[].installedAt").description(MgmtApiModelProperties.INSTALLED_AT),
|
||||
fieldWithPath("content[].lastModifiedAt")
|
||||
.description(ApiModelPropertiesGeneric.LAST_MODIFIED_AT).type("Number"),
|
||||
@@ -142,67 +147,71 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
.attributes(key("value")
|
||||
.value("['error', 'in_sync', 'pending', 'registered', 'unknown']")),
|
||||
fieldWithPath("[]securityToken").description(MgmtApiModelProperties.SECURITY_TOKEN),
|
||||
fieldWithPath("[]requestAttributes").description(MgmtApiModelProperties.REQUEST_ATTRIBUTES),
|
||||
fieldWithPath("[]requestAttributes")
|
||||
.description(MgmtApiModelProperties.REQUEST_ATTRIBUTES),
|
||||
fieldWithPath("[]_links.self").ignored())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the DELETE request of deleting a single target within SP. Required Permission: DELETE_TARGET.")
|
||||
public void deleteTarget() throws Exception {
|
||||
final Target target = testdataFactory.createTarget(controllerId);
|
||||
final Target target = testdataFactory.createTarget(targetId);
|
||||
|
||||
mockMvc.perform(
|
||||
delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}", target.getControllerId()))
|
||||
delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", target.getControllerId()))
|
||||
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print()).andDo(this.document.document(
|
||||
pathParameters(parameterWithName("controllerId").description(ApiModelPropertiesGeneric.NAME))));
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving a single target within SP. Required Permission: READ_TARGET.")
|
||||
public void getTarget() throws Exception {
|
||||
final Target target = createTargetByGivenNameWithAttributes(controllerId, createDistributionSet());
|
||||
final Target target = createTargetByGivenNameWithAttributes(targetId, createDistributionSet());
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}", target.getControllerId()))
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", target.getControllerId()))
|
||||
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
getResponseFieldTarget(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the PUT request of updating a target within SP. Required Permission: UPDATE_TARGET.")
|
||||
public void putTarget() throws Exception {
|
||||
final Target target = createTargetByGivenNameWithAttributes(controllerId, createDistributionSet());
|
||||
final String targetAsJson = createJsonTarget(controllerId, "newTargetName", "I've been updated");
|
||||
final Target target = createTargetByGivenNameWithAttributes(targetId, createDistributionSet());
|
||||
final String targetAsJson = createJsonTarget(targetId, "newTargetName", "I've been updated");
|
||||
|
||||
mockMvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}", target.getControllerId())
|
||||
mockMvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}", target.getControllerId())
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8).content(targetAsJson)).andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
requestFields(optionalRequestFieldWithPath("name").description(ApiModelPropertiesGeneric.NAME),
|
||||
optionalRequestFieldWithPath("description").description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
optionalRequestFieldWithPath("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
optionalRequestFieldWithPath("description")
|
||||
.description(ApiModelPropertiesGeneric.DESCRPTION),
|
||||
optionalRequestFieldWithPath("controllerId")
|
||||
.description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
optionalRequestFieldWithPath("address").description(MgmtApiModelProperties.ADDRESS),
|
||||
optionalRequestFieldWithPath("securityToken")
|
||||
.description(MgmtApiModelProperties.SECURITY_TOKEN),
|
||||
optionalRequestFieldWithPath("requestAttributes").description(MgmtApiModelProperties.REQUEST_ATTRIBUTES)),
|
||||
optionalRequestFieldWithPath("requestAttributes")
|
||||
.description(MgmtApiModelProperties.REQUEST_ATTRIBUTES)),
|
||||
getResponseFieldTarget(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving the full action history of a specific target. Required Permission: READ_TARGET.")
|
||||
public void getActionsFromTarget() throws Exception {
|
||||
generateActionForTarget(controllerId);
|
||||
generateActionForTarget(targetId);
|
||||
|
||||
mockMvc.perform(get(
|
||||
MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
|
||||
controllerId)).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
|
||||
targetId)).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(
|
||||
fieldWithPath("size").type(JsonFieldType.NUMBER)
|
||||
.description(ApiModelPropertiesGeneric.SIZE),
|
||||
@@ -227,14 +236,14 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving the full action history of a specific target with maintenance window. Required Permission: READ_TARGET.")
|
||||
public void getActionsFromTargetWithMaintenanceWindow() throws Exception {
|
||||
generateActionForTarget(controllerId, true, false, getTestSchedule(2), getTestDuration(1), getTestTimeZone());
|
||||
generateActionForTarget(targetId, true, false, getTestSchedule(2), getTestDuration(1), getTestTimeZone());
|
||||
|
||||
mockMvc.perform(get(
|
||||
MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
|
||||
controllerId)).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/" + MgmtRestConstants.TARGET_V1_ACTIONS,
|
||||
targetId)).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(
|
||||
fieldWithPath("size").type(JsonFieldType.NUMBER)
|
||||
.description(ApiModelPropertiesGeneric.SIZE),
|
||||
@@ -269,9 +278,9 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving all targets within SP based by parameter. Required Permission: READ_TARGET.")
|
||||
public void getActionsFromTargetWithParameters() throws Exception {
|
||||
generateActionForTarget(controllerId);
|
||||
generateActionForTarget(targetId);
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + controllerId + "/"
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId + "/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "?limit=10&sort=id:ASC&offset=0&q=status==pending"))
|
||||
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(requestParameters(
|
||||
@@ -285,22 +294,22 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Cancels an active action, only active actions can be deleted. Required Permission: UPDATE_TARGET.")
|
||||
public void deleteActionFromTarget() throws Exception {
|
||||
final Action actions = generateActionForTarget(controllerId, false);
|
||||
final Action actions = generateActionForTarget(targetId, false);
|
||||
|
||||
mockMvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", controllerId, actions.getId()))
|
||||
mockMvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", targetId, actions.getId()))
|
||||
.andExpect(status().isNoContent()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving all targets within SP based by parameter. Required Permission: READ_TARGET.")
|
||||
public void deleteActionsFromTargetWithParameters() throws Exception {
|
||||
generateActionForTarget(controllerId);
|
||||
generateActionForTarget(targetId);
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + controllerId + "/"
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId + "/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "?force=true")).andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print()).andDo(this.document.document(
|
||||
requestParameters(parameterWithName("force").description(MgmtApiModelProperties.FORCE))));
|
||||
@@ -309,15 +318,15 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving a specific action on a specific target. Required Permission: READ_TARGET.")
|
||||
public void getActionFromTarget() throws Exception {
|
||||
final Action action = generateActionForTarget(controllerId, true, true);
|
||||
final Action action = generateActionForTarget(targetId, true, true);
|
||||
assertThat(deploymentManagement.findAction(action.getId()).get().getActionType())
|
||||
.isEqualTo(ActionType.TIMEFORCED);
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", controllerId, action.getId()))
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", targetId, action.getId()))
|
||||
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
|
||||
fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
|
||||
@@ -343,14 +352,14 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving a specific action on a specific target. Required Permission: READ_TARGET.")
|
||||
public void getActionFromTargetWithMaintenanceWindow() throws Exception {
|
||||
final Action action = generateActionForTarget(controllerId, true, true, getTestSchedule(2), getTestDuration(1),
|
||||
final Action action = generateActionForTarget(targetId, true, true, getTestSchedule(2), getTestDuration(1),
|
||||
getTestTimeZone());
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", controllerId, action.getId()))
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", targetId, action.getId()))
|
||||
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(fieldWithPath("createdBy").description(ApiModelPropertiesGeneric.CREATED_BY),
|
||||
fieldWithPath("createdAt").description(ApiModelPropertiesGeneric.CREATED_AT),
|
||||
@@ -386,7 +395,7 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the PUT request to switch an action from soft to forced. Required Permission: UPDATE_TARGET.")
|
||||
public void switchActionToForced() throws Exception {
|
||||
final Target target = testdataFactory.createTarget(controllerId);
|
||||
final Target target = testdataFactory.createTarget(targetId);
|
||||
final DistributionSet set = testdataFactory.createDistributionSet();
|
||||
final Long actionId = deploymentManagement
|
||||
.assignDistributionSet(set.getId(), ActionType.SOFT, 0, Arrays.asList(target.getControllerId()))
|
||||
@@ -396,13 +405,13 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
final Map<String, Object> body = new HashMap<>();
|
||||
body.put("forceType", "forced");
|
||||
|
||||
mockMvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", controllerId, actionId)
|
||||
mockMvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}", targetId, actionId)
|
||||
.content(this.objectMapper.writeValueAsString(body))
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
requestFields(
|
||||
requestFieldWithPath("forceType").description(MgmtApiModelProperties.ACTION_FORCED)),
|
||||
@@ -428,13 +437,13 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving a specific action on a specific target. Required Permission: READ_TARGET.")
|
||||
public void getStatusFromAction() throws Exception {
|
||||
final Action action = generateActionForTarget(controllerId);
|
||||
final Action action = generateActionForTarget(targetId);
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/{actionId}/" + MgmtRestConstants.TARGET_V1_ACTION_STATUS,
|
||||
controllerId, action.getId())).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
targetId, action.getId())).andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("actionId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(
|
||||
fieldWithPath("size").type(JsonFieldType.NUMBER)
|
||||
@@ -454,9 +463,9 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving all targets within SP based by parameter. Required Permission: READ_TARGET.")
|
||||
public void getStatusFromActionWithParameters() throws Exception {
|
||||
final Action action = generateActionForTarget(controllerId);
|
||||
final Action action = generateActionForTarget(targetId);
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + controllerId + "/"
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + targetId + "/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTIONS + "/" + action.getId() + "/"
|
||||
+ MgmtRestConstants.TARGET_V1_ACTION_STATUS + "?limit=10&sort=id:ASC&offset=0"))
|
||||
.andExpect(status().isOk()).andDo(MockMvcResultPrinter.print())
|
||||
@@ -469,21 +478,21 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving the assigned distribution set of an specific target. Required Permission: READ_TARGET.")
|
||||
public void getAssignedDistributionSetFromAction() throws Exception {
|
||||
generateActionForTarget(controllerId);
|
||||
generateActionForTarget(targetId);
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET, controllerId)).andExpect(status().isOk())
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET, targetId)).andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
getResponseFieldsDistributionSet(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the POST request for assigning a distribution set to a specific target. Required Permission: READ_REPOSITORY and UPDATE_TARGET.")
|
||||
public void postAssignDistributionSetToTarget() throws Exception {
|
||||
testdataFactory.createTarget(controllerId);
|
||||
testdataFactory.createTarget(targetId);
|
||||
final DistributionSet set = testdataFactory.createDistributionSet("one");
|
||||
|
||||
final long forceTime = System.currentTimeMillis();
|
||||
@@ -492,13 +501,13 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
getMaintenanceWindow(getTestSchedule(10), getTestDuration(10), getTestTimeZone()))
|
||||
.toString();
|
||||
|
||||
mockMvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET, controllerId).content(body)
|
||||
mockMvc.perform(post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_ASSIGNED_DISTRIBUTION_SET, targetId).content(body)
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
requestParameters(parameterWithName("offline")
|
||||
.description(MgmtApiModelProperties.OFFLINE_UPDATE).optional()),
|
||||
requestFields(requestFieldWithPath("forcetime").description(MgmtApiModelProperties.FORCETIME),
|
||||
@@ -528,32 +537,193 @@ public class TargetResourceDocumentationTest extends AbstractApiRestDocumentatio
|
||||
final Map<String, String> knownControllerAttrs = new HashMap<>();
|
||||
knownControllerAttrs.put("a", "1");
|
||||
knownControllerAttrs.put("b", "2");
|
||||
final Target target = testdataFactory.createTarget(controllerId);
|
||||
controllerManagement.updateControllerAttributes(controllerId, knownControllerAttrs, null);
|
||||
final Target target = testdataFactory.createTarget(targetId);
|
||||
controllerManagement.updateControllerAttributes(targetId, knownControllerAttrs, null);
|
||||
|
||||
// test query target over rest resource
|
||||
mockMvc.perform(
|
||||
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/attributes", target.getName()))
|
||||
get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/attributes", target.getName()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().is2xxSuccessful())
|
||||
.andExpect(jsonPath("$.a", equalTo("1"))).andExpect(jsonPath("$.b", equalTo("2")))
|
||||
.andDo(this.document.document(pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Handles the GET request of retrieving the installed distribution set of an specific target. Required Permission: READ_TARGET.")
|
||||
public void getInstalledDistributionSetFromTarget() throws Exception {
|
||||
final Target target = createTargetByGivenNameWithAttributes(controllerId, createDistributionSet());
|
||||
final Target target = createTargetByGivenNameWithAttributes(targetId, createDistributionSet());
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{controllerId}/"
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/"
|
||||
+ MgmtRestConstants.TARGET_V1_INSTALLED_DISTRIBUTION_SET, target.getName())).andExpect(status().isOk())
|
||||
.andDo(MockMvcResultPrinter.print())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("controllerId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
getResponseFieldsDistributionSet(false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Get a paged list of meta data for a target with standard page size." + " Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public void getMetadata() throws Exception {
|
||||
final int totalMetadata = 4;
|
||||
final String knownKeyPrefix = "knownKey";
|
||||
final String knownValuePrefix = "knownValue";
|
||||
final Target testTarget = testdataFactory.createTarget(targetId);
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
targetManagement.createMetaData(testTarget.getControllerId(), Lists.newArrayList(
|
||||
entityFactory.generateTargetMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
|
||||
}
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata",
|
||||
testTarget.getControllerId())).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS),
|
||||
fieldWithPath("size").type(JsonFieldType.NUMBER)
|
||||
.description(ApiModelPropertiesGeneric.SIZE),
|
||||
fieldWithPath("content").description(MgmtApiModelProperties.META_DATA),
|
||||
fieldWithPath("content[].key").description(MgmtApiModelProperties.META_DATA_KEY),
|
||||
fieldWithPath("content[].value").description(MgmtApiModelProperties.META_DATA_VALUE))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Get a paged list of meta data for a target with defined page size and sorting by name descending and key starting with 'known'."
|
||||
+ " Required Permission: " + SpPermission.READ_REPOSITORY)
|
||||
public void getMetadataWithParameters() throws Exception {
|
||||
final int totalMetadata = 4;
|
||||
|
||||
final String knownKeyPrefix = "knownKey";
|
||||
final String knownValuePrefix = "knownValue";
|
||||
final Target testTarget = testdataFactory.createTarget(targetId);
|
||||
for (int index = 0; index < totalMetadata; index++) {
|
||||
targetManagement.createMetaData(testTarget.getControllerId(), Lists.newArrayList(
|
||||
entityFactory.generateTargetMetadata(knownKeyPrefix + index, knownValuePrefix + index)));
|
||||
}
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata",
|
||||
testTarget.getControllerId()).param("offset", "1").param("limit", "2").param("sort", "key:DESC")
|
||||
.param("q", "key==known*"))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
|
||||
.andDo(this.document.document(
|
||||
requestParameters(
|
||||
parameterWithName("limit").attributes(key("type").value("query"))
|
||||
.description(ApiModelPropertiesGeneric.LIMIT),
|
||||
parameterWithName("sort").description(ApiModelPropertiesGeneric.SORT),
|
||||
parameterWithName("offset").description(ApiModelPropertiesGeneric.OFFSET),
|
||||
parameterWithName("q").description(ApiModelPropertiesGeneric.FIQL)),
|
||||
responseFields(fieldWithPath("total").description(ApiModelPropertiesGeneric.TOTAL_ELEMENTS),
|
||||
fieldWithPath("size").type(JsonFieldType.NUMBER)
|
||||
.description(ApiModelPropertiesGeneric.SIZE),
|
||||
fieldWithPath("content").description(MgmtApiModelProperties.META_DATA),
|
||||
fieldWithPath("content[].key").description(MgmtApiModelProperties.META_DATA_KEY),
|
||||
fieldWithPath("content[].value").description(MgmtApiModelProperties.META_DATA_VALUE))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Get a single meta data value for a meta data key." + " Required Permission: "
|
||||
+ SpPermission.READ_REPOSITORY)
|
||||
public void getMetadataValue() throws Exception {
|
||||
|
||||
// prepare and create metadata
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
final Target testTarget = testdataFactory.createTarget(targetId);
|
||||
targetManagement.createMetaData(testTarget.getControllerId(),
|
||||
Arrays.asList(entityFactory.generateTargetMetadata(knownKey, knownValue)));
|
||||
|
||||
mockMvc.perform(get(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata/{metadatakey}",
|
||||
testTarget.getControllerId(), knownKey)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("metadatakey").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY),
|
||||
fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Update a single meta data value for specific key." + " Required Permission: "
|
||||
+ SpPermission.UPDATE_REPOSITORY)
|
||||
public void updateMetadata() throws Exception {
|
||||
// prepare and create metadata for update
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
final String updateValue = "valueForUpdate";
|
||||
|
||||
final Target testTarget = testdataFactory.createTarget(targetId);
|
||||
targetManagement.createMetaData(testTarget.getControllerId(),
|
||||
Arrays.asList(entityFactory.generateTargetMetadata(knownKey, knownValue)));
|
||||
|
||||
final JSONObject jsonObject = new JSONObject().put("key", knownKey).put("value", updateValue);
|
||||
|
||||
mockMvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata/{metadatakey}",
|
||||
testTarget.getControllerId(), knownKey)
|
||||
.contentType(MediaType.APPLICATION_JSON_UTF8).content(jsonObject.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("metadatakey").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
requestFields(requestFieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY),
|
||||
requestFieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE)),
|
||||
responseFields(fieldWithPath("key").description(MgmtApiModelProperties.META_DATA_KEY),
|
||||
fieldWithPath("value").description(MgmtApiModelProperties.META_DATA_VALUE))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Delete a single meta data." + " Required Permission: " + SpPermission.UPDATE_REPOSITORY)
|
||||
public void deleteMetadata() throws Exception {
|
||||
// prepare and create metadata for deletion
|
||||
final String knownKey = "knownKey";
|
||||
final String knownValue = "knownValue";
|
||||
|
||||
final Target testTarget = testdataFactory.createTarget(targetId);
|
||||
targetManagement.createMetaData(testTarget.getControllerId(),
|
||||
Arrays.asList(entityFactory.generateTargetMetadata(knownKey, knownValue)));
|
||||
|
||||
mockMvc.perform(delete(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata/{key}",
|
||||
testTarget.getControllerId(), knownKey)).andDo(MockMvcResultPrinter.print()).andExpect(status().isOk())
|
||||
.andDo(this.document.document(
|
||||
pathParameters(parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID),
|
||||
parameterWithName("key").description(ApiModelPropertiesGeneric.ITEM_ID))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Create a list of meta data entries" + " Required Permission: " + SpPermission.READ_REPOSITORY
|
||||
+ " and " + SpPermission.UPDATE_TARGET)
|
||||
public void createMetadata() throws Exception {
|
||||
|
||||
final Target testTarget = testdataFactory.createTarget(targetId);
|
||||
|
||||
final String knownKey1 = "knownKey1";
|
||||
final String knownKey2 = "knownKey2";
|
||||
|
||||
final String knownValue1 = "knownValue1";
|
||||
final String knownValue2 = "knownValue2";
|
||||
|
||||
final JSONArray jsonArray = new JSONArray();
|
||||
jsonArray.put(new JSONObject().put("key", knownKey1).put("value", knownValue1));
|
||||
jsonArray.put(new JSONObject().put("key", knownKey2).put("value", knownValue2));
|
||||
|
||||
mockMvc.perform(
|
||||
post(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/{targetId}/metadata",
|
||||
testTarget.getControllerId()).contentType(MediaType.APPLICATION_JSON_UTF8)
|
||||
.content(jsonArray.toString()))
|
||||
.andDo(MockMvcResultPrinter.print()).andExpect(status().isCreated())
|
||||
.andExpect(content().contentType(APPLICATION_JSON_HAL_UTF))
|
||||
.andDo(this.document.document(
|
||||
pathParameters(
|
||||
parameterWithName("targetId").description(ApiModelPropertiesGeneric.ITEM_ID)),
|
||||
requestFields(requestFieldWithPath("[]key").description(MgmtApiModelProperties.META_DATA_KEY),
|
||||
optionalRequestFieldWithPath("[]value")
|
||||
.description(MgmtApiModelProperties.META_DATA_VALUE))));
|
||||
}
|
||||
|
||||
private String createTargetJsonForPostRequest(final String controllerId, final String name,
|
||||
final String description) throws JsonProcessingException {
|
||||
final Map<String, Object> target = new HashMap<>();
|
||||
|
||||
Reference in New Issue
Block a user