ElementValidator implements Validator<Element> { @Override public boolean validate(final Element element) { if (null == element) { return false; } if (null != schema) { return validateWithSchema(element); } if (null != view) { return validateAgainstViewFilter(element, FilterType.PRE_AGGREGATION_FILTER) && validateAgainstViewFilter(element, FilterType.POST_AGGREGATION_FILTER) && validateAgainstViewFilter(element, FilterType.POST_TRANSFORM_FILTER); } return true; } 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 shouldReturnTrueWhenSchemaValidateWithValidElement() { 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.test(elm)).willReturn(true); final boolean isValid = validator.validate(elm); assertTrue(isValid); }
@Test public void shouldReturnTrueWhenSchemaValidateWithoutIsAWithValidElement() { 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 = false; 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.test(elm)).willReturn(true); final boolean isValid = validator.validate(elm); assertTrue(isValid); }
@Test public void shouldReturnFalseWhenSchemaValidateWithInvalidElement() { 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.test(elm)).willReturn(false); final boolean isValid = validator.validate(elm); assertFalse(isValid); }
@Test public void shouldReturnFalseWhenNoSchemaElementDefinition() { final Schema schema = mock(Schema.class); final String group = TestGroups.EDGE; final Element elm = mock(Element.class); final boolean includeIsA = true; final ElementValidator validator = new ElementValidator(schema, includeIsA); given(elm.getGroup()).willReturn(group); given(schema.getElement(group)).willReturn(null); final boolean isValid = validator.validate(elm); assertFalse(isValid); }
@Test public void shouldReturnTrueWhenViewValidateWithValidElement() { final View view = mock(View.class); final String group = TestGroups.EDGE; final Element elm = mock(Element.class); final ViewElementDefinition elementDef = mock(ViewElementDefinition.class); final ElementFilter filter = mock(ElementFilter.class); final ElementValidator validator = new ElementValidator(view); given(elm.getGroup()).willReturn(group); given(view.getElement(group)).willReturn(elementDef); given(elementDef.getPreAggregationFilter()).willReturn(filter); given(filter.test(elm)).willReturn(true); final boolean isValid = validator.validate(elm); assertTrue(isValid); }
@Test public void shouldReturnFalseWhenViewValidateWithInvalidElement() { final View view = mock(View.class); final String group = TestGroups.EDGE; final Element elm = mock(Element.class); final ViewElementDefinition elementDef = mock(ViewElementDefinition.class); final ElementFilter filter = mock(ElementFilter.class); final ElementValidator validator = new ElementValidator(view); given(elm.getGroup()).willReturn(group); given(view.getElement(group)).willReturn(elementDef); given(elementDef.getPreAggregationFilter()).willReturn(filter); given(filter.test(elm)).willReturn(false); final boolean isValid = validator.validate(elm); assertFalse(isValid); }
@Test public void shouldReturnFalseWhenNoViewElementDefinition() { final View view = mock(View.class); final String group = TestGroups.EDGE; final Element elm = mock(Element.class); final ElementValidator validator = new ElementValidator(view); given(elm.getGroup()).willReturn(group); given(view.getElement(group)).willReturn(null); final boolean isValid = validator.validate(elm); assertFalse(isValid); }