David Edds

Greenhorn
+ Follow
since Dec 06, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by David Edds

In case anyone is thinking about this problem...

I have come to the realisation that the problem is that I am chaining together XSL transforms (this wasn't mentioned in the original post) and that the output from one (a DOMResult) cannot be manipulated as I hoped. It is the fact of putting XML tags into the DOM that causes the strange result that I was getting.

Quite how I solve this, I don't know.
Hi,

Consider I have a large XML file of the format: /a/b/c/d

I would like to insert the structure e/f/blah blah blah at a point in the existing document (for example at point c). How can I use an XSL transform to do this?

Personally (for better or worse) I have used the following XSL, where the parameter enrichment supplies the text to be inserted:



Now a further question is, rather than inserting it at a point defined in the XSL (/a/b/c) how can I make the insertion at a point as defined by parameter?

Thanks,
David
Hi,

I am having a problem inserting a parameter into an XSL transform using the Java API. The main problem is that the parameter value is some XML.

The fragment of my XSL is as follows:


In my Java I am doing the following:

String partNumber = "<Id>12345</Id>";
transformer.setParameter("enrichment", partNumber);
transformer.transform(source, result);

But in my resultant XML I get the following:

...
& lt; Id & gt; 12345 & lt; /Id & gt;
...

Note: There isn't really a space between the characters & and lt; . I just cant get it to display in the post without it being automatically convereted to XML.

The HTML has been coverted to its corresponding codes! This is not what I want. How can I stop this?

I have tried



but this produces:

& lt;?javax.xsl.transform.disable-output-escaping ?& gt;& lt;Id& gt;12345& lt;/Id& gt;& lt;?javax.xsl.transform.disable-output-escaping ?& gt;


Which to me sugegsts that my transformer (XALAN) does not understand the disable-output-escaping tag.

If anyone can explain why any of the above is happening I would be very grateful. Sorry I haven't posted full code - I am unable to for legal reasons. I could create a working example example if anyone wants but that will take me some time to produce.

Thanks,
David

[ March 16, 2005: Message edited by: David Edds ]

[ March 16, 2005: Message edited by: David Edds ]

[ March 16, 2005: Message edited by: David Edds ]

[ March 16, 2005: Message edited by: David Edds ]

Sorry about all the editing - I am havign a VERY hard time posting this and preserving what I am typing without it turning into HTML / smilies
[ March 16, 2005: Message edited by: David Edds ]

Originally posted by Lasse Koskela:

Is it really the correct place? Is this dummy object an essential part of your Controller's responsibility? If so, then why is it a separate object?



Yes it is. The Controller is a general part which is deploeyd in many places across the system. The XSLT are "business rules" that define the behaviour the Controller exhibits when supplied with a particular message. The idea of this decoupling is to allow business analysts (who can't code Java) to define the behaviour of the system. Personally I don't agree with this approach, but there you go.

The Controller uses reflection to instantiate an object and call a method defined in the Plugin interface. Once this method has returned the Controller disposes of the object (by forgetting its references to the object). So outside of the Controller, you have no access to the created Plugin.

Now thanks to everyone's advice so far I can see how I can test Plugin objects with JUnit, since they have defined inputs and outputs (as defined by the interface). I can also test my Controller classes, since the Controller reacts to an i/p and I (in my test case) can know and define the business rules.

However my original question (which probably wasn't very clear) is how do I test the whole system from within JUnit? For example let us assume that the Controller and associated Plugin objects are working correctly and are being tested. The business analyst comes along and supplies me with the XSL transform and input(s) for the Controller. From JUnit how do I test this? As far as I can see, I am no longer testing units, but a system. My lack of ability to test is because without anlayzing the business rules, I don't know what's going on and hence can't write the test code. Even without testing the business analyst's particular test, provided I have tested my Plugins are tested my Controller, the only untested part is the XSL transforms. And surely there are tools out there to check XSL?

I guess though that it is the chaining together of the functionality that I would also be missing. For example, suppose the business rule is do a transform, call Plugin 1, do another transform, call Plugin 2, etc. This is the sort of test that needs to be done, but a test that can only be defined by knowing what is being tested!


Originally posted by Lasse Koskela:
Whether you code your test methods into a single TestCase class or multiple makes no difference with regards to whether JUnit executes them in parallel. I'd definitely recommend organizing your test methods in such a way that is optimal from a maintainability point of view. I tend to recommend placing tests that operate on a common test fixture (the object hierarchy being tested and its state) into a single TestCase class.



OK. I tend to follow the same approach as you - putting tests on a single or group of objects in the same TestCase, provided the state is something that is not something that needs a great deal of setup between tests. So if I was testing the Foo class, I would put all the tests in one TestCase, unless my setUp() method varied considerably, dependant on the tests in the TestCase.

BTW Thanks to everyone's responses so far. They have really helped me to focus and understand EXACTLY what it is I am trying to do and test.

David
19 years ago

Originally posted by Jeanne Boyarsky:
Tests should still be independent of each other even though they aren't being run in parallel. Junit makes no guarantees of the order the tests are run in.



Great - that makes sense to me. Thanks for that.

David
19 years ago
Thanks both of you.

For Ilja, I shall attempt to explain the issue further.

- The Controller consists of 3 classes that interact with each other. The Contoller takes as input an XML message and processes the message from rules defined in an XML transform that the Controller is supplied with.

- This XML transform can transform the message, call a Plugin object or call another XSL transform (or a combination of the above)

- A Plugin object takes as input an XML message, and processes it in whatever way it wants to (e.g. does a database look-up and populates fields in the XML message). It returns an XML message to the Controller, who decides what to do next.

- Generally this sequence ends with a call to a Plugin object that publishes the XML on an MQ Queue. This Pluging object returns a message of a type, that tells the Controller not to do any further work. The Controller just stops and does NOT report back a success or failure.

- The Controller throws exceptions if something goes wrong at any stage.

So the Controller is working as far as I can see, but how can I test it? Given a configuration that will call a Dummy Object, my JUnit pseudo code would be something like this:

XMLMessage msg = "<dave>blah blah</dave>";
Controller c = new Controller(xsltRules);
c.process(msg);
assertTrue(dummyObject.returnSuccess());

But I can't write the last line, since I have no access to Dummy Object as it is instantiated within the Controller (which is the correct place for it to be instantiated). I could start subclassing the Controller classes but that seems to me to be testing my testing code rather than the production code. I also don't want to change the production code purely so that tests can be run.

I have considered in Dummy Object doing something like System.setProperty(thisTestWorked, true) but won't I have to be VERY careful that other tests wont pick up this property when it has been set by another test.

Since I have stated that the Plugin objects and Controller BOTH throw exceptions if anything goes wrong, then if no exceptions are thrown I can assume that everything has been performed successfully. This will have to be drummed into the development team so that all Plugins work like this!

Jeanne - you said I should pass the objects in to the class, so the JUnit test can access them. The problem here is that I want to test the whole of the Controller (all 3 classes) and the plugins that are being called. Am I going beyond the scope of JUnit (this doesn't sound like a UNIT test)? What other tools could / should I be using?

I assumed that the JUnit test environment would decide on whether to run tests consecutively or concurrently so that each test should be independant of another. I assume that this is not the case now. But should I code so that two seperate Test Cases (as in JUnit test cases, not two tests within the same Test Case) don't tread on each others toes (e.g. manipulate the same system property)?

Thanks again,
David
19 years ago
Hi,

I am working in a large project where we have been using JUnit to test parts of our code. This enables us to do overnight builds and tests and generate reports. I think I understand when JUnit testing should be used - to test individual functions and do so in a controlled and automated manner, and possibly what I am trying to do is beyond the scope of JUnit.

This is my situation:

I have a process (Processer) that uses reflection at runtime to instantiate a class and get it to perform some work. So my Processor class calls a Plugin object. Now I can write a test Plugin object and see if that is called (rather than my real Plugin object). This will be a test to ensure that my Processor class and its configuration is working correctly.

But how can I wire this into JUnit? My JUnit test method could create an object (e.g. Controller) and my test Plugin object could report back to Controller. But the interface to Plugin does NOT support this new Controller object. So how could my test plugin report back successfully?

Now I need to do a number of these tests, so a singleton or System object can not be used, since many Junit tests could be running simultaneously.

Or am I going beyond the scope of JUnit? Should I be using some other tool?

Any help or advice will be greatfully appreciated,

Thanks,
David
19 years ago
Jeanne,

Yes that has worked for me. I created a Java WSAD project (a simple project seemed not to work) called "Resources" and put my .proeprties file in there. Putting a dependency on the other projects so they referred to the "Resources" project puts the project on the classpath by default and the .properties file is picked up by default.

I also put all of the dependant .jar files in "Resources" too, so it's starting to become a little large, but at least everything is located in one central location.

Thanks for the advice. It's worked in exactly the way I wanted.
David
19 years ago
Hi,

I would like it so that when I go to run a Java application (or unit test) from within WebSphere, the directory MyProject/lib is already (by default) on the classpath. This lib directory contains properties files (for log4j) that the applications require to run succesfully.

Now I can achieve this by going into the Run... dialog, selecting the Classpath tag, unchecking "Use default class path" and adding the lib folder. But since this is required for a medium sized development team involving, it would be much more convenient if the lib directory was there by default. Also by unticking the "Use default class path" check-box, any further changes that are made to the project are not picked up when the Run configuration is re-invoked.

The classpath that is specified by default, is I assume, derived from the build-path of the project. However I see no way to add a non Java source folder to the build path (indeed, why would a java compiler require this!). Does anyone know how websphere derives the default class-path and if a non java source folder can be added?

There is also a tag on the Run... dialog which specifies the "bootstrap classes". Does anyone know how this can be modified so I could add the folder?

Thanks in advance,
David
19 years ago
Thanks Madhu,

That is the sort of thing I need. I have tried it out and it works well.

Thanks again,
David
19 years ago
Hi,

I have limited experience of ant, but am wondering if it is possible to pass arguments to a target so the target operates on the supplied values. Note that I am making a distincation using "environment variables". What I wish to do is pass a value to a target and then run the target operating on those values. I guess this is impossible, since I assume that this is not the way ant really works, but I wondered if anyone knew how to do this.

The reason I want to do this, is because I have the following scenario:

I have a series of tasks to perform in ant. They start off with general tasks, (e.g. cvsCheckout, amalgamate) and then go into a series of tasks for a particular file-set (e.g. compile, junit, coverage, javadoc). I need to repeat that set of tasks for different file sets. Once I have done that I do a couple more general tasks (e.g. clean-up, publish) and I'm done.

I can achieve the above by writing the following targets in my ant script:
cvsCheckout
amalgamate
compileSet1
junitSet1
coverageSet1
...
compileSet2
junitSet2
coverageSet2
...
compileSet3
junitSet3
coverageSet3
...
publish

But surely there is a way to do this without all of the repetition? The targets compileSet1 and compileSet2 are very similar, they just work on different filesets and different file locations.

Any help or advice is greatly appreciated,
David
19 years ago
Hi,

I suspect that this is impossible, but I am asking anyway. I would like to call a transform from within another transform. For example here is a segment of file1.xslt :



I have investigated import and include and these don't seem to be able to provide the functionality I require. If I have a

in each file, then only file1 is actually processed.

My reason for wanting to achieve this, is that the called transform file (file2) is being generated outside of our system and it would be nice to be able to call that file as is, without having to edit it or merge it with file1.

Help and advice gratefully appreciated, even if it is just to say that this can't be done.

Thanks
David
Marc,

Thanks for your reply. That's really cleared things up.
Thanks to everyone else who posted too.

David
19 years ago
Thanks for the quick replies!

So what you're saying is that the method call is bound at compile time. OK I accept this. However what about the following:

Classes B and C both subclass class A. All classes have a method called doFoo

I write some code:


Depending on what object is passed into doWork, the appropriate method is called in the class. So passing in a class of C, calls the method in class C, NOT the method in class A.

So can someone explain when compiler-binding is performed and when runtime-binding is performed (sorry, I don't know the correct terminology)

Thanks
19 years ago
Hi,

I have a situation in Java that I don't really understand. It involves calling a method with different object classes.

Suppose we have a class A, and a class B which subclasses A

In another class, we have the following code:



When sillyMethod is run, the method doFoo(A) will always be called. I understand that there must be the method doFoo(A) since the compiler expects that method to exist. However why isn't doFoo(B) called at runtime?

Any explanation or links to areas where I can read up on this further would be greatly appreciated.

Thanks,
Dave
19 years ago