MgmtTargetTagResource implements MgmtTargetTagRestApi { @Override public ResponseEntity<List<MgmtTarget>> assignTargets(@PathVariable("targetTagId") final Long targetTagId, @RequestBody final List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies) { LOG.debug("Assign Targets {} for target tag {}", assignedTargetRequestBodies.size(), targetTagId); final List<Target> assignedTarget = this.targetManagement .assignTag(findTargetControllerIds(assignedTargetRequestBodies), targetTagId); return ResponseEntity.ok(MgmtTargetMapper.toResponse(assignedTarget)); } MgmtTargetTagResource(final TargetTagManagement tagManagement, final TargetManagement targetManagement,
            final EntityFactory entityFactory); @Override ResponseEntity<PagedList<MgmtTag>> getTargetTags(
            @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); @Override ResponseEntity<MgmtTag> getTargetTag(@PathVariable("targetTagId") final Long targetTagId); @Override ResponseEntity<List<MgmtTag>> createTargetTags(@RequestBody final List<MgmtTagRequestBodyPut> tags); @Override ResponseEntity<MgmtTag> updateTargetTag(@PathVariable("targetTagId") final Long targetTagId,
            @RequestBody final MgmtTagRequestBodyPut restTargetTagRest); @Override ResponseEntity<Void> deleteTargetTag(@PathVariable("targetTagId") final Long targetTagId); @Override ResponseEntity<List<MgmtTarget>> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId); @Override ResponseEntity<PagedList<MgmtTarget>> getAssignedTargets(@PathVariable("targetTagId") final Long targetTagId,
            @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); @Override ResponseEntity<MgmtTargetTagAssigmentResult> toggleTagAssignment(
            @PathVariable("targetTagId") final Long targetTagId,
            @RequestBody final List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies); @Override ResponseEntity<List<MgmtTarget>> assignTargets(@PathVariable("targetTagId") final Long targetTagId,
            @RequestBody final List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies); @Override ResponseEntity<Void> unassignTarget(@PathVariable("targetTagId") final Long targetTagId,
            @PathVariable("controllerId") final String controllerId); @Override ResponseEntity<MgmtTargetTagAssigmentResult> toggleTagAssignmentUnpaged(
            @PathVariable("targetTagId") final Long targetTagId,
            @RequestBody final List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies); @Override ResponseEntity<List<MgmtTarget>> assignTargetsUnpaged(@PathVariable("targetTagId") final Long targetTagId,
            @RequestBody final List<MgmtAssignedTargetRequestBody> assignedTargetRequestBodies); @Override ResponseEntity<Void> unassignTargetUnpaged(@PathVariable("targetTagId") final Long targetTagId,
            @PathVariable("controllerId") final String controllerId);  }
@Test @Description("Verfies that tag assignments done through tag API command are correctly stored in the repository.") @ExpectEvents({ @Expect(type = TargetTagCreatedEvent.class, count = 1), @Expect(type = TargetCreatedEvent.class, count = 2), @Expect(type = TargetUpdatedEvent.class, count = 2) }) public void assignTargets() throws Exception { final TargetTag tag = testdataFactory.createTargetTags(1, "").get(0); final int targetsAssigned = 2; final List<Target> targets = testdataFactory.createTargets(targetsAssigned); final ResultActions result = mvc .perform(post(MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING + "/" + tag.getId() + "/assigned") .content(JsonBuilder.controllerIds( targets.stream().map(Target::getControllerId).collect(Collectors.toList()))) .contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)); final List<Target> updated = targetManagement.findByTag(PAGE, tag.getId()).getContent(); assertThat(updated.stream().map(Target::getControllerId).collect(Collectors.toList())) .containsAll(targets.stream().map(Target::getControllerId).collect(Collectors.toList())); result.andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(0))) .andExpect(applyTargetEntityMatcherOnArrayResult(updated.get(1))); }