Ich muss einige Komponententests für Camel-Routen schreiben, die die CXF-Komponente verwenden, um einen SOAP-Webdienst aufzurufen.
Was wäre der sauberste Weg, um die SOAP-Anfrage zu überspringen und eine Stubbed-Antwort zurückzugeben?
Ich versuche mit Mock-Endpunkten, aber die Anfrage wird entweder an den tatsächlichen Endpunkt übergeben oder in whenAnyExchangeReceived
Prozessor-Rückruf ignoriert.Wie man den CXF-Endpunkt in Camel Blueprint stopft
Ich konfiguriere Camel mit Blueprint und starte es mit camel-test-blueprint 2.17.1. So sieht meine blueprint.xml-Konfiguration aus.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
xsi:schemaLocation="
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.0.0.xsd
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder id="routeConfiguration"
persistent-id="my.app" />
<camelcxf:cxfEndpoint id="myWebService"
address="${myWebService.url}"
wsdlURL="classpath:wsdl/MyWebService.wsdl"
serviceClass="my.web.service.Ws"
serviceName="s:MyWebServiceImpl"
xmlns:s="http://mywebservice.it/"/>
<camelContext trace="false" id="myCamelContext"
xmlns="http://camel.apache.org/schema/blueprint">
<propertyPlaceholder location="blueprint:routeConfiguration" />
<route id="IwantToStubInsideHere">
<from uri="activemq:someQueue"/>
<to uri="cxf:bean:myWebService"/>
<to uri="direct:processWebServiceResponse"/>
</route>
</camelContext>
</blueprint>
Prüfklasse
public class RouteTest extends CamelBlueprintTestSupport {
@Override
public String isMockEndpointsAndSkip() {
return "cxf*";
}
@Test
public void testMethod() {
MockEndpoint mockEndpoint = getMockEndpoint("mock:cxf:bean:myWebService");
mockEndpoint.expectedMessageCount(1);
mockEndpoint.whenAnyExchangeReceived(new StubWsProcessor());
// run route here
}
}
Dies ist genau das Problem, vor dem wir stehen. Im Moment sahen wir keine andere Alternative, um einen gefälschten Server zu erstellen (wie mit SOAP-UI), aber wir sind nicht auf diese Weise gegangen. Momentan machen wir Integrationstests nur für diesen Fall mit dem echten WS. –
@rufp Ich habe meine aktuelle Konfiguration veröffentlicht. Funktioniert ziemlich gut für meinen Fall, hoffe, dass Sie es Ihrer Situation anpassen können. –