org.apache.tinkerpop.gremlin

## Class TestHelper

- java.lang.Object
- - org.apache.tinkerpop.gremlin.TestHelper

-     public final class TestHelper
      extends Object

  Utility methods for test development.
  Author:
    Stephen Mallette (http://stephen.genoprime.com)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `TEST_DATA_RELATIVE_DIR`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `assumeNonDeterministic()` Used at the start of a test to make it one that should only be executed when the `assertNonDeterministic` system property is set to `true`.
    `static String` | `cleanPathSegment(String toClean)` Removes characters that aren't acceptable in a file path (mostly for windows).
    `static String` | `convertPackageToResourcePath(Class clazz)` Takes a class and converts its package name to a path that can be used to access a resource in that package.
    `static String` | `convertToRelative(Class clazz, File f)`
    `static void` | `createRandomGraph(Graph graph, int numberOfVertices, int maxNumberOfEdgesPerVertex)`
    `static File` | `generateTempFile(Class clazz, String fileName, String fileNameSuffix)` Creates a `File` reference in the path returned from `makeTestDataPath(java.lang.Class, java.lang.String...)` in a subdirectory called `temp`.
    `static File` | `generateTempFileFromResource(Class graphClass, Class resourceClass, String resourceName, String extension)` Copies a file stored as part of a resource to the file system in the path returned from `makeTestDataPath(java.lang.Class, java.lang.String...)` in a subdirectory called `temp/resources`.
    `static File` | `generateTempFileFromResource(Class resourceClass, String resourceName, String extension)` Copies a file stored as part of a resource to the file system in the path returned from `makeTestDataPath(java.lang.Class, java.lang.String...)` in a subdirectory called `temp/resources`.
    `static File` | `getRootOfBuildDirectory(Class clazz)` Gets and/or creates the root of the test data directory.
    `static String` | `makeTestDataDirectory(Class clazz, String... childPath)` Internally calls `makeTestDataPath(Class, String...)` but returns the path as a string with the system separator appended to the end.
    `static File` | `makeTestDataPath(Class clazz, String... childPath)` Creates a `File` reference that points to a directory relative to the supplied class in the `/target` directory.
    `static void` | `validateEdgeEquality(Edge originalEdge, Edge otherEdge)`
    `static void` | `validateEquality(Object original, Object other)`
    `static void` | `validatePropertyEquality(Property originalProperty, Property otherProperty)`
    `static void` | `validateVertexEquality(Vertex originalVertex, Vertex otherVertex, boolean testEdges)`
    `static void` | `validateVertexPropertyEquality(VertexProperty originalVertexProperty, VertexProperty otherVertexProperty)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### TEST_DATA_RELATIVE_DIR

          public static final String TEST_DATA_RELATIVE_DIR

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### makeTestDataPath

          public static File makeTestDataPath(Class clazz,
                                              String... childPath)

      Creates a `File` reference that points to a directory relative to the supplied class in the `/target` directory. Each `childPath` passed introduces a new sub-directory and all are placed below the `TEST_DATA_RELATIVE_DIR`. For example, calling this method with "a", "b", and "c" as the `childPath` arguments would yield a relative directory like: `test-case-data/clazz/a/b/c`. It is a good idea to use the test class for the `clazz` argument so that it's easy to find the data if necessary after test execution.

    - #### convertToRelative

          public static String convertToRelative(Class clazz,
                                                 File f)

    - #### makeTestDataDirectory

          public static String makeTestDataDirectory(Class clazz,
                                                     String... childPath)

      Internally calls `makeTestDataPath(Class, String...)` but returns the path as a string with the system separator appended to the end.

    - #### getRootOfBuildDirectory

          public static File getRootOfBuildDirectory(Class clazz)

      Gets and/or creates the root of the test data directory. This method is here as a convenience and should not be used to store test data. Use `makeTestDataPath(Class, String...)` instead.

    - #### generateTempFile

          public static File generateTempFile(Class clazz,
                                              String fileName,
                                              String fileNameSuffix)
                                       throws IOException

      Creates a `File` reference in the path returned from `makeTestDataPath(java.lang.Class, java.lang.String...)` in a subdirectory called `temp`.
      Throws:
        `IOException`

    - #### generateTempFileFromResource

          public static File generateTempFileFromResource(Class resourceClass,
                                                          String resourceName,
                                                          String extension)
                                                   throws IOException

      Copies a file stored as part of a resource to the file system in the path returned from `makeTestDataPath(java.lang.Class, java.lang.String...)` in a subdirectory called `temp/resources`.
      Throws:
        `IOException`

    - #### generateTempFileFromResource

          public static File generateTempFileFromResource(Class graphClass,
                                                          Class resourceClass,
                                                          String resourceName,
                                                          String extension)
                                                   throws IOException

      Copies a file stored as part of a resource to the file system in the path returned from `makeTestDataPath(java.lang.Class, java.lang.String...)` in a subdirectory called `temp/resources`.
      Throws:
        `IOException`

    - #### convertPackageToResourcePath

          public static String convertPackageToResourcePath(Class clazz)

      Takes a class and converts its package name to a path that can be used to access a resource in that package.

    - #### cleanPathSegment

          public static String cleanPathSegment(String toClean)

      Removes characters that aren't acceptable in a file path (mostly for windows).

    - #### assumeNonDeterministic

          public static void assumeNonDeterministic()

      Used at the start of a test to make it one that should only be executed when the `assertNonDeterministic` system property is set to `true`. Tests that call this method are ones that may sometimes fail in certain environments or behave in other random ways. Usually such tests should be removed or re-worked, but there are situations where that may not be possible as there is no other good way to test the feature. In these cases, the tests won't fail a standard build. For this benefit, the downside is that the feature isn't tested as often as it would otherwise, since the `assertNonDeterministic` option is not used often and definitely not in automated builds like Travis.

    - #### validateVertexEquality

          public static void validateVertexEquality(Vertex originalVertex,
                                                    Vertex otherVertex,
                                                    boolean testEdges)

    - #### validateVertexPropertyEquality

          public static void validateVertexPropertyEquality(VertexProperty originalVertexProperty,
                                                            VertexProperty otherVertexProperty)

    - #### validatePropertyEquality

          public static void validatePropertyEquality(Property originalProperty,
                                                      Property otherProperty)

    - #### validateEdgeEquality

          public static void validateEdgeEquality(Edge originalEdge,
                                                  Edge otherEdge)

    - #### validateEquality

          public static void validateEquality(Object original,
                                              Object other)

    - #### createRandomGraph

          public static void createRandomGraph(Graph graph,
                                               int numberOfVertices,
                                               int maxNumberOfEdgesPerVertex)

Copyright © 2013–2018 Apache Software Foundation. All rights reserved.