Search in sources :

Example 21 with ExportToOtherGraph

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();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Operation(uk.gov.gchq.gaffer.operation.Operation) ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) OtherGraphExporter(uk.gov.gchq.gaffer.operation.export.graph.OtherGraphExporter) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.jupiter.api.Test)

Example 22 with ExportToOtherGraph

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);
}
Also used : ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 23 with ExportToOtherGraph

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());
}
Also used : ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.jupiter.api.Test)

Example 24 with ExportToOtherGraph

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());
}
Also used : ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) Graph(uk.gov.gchq.gaffer.graph.Graph) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 25 with ExportToOtherGraph

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"));
}
Also used : ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)25 ExportToOtherGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph)25 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)14 Schema (uk.gov.gchq.gaffer.store.schema.Schema)10 Graph (uk.gov.gchq.gaffer.graph.Graph)7 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)3 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)1 Operation (uk.gov.gchq.gaffer.operation.Operation)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 OtherGraphExporter (uk.gov.gchq.gaffer.operation.export.graph.OtherGraphExporter)1 Context (uk.gov.gchq.gaffer.store.Context)1 Store (uk.gov.gchq.gaffer.store.Store)1 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)1 User (uk.gov.gchq.gaffer.user.User)1