Target attributes update can be (re-)triggered by management API (#690)

* extend Management API with attribute `requestAttributes`
* introduce new DMF Event Topic `REQUEST_ATTRIBUTES_UPDATE`
* enhance REST documentation by new functionality
* add tests for:
  * Management API
  * Amqp Message Dispatcher Service
  * Repository (Target Management)

Signed-off-by: Jeroen Jan Laverman (INST/ESY3) <jeroen.laverman@bosch-si.com>
This commit is contained in:
Jeroen Laverman
2018-06-14 12:48:31 +02:00
committed by Dominic Schabel
parent f4340098d9
commit ecfe774e53
18 changed files with 275 additions and 17 deletions

View File

@@ -133,6 +133,7 @@ public final class MgmtTargetMapper {
targetRest.setLastModifiedAt(target.getLastModifiedAt());
targetRest.setSecurityToken(target.getSecurityToken());
targetRest.setRequestAttributes(target.isRequestControllerAttributes());
// last target query is the last controller request date
final Long lastTargetQuery = target.getLastTargetQuery();

View File

@@ -120,9 +120,18 @@ public class MgmtTargetResource implements MgmtTargetRestApi {
public ResponseEntity<MgmtTarget> updateTarget(@PathVariable("controllerId") final String controllerId,
@RequestBody final MgmtTargetRequestBody targetRest) {
if (targetRest.isRequestAttributes() != null) {
if (targetRest.isRequestAttributes()) {
targetManagement.requestControllerAttributes(controllerId);
} else {
return ResponseEntity.badRequest().build();
}
}
final Target updateTarget = this.targetManagement.update(entityFactory.target().update(controllerId)
.name(targetRest.getName()).description(targetRest.getDescription()).address(targetRest.getAddress())
.securityToken(targetRest.getSecurityToken()));
.securityToken(targetRest.getSecurityToken()).requestAttributes(targetRest.isRequestAttributes()));
final MgmtTarget response = MgmtTargetMapper.toResponse(updateTarget);
MgmtTargetMapper.addPollStatus(updateTarget, response);

View File

@@ -68,6 +68,7 @@ import com.jayway.jsonpath.JsonPath;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Step;
import ru.yandex.qatools.allure.annotations.Stories;
/**
@@ -1539,6 +1540,56 @@ public class MgmtTargetResourceTest extends AbstractManagementApiIntegrationTest
.andDo(MockMvcResultPrinter.print()).andExpect(status().is(HttpStatus.NO_CONTENT.value()));
}
@Test
@Description("Request update of Controller Attributes.")
public void triggerControllerAttributesUpdate() throws Exception {
// create target with attributes
final String knownTargetId = "targetIdNeedsUpdate";
final Map<String, String> knownControllerAttrs = new HashMap<>();
knownControllerAttrs.put("a", "1");
knownControllerAttrs.put("b", "2");
testdataFactory.createTarget(knownTargetId);
controllerManagement.updateControllerAttributes(knownTargetId, knownControllerAttrs, null);
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isFalse();
verifyAttributeUpdateCanBeRequested(knownTargetId);
verifyRequestAttributesAttributeIsOptional(knownTargetId);
verifyResettingRequestAttributesIsNotAllowed(knownTargetId);
}
@Step
private void verifyAttributeUpdateCanBeRequested(final String knownTargetId) throws Exception {
final String body = new JSONObject().put("requestAttributes", true).toString();
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId).content(body)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isTrue();
}
@Step
private void verifyRequestAttributesAttributeIsOptional(final String knownTargetId) throws Exception {
final String body = new JSONObject().put("description", "verify attribute can be missing").toString();
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId).content(body)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isOk());
}
@Step
private void verifyResettingRequestAttributesIsNotAllowed(final String knownTargetId) throws Exception {
final String body = new JSONObject().put("requestAttributes", false).toString();
mvc.perform(put(MgmtRestConstants.TARGET_V1_REQUEST_MAPPING + "/" + knownTargetId).content(body)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultPrinter.print()).andExpect(status().isBadRequest());
assertThat(targetManagement.isControllerAttributesRequested(knownTargetId)).isTrue();
}
@Test
public void searchTargetsUsingRsqlQuery() throws Exception {
final int amountTargets = 10;