Class ProctorUtils


  • public abstract class ProctorUtils
    extends java.lang.Object
    Helper functions mostly to verify TestMatrix instances.
    • Field Detail

      • UNITLESS_ALLOCATION_IDENTIFIER

        public static final java.lang.String UNITLESS_ALLOCATION_IDENTIFIER
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProctorUtils

        public ProctorUtils()
    • Method Detail

      • createMessageDigest

        public static java.security.MessageDigest createMessageDigest()
      • convertToValueExpressionMap

        @Nonnull
        public static java.util.Map<java.lang.String,​javax.el.ValueExpression> convertToValueExpressionMap​(@Nonnull
                                                                                                                 javax.el.ExpressionFactory expressionFactory,
                                                                                                                 @Nonnull
                                                                                                                 java.util.Map<java.lang.String,​java.lang.Object> values)
      • convertConstantsToValueExpressionMap

        @Nonnull
        public static java.util.Map<java.lang.String,​javax.el.ValueExpression> convertConstantsToValueExpressionMap​(@Nonnull
                                                                                                                          javax.el.ExpressionFactory expressionFactory,
                                                                                                                          @Nonnull
                                                                                                                          java.util.Map<java.lang.String,​java.lang.Object> values)
      • convertToArtifact

        public static java.lang.String convertToArtifact​(@Nonnull
                                                         TestMatrixVersion testMatrix)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeArtifact

        @Deprecated
        public static void serializeArtifact​(java.io.Writer writer,
                                             TestMatrixArtifact artifact)
                                      throws java.io.IOException
        Deprecated.
        Use serialization library like jackson
        Throws:
        java.io.IOException
      • serializeArtifact

        @Deprecated
        public static void serializeArtifact​(com.fasterxml.jackson.core.JsonGenerator jsonGenerator,
                                             Proctor proctor)
                                      throws java.io.IOException
        Deprecated.
        Use serialization library like jackson
        Throws:
        java.io.IOException
      • serializeTestDefinition

        @Deprecated
        public static void serializeTestDefinition​(java.io.Writer writer,
                                                   TestDefinition definition)
                                            throws java.io.IOException
        Deprecated.
        Use serialization library like jackson
        Throws:
        java.io.IOException
      • readJsonFromFile

        @Deprecated
        public static com.fasterxml.jackson.databind.JsonNode readJsonFromFile​(java.io.File input)
                                                                        throws java.io.IOException
        Deprecated.
        Use serialization library like jackson
        Throws:
        java.io.IOException
      • serializeTestSpecification

        @Deprecated
        public static void serializeTestSpecification​(java.io.Writer writer,
                                                      TestSpecification specification)
                                               throws java.io.IOException
        Deprecated.
        Use serialization library like jackson
        Throws:
        java.io.IOException
      • readSpecification

        public static ProctorSpecification readSpecification​(java.io.File inputFile)
      • readSpecification

        public static ProctorSpecification readSpecification​(java.io.InputStream inputFile)
      • verifyAndConsolidate

        public static ProctorLoadResult verifyAndConsolidate​(@Nonnull
                                                             TestMatrixArtifact testMatrix,
                                                             java.lang.String matrixSource,
                                                             @Nonnull
                                                             java.util.Map<java.lang.String,​TestSpecification> requiredTests,
                                                             @Nonnull
                                                             javax.el.FunctionMapper functionMapper)
        Verifies that the TestMatrix is compatible with all the required tests. Removes non-required tests from the TestMatrix Replaces invalid or missing tests (buckets are not compatible) with default implementation returning the fallback value see defaultFor
        Parameters:
        testMatrix - the TestMatrixArtifact to be verified.
        matrixSource - a String of the source of proctor artifact. For example, a path of proctor artifact file.
        requiredTests - a Map of required test. The TestSpecification would be verified
        functionMapper - a given el FunctionMapper
        Returns:
        a ProctorLoadResult to describe the result of verification. It contains errors of verification and a list of missing test.
      • verifyAndConsolidate

        public static ProctorLoadResult verifyAndConsolidate​(@Nonnull
                                                             TestMatrixArtifact testMatrix,
                                                             java.lang.String matrixSource,
                                                             @Nonnull
                                                             java.util.Map<java.lang.String,​TestSpecification> requiredTests,
                                                             @Nonnull
                                                             javax.el.FunctionMapper functionMapper,
                                                             ProvidedContext providedContext,
                                                             @Nonnull
                                                             java.util.Set<java.lang.String> dynamicTests)
        Parameters:
        testMatrix - will be modified by removing unused tests and adding missing tests
      • verifyWithoutSpecification

        public static ProctorLoadResult verifyWithoutSpecification​(@Nonnull
                                                                   TestMatrixArtifact testMatrix,
                                                                   java.lang.String matrixSource)
        Verifies that the TestMatrix is correct and sane without using a specification. The Proctor API doesn't use a test specification so that it can serve all tests in the matrix without restriction. Does a limited set of sanity checks that are applicable when there is no specification, and thus no required tests or provided context.
        Parameters:
        testMatrix - the TestMatrixArtifact to be verified.
        matrixSource - a String of the source of proctor artifact. For example, a path of proctor artifact file.
        Returns:
        a ProctorLoadResult to describe the result of verification. It contains errors of verification and a list of missing test.
      • verify

        public static ProctorLoadResult verify​(@Nonnull
                                               TestMatrixArtifact testMatrix,
                                               java.lang.String matrixSource,
                                               @Nonnull
                                               java.util.Map<java.lang.String,​TestSpecification> requiredTests)
        verify with default function mapper and empty context and no dynamic tests
      • verify

        public static ProctorLoadResult verify​(@Nonnull
                                               TestMatrixArtifact testMatrix,
                                               java.lang.String matrixSource,
                                               @Nonnull
                                               java.util.Map<java.lang.String,​TestSpecification> requiredTests,
                                               @Nonnull
                                               java.util.Set<java.lang.String> dynamicTests)
        verify with default function mapper and empty context
      • verify

        public static ProctorLoadResult verify​(@Nonnull
                                               TestMatrixArtifact testMatrix,
                                               java.lang.String matrixSource,
                                               @Nonnull
                                               java.util.Map<java.lang.String,​TestSpecification> requiredTests,
                                               @Nonnull
                                               javax.el.FunctionMapper functionMapper,
                                               ProvidedContext providedContext)
        verify with default function mapper and no dynamic tests
      • verify

        public static ProctorLoadResult verify​(@Nonnull
                                               TestMatrixArtifact testMatrix,
                                               java.lang.String matrixSource,
                                               @Nonnull
                                               java.util.Map<java.lang.String,​TestSpecification> requiredTests,
                                               @Nonnull
                                               javax.el.FunctionMapper functionMapper,
                                               ProvidedContext providedContext,
                                               @Nonnull
                                               java.util.Set<java.lang.String> dynamicTests)
        Does not mutate the TestMatrix. Verifies that the test matrix contains all the required tests and that each required test is valid.
        Parameters:
        testMatrix - the TestMatrixArtifact to be verified.
        matrixSource - a String of the source of proctor artifact. For example, a path of proctor artifact file.
        requiredTests - a Map of required test. The TestSpecification would be verified
        functionMapper - a given el FunctionMapper
        providedContext - a Map containing variables describing the context in which the request is executing. These will be supplied to verifying all rules.
        dynamicTests - a Set of dynamic tests determined by filters.
        Returns:
        a ProctorLoadResult to describe the result of verification. It contains errors of verification and a list of missing test.
      • verifyRequiredTest

        public static void verifyRequiredTest​(@Nonnull
                                              java.lang.String testName,
                                              @Nonnull
                                              ConsumableTestDefinition testDefinition,
                                              @Nonnull
                                              TestSpecification testSpecification,
                                              @Nonnull
                                              java.lang.String matrixSource,
                                              @Nonnull
                                              javax.el.FunctionMapper functionMapper,
                                              ProvidedContext providedContext)
                                       throws IncompatibleTestMatrixException
        Verifies that a single required test is valid against TestSpecification and FunctionMapper and ProvidedContext.
        Parameters:
        testName - the name of the test
        testDefinition - ConsumableTestDefinition of the test
        testSpecification - TestSpecification defined in an application for the test
        matrixSource - a String of the source of proctor artifact. For example, a path of proctor artifact file.
        functionMapper - a given el FunctionMapper
        providedContext - a Map containing variables describing the context in which the request is executing. These will be supplied to verifying all rules.
        Throws:
        IncompatibleTestMatrixException - if validation is failed.
      • verifyDynamicTest

        public static void verifyDynamicTest​(@Nonnull
                                             java.lang.String testName,
                                             @Nonnull
                                             ConsumableTestDefinition testDefinition,
                                             @Nonnull
                                             java.lang.String matrixSource,
                                             @Nonnull
                                             javax.el.FunctionMapper functionMapper,
                                             ProvidedContext providedContext)
                                      throws IncompatibleTestMatrixException
        Verifies that a single dynamic test is valid against FunctionMapper and ProvidedContext.
        Parameters:
        testName - the name of the test
        testDefinition - ConsumableTestDefinition of the test
        matrixSource - a String of the source of proctor artifact. For example, a path of proctor artifact file.
        functionMapper - a given el FunctionMapper
        providedContext - a Map containing variables describing the context in which the request is executing. These will be supplied to verifying all rules.
        Throws:
        IncompatibleTestMatrixException - if validation is failed.
      • convertContextToTestableMap

        public static ProvidedContext convertContextToTestableMap​(java.util.Map<java.lang.String,​java.lang.String> providedContext)
      • convertContextToTestableMap

        public static ProvidedContext convertContextToTestableMap​(java.util.Map<java.lang.String,​java.lang.String> providedContext,
                                                                  java.util.Map<java.lang.String,​java.lang.Object> ruleVerificationContext)
      • generateSpecification

        @Deprecated
        public static TestSpecification generateSpecification​(@Nonnull
                                                              TestDefinition testDefinition)
        Deprecated.
        use SpecificationGenerator
        Generates a usable test specification for a given test definition Uses the bucket with smallest value as the fallback value
        Parameters:
        testDefinition - a TestDefinition
        Returns:
        a TestSpecification which corresponding to given test definition.
      • removeElExpressionBraces

        @CheckForNull
        public static java.lang.String removeElExpressionBraces​(@Nullable
                                                                java.lang.String rule)
        Removes the expression braces "${ ... }" surrounding the rule.
        Parameters:
        rule - a given rule String.
        Returns:
        the given rule with the most outside braces stripped
      • containsUnitlessAllocation

        public static boolean containsUnitlessAllocation​(@Nonnull
                                                         TestDefinition testDefinition)