package com.tinkerpop.blueprints;

import com.tinkerpop.blueprints.util.GraphFactory;
import org.junit.Test;

import java.lang.reflect.Modifier;
import java.util.Arrays;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
 * @author Stephen Mallette (http://stephen.genoprime.com)
 */
public class GraphTest extends AbstractBlueprintsTest {

    /**
     * All Blueprints implementations should be constructable through GraphFactory.
     */
    @Test
    public void shouldOpenInMemoryGraphViaApacheConfig() {
        final Graph expectedGraph = g;
        final Graph createdGraph = GraphFactory.open(config);

        assertNotNull(createdGraph);
        assertEquals(expectedGraph.getClass(), createdGraph.getClass());
    }

    /**
     * Blueprints implementations should have private constructor as all graphs.  They should be only instantiated
     * through the GraphFactory or the static open() method on the Graph implementation itself.
     */
    @Test
    public void shouldHavePrivateConstructor() {
        assertTrue(Arrays.asList(g.getClass().getConstructors()).stream().allMatch(c -> {
            final int modifier = c.getModifiers();
            return Modifier.isPrivate(modifier) || Modifier.isPrivate(modifier);
        }));
    }

    /**
     * Test graph counts with addition and removal of vertices.
     */
    @Test
    public void shouldCountVerticesAndEdgesInTheGraph() {
        BlueprintsSuite.assertVertexEdgeCounts(g, 0, 0);
        final Vertex v = g.addVertex();
        BlueprintsSuite.assertVertexEdgeCounts(g, 1, 0);
        assertEquals(v, g.query().vertices().iterator().next());
        assertEquals(v.getId(), g.query().vertices().iterator().next().getId());
        assertEquals(v.getLabel(), g.query().vertices().iterator().next().getLabel());
        v.remove();
        BlueprintsSuite.assertVertexEdgeCounts(g, 0, 0);
        g.addVertex();
        g.addVertex();
        BlueprintsSuite.assertVertexEdgeCounts(g, 2, 0);
        g.query().vertices().forEach(Vertex::remove);
        BlueprintsSuite.assertVertexEdgeCounts(g, 0, 0);
    }
}

@@ -133,39 +133,216 @@
 ct.M
-odifier;%0Aimport java.util.Array
+ethod;%0Aimport java.lang.reflect.Modifier;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0Aimport java.util.stream.Collector;%0Aimport java.util.stream.Collector
 s;%0A%0A
@@ -474,16 +474,53 @@
 ertTrue;
+%0Aimport static org.junit.Assert.fail;
 %0A%0A/**%0A *
@@ -1545,32 +1545,1241 @@
     %7D));%0A    %7D%0A%0A
+    /**%0A     * Ensure compliance with Features by checking that all Features are exposed by the implementation.%0A     */%0A    @Test%0A    public void shouldImplementAndExposeFeatures() %7B%0A        final Graph.Features features = g.getFeatures();%0A        assertNotNull(features);%0A%0A        final AtomicInteger counter = new AtomicInteger(0);%0A%0A        // get all features.%0A        final List%3CMethod%3E methods = Arrays.asList(Graph.Features.class.getMethods()).stream()%0A                .filter(m -%3E m.getReturnType().equals(Graph.Features.FeatureSet.class))%0A                .collect(Collectors.toList());%0A%0A        methods.forEach(m -%3E %7B%0A                    try %7B%0A                        assertNotNull(m.invoke(features));%0A                        counter.incrementAndGet();%0A                    %7D catch (Exception ex) %7B%0A                        ex.printStackTrace();%0A                        fail(%22Exception while dynamically checking compliance on Feature implementation%22);%0A                    %7D%0A                %7D);%0A%0A        // always should be some feature methods%0A        assertTrue(methods.size() %3E 0);%0A%0A        // ensure that every method exposed was checked%0A        assertEquals(methods.size(), counter.get());%0A    %7D%0A%0A
     /**%0A     * T

Validate compliance with Features in Blueprints Test Suite.