Class ModelTestUtils

    • Constructor Summary

      Constructors 
      Constructor Description
      ModelTestUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.jboss.dmr.ModelNode checkFailed​(org.jboss.dmr.ModelNode result)
      Checks that the operation failes
      static void checkFailedTransformedBootOperations​(ModelTestKernelServices<?> mainServices, org.jboss.as.controller.ModelVersion modelVersion, List<org.jboss.dmr.ModelNode> operations, FailedOperationTransformationConfig config)
      A standard test for transformers where things should be rejected.
      static void checkModelAgainstDefinition​(org.jboss.dmr.ModelNode model, org.jboss.as.controller.registry.ManagementResourceRegistration rr)  
      static org.jboss.dmr.ModelNode checkOutcome​(org.jboss.dmr.ModelNode result)
      Checks that the result was successful
      static org.jboss.dmr.ModelNode checkResultAndGetContents​(org.jboss.dmr.ModelNode result)
      Checks that the result was successful and gets the real result contents
      static void compare​(org.jboss.dmr.ModelNode node1, org.jboss.dmr.ModelNode node2)
      Compares two models to make sure that they are the same
      static void compare​(org.jboss.dmr.ModelNode node1, org.jboss.dmr.ModelNode node2, boolean ignoreUndefined)
      Compares two models to make sure that they are the same
      static void compareXml​(String original, String marshalled)
      Validate the marshalled xml without adjusting the namespaces for the original and marshalled xml.
      static void compareXml​(String original, String marshalled, boolean ignoreNamespace)
      Validate the marshalled xml without adjusting the namespaces for the original and marshalled xml.
      static org.jboss.dmr.ModelNode getSubModel​(org.jboss.dmr.ModelNode model, org.jboss.as.controller.PathAddress pathAddress)  
      static org.jboss.dmr.ModelNode getSubModel​(org.jboss.dmr.ModelNode model, org.jboss.as.controller.PathElement pathElement)  
      static List<org.jboss.as.controller.PathElement> moveWildcardChildrenToEnd​(Set<org.jboss.as.controller.PathElement> children)  
      static String normalizeXML​(String xml)
      Normalize and pretty-print XML so that it can be compared using string compare.
      static String readResource​(Class<?> clazz, String name)
      Read the classpath resource with the given name and return its contents as a string.
      static void resolveAndCompareModels​(org.jboss.dmr.ModelNode node1, org.jboss.dmr.ModelNode node2)
      Resolve two models and compare them to make sure that they have same content after expression resolution
      static void scanForExpressionFormattedStrings​(org.jboss.dmr.ModelNode model)
      Scans for entries of type STRING containing expression formatted strings.
      static void validateModelDescriptions​(org.jboss.as.controller.PathAddress address, org.jboss.as.controller.registry.ImmutableManagementResourceRegistration reg)  
    • Constructor Detail

      • ModelTestUtils

        public ModelTestUtils()
    • Method Detail

      • readResource

        public static String readResource​(Class<?> clazz,
                                          String name)
                                   throws IOException
        Read the classpath resource with the given name and return its contents as a string. Hook to for reading in classpath resources for subsequent parsing. The resource is loaded using similar semantics to Class.getResource(String)
        Parameters:
        name - the name of the resource
        Returns:
        the contents of the resource as a string
        Throws:
        IOException
      • checkResultAndGetContents

        public static org.jboss.dmr.ModelNode checkResultAndGetContents​(org.jboss.dmr.ModelNode result)
        Checks that the result was successful and gets the real result contents
        Parameters:
        result - the result to check
        Returns:
        the result contents
      • checkOutcome

        public static org.jboss.dmr.ModelNode checkOutcome​(org.jboss.dmr.ModelNode result)
        Checks that the result was successful
        Parameters:
        result - the result to check
        Returns:
        the result contents
      • checkFailed

        public static org.jboss.dmr.ModelNode checkFailed​(org.jboss.dmr.ModelNode result)
        Checks that the operation failes
        Parameters:
        result - the result to check
        Returns:
        the failure desciption contents
      • validateModelDescriptions

        public static void validateModelDescriptions​(org.jboss.as.controller.PathAddress address,
                                                     org.jboss.as.controller.registry.ImmutableManagementResourceRegistration reg)
      • compare

        public static void compare​(org.jboss.dmr.ModelNode node1,
                                   org.jboss.dmr.ModelNode node2)
        Compares two models to make sure that they are the same
        Parameters:
        node1 - the first model
        node2 - the second model
      • resolveAndCompareModels

        public static void resolveAndCompareModels​(org.jboss.dmr.ModelNode node1,
                                                   org.jboss.dmr.ModelNode node2)
        Resolve two models and compare them to make sure that they have same content after expression resolution
        Parameters:
        node1 - the first model
        node2 - the second model
      • compare

        public static void compare​(org.jboss.dmr.ModelNode node1,
                                   org.jboss.dmr.ModelNode node2,
                                   boolean ignoreUndefined)
        Compares two models to make sure that they are the same
        Parameters:
        node1 - the first model
        node2 - the second model
        ignoreUndefined - true if keys containing undefined nodes should be ignored
      • normalizeXML

        public static String normalizeXML​(String xml)
                                   throws Exception
        Normalize and pretty-print XML so that it can be compared using string compare. The following code does the following: - Removes comments - Makes sure attributes are ordered consistently - Trims every element - Pretty print the document
        Parameters:
        xml - The XML to be normalized
        Returns:
        The equivalent XML, but now normalized
        Throws:
        Exception
      • compareXml

        public static void compareXml​(String original,
                                      String marshalled)
                               throws Exception
        Validate the marshalled xml without adjusting the namespaces for the original and marshalled xml.
        Parameters:
        original - the original subsystem xml
        marshalled - the marshalled subsystem xml
        Throws:
        Exception
      • compareXml

        public static void compareXml​(String original,
                                      String marshalled,
                                      boolean ignoreNamespace)
                               throws Exception
        Validate the marshalled xml without adjusting the namespaces for the original and marshalled xml.
        Parameters:
        original - the original subsystem xml
        marshalled - the marshalled subsystem xml
        ignoreNamespace - if true the subsystem's namespace is ignored, otherwise it is taken into account when comparing the normalized xml.
        Throws:
        Exception
      • getSubModel

        public static org.jboss.dmr.ModelNode getSubModel​(org.jboss.dmr.ModelNode model,
                                                          org.jboss.as.controller.PathElement pathElement)
      • getSubModel

        public static org.jboss.dmr.ModelNode getSubModel​(org.jboss.dmr.ModelNode model,
                                                          org.jboss.as.controller.PathAddress pathAddress)
      • scanForExpressionFormattedStrings

        public static void scanForExpressionFormattedStrings​(org.jboss.dmr.ModelNode model)
        Scans for entries of type STRING containing expression formatted strings. This is to trap where parsers call ModelNode.set("${A}") when ModelNode.setExpression("${A}) should have been used
        Parameters:
        model - the model to check
      • checkModelAgainstDefinition

        public static void checkModelAgainstDefinition​(org.jboss.dmr.ModelNode model,
                                                       org.jboss.as.controller.registry.ManagementResourceRegistration rr)
      • checkFailedTransformedBootOperations

        public static void checkFailedTransformedBootOperations​(ModelTestKernelServices<?> mainServices,
                                                                org.jboss.as.controller.ModelVersion modelVersion,
                                                                List<org.jboss.dmr.ModelNode> operations,
                                                                FailedOperationTransformationConfig config)
                                                         throws org.jboss.as.controller.OperationFailedException

        A standard test for transformers where things should be rejected. Takes the operations and installs them in the main controller.

        It then attempts to transform the same operations for the legacy controller, validating that expected failures take place. It then attempts to fix the operations so they can be executed in the legacy controller, since if an 'add' fails, there could be adds for children later in the list.

        Internally the operations (both for the main and legacy controllers) are added to a composite so that we have everything we need if any versions of the subsystem use capabilities and requirements. Normally this composite will contain the original operations that have been fixed by the config. This composite is then transformed before executing it in the legacy controller. However, in some extreme cases the one-shot transformation of the composite intended for the legacy controller may not be possible. For these cases you can call FailedOperationTransformationConfig.setDontTransformComposite() and the individually transformed operations get added to the composite, which is then used as-is (without any transformation).

        To configure a callback that gets executed before the composite is transformed for the legacy controller, and executed there, you can call FailedOperationTransformationConfig.setCallback(FailedOperationTransformationConfig.BeforeExecuteCompositeCallback).

        Parameters:
        mainServices - The main controller services
        modelVersion - The version of the legacy controller
        operations - the operations
        config - the config
        Throws:
        org.jboss.as.controller.OperationFailedException
      • moveWildcardChildrenToEnd

        public static List<org.jboss.as.controller.PathElement> moveWildcardChildrenToEnd​(Set<org.jboss.as.controller.PathElement> children)