@Test(expected = ValidationException.class) public void testValidateInvalidEntities() { SetFollowingStatusRequest request = new SetFollowingStatusRequest("ntaccount", "groupshortname", EntityType.GROUP, false, Follower.FollowerStatus.FOLLOWING); context.checking(new Expectations() { { oneOf(domainGroupMapperMock).fetchUniqueResult(with(any(String.class))); will(returnValue(null)); } }); ServiceActionContext currentContext = new ServiceActionContext(request, principalMock); sut.validate(currentContext); context.assertIsSatisfied(); }
@Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException vex = new ValidationException(); SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); if (!inRequest.getTargetEntityType().equals(EntityType.GROUP)) { vex.addError("EntityType", "This action only supports following a group."); } DomainGroupModelView targetResult = domainGroupMapper.fetchUniqueResult(inRequest.getTargetUniqueId()); if (targetResult == null) { vex.addError("FollowerAndTarget", "Target unique id must refer to valid entity."); } if (vex.getErrors().size() > 0) { throw vex; } }
SetFollowingGroupStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException vex = new ValidationException(); SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); if (!inRequest.getTargetEntityType().equals(EntityType.GROUP)) { vex.addError("EntityType", "This action only supports following a group."); } DomainGroupModelView targetResult = domainGroupMapper.fetchUniqueResult(inRequest.getTargetUniqueId()); if (targetResult == null) { vex.addError("FollowerAndTarget", "Target unique id must refer to valid entity."); } if (vex.getErrors().size() > 0) { throw vex; } } }
SetFollowingGroupStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException vex = new ValidationException(); SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); if (!inRequest.getTargetEntityType().equals(EntityType.GROUP)) { vex.addError("EntityType", "This action only supports following a group."); } DomainGroupModelView targetResult = domainGroupMapper.fetchUniqueResult(inRequest.getTargetUniqueId()); if (targetResult == null) { vex.addError("FollowerAndTarget", "Target unique id must refer to valid entity."); } if (vex.getErrors().size() > 0) { throw vex; } } SetFollowingGroupStatusValidation(final GetDomainGroupsByShortNames inDomainGroupMapper); }
SetFollowingGroupStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException vex = new ValidationException(); SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); if (!inRequest.getTargetEntityType().equals(EntityType.GROUP)) { vex.addError("EntityType", "This action only supports following a group."); } DomainGroupModelView targetResult = domainGroupMapper.fetchUniqueResult(inRequest.getTargetUniqueId()); if (targetResult == null) { vex.addError("FollowerAndTarget", "Target unique id must refer to valid entity."); } if (vex.getErrors().size() > 0) { throw vex; } } SetFollowingGroupStatusValidation(final GetDomainGroupsByShortNames inDomainGroupMapper); @Override void validate(final PrincipalActionContext inActionContext); }
SetFollowingGroupStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException vex = new ValidationException(); SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); if (!inRequest.getTargetEntityType().equals(EntityType.GROUP)) { vex.addError("EntityType", "This action only supports following a group."); } DomainGroupModelView targetResult = domainGroupMapper.fetchUniqueResult(inRequest.getTargetUniqueId()); if (targetResult == null) { vex.addError("FollowerAndTarget", "Target unique id must refer to valid entity."); } if (vex.getErrors().size() > 0) { throw vex; } } SetFollowingGroupStatusValidation(final GetDomainGroupsByShortNames inDomainGroupMapper); @Override void validate(final PrincipalActionContext inActionContext);  }