@Test public void testFailedValidationWrongEntity() { SetFollowingStatusRequest request = new SetFollowingStatusRequest("ntaccount", "followingntaccount", EntityType.NOTSET, false, Follower.FollowerStatus.FOLLOWING); context.checking(new Expectations() { { oneOf(getPersonIdByAccountIdMapper).execute("followingntaccount"); will(returnValue(2L)); } }); Map<String, String> errors = null; try { ServiceActionContext currentContext = new ServiceActionContext(request, principalMock); sut.validate(currentContext); } catch (ValidationException vex) { errors = vex.getErrors(); } assertTrue(errors.containsKey("EntityType")); context.assertIsSatisfied(); }
@Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); ValidationException vex = new ValidationException(); if (!inRequest.getTargetEntityType().equals(EntityType.PERSON)) { vex.addError("EntityType", "This action only supports following a person."); } Long followingId = getPersonIdByAccountIdMapper.execute(inRequest.getTargetUniqueId()); if (followingId == null) { vex.addError("FollowerAndTarget", "Target unique id for valid users must be supplied."); } if (vex.getErrors().size() > 0) { throw vex; } }
SetFollowingPersonStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); ValidationException vex = new ValidationException(); if (!inRequest.getTargetEntityType().equals(EntityType.PERSON)) { vex.addError("EntityType", "This action only supports following a person."); } Long followingId = getPersonIdByAccountIdMapper.execute(inRequest.getTargetUniqueId()); if (followingId == null) { vex.addError("FollowerAndTarget", "Target unique id for valid users must be supplied."); } if (vex.getErrors().size() > 0) { throw vex; } } }
SetFollowingPersonStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); ValidationException vex = new ValidationException(); if (!inRequest.getTargetEntityType().equals(EntityType.PERSON)) { vex.addError("EntityType", "This action only supports following a person."); } Long followingId = getPersonIdByAccountIdMapper.execute(inRequest.getTargetUniqueId()); if (followingId == null) { vex.addError("FollowerAndTarget", "Target unique id for valid users must be supplied."); } if (vex.getErrors().size() > 0) { throw vex; } } SetFollowingPersonStatusValidation(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper); }
SetFollowingPersonStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); ValidationException vex = new ValidationException(); if (!inRequest.getTargetEntityType().equals(EntityType.PERSON)) { vex.addError("EntityType", "This action only supports following a person."); } Long followingId = getPersonIdByAccountIdMapper.execute(inRequest.getTargetUniqueId()); if (followingId == null) { vex.addError("FollowerAndTarget", "Target unique id for valid users must be supplied."); } if (vex.getErrors().size() > 0) { throw vex; } } SetFollowingPersonStatusValidation(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper); @Override void validate(final PrincipalActionContext inActionContext); }
SetFollowingPersonStatusValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { SetFollowingStatusRequest inRequest = (SetFollowingStatusRequest) inActionContext.getParams(); ValidationException vex = new ValidationException(); if (!inRequest.getTargetEntityType().equals(EntityType.PERSON)) { vex.addError("EntityType", "This action only supports following a person."); } Long followingId = getPersonIdByAccountIdMapper.execute(inRequest.getTargetUniqueId()); if (followingId == null) { vex.addError("FollowerAndTarget", "Target unique id for valid users must be supplied."); } if (vex.getErrors().size() > 0) { throw vex; } } SetFollowingPersonStatusValidation(final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper); @Override void validate(final PrincipalActionContext inActionContext);  }