FactoryBaseValidator { protected void validateCurrentTimeBeforeSinceUntil(Factory factory) throws ConflictException { final Policies policies = factory.getPolicies(); if (policies == null) { return; } Long validSince = policies.getValidSince(); Long validUntil = policies.getValidUntil(); if (validSince != null && validSince != 0 && validUntil != null && validUntil != 0 && validSince >= validUntil) { throw new ConflictException(FactoryConstants.INVALID_VALIDSINCEUNTIL_MESSAGE); } if (validSince != null && validSince != 0 && new Date().after(new Date(validSince))) { throw new ConflictException(FactoryConstants.INVALID_VALIDSINCE_MESSAGE); } if (validUntil != null && validUntil != 0 && new Date().after(new Date(validUntil))) { throw new ConflictException(FactoryConstants.INVALID_VALIDUNTIL_MESSAGE); } } FactoryBaseValidator(AccountDao accountDao,
                                UserDao userDao,
                                PreferenceDao preferenceDao);   }
@Test public void shouldValidateIfCurrentTimeBeforeSinceUntil() throws ConflictException { Long currentTime = new Date().getTime(); factory.withPolicies(dto.createDto(Policies.class) .withValidSince(currentTime + 10000L) .withValidUntil(currentTime + 20000L) ); validator.validateCurrentTimeBeforeSinceUntil(factory); }
@Test(expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = FactoryConstants.INVALID_VALIDSINCE_MESSAGE) public void shouldNotValidateIfValidSinceBeforeCurrent() throws ApiException { factory.withPolicies(dto.createDto(Policies.class) .withValidSince(1L) ); validator.validateCurrentTimeBeforeSinceUntil(factory); }
@Test(expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = FactoryConstants.INVALID_VALIDUNTIL_MESSAGE) public void shouldNotValidateIfValidUntilBeforeCurrent() throws ApiException { factory.withPolicies(dto.createDto(Policies.class) .withValidUntil(1L) ); validator.validateCurrentTimeBeforeSinceUntil(factory); }
@Test(expectedExceptions = ApiException.class, expectedExceptionsMessageRegExp = FactoryConstants.INVALID_VALIDSINCEUNTIL_MESSAGE) public void shouldNotValidateIfValidUntilBeforeValidSince() throws ApiException { factory.withPolicies(dto.createDto(Policies.class) .withValidSince(2L) .withValidUntil(1L) ); validator.validateCurrentTimeBeforeSinceUntil(factory); }