0
Spring WebServiceTemplateを使用してSOAP Webサービスを使用しています。 JUnitを実行している間、私は問題に直面しています。
JUnit for Spring WebServiceTemplateが動作しない
マイClientクラス:
@Service
public class MyWsClient extends WebServiceGatewaySupport {
@Autowired
private WebServiceTemplate webServiceTemplate;
public String getData(...) throws Exception{
...
SampleResponse response = (SampleResponse) webServiceTemplate.marshalSendAndReceive(request);
...
return response.getData();
}}
私のテストクラス:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext-junit.xml"})
public class MyWsClientTest {
@Autowired
ApplicationContext applicationContext;
@InjectMocks
MyWsClient myWsClient;
private MockWebServiceServer mockServer;
@Before
public void init() {
MockitoAnnotations.initMocks(this);
mockServer = MockWebServiceServer.createServer(applicationContext);
}
@Test
public void testGetData() throws Exception {
Source expectedRequestPayload = new StringSource(
"<customerCountRequest xmlns=\"http://springframework.org/spring-ws/test\" />");
Source responsePayload = new StringSource(
"<customerCountResponse xmlns='http://springframework.org/spring-ws/test'>"
+ "<customerCount>10</customerCount>" + "</customerCountResponse>");
mockServer.expect(RequestMatchers.payload(expectedRequestPayload)).andRespond(ResponseCreators.withPayload(responsePayload));
String data = myWsClient.getData(...);
assertNotNull(data);
mockServer.verify();
}}
問題:
私は私のテストケースを実行すると、私は "行のNullPointerExceptionが取得していますwebServiceTemplate.marshalSendAndReceive(リクエスト) "内のClie ntクラス。
webServiceTemplateがnullとして返されます。
私が間違っていることは何ですか?