@Test public void testValidateForUpdate_WhenUserNotFound_ThrowsInvalidEntryException() throws Exception { Long idNotFound = 10L; this.existingUserDto.setId(idNotFound); this.exception.expect(VmidcBrokerValidationException.class); this.exception.expectMessage(MessageFormat.format("User entry with name {0} is not found.", this.existingUserDto.getLoginName())); this.validator.validateForUpdate(this.existingUserDto); }
@Override public User validateForUpdate(UserDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); validate(dto); OSCEntityManager<User> emgr = new OSCEntityManager<User>(User.class, this.em, this.txBroadcastUtil); User user = emgr.findByPrimaryKey(dto.getId()); if (user == null) { throw new VmidcBrokerValidationException("User entry with name " + dto.getLoginName() + " is not found."); } return user; }
UserDtoValidator implements DtoValidator<UserDto, User> { @Override public User validateForUpdate(UserDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); validate(dto); OSCEntityManager<User> emgr = new OSCEntityManager<User>(User.class, this.em, this.txBroadcastUtil); User user = emgr.findByPrimaryKey(dto.getId()); if (user == null) { throw new VmidcBrokerValidationException("User entry with name " + dto.getLoginName() + " is not found."); } return user; } }
UserDtoValidator implements DtoValidator<UserDto, User> { @Override public User validateForUpdate(UserDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); validate(dto); OSCEntityManager<User> emgr = new OSCEntityManager<User>(User.class, this.em, this.txBroadcastUtil); User user = emgr.findByPrimaryKey(dto.getId()); if (user == null) { throw new VmidcBrokerValidationException("User entry with name " + dto.getLoginName() + " is not found."); } return user; } UserDtoValidator(EntityManager em, TransactionalBroadcastUtil txBroadcastUtil); }
UserDtoValidator implements DtoValidator<UserDto, User> { @Override public User validateForUpdate(UserDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); validate(dto); OSCEntityManager<User> emgr = new OSCEntityManager<User>(User.class, this.em, this.txBroadcastUtil); User user = emgr.findByPrimaryKey(dto.getId()); if (user == null) { throw new VmidcBrokerValidationException("User entry with name " + dto.getLoginName() + " is not found."); } return user; } UserDtoValidator(EntityManager em, TransactionalBroadcastUtil txBroadcastUtil); @Override void validateForCreate(UserDto dto); @Override User validateForUpdate(UserDto dto); static void checkForNullFields(UserDto dto); static void checkFieldLength(UserDto dto); }
UserDtoValidator implements DtoValidator<UserDto, User> { @Override public User validateForUpdate(UserDto dto) throws Exception { BaseDtoValidator.checkForNullId(dto); validate(dto); OSCEntityManager<User> emgr = new OSCEntityManager<User>(User.class, this.em, this.txBroadcastUtil); User user = emgr.findByPrimaryKey(dto.getId()); if (user == null) { throw new VmidcBrokerValidationException("User entry with name " + dto.getLoginName() + " is not found."); } return user; } UserDtoValidator(EntityManager em, TransactionalBroadcastUtil txBroadcastUtil); @Override void validateForCreate(UserDto dto); @Override User validateForUpdate(UserDto dto); static void checkForNullFields(UserDto dto); static void checkFieldLength(UserDto dto);  }