@Test
  @TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
  public void testFilteringIdentifiers() throws OperationException {
    // Given
    final List<ElementSeed> seeds = Collections.singletonList((ElementSeed) new EntitySeed("A3"));

    final GetRelatedElements<ElementSeed, Element> getElementsWithoutFiltering =
        new GetRelatedElements.Builder<>().seeds(seeds).build();

    final GetRelatedElements<ElementSeed, Element> getElementsWithFiltering =
        new GetRelatedElements.Builder<>()
            .seeds(seeds)
            .view(
                new View.Builder()
                    .entity(TestGroups.ENTITY)
                    .edge(
                        TestGroups.EDGE,
                        new ViewElementDefinition.Builder()
                            .preAggregationFilter(
                                new ElementFilter.Builder()
                                    .select(IdentifierType.DESTINATION)
                                    .execute(new IsEqual("B3"))
                                    .build())
                            .build())
                    .build())
            .build();

    // When - without filtering
    final List<Element> resultsWithoutFiltering =
        Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));

    // When - with filtering
    final List<Element> resultsWithFiltering =
        Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));

    // Then - without filtering
    assertNotNull(resultsWithoutFiltering);
    assertEquals(5, resultsWithoutFiltering.size());
    assertThat(
        resultsWithoutFiltering,
        IsCollectionContaining.hasItems(
            getEdge("A3", "A3", false),
            getEdge("A3", "B3", false),
            getEdge("A3", "C3", false),
            getEdge("A3", "D3", false),
            getEntity("A3")));

    // Then - with filtering
    assertNotNull(resultsWithFiltering);
    assertEquals(2, resultsWithFiltering.size());
    assertThat(
        resultsWithFiltering,
        IsCollectionContaining.hasItems(getEdge("A3", "B3", false), getEntity("A3")));
  }
  private void verifyResults(final CloseableIterable<String> resultsItr) {
    final String[] expectedResults = {"2,3,1", "3,1,1", "3,4,1", "4,1,2", "4,2,1"};

    final List<String> results = Lists.newArrayList(resultsItr);
    assertEquals(expectedResults.length, results.size());
    assertThat(results, IsCollectionContaining.hasItems(expectedResults));
  }
 @Test
 public void testAddingCacheEventListenerConfigurationAtCacheLevel() {
   CacheManagerBuilder<CacheManager> cacheManagerBuilder =
       CacheManagerBuilder.newCacheManagerBuilder();
   CacheEventListenerConfiguration cacheEventListenerConfiguration =
       CacheEventListenerConfigurationBuilder.newEventListenerConfiguration(
               ListenerObject.class, EventType.CREATED)
           .unordered()
           .asynchronous()
           .build();
   CacheManager cacheManager = cacheManagerBuilder.build(true);
   final Cache<Long, String> cache =
       cacheManager.createCache(
           "cache",
           CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class)
               .add(cacheEventListenerConfiguration)
               .withResourcePools(
                   ResourcePoolsBuilder.newResourcePoolsBuilder()
                       .heap(100, EntryUnit.ENTRIES)
                       .build())
               .build());
   Collection<ServiceConfiguration<?>> serviceConfiguration =
       cache.getRuntimeConfiguration().getServiceConfigurations();
   assertThat(
       serviceConfiguration,
       IsCollectionContaining.<ServiceConfiguration<?>>hasItem(
           instanceOf(DefaultCacheEventListenerConfiguration.class)));
   cacheManager.close();
 }
 /**
  * Tests {@link ProjectConfigurationScript#setCommands(List)} and {@link
  * ProjectConfigurationScript#getCommandList()}.
  */
 @Test
 public void testSetGetCommands() {
   final List<IProjectConfigurationCommand> commands =
       Arrays.asList(
           (IProjectConfigurationCommand)
               new CommentProjectConfigurationCommand(null, null, "plugin1", null),
           (IProjectConfigurationCommand)
               new CommentProjectConfigurationCommand(null, null, "plugin2", null));
   this.script.setCommands(commands);
   assertThat(this.script.getCommandList().size(), Is.is(2));
   assertThat(
       this.script.getCommandList(), IsCollectionContaining.hasItem(hasPluginId("plugin1")));
 }
  @Test
  public void shouldGetAllElementsWithFilterWithoutSummarisation() throws Exception {
    final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
    edge1.putProperty(TestPropertyNames.INT, 100);
    edge1.putProperty(TestPropertyNames.COUNT, 1L);

    final Edge edge2 = edge1.emptyClone();
    edge2.putProperty(TestPropertyNames.INT, 101);
    edge2.putProperty(TestPropertyNames.COUNT, 1L);

    graph.execute(
        new AddElements.Builder().elements(Arrays.asList((Element) edge1, edge2)).build(),
        getUser());

    final GetAllElements<Element> op =
        new GetAllElements.Builder<>()
            .view(
                new View.Builder()
                    .edge(
                        TestGroups.EDGE,
                        new ViewElementDefinition.Builder()
                            .preAggregationFilter(
                                new ElementFilter.Builder()
                                    .select(TestPropertyNames.INT)
                                    .execute(new IsIn(Arrays.asList((Object) 100, 101)))
                                    .build())
                            .build())
                    .build())
            .build();

    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());

    // Then
    final List<Element> resultList = Lists.newArrayList(results);
    assertEquals(2, resultList.size());
    assertThat(resultList, IsCollectionContaining.hasItems((Element) edge1, edge2));
  }
  @Test
  @TraitRequirement(StoreTrait.POST_AGGREGATION_FILTERING)
  public void testPostAggregationFilteringProperties() throws OperationException {
    // Given
    final List<ElementSeed> seeds =
        Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));

    final GetRelatedElements<ElementSeed, Element> getElementsWithoutFiltering =
        new GetRelatedElements.Builder<>().seeds(seeds).build();

    final GetRelatedElements<ElementSeed, Element> getElementsWithFiltering =
        new GetRelatedElements.Builder<>()
            .seeds(seeds)
            .view(
                new View.Builder()
                    .entity(
                        TestGroups.ENTITY,
                        new ViewElementDefinition.Builder()
                            .postAggregationFilter(
                                new ElementFilter.Builder()
                                    .select(IdentifierType.VERTEX)
                                    .execute(new IsEqual("A5"))
                                    .build())
                            .build())
                    .edge(
                        TestGroups.EDGE,
                        new ViewElementDefinition.Builder()
                            .postAggregationFilter(
                                new ElementFilter.Builder()
                                    .select(TestPropertyNames.INT)
                                    .execute(new IsLessThan(2))
                                    .build())
                            .build())
                    .build())
            .build();

    // When - without filtering
    final List<Element> resultsWithoutFiltering =
        Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));

    // When - with filtering
    final List<Element> resultsWithFiltering =
        Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));

    // Then - without filtering
    assertNotNull(resultsWithoutFiltering);
    assertEquals(8, resultsWithoutFiltering.size());
    assertThat(
        resultsWithoutFiltering,
        IsCollectionContaining.hasItems(
            getEdge("A3", "A3", false),
            getEdge("A3", "B3", false),
            getEdge("A3", "C3", false),
            getEdge("A3", "D3", false),
            getEdge("A5", "B5", false),
            getEntity("A5"),
            getEntity("B5")));

    // Then - with filtering
    assertNotNull(resultsWithFiltering);
    assertEquals(6, resultsWithFiltering.size());
    assertThat(
        resultsWithFiltering,
        IsCollectionContaining.hasItems(
            getEdge("A3", "A3", false),
            getEdge("A3", "B3", false),
            getEdge("A5", "B5", false),
            getEdge("A3", "D3", false),
            getEdge("A3", "C3", false),
            getEntity("A5")));
  }