use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldValidateSchemaUsedWhenGraphIdAlreadyExistsAndIsSame.
@Test
public void shouldValidateSchemaUsedWhenGraphIdAlreadyExistsAndIsSame() {
// Given
Schema schema1 = new Schema.Builder().edge("testEdge", new SchemaEdgeDefinition()).build();
graphLibrary.add(GRAPH_ID + 1, SCHEMA_ID + 1, schema1, STORE_PROPS_ID, new StoreProperties());
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).schema(schema1).build();
// When / Then
validate(export);
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldValidateParentSchemaIdCannotBeUsedWhenGraphIdAlreadyExists.
@Test
public void shouldValidateParentSchemaIdCannotBeUsedWhenGraphIdAlreadyExists() {
// Given
graphLibrary.add(GRAPH_ID + 1, SCHEMA_ID_1, new Schema.Builder().edge("edge", new SchemaEdgeDefinition()).build(), STORE_PROPS_ID, new StoreProperties());
graphLibrary.addSchema(SCHEMA_ID, new Schema.Builder().build());
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).parentSchemaIds(SCHEMA_ID).build();
// When / Then
final String expectedMessage = "Validation errors: \n" + String.format(GRAPH_S_ALREADY_EXISTS_SO_YOU_CANNOT_USE_A_DIFFERENT_S_DO_NOT_SET_THE_S_FIELD, "graphId1", SCHEMA_STRING, "parentSchemaIds");
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessage(expectedMessage);
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class FilterValidator method validateOperation.
@Override
protected ValidationResult validateOperation(final Filter operation, final Schema schema) {
final ValidationResult result = new ValidationResult();
final Map<String, ?> entities = null != operation.getEntities() ? operation.getEntities() : new HashMap<>();
final Map<String, ?> edges = null != operation.getEdges() ? operation.getEdges() : new HashMap<>();
for (final Map.Entry<String, ?> entry : edges.entrySet()) {
result.add(validateEdge(entry, schema));
result.add(validateElementFilter((ElementFilter) entry.getValue()));
result.add(validateFilterPropertyClasses(schema.getEdge(entry.getKey()), (ElementFilter) entry.getValue()));
}
for (final Map.Entry<String, ?> entry : entities.entrySet()) {
result.add(validateEntity(entry, schema));
result.add(validateElementFilter((ElementFilter) entry.getValue()));
result.add(validateFilterPropertyClasses(schema.getEntity(entry.getKey()), (ElementFilter) entry.getValue()));
}
if (null != operation.getGlobalElements()) {
for (final SchemaEdgeDefinition edgeDefinition : schema.getEdges().values()) {
result.add(validateFilterPropertyClasses(edgeDefinition, operation.getGlobalElements()));
}
for (final SchemaEntityDefinition entityDefinition : schema.getEntities().values()) {
result.add(validateFilterPropertyClasses(entityDefinition, operation.getGlobalElements()));
}
}
if (null != operation.getGlobalEdges()) {
for (final SchemaEdgeDefinition edgeDefinition : schema.getEdges().values()) {
result.add(validateFilterPropertyClasses(edgeDefinition, operation.getGlobalEdges()));
}
}
if (null != operation.getGlobalEntities()) {
for (final SchemaEntityDefinition entityDefinition : schema.getEntities().values()) {
result.add(validateFilterPropertyClasses(entityDefinition, operation.getGlobalEntities()));
}
}
return result;
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class FunctionValidator method validateEdge.
protected ValidationResult validateEdge(final Map.Entry<String, ?> edgeEntry, final Schema schema) {
final ValidationResult result = new ValidationResult();
if (null != edgeEntry) {
final String group = edgeEntry.getKey();
final SchemaEdgeDefinition schemaEdgeDefinition = schema.getEdge(group);
if (null == schemaEdgeDefinition) {
result.addError("Edge group: " + group + " does not exist in the schema.");
}
}
return result;
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class AccumuloKeyValueReducerTest method shouldGetGroupFromElementConverter.
@Test
public void shouldGetGroupFromElementConverter() throws IOException, InterruptedException {
// Given
MockAccumuloElementConverter.mock = mock(AccumuloElementConverter.class);
final Key key = mock(Key.class);
final List<Value> values = Arrays.asList(mock(Value.class), mock(Value.class));
final Reducer.Context context = mock(Reducer.Context.class);
final Configuration conf = mock(Configuration.class);
final Schema schema = new Schema.Builder().edge(TestGroups.ENTITY, new SchemaEdgeDefinition()).build();
final ByteSequence colFamData = mock(ByteSequence.class);
final byte[] colFam = StringUtil.toBytes(TestGroups.ENTITY);
given(context.nextKey()).willReturn(true, false);
given(context.getCurrentKey()).willReturn(key);
given(context.getValues()).willReturn(values);
given(context.getConfiguration()).willReturn(conf);
given(context.getCounter(any(), any())).willReturn(mock(Counter.class));
given(conf.get(SCHEMA)).willReturn(StringUtil.toString(schema.toCompactJson()));
given(conf.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS)).willReturn(MockAccumuloElementConverter.class.getName());
given(colFamData.getBackingArray()).willReturn(colFam);
given(key.getColumnFamilyData()).willReturn(colFamData);
given(MockAccumuloElementConverter.mock.getGroupFromColumnFamily(colFam)).willReturn(TestGroups.ENTITY);
final AccumuloKeyValueReducer reducer = new AccumuloKeyValueReducer();
// When
reducer.run(context);
// Then
verify(MockAccumuloElementConverter.mock, times(1)).getGroupFromColumnFamily(colFam);
}
Aggregations