ViewValidator { public ValidationResult validate(final View view, final Schema schema, final Set<StoreTrait> storeTraits) { final boolean isStoreOrdered = storeTraits.contains(StoreTrait.ORDERED); final ValidationResult result = new ValidationResult(); if (null != view) { validateEntities(view, schema, storeTraits, isStoreOrdered, result); validateEdge(view, schema, storeTraits, isStoreOrdered, result); } return result; }  ValidationResult validate(final View view, final Schema schema, final Set<StoreTrait> storeTraits); static final String SKIP_VIEW_VALIDATION; }
@Test public void shouldValidateAndReturnTrueWhenEmptyFunctions() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder().build(); final Schema schema = new Schema(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnFalseWhenEntityTransientPropertyIsInSchema() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_1, String.class) .build()) .build(); final Schema schema = new Schema.Builder() .type("prop1", Object.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "prop1") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertFalse(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEntityTransientPropertyIsNotInSchema() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_1, String.class) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_2, "obj") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEntityFilterSelectionUnknownProperty() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_3, String.class) .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1) .execute(new ExampleFilterFunction()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEntityTransformerSelectionUnknownProperty() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEntityTransformerProjectsToUnknownProperty() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("string", Object.class) .type("int", Object.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "string") .property(TestPropertyNames.PROP_2, "int") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEntityTransformerResult() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("double", Double.class) .type("int", Integer.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "double") .property(TestPropertyNames.PROP_2, "int") .property(TestPropertyNames.PROP_3, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWithMatchedVertexFilter() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select(IdentifierType.MATCHED_VERTEX.name()) .execute(new IsMoreThan("testValue1")) .build()) .postAggregationFilter(new ElementFilter.Builder() .select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()) .execute(new IsMoreThan("testValue2")) .build()) .postTransformFilter(new ElementFilter.Builder() .select(IdentifierType.MATCHED_VERTEX.name()) .execute(new IsMoreThan("testValue3")) .build()) .build()) .build(); Schema schema = new Schema.Builder() .type("double", Double.class) .type("int", Integer.class) .type("string", String.class) .type("true", Boolean.class) .type("vertex", String.class) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .source("vertex") .destination("vertex") .directed("true") .property(TestPropertyNames.PROP_1, "double") .property(TestPropertyNames.PROP_2, "int") .property(TestPropertyNames.PROP_3, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid(), result.getErrorString()); }
@Test public void shouldValidateAndReturnFalseWhenEdgeTransientPropertyIsInSchema() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_1, String.class) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertFalse(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEdgeTransientPropertyIsNotInSchema() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_1, String.class) .build()) .build(); final Schema schema = new Schema.Builder() .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_2, "obj") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEdgeFilterSelectionUnknownProperty() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_3, String.class) .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1) .execute(new ExampleFilterFunction()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEdgeTransformerSelectionUnknownProperty() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEdgeTransformerProjectsToUnknownProperty() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("int", Integer.class) .type("string", String.class) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_1, "int") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenEdgeTransformerResult() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("double", Double.class) .type("int", Integer.class) .type("string", String.class) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .property(TestPropertyNames.PROP_1, "double") .property(TestPropertyNames.PROP_2, "int") .property(TestPropertyNames.PROP_3, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueNoGroupByProperties() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY) .edge(TestGroups.EDGE) .build(); final Schema schema = new Schema.Builder() .type("vertex", String.class) .type("true", Boolean.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .vertex("vertex") .build()) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .source("vertex") .destination("vertex") .directed("true") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueForNullView() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder().build(); final Schema schema = new Schema.Builder() .type("vertex", String.class) .type("true", Boolean.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .vertex("vertex") .build()) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .source("vertex") .destination("vertex") .directed("true") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenGroupByPropertiesInSchema() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .groupBy(TestPropertyNames.PROP_1) .build()) .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .groupBy(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .build()) .build(); final Schema schema = new Schema.Builder() .type("vertex", String.class) .type("string|ColumnQualifier", new TypeDefinition.Builder() .clazz(String.class) .build()) .type("string|Value", new TypeDefinition.Builder() .clazz(String.class) .build()) .type("true", Boolean.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .vertex("vertex") .property(TestPropertyNames.PROP_1, "string|ColumnQualifier") .property(TestPropertyNames.PROP_2, "string|ColumnQualifier") .property(TestPropertyNames.PROP_3, "string|Value") .groupBy(TestPropertyNames.PROP_1) .build()) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .source("vertex") .destination("vertex") .directed("true") .property(TestPropertyNames.PROP_1, "string|ColumnQualifier") .property(TestPropertyNames.PROP_2, "string|ColumnQualifier") .property(TestPropertyNames.PROP_3, "string|Value") .groupBy(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .build()) .visibilityProperty(TestPropertyNames.PROP_2) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnFalseWhenTimestampGroupByPropertyUsedInEntity() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .groupBy(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .build()) .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .groupBy(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .build()) .build(); final Schema schema = new Schema.Builder() .type("vertex", String.class) .type("string|Timestamp", new TypeDefinition.Builder() .clazz(String.class) .build()) .type("string|Value", new TypeDefinition.Builder() .clazz(String.class) .build()) .type("true", Boolean.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .vertex("vertex") .property(TestPropertyNames.PROP_1, "string|Timestamp") .property(TestPropertyNames.PROP_2, "string|Value") .build()) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .source("vertex") .destination("vertex") .directed("true") .property(TestPropertyNames.PROP_2, "string|Value") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertFalse(result.isValid()); }
@Test public void shouldValidateAndReturnFalseWhenGroupByPropertyNotInSchema() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .groupBy(TestPropertyNames.PROP_1) .build()) .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .groupBy(TestPropertyNames.PROP_2) .build()) .build(); final Schema schema = new Schema.Builder() .type("vertex", String.class) .type("string|Timestamp", new TypeDefinition.Builder() .clazz(String.class) .build()) .type("string|Value", new TypeDefinition.Builder() .clazz(String.class) .build()) .type("true", Boolean.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .vertex("vertex") .property(TestPropertyNames.PROP_2, "string|Value") .groupBy(TestPropertyNames.PROP_2) .build()) .edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder() .source("vertex") .destination("vertex") .directed("true") .property(TestPropertyNames.PROP_1, "string|Timestamp") .property(TestPropertyNames.PROP_2, "string|Value") .groupBy(TestPropertyNames.PROP_1) .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertFalse(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenPostTransformerFilterSet() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .postTransformFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_3) .execute(new ExampleFilterFunction()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "obj") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenPostTransformerSelectionIsUnknown() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_3, String.class) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .postTransformFilter(new ElementFilter.Builder() .select(TestPropertyNames.TRANSIENT_1) .execute(new ExampleFilterFunction()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "obj") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnTrueForOrFilter() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new Or.Builder() .select(0) .execute(new IsEqual("some value")) .select(1) .execute(new IsEqual("some other value")) .build()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid(), result.getErrorString()); }
@Test public void shouldValidateAndReturnFalseForOrFilterWithIncompatibleProperties() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new Or.Builder() .select(0) .execute(new IsMoreThan(2)) .select(1) .execute(new IsEqual("some other value")) .build()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertFalse(result.isValid()); }
@Test public void shouldValidateAndReturnTrueForAndFilter() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new And.Builder() .select(0) .execute(new IsEqual("some value")) .select(1) .execute(new IsEqual("some other value")) .build()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid(), result.getErrorString()); }
@Test public void shouldValidateAndReturnFalseForAndFilterWithIncompatibleProperties() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new And.Builder() .select(0) .execute(new IsMoreThan(2)) .select(1) .execute(new IsEqual("some other value")) .build()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertFalse(result.isValid()); }
@Test public void shouldValidateAndReturnTrueForNotFilter() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new Not<>(new Or.Builder<>() .select(0) .execute(new IsEqual("some value")) .select(1) .execute(new IsEqual("some other value")) .build())) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", Object.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid(), result.getErrorString()); }
@Test public void shouldValidateAndReturnFalseForNotFilterWithIncompatibleProperties() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new Not<>(new Or.Builder<>() .select(0) .execute(new IsMoreThan("abcd")) .select(1) .execute(new IsEqual("some other value")) .build())) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("int", Integer.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "int") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertFalse(result.isValid()); }
@Test public void shouldValidateAndReturnTrueWhenAggregatorSelectionUnknownProperty() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .aggregator(new ElementAggregator.Builder() .select(TestPropertyNames.PROP_1) .execute(new StringConcat()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .build()) .build(); final ValidationResult result = validator.validate(view, schema, ALL_STORE_TRAITS); assertTrue(result.isValid()); }
@Test public void shouldValidateAndReturnFalseWhenMissingTraits() { final ViewValidator validator = new ViewValidator(); final View view = new View.Builder() .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .transientProperty(TestPropertyNames.PROP_3, String.class) .preAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_1) .execute(new Exists()) .build()) .aggregator(new ElementAggregator.Builder() .select(TestPropertyNames.PROP_1) .execute(new StringConcat()) .build()) .postAggregationFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_2) .execute(new Exists()) .build()) .transformer(new ElementTransformer.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new ExampleTransformFunction()) .project(TestPropertyNames.PROP_3) .build()) .postTransformFilter(new ElementFilter.Builder() .select(TestPropertyNames.PROP_3) .execute(new Exists()) .build()) .build()) .build(); final Schema schema = new Schema.Builder() .type("obj", String.class) .type("string", String.class) .entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder() .property(TestPropertyNames.PROP_1, "obj") .property(TestPropertyNames.PROP_2, "string") .build()) .build(); final ValidationResult result = validator.validate(view, schema, NO_STORE_TRAITS); final String errPrefix = "This store does not currently support "; assertFalse(result.isValid()); assertEquals(Sets.newHashSet( errPrefix + StoreTrait.PRE_AGGREGATION_FILTERING.name(), errPrefix + StoreTrait.QUERY_AGGREGATION.name(), errPrefix + StoreTrait.POST_AGGREGATION_FILTERING.name(), errPrefix + StoreTrait.TRANSFORMATION.name(), errPrefix + StoreTrait.POST_TRANSFORMATION_FILTERING.name() ), result.getErrors()); }