@Test void testAllProfiles() { assertTrue(vtor.matchProfiles(new String[]{Vtor.ALL_PROFILES})); assertFalse(vtor.matchProfiles(new String[]{Vtor.ALL_PROFILES, "someProfile"})); }
@Test void testDefaultProfile() { //when vtor.useProfile(Vtor.DEFAULT_PROFILE); //then assertTrue(vtor.matchProfiles(null), "result must be true when match null value"); assertTrue(vtor.matchProfiles(new String[]{"testProfile2", "", "testProfile3"}), "result must be true when match a list with empty profile"); assertFalse(vtor.matchProfiles(new String[]{"testProfile2", "testProfile3"}), "result must be false when match a list without empty profile"); }
@Test void testMatchProfilesAgainstSomeProfile() { //when vtor.useProfile("testProfile1"); //then assertFalse(vtor.matchProfiles(null), "result must be false when match null value"); assertFalse(vtor.matchProfiles(new String[]{"testProfile2", "testProfile3"}), "result must be false when match list of profiles without any assigned profiles"); assertTrue(vtor.matchProfiles(new String[]{"testProfile1", "testProfile2", "testProfile3"}), "result must be true when match list of profiles with one assigned profile"); assertTrue(vtor.matchProfiles(new String[]{"testProfile1", "testProfile2", "testProfile3"}), "result must be true when match list of profiles with one assigned profile"); assertTrue(vtor.matchProfiles(new String[]{"testProfile1", "testProfile2", "testProfile3"}), "result must be true when match list of profiles with one assigned profile"); assertTrue(vtor.matchProfiles(new String[]{"testProfile1", "testProfile2", "testProfile3"}), "result must be true when match list of profiles with one assigned profile"); assertTrue(vtor.matchProfiles(new String[]{"testProfile2", "testProfile1", "testProfile3"}), "result must be true when match unordered list of profiles with one assigned profile"); assertFalse(vtor.matchProfiles(new String[]{"+testProfile2", "testProfile1", "testProfile3"}), "result must be false when match a list of profiles with one wrong mandatory profile"); assertFalse(vtor.matchProfiles(new String[]{"testProfile2", "-testProfile1", "testProfile3"}), "result must be false when match a list of profiles with one assigned profile which was marked as optional"); }
@Test void testNonSpecialProfiles(){ assertFalse(vtor.matchProfiles(new String[]{"testProfile1", "testProfile2"})); }
@Test void testOneProfileIsDefault() { assertTrue(vtor.matchProfiles(new String[]{Vtor.DEFAULT_PROFILE, "testProfile"})); }
@Test void testEmptyListOfProfiles() { assertTrue(vtor.matchProfiles(new String[]{})); }
@Test void testOneProfileIsEmpty() { assertTrue(vtor.matchProfiles(new String[]{"", "testProfile"})); }
@Test void testNullProfiles() { assertTrue(vtor.matchProfiles(null)); }
/** * Performs validation of provided validation context and appends violations. */ public List<Violation> validate(final ValidationContext ctx, final Object target, final String targetName) { for (Map.Entry<String, List<Check>> entry : ctx.map.entrySet()) { String name = entry.getKey(); Object value = BeanUtil.declaredSilent.getProperty(target, name); String valueName = targetName != null ? (targetName + '.' + name) : name; // move up ValidationConstraintContext vcc = new ValidationConstraintContext(this, target, valueName); for (Check check : entry.getValue()) { String[] checkProfiles = check.getProfiles(); if (!matchProfiles(checkProfiles)) { continue; } if (check.getSeverity() < severity) { continue; } ValidationConstraint constraint = check.getConstraint(); if (!constraint.isValid(vcc, value)) { addViolation(new Violation(valueName, target, value, check)); } } } return getViolations(); }
@Test void testValidateAllProfilesByDefaultIsTrue() { vtor.setValidateAllProfilesByDefault(true); assertTrue(vtor.matchProfiles(new String[]{"testProfile"})); }
/** * Performs validation of provided validation context and appends violations. */ public void validate(ValidationContext ctx, Object target, String targetName) { for (Map.Entry<String, List<Check>> entry : ctx.map.entrySet()) { String name = entry.getKey(); Object value = BeanUtil.getDeclaredPropertySilently(target, name); String valueName = targetName != null ? (targetName + '.' + name) : name; // move up ValidationConstraintContext vcc = new ValidationConstraintContext(this, target, valueName); for (Check check : entry.getValue()) { String[] checkProfiles = check.getProfiles(); if (matchProfiles(checkProfiles) == false) { continue; } if (check.getSeverity() < severity) { continue; } ValidationConstraint constraint = check.getConstraint(); if (constraint.isValid(vcc, value) == false) { addViolation(new Violation(valueName, target, value, check)); } } } }