-
1. Re: Registering a service using SwitchYardTestKit
kcbabo Nov 29, 2012 2:30 PM (in response to kostas_papag)1 of 1 people found this helpfulThe short answer is that you now need to do this:
The long answer is that we made some changes to the internal addressing of SY core and tightened things up a bit. In 0.5 the ability to replace a service in the test kit was a happy accident based on the way that dispatchers were created. In reality, it's possible to have multiple implementations of a given service and the current behavior of 0.6 is correct in allowing both to be registered and choosing one. One solution is to simply remove the original registration as part of your test as in the example linked above. Another option, depending on what you are trying to assert in your test, is to introduce an Auditor to intercept the processing of the exchange.
Sorry this bit you in the move from 0.5 to 0.6, but I hope the above is both clear and functional for your use case.
cheers,
keith
-
2. Re: Registering a service using SwitchYardTestKit
kostas_papag Dec 3, 2012 11:01 AM (in response to kcbabo)Hello Keith,
thank you for the suggestions.
Regarding the actual tests, as I mentioned above I have already followed the quickstart example ( removing & then registering the service) but got some issues with the transformers. I am attaching a small example similar to the issue I am facing. Is my example failing due to some configuration error from my side, or some misuse of the SwitchYardTestKit? Any help will be appreciated.
If no other way we will move on using the Auditors as you suggest. I would like to avoid them though, cause Auditors are powerful tools and using them for assertions in tests is like "using a sledgehammer to crack a nut".As I see it some SwitchYardTestKit enhancements that would allow easier mocking of switchyard services , would be more handy for such a case.
Regards,
Kostas
-
3. Re: Registering a service using SwitchYardTestKit
kostas_papag Dec 3, 2012 11:01 AM (in response to kcbabo)I am re - attaching the example due to a problem in the switchyard.xml of the previous one. Sorry for any inconvenience.
-
camel-service.tar.gz 15.1 KB
-
-
4. Re: Registering a service using SwitchYardTestKit
kostas_papag Dec 7, 2012 10:33 AM (in response to kostas_papag)Eventually I got the example running.
Some of the issues that would cause the test to fail, were solved based on solutions discussed here: https://community.jboss.org/thread/214238
Regarding the mock-specific part, I got the transformers to work for mocked services using a slightly approach :
public class CamelServiceTest {
....
SwitchYardTestKit testkit;
....
testKit.removeService("StringPrinter");
MockHandler handler = new MockHandler();
testKit.registerInOutService("StringPrinter", handler, JavaService.fromClass(StringPrinter.class));
....
}
Registering the service by providing the Java Interface allows transformation to work fine even in the mocked environment.
This is only possible when registering mocked services as InOut. For some reason the SwitchYardTestKit doesn't offer the same functionality for InOnly services, but this doesn't seem to affect the test in any way.
I'm attaching the solution to the above example in .zip format.
-
camel-service.zip 175.2 KB
-