Search in sources :

Example 11 with SchemaEdgeDefinition

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

Example 12 with SchemaEdgeDefinition

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");
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Test(org.junit.jupiter.api.Test)

Example 13 with SchemaEdgeDefinition

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();
}
Also used : HashMap(java.util.HashMap) Schema(uk.gov.gchq.gaffer.store.schema.Schema) IteratorEnvironment(org.apache.accumulo.core.iterators.IteratorEnvironment) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) AccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.AccumuloElementConverter) MockAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.MockAccumuloElementConverter) Value(org.apache.accumulo.core.data.Value) MockAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.MockAccumuloElementConverter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Key(org.apache.accumulo.core.data.Key) ByteSequence(org.apache.accumulo.core.data.ByteSequence) Test(org.junit.jupiter.api.Test)

Example 14 with SchemaEdgeDefinition

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();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Store(uk.gov.gchq.gaffer.store.Store) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 15 with SchemaEdgeDefinition

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) UpdateViewHook(uk.gov.gchq.gaffer.graph.hook.UpdateViewHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)25 Test (org.junit.jupiter.api.Test)15 Schema (uk.gov.gchq.gaffer.store.schema.Schema)15 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)11 SchemaEntityDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition)10 Store (uk.gov.gchq.gaffer.store.Store)8 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)7 Context (uk.gov.gchq.gaffer.store.Context)7 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 UpdateViewHook (uk.gov.gchq.gaffer.graph.hook.UpdateViewHook)5 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)5 Operation (uk.gov.gchq.gaffer.operation.Operation)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 HashMap (java.util.HashMap)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)4 BeforeAll (org.junit.jupiter.api.BeforeAll)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)3 ByteSequence (org.apache.accumulo.core.data.ByteSequence)2