Class ModelTestUtils
- Author:
- Kabir Khan
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.jboss.dmr.ModelNodecheckFailed(org.jboss.dmr.ModelNode result) Checks that the operation failesstatic voidcheckFailedTransformedBootOperations(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 voidcheckModelAgainstDefinition(org.jboss.dmr.ModelNode model, org.jboss.as.controller.registry.ManagementResourceRegistration rr) static org.jboss.dmr.ModelNodecheckOutcome(org.jboss.dmr.ModelNode result) Checks that the result was successfulstatic org.jboss.dmr.ModelNodecheckResultAndGetContents(org.jboss.dmr.ModelNode result) Checks that the result was successful and gets the real result contentsstatic voidcompare(org.jboss.dmr.ModelNode node1, org.jboss.dmr.ModelNode node2) Compares two models to make sure that they are the samestatic voidcompare(org.jboss.dmr.ModelNode node1, org.jboss.dmr.ModelNode node2, boolean ignoreUndefined) Compares two models to make sure that they are the samestatic voidcompareXml(String original, String marshalled) Validate the marshalled xml without adjusting the namespaces for the original and marshalled xml.static voidcompareXml(String original, String marshalled, boolean ignoreNamespace) Validate the marshalled xml without adjusting the namespaces for the original and marshalled xml.static org.jboss.dmr.ModelNodegetSubModel(org.jboss.dmr.ModelNode model, org.jboss.as.controller.PathAddress pathAddress) static org.jboss.dmr.ModelNodegetSubModel(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 StringnormalizeXML(String xml) Normalize and pretty-print XML so that it can be compared using string compare.static StringreadResource(Class<?> clazz, String name) Read the classpath resource with the given name and return its contents as a string.static voidresolveAndCompareModels(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 resolutionstatic voidscanForExpressionFormattedStrings(org.jboss.dmr.ModelNode model) Scans for entries of type STRING containing expression formatted strings.static voidvalidateModelDescriptions(org.jboss.as.controller.PathAddress address, org.jboss.as.controller.registry.ImmutableManagementResourceRegistration reg)
-
Constructor Details
-
ModelTestUtils
public ModelTestUtils()
-
-
Method Details
-
readResource
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 toClass.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 modelnode2- 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 modelnode2- 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 modelnode2- the second modelignoreUndefined-trueif keys containing undefined nodes should be ignored
-
normalizeXML
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
Validate the marshalled xml without adjusting the namespaces for the original and marshalled xml.- Parameters:
original- the original subsystem xmlmarshalled- 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 xmlmarshalled- the marshalled subsystem xmlignoreNamespace- iftruethe 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 callFailedOperationTransformationConfig.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 servicesmodelVersion- The version of the legacy controlleroperations- the operationsconfig- the config- Throws:
org.jboss.as.controller.OperationFailedException
-
moveWildcardChildrenToEnd
-