Search in sources :

Example 51 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class AbstractExamplesFactoryTest method shouldUseSchemaToCreateGetElementsInput.

@Test
public void shouldUseSchemaToCreateGetElementsInput() throws InstantiationException, IllegalAccessException {
    // Given
    TestExamplesFactory examplesFactory = new TestExamplesFactory(SCHEMA);
    // When
    GetElements operation = (GetElements) examplesFactory.generateExample(GetElements.class);
    // Then
    int size = 0;
    for (ElementId e : operation.getInput()) {
        size++;
        if (e instanceof EntityId) {
            assertEquals(String.class, ((EntityId) e).getVertex().getClass());
        } else {
            assertEquals(String.class, ((EdgeId) e).getDestination().getClass());
            assertEquals(String.class, ((EdgeId) e).getSource().getClass());
        }
    }
    assertEquals(2, size);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 52 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class GetElementsInRangesTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    // Given
    final Pair<ElementId, ElementId> seed = new Pair<>(AccumuloTestData.SEED_A, AccumuloTestData.SEED_B);
    final View view = new View.Builder().edge("testEdgeGroup").build();
    final GetElementsInRanges getElementsInRanges = new GetElementsInRanges.Builder().inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.EITHER).input(seed).directedType(DirectedType.UNDIRECTED).option(AccumuloTestData.TEST_OPTION_PROPERTY_KEY, "true").view(view).build();
    // When
    final GetElementsInRanges clone = getElementsInRanges.shallowClone();
    // Then
    assertNotSame(getElementsInRanges, clone);
    assertEquals("true", clone.getOption(AccumuloTestData.TEST_OPTION_PROPERTY_KEY));
    assertEquals(SeededGraphFilters.IncludeIncomingOutgoingType.EITHER, clone.getIncludeIncomingOutGoing());
    assertEquals(DirectedType.UNDIRECTED, clone.getDirectedType());
    assertThat(clone.getInput().iterator().next()).isEqualTo(seed);
    assertEquals(view, clone.getView());
}
Also used : View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 53 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class SummariseGroupOverRangesTest method shouldShallowCloneOperation.

@Test
@Override
public void shouldShallowCloneOperation() {
    // Given
    final Pair<ElementId, ElementId> seed = new Pair<>(AccumuloTestData.SEED_A, AccumuloTestData.SEED_B);
    final View view = new View.Builder().edge("testEdgeGroup").build();
    final SummariseGroupOverRanges summariseGroupOverRanges = new SummariseGroupOverRanges.Builder().inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.EITHER).input(seed).directedType(DirectedType.UNDIRECTED).option(AccumuloTestData.TEST_OPTION_PROPERTY_KEY, "true").view(view).build();
    // When
    final SummariseGroupOverRanges clone = summariseGroupOverRanges.shallowClone();
    // Then
    assertNotSame(summariseGroupOverRanges, clone);
    assertEquals("true", clone.getOption(AccumuloTestData.TEST_OPTION_PROPERTY_KEY));
    assertEquals(SeededGraphFilters.IncludeIncomingOutgoingType.EITHER, clone.getIncludeIncomingOutGoing());
    assertEquals(DirectedType.UNDIRECTED, clone.getDirectedType());
    assertThat(clone.getInput().iterator().next()).isEqualTo(seed);
    assertEquals(view, clone.getView());
}
Also used : View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 54 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testUndirectedEdgeIdQueries.

private void testUndirectedEdgeIdQueries(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever<?> retriever = null;
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    operation.setDirectedType(DirectedType.UNDIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever<>(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("B", edge.getDestination());
    }
    // We should have only 1000 returned the i-B edges that are undirected
    assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Example 55 with ElementId

use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEdgesOnly.

private void testEntityIdQueryEdgesOnly(final AccumuloStore store) throws StoreException {
    setupGraph(store, NUM_ENTRIES);
    final User user = new User();
    // Create set to query for
    final Set<ElementId> ids = new HashSet<>();
    for (int i = 0; i < NUM_ENTRIES; i++) {
        ids.add(new EntitySeed("" + i));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (final IteratorSettingException e) {
        throw new RuntimeException(e);
    }
    // Should find both i-B and i-C edges.
    assertEquals(NUM_ENTRIES * 2, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Aggregations

ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)58 Test (org.junit.jupiter.api.Test)32 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)29 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)19 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)19 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)17 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)14 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)14 HashSet (java.util.HashSet)11 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 User (uk.gov.gchq.gaffer.user.User)9 ArrayList (java.util.ArrayList)7 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)7 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)7 Test (org.junit.Test)6 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)5 Key (org.apache.accumulo.core.data.Key)4