use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldValidateSchemaCannotBeUsedWhenGraphIdAlreadyExists.
@Test
public void shouldValidateSchemaCannotBeUsedWhenGraphIdAlreadyExists() {
// Given
graphLibrary.add(GRAPH_ID + 1, SCHEMA_ID, new Schema.Builder().edge("testEdge", new SchemaEdgeDefinition()).build(), STORE_PROPS_ID, new StoreProperties());
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).schema(new Schema()).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, SCHEMA_STRING);
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessage(expectedMessage);
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class AbstractGraphLibraryTest method shouldThrowExceptionWhenGraphIdWithDifferentSchemaExists.
@Test
public void shouldThrowExceptionWhenGraphIdWithDifferentSchemaExists() {
// Given
graphLibrary.add(TEST_GRAPH_ID, schema, storeProperties);
Schema tempSchema = new Schema.Builder().edge("testEdge", new SchemaEdgeDefinition()).build();
// When / Then
assertThatExceptionOfType(OverwritingException.class).isThrownBy(() -> graphLibrary.add(TEST_GRAPH_ID, tempSchema, storeProperties)).withMessageContaining("already exists with a different schema");
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class AggregatorIteratorTest method shouldGetGroupFromElementConverter.
@Test
public void shouldGetGroupFromElementConverter() throws IOException {
MockAccumuloElementConverter.cleanUp();
// 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 Schema schema = new Schema.Builder().edge(TestGroups.ENTITY, new SchemaEdgeDefinition()).build();
final ByteSequence colFamData = mock(ByteSequence.class);
final byte[] colFam = StringUtil.toBytes(TestGroups.ENTITY);
final SortedKeyValueIterator sortedKeyValueIterator = mock(SortedKeyValueIterator.class);
final IteratorEnvironment iteratorEnvironment = mock(IteratorEnvironment.class);
final Map<String, String> options = new HashMap();
options.put("columns", "test");
options.put(AccumuloStoreConstants.SCHEMA, new String(schema.toCompactJson()));
options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, MockAccumuloElementConverter.class.getName());
given(colFamData.getBackingArray()).willReturn(colFam);
given(key.getColumnFamilyData()).willReturn(colFamData);
given(MockAccumuloElementConverter.mock.getGroupFromColumnFamily(colFam)).willReturn(TestGroups.ENTITY);
final AggregatorIterator aggregatorIterator = new AggregatorIterator();
// When
aggregatorIterator.init(sortedKeyValueIterator, options, iteratorEnvironment);
aggregatorIterator.reduce(key, values.iterator());
// Then
verify(MockAccumuloElementConverter.mock, times(1)).getGroupFromColumnFamily(colFam);
MockAccumuloElementConverter.cleanUp();
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class TransformHandlerTest method setup.
@BeforeEach
public void setup() {
input = new ArrayList<>();
expected = new ArrayList<>();
store = mock(Store.class);
context = new Context();
handler = new TransformHandler();
schema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition()).entity(TestGroups.ENTITY, new SchemaEntityDefinition()).entity(TestGroups.ENTITY_2, new SchemaEntityDefinition()).build();
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class GraphTest method shouldRerunMultipleUpdateViewHooksToRemoveAllBlacklistedElements.
@Test
public void shouldRerunMultipleUpdateViewHooksToRemoveAllBlacklistedElements() throws OperationException {
// Given
operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).edge(TestGroups.EDGE_2).build()).build();
final UpdateViewHook first = new UpdateViewHook.Builder().blackListElementGroups(Collections.singleton(TestGroups.EDGE)).withOpAuth(Sets.newHashSet("opAuth1")).build();
final UpdateViewHook second = new UpdateViewHook.Builder().blackListElementGroups(Collections.singleton(TestGroups.EDGE_2)).withOpAuth(Sets.newHashSet("opAuth2")).build();
given(opChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(opChain.shallowClone()).willReturn(clonedOpChain);
given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(clonedOpChain.flatten()).willReturn(Arrays.asList(operation));
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition()).build());
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(first).addHook(second).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> contextCaptor1 = ArgumentCaptor.forClass(Context.class);
given(store.execute(captor.capture(), contextCaptor1.capture())).willReturn(new ArrayList<>());
User user = new User.Builder().userId("user").opAuths("opAuth1", "opAuth2").build();
// When / Then
graph.execute(opChain, user);
final List<Operation> ops = captor.getValue().getOperations();
JsonAssert.assertEquals(new View.Builder().build().toCompactJson(), ((GetElements) ops.get(0)).getView().toCompactJson());
}
Aggregations