Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine#Type

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine#Type . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractGremlinSuite.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private void registerOptOuts(final Class<?> classWithOptOuts,
                             final Optional<GraphProvider.Descriptor> graphProviderDescriptor,
                             final TraversalEngine.Type traversalEngineType) throws InitializationError {
    // don't get why getAnnotationsByType() refuses to pick up OptOuts on the superclass. doing it manually and
    // only for the immediate superclass for now
    final List<Graph.OptOut> optOuts = getAllOptOuts(classWithOptOuts);

    if (!optOuts.isEmpty()) {
        // validate annotation - test class and reason must be set
        if (!optOuts.stream().allMatch(ignore -> ignore.test() != null && ignore.reason() != null && !ignore.reason().isEmpty()))
            throw new InitializationError("Check @IgnoreTest annotations - all must have a 'test' and 'reason' set");

        try {
            final Graph.OptOut[] oos = new Graph.OptOut[optOuts.size()];
            optOuts.toArray(oos);
            filter(new OptOutTestFilter(oos, graphProviderDescriptor, traversalEngineType));
        } catch (NoTestsRemainException ex) {
            throw new InitializationError(ex);
        }
    }
}
 
Example 2
Source File: AbstractGremlinSuite.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a Gremlin Test Suite implementation.
 *
 * @param klass               Required for JUnit Suite construction
 * @param builder             Required for JUnit Suite construction
 * @param testsToExecute      The list of tests to execute
 * @param testsToEnforce      The list of tests to "enforce" such that a check is made to ensure that in this list,
 *                            there exists an implementation in the testsToExecute (use {@code null} for no
 *                            enforcement).
 * @param gremlinFlavorSuite  Ignore validation of {@link Graph.OptIn} annotations which is typically reserved for structure tests
 * @param traversalEngineType The {@link TraversalEngine.Type} to enforce on this suite
 */
public AbstractGremlinSuite(final Class<?> klass, final RunnerBuilder builder, final Class<?>[] testsToExecute,
                            final Class<?>[] testsToEnforce, final boolean gremlinFlavorSuite,
                            final TraversalEngine.Type traversalEngineType) throws InitializationError {
    super(builder, klass, enforce(testsToExecute, testsToEnforce));

    this.gremlinFlavorSuite = gremlinFlavorSuite;

    // figures out what the implementer assigned as the GraphProvider class and make it available to tests.
    // the klass is the Suite that implements this suite (e.g. GroovyTinkerGraphProcessStandardTest).
    // this class should be annotated with GraphProviderClass.  Failure to do so will toss an InitializationError
    final Pair<Class<? extends GraphProvider>, Class<? extends Graph>> pair = getGraphProviderClass(klass);

    // the GraphProvider.Descriptor is only needed right now if the test if for a computer engine - an
    // exception is thrown if it isn't present.
    final Optional<GraphProvider.Descriptor> graphProviderDescriptor = getGraphProviderDescriptor(traversalEngineType, pair.getValue0());

    // validate public acknowledgement of the test suite and filter out tests ignored by the implementation
    validateOptInToSuite(pair.getValue1());
    validateOptInAndOutAnnotations(pair.getValue0());
    validateOptInAndOutAnnotations(pair.getValue1());

    registerOptOuts(pair.getValue0(), graphProviderDescriptor, traversalEngineType);
    registerOptOuts(pair.getValue1(), graphProviderDescriptor, traversalEngineType);

    try {
        final GraphProvider graphProvider = pair.getValue0().newInstance();
        GraphManager.setGraphProvider(graphProvider);
        GraphManager.setTraversalEngineType(traversalEngineType);
    } catch (Exception ex) {
        throw new InitializationError(ex);
    }
}
 
Example 3
Source File: AbstractGremlinSuite.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private Optional<GraphProvider.Descriptor> getGraphProviderDescriptor(final TraversalEngine.Type traversalEngineType,
                                                                      final Class<? extends GraphProvider> klass) throws InitializationError {
    final GraphProvider.Descriptor descriptorAnnotation = klass.getAnnotation(GraphProvider.Descriptor.class);
    if (traversalEngineType == TraversalEngine.Type.COMPUTER) {
        // can't be null if this is graph computer business
        if (null == descriptorAnnotation)
            throw new InitializationError(String.format("For 'computer' tests, '%s' must have a GraphProvider.Descriptor annotation", klass.getName()));
    }

    return Optional.ofNullable(descriptorAnnotation);
}
 
Example 4
Source File: AbstractGremlinSuite.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public OptOutTestFilter(final Graph.OptOut[] optOuts,
                        final Optional<GraphProvider.Descriptor> graphProviderDescriptor,
                        final TraversalEngine.Type traversalEngineType) {
    this.graphProviderDescriptor = graphProviderDescriptor;
    this.traversalEngineType = traversalEngineType;

    // split the tests to filter into two groups - true represents those that should ignore a whole
    final Map<Boolean, List<Graph.OptOut>> split = Arrays.stream(optOuts)
            .filter(this::checkGraphProviderDescriptorForComputer)
            .collect(Collectors.groupingBy(optOut -> optOut.method().equals("*")));

    final List<Graph.OptOut> optOutsOfIndividualTests = split.getOrDefault(Boolean.FALSE, Collections.emptyList());
    individualSpecificTestsToIgnore = optOutsOfIndividualTests.stream()
            .filter(ignoreTest -> !ignoreTest.method().equals("*"))
            .filter(allowAbstractMethod(false))
            .<Pair>map(ignoreTest -> Pair.with(ignoreTest.test(), ignoreTest.specific().isEmpty() ? ignoreTest.method() : String.format("%s[%s]", ignoreTest.method(), ignoreTest.specific())))
            .<Description>map(p -> Description.createTestDescription(p.getValue0().toString(), p.getValue1().toString()))
            .collect(Collectors.toList());

    testGroupToIgnore = optOutsOfIndividualTests.stream()
            .filter(ignoreTest -> !ignoreTest.method().equals("*"))
            .filter(allowAbstractMethod(true))
            .<Pair>map(ignoreTest -> Pair.with(ignoreTest.test(), ignoreTest.specific().isEmpty() ? ignoreTest.method() : String.format("%s[%s]", ignoreTest.method(), ignoreTest.specific())))
            .<Description>map(p -> Description.createTestDescription(p.getValue0().toString(), p.getValue1().toString()))
            .collect(Collectors.toList());

    entireTestCaseToIgnore = split.getOrDefault(Boolean.TRUE, Collections.emptyList());
}
 
Example 5
Source File: GraphManager.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static TraversalEngine.Type setTraversalEngineType(final TraversalEngine.Type traversalEngine) {
    final TraversalEngine.Type old = GraphManager.traversalEngineType;
    GraphManager.traversalEngineType = traversalEngine;
    return old;
}
 
Example 6
Source File: GraphManager.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static TraversalEngine.Type getTraversalEngineType() {
    return traversalEngineType;
}