WsdlMockOperation extends AbstractMockOperation<MockOperationConfig, WsdlMockResponse> { public WsdlMockResult dispatchRequest(WsdlMockRequest request) throws DispatchException { try { request.setOperation(getOperation()); WsdlMockResult result = new WsdlMockResult(request); if (getMockResponseCount() == 0) { throw new DispatchException("Missing MockResponse(s) in MockOperation [" + getName() + "]"); } result.setMockOperation(this); WsdlMockResponse response = (WsdlMockResponse) getDispatcher().selectMockResponse(request, result); if (response == null) { response = getMockResponseByName(getDefaultResponse()); } if (response == null) { throw new DispatchException("Failed to find MockResponse"); } result.setMockResponse(response); response.execute(request, result); return result; } catch (Throwable e) { if (e instanceof DispatchException) { throw (DispatchException) e; } else { throw new DispatchException(e); } } } WsdlMockOperation(WsdlMockService mockService, MockOperationConfig config);  WsdlMockOperation(WsdlMockService mockService, MockOperationConfig config, WsdlOperation operation); @Override ImageIcon getIcon(); WsdlMockService getMockService(); WsdlOperation getOperation(); @Override String getScriptHelpUrl(); @Override MockResponse addNewMockResponse(String name); WsdlMockResponse addNewMockResponse(MockResponseConfig responseConfig); WsdlMockResponse addNewMockResponse(String name, boolean createResponse); WsdlMockResult dispatchRequest(WsdlMockRequest request); @Override MockOperationDispatcher setDispatchStyle(String dispatchStyle); @Override void release(); String getWsdlOperationName(); void propertyChange(PropertyChangeEvent arg0); void setOperation(WsdlOperation operation); @Override void removeResponseFromConfig(int index); boolean isOneWay(); boolean isNotification(); boolean isSolicitResponse(); boolean isUnidirectional(); boolean isBidirectional(); List<? extends ModelItem> getChildren(); void exportMockOperation(File file); final static String OPERATION_PROPERTY; static final String ICON_NAME; }
@Test public void testDispatchRequestReturnsHttpStatus() throws Exception { mockResponse.setResponseHttpStatus(HttpStatus.SC_BAD_REQUEST); WsdlMockResult mockResult = mockOperation.dispatchRequest(restMockRequest); verify(mockResult.getMockRequest().getHttpResponse()).setStatus(HttpStatus.SC_BAD_REQUEST); assertThat(mockResult.getMockResponse().getResponseHttpStatus(), is(HttpStatus.SC_BAD_REQUEST)); }
@Test public void testDispatchRequestReturnsResponseContent() throws Exception { String responseContent = "mock response content"; mockResponse.setResponseContent(responseContent); WsdlMockResult mockResult = mockOperation.dispatchRequest(restMockRequest); assertThat(mockResult.getMockResponse().getResponseContent(), is(responseContent)); }
@Test public void testDispatchRequestReturnsHttpHeader() throws Exception { StringToStringsMap responseHeaders = mockResponse.getResponseHeaders(); String headerKey = "awesomekey"; String headerValue = "awesomevalue"; responseHeaders.add(headerKey, headerValue); mockResponse.setResponseHeaders(responseHeaders); WsdlMockResult mockResult = mockOperation.dispatchRequest(restMockRequest); verify(mockResult.getMockRequest().getHttpResponse()).addHeader(headerKey, headerValue); assertThat(mockResult.getResponseHeaders().get(headerKey, ""), is(headerValue)); assertThat(mockResult.getMockResponse().getResponseHeaders().get(headerKey, ""), is(headerValue)); }