[jboss-as7-dev] Subsystem testing harness

Kabir Khan kabir.khan at jboss.com
Mon Aug 1 07:11:55 EDT 2011


I moved the normalizeXml() method into AbstractSubsystemTest along with a few other small tweaks: https://github.com/jbossas/jboss-as/commit/0d3de0f834b0af7f7a0ca87e1c79c7aa50c491c1
On 25 Jul 2011, at 15:37, David Bosschaert wrote:

> Hi Kabir,
> 
> It works for me. It allows for the following generic code to test 
> read+write of any subsystem :)
>     String subsystemXML = "..."; // my subsystem XML
>     KernelServices services = installInController(new 
> EmptyAdditionalInitialization() {
>         @Override
>         public Type getType() {
>             return Type.MANAGEMENT;
>         }
>     }, subsystemXml);
>     ModelNode model = services.readWholeModel();
>     String marshalled = outputModel(model);
>     Assert.assertEquals(normalizeXML(subsystemXml), 
> normalizeXML(marshalled));
> 
> Note that I used a normalizeXML method to treat the XML strings before 
> using string compare to evaluate them. It takes into account things like 
> normalizing attribute order, ignoring comments and pretty-printing 
> elements to make sure that they are organized the same way. It might be 
> an idea to add normalizeXML() to AbstractSubsystemTest. I've pasted it 
> below.
> 
> Cheers & thanks!
> 
> David
> 
> /**
>  * 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
>  * @param xml The XML to be normalized
>  * @return The equivalent XML, but now normalized
>  */
> private String normalizeXML(String xml) throws Exception {
>     // Remove all white space adjoining tags ("trim all elements")
>     xml = xml.replaceAll("\\s*<", "<");
>     xml = xml.replaceAll(">\\s*", ">");
> 
>     DOMImplementationRegistry registry = 
> DOMImplementationRegistry.newInstance();
>     DOMImplementationLS domLS = (DOMImplementationLS) 
> registry.getDOMImplementation("LS");
>     LSParser lsParser = 
> domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
> 
>     LSInput input = domLS.createLSInput();
>     input.setStringData(xml);
>     Document document = lsParser.parse(input);
> 
>     LSSerializer lsSerializer = domLS.createLSSerializer();
>     lsSerializer.getDomConfig().setParameter("comments", Boolean.FALSE);
>     lsSerializer.getDomConfig().setParameter("format-pretty-print", 
> Boolean.TRUE);
>     return lsSerializer.writeToString(document);
> }
> 
> 
> On 21/07/2011 16:16, Kabir Khan wrote:
>> It has changed slightly after some comments from Brian and Emanuel. New commit is here: https://github.com/kabir/jboss-as/commit/e5144e1c6832756408f9385ed21b4df6abe49a33
>> 
>> AdditionalInitialization.getType() == MANAGEMENT forces the non-install of services now
>> On 21 Jul 2011, at 16:43, David Bosschaert wrote:
>> 
>>> Nice, thanks Kabir!
>>> 
>>> I'll play around with that soon!
>>> 
>>> David
>>> 
>>> On 21/07/2011 15:37, Kabir Khan wrote:
>>>> My https://github.com/kabir/jboss-as/commits/parsing-harness contains some adjustements.
>>>> 
>>>> https://github.com/kabir/jboss-as/commit/8f6538850604e0633c34c27d6fa70bb81dc180de#L6R108
>>>> shows how to invoke the ops without doing the RUNTIME part of the operation handlers, i.e. services will not get installed.
>>>> 
>>>> https://github.com/kabir/jboss-as/commit/8f6538850604e0633c34c27d6fa70bb81dc180de#L6R186
>>>> shows how to just marshall a raw model to xml.
>>>> 
>>>> 
>>>> On 20 Jul 2011, at 16:40, David Bosschaert wrote:
>>>> 
>>>>> On 20/07/2011 15:34, Kabir Khan wrote:
>>>>>> You need to start up MSC to get reference to the model controller since that is the only real way to get hold of the model controller. I guess you are saying you want the model changes and associated persistence of the xml to happen when invoking your ops, but not the installation of services?
>>>>> Yes, from a unit testing point of view that would be nice :)
>>>>> 
>>>>> Currently I can test the reading part as a unit without causing any side effects in the system, i.e. XML ->   ModelNodes
>>>>> It would be great to be able to test the writing part as a unit too: ModelNodes ->   XML
>>>>> 
>>>>> Cheers,
>>>>> 
>>>>> David
>> 
> 
> _______________________________________________
> jboss-as7-dev mailing list
> jboss-as7-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-as7-dev




More information about the jboss-as7-dev mailing list