ElementValidator implements Validator<Element> { @Override public ValidationResult validateWithValidationResult(final Element element) { final ValidationResult validationResult = new ValidationResult(); if (null == element) { validationResult.addError("Element was null"); } else if (null != schema) { validationResult.add(validateWithSchemaWithValidationResult(element)); } else if (null != view) { validationResult.add(validateAgainstViewFilterWithValidationResult(element, FilterType.PRE_AGGREGATION_FILTER)); validationResult.add(validateAgainstViewFilterWithValidationResult(element, FilterType.POST_AGGREGATION_FILTER)); validationResult.add(validateAgainstViewFilterWithValidationResult(element, FilterType.POST_TRANSFORM_FILTER)); } return validationResult; } ElementValidator(final Schema schema);  ElementValidator(final Schema schema, final boolean includeIsA);  ElementValidator(final View view); @Override boolean validate(final Element element); @Override ValidationResult validateWithValidationResult(final Element element); boolean validateInput(final Element element); boolean validateAggregation(final Element element); boolean validateTransform(final Element element); boolean validateWithSchema(final Element element); Schema getSchema(); View getView();  }
@Test public void shouldReturnValidValidationResultWhenSchemaValidateWithValidElement() { final Schema schema = mock(Schema.class); final String group = TestGroups.EDGE; final Element elm = mock(Element.class); final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class); final ElementFilter filter = mock(ElementFilter.class); final boolean includeIsA = true; final ElementValidator validator = new ElementValidator(schema, includeIsA); given(elm.getGroup()).willReturn(group); given(schema.getElement(group)).willReturn(elementDef); given(elementDef.getValidator(includeIsA)).willReturn(filter); given(filter.testWithValidationResult(elm)).willReturn(new ValidationResult()); final ValidationResult result = validator.validateWithValidationResult(elm); assertTrue(result.isValid()); }
@Test public void shouldReturnFailedValidationResultWhenSchemaValidateWithInvalidElement() { final Schema schema = mock(Schema.class); final String group = TestGroups.EDGE; final Element elm = mock(Element.class); final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class); final ElementFilter filter = mock(ElementFilter.class); final boolean includeIsA = true; final ElementValidator validator = new ElementValidator(schema, includeIsA); given(elm.getGroup()).willReturn(group); given(schema.getElement(group)).willReturn(elementDef); given(elementDef.getValidator(includeIsA)).willReturn(filter); given(filter.testWithValidationResult(elm)).willReturn(new ValidationResult("some error")); final ValidationResult result = validator.validateWithValidationResult(elm); assertFalse(result.isValid()); assertTrue(result.getErrorString().contains("some error")); }