use of uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldCreateExporter.
@Test
public void shouldCreateExporter() throws OperationException {
// Given
graphLibrary.add(GRAPH_ID + 1, SCHEMA_ID, schema, STORE_PROPS_ID, storeProperties);
final Context context = mock(Context.class);
final User user = new User();
given(context.getUser()).willReturn(user);
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).build();
final ExportToOtherGraphHandler handler = new ExportToOtherGraphHandler();
// When
OtherGraphExporter exporter = handler.createExporter(export, context, store);
// Then
assertNotNull(exporter);
TestStore.mockStore = mock(Store.class);
final Iterable elements = mock(Iterable.class);
exporter.add("key", elements);
final ArgumentCaptor<OperationChain> opChainCaptor = ArgumentCaptor.forClass(OperationChain.class);
verify(TestStore.mockStore).execute(opChainCaptor.capture(), Mockito.any(Context.class));
final List<Operation> ops = opChainCaptor.getValue().getOperations();
assertThat(ops).hasSize(1);
assertSame(elements, ((AddElements) ops.get(0)).getInput());
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> exporter.get("key")).extracting("message").isNotNull();
}
use of uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldThrowExceptionSchemaCannotBeUsedIfNotDefinedOrFound.
@Test
public void shouldThrowExceptionSchemaCannotBeUsedIfNotDefinedOrFound() {
// Given
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).storeProperties(new StoreProperties()).build();
// When / Then
final String expectedMessage = "Validation errors: \n" + String.format(GRAPH_ID_S_CANNOT_BE_CREATED_WITHOUT_DEFINED_KNOWN_S, GRAPH_ID + 1, SCHEMA_STRING);
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessage(expectedMessage);
}
use of uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldCreateNewGraphWithStoresStoreProperties.
@Test
public void shouldCreateNewGraphWithStoresStoreProperties() {
// Given
given(store.getProperties()).willReturn(storeProperties);
given(store.getGraphLibrary()).willReturn(null);
Schema schema1 = new Schema.Builder().build();
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).schema(schema1).build();
// When
Graph graph = createGraph(export);
// Then
assertEquals(GRAPH_ID + 1, graph.getGraphId());
assertEquals(schema1, graph.getSchema());
assertEquals(store.getProperties(), graph.getStoreProperties());
}
use of uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldCreateNewGraphWithParentStorePropertiesId.
@Test
public void shouldCreateNewGraphWithParentStorePropertiesId() {
// Given
StoreProperties storeProperties1 = StoreProperties.loadStoreProperties(StreamUtil.storeProps(getClass()));
graphLibrary.addOrUpdate(GRAPH_ID + 1, SCHEMA_ID, schema, STORE_PROPS_ID, storeProperties);
graphLibrary.addProperties(STORE_PROPS_ID_1, storeProperties1);
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 2).schema(schema).parentStorePropertiesId(STORE_PROPS_ID_1).build();
// When
Graph graph = createGraph(export);
// Then
assertEquals(GRAPH_ID + 2, graph.getGraphId());
assertEquals(schema, graph.getSchema());
assertEquals(storeProperties1, graph.getStoreProperties());
}
use of uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph in project Gaffer by gchq.
the class ExportToOtherGraphHandlerTest method shouldValidateParentPropsIdCannotBeUsedWithoutGraphLibrary.
@Test
public void shouldValidateParentPropsIdCannotBeUsedWithoutGraphLibrary() {
// Given
given(store.getGraphLibrary()).willReturn(null);
final ExportToOtherGraph export = new ExportToOtherGraph.Builder().graphId(GRAPH_ID + 1).parentStorePropertiesId(STORE_PROPS_ID_1).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessage(getErrorMessage(S_CANNOT_BE_USED_WITHOUT_A_GRAPH_LIBRARY, "parentStorePropertiesId"));
}
Aggregations