001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.panels.request.components.editor.views.source;
014:
015: import javax.swing.JPopupMenu;
016: import javax.swing.JSeparator;
017:
018: import com.eviware.soapui.impl.wsdl.WsdlInterface;
019: import com.eviware.soapui.impl.wsdl.WsdlOperation;
020: import com.eviware.soapui.impl.wsdl.WsdlRequest;
021: import com.eviware.soapui.impl.wsdl.actions.request.AddWSSUsernameTokenAction;
022: import com.eviware.soapui.impl.wsdl.actions.request.AddWSTimestampAction;
023: import com.eviware.soapui.impl.wsdl.mock.WsdlMockResponse;
024: import com.eviware.soapui.impl.wsdl.panels.mockoperation.WsdlMockResponseMessageExchange;
025: import com.eviware.soapui.impl.wsdl.panels.mockoperation.WsdlMockResultMessageExchange;
026: import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlEditor;
027: import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlEditorView;
028: import com.eviware.soapui.impl.wsdl.panels.request.components.editor.support.ValidationError;
029: import com.eviware.soapui.impl.wsdl.panels.request.components.editor.views.registry.RequestEditorViewFactory;
030: import com.eviware.soapui.impl.wsdl.panels.request.components.editor.views.registry.ResponseEditorViewFactory;
031: import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator;
032: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext;
033: import com.eviware.soapui.impl.wsdl.teststeps.WsdlResponseMessageExchange;
034: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest;
035: import com.eviware.soapui.impl.wsdl.teststeps.assertions.AssertionError;
036: import com.eviware.soapui.model.ModelItem;
037: import com.eviware.soapui.support.xml.JXEditTextArea;
038:
039: /**
040: * Factory for default "XML" source editor view in soapUI
041: *
042: * @author ole.matzura
043: */
044:
045: public class XmlSourceEditorFactory implements
046: ResponseEditorViewFactory, RequestEditorViewFactory {
047: public static final String VIEW_ID = "Source";
048:
049: public XmlEditorView createEditorView(XmlEditor editor) {
050: return new XmlSourceEditorView(editor);
051: }
052:
053: public String getViewId() {
054: return VIEW_ID;
055: }
056:
057: public XmlEditorView createRequestEditorView(XmlEditor editor,
058: ModelItem modelItem) {
059: if (modelItem instanceof WsdlRequest) {
060: return new WsdlRequestXmlSourceEditor(editor,
061: (WsdlRequest) modelItem);
062: } else if (modelItem instanceof WsdlMockResponse) {
063: return new WsdlMockRequestXmlSourceEditor(editor,
064: (WsdlMockResponse) modelItem);
065: }
066:
067: return null;
068: }
069:
070: public XmlEditorView createResponseEditorView(XmlEditor editor,
071: ModelItem modelItem) {
072: if (modelItem instanceof WsdlRequest) {
073: return new WsdlResponseXmlSourceEditor(editor,
074: (WsdlRequest) modelItem);
075: } else if (modelItem instanceof WsdlMockResponse) {
076: return new WsdlMockResponseXmlSourceEditor(editor,
077: (WsdlMockResponse) modelItem);
078: }
079:
080: return null;
081: }
082:
083: /**
084: * XmlSource editor for a WsdlRequest
085: *
086: * @author ole.matzura
087: */
088:
089: public static class WsdlRequestXmlSourceEditor extends
090: XmlSourceEditorView {
091: private final WsdlRequest request;
092:
093: public WsdlRequestXmlSourceEditor(XmlEditor xmlEditor,
094: WsdlRequest request) {
095: super (xmlEditor);
096: this .request = request;
097: }
098:
099: protected ValidationError[] validateXml(String xml) {
100: WsdlOperation operation = (WsdlOperation) request
101: .getOperation();
102: WsdlValidator validator = new WsdlValidator(
103: ((WsdlInterface) operation.getInterface())
104: .getWsdlContext());
105:
106: WsdlResponseMessageExchange wsdlResponseMessageExchange = new WsdlResponseMessageExchange(
107: request);
108: wsdlResponseMessageExchange.setRequestContent(xml);
109: return validator.assertRequest(wsdlResponseMessageExchange,
110: false);
111: }
112:
113: protected void buildPopup(JPopupMenu inputPopup,
114: JXEditTextArea editArea) {
115: super .buildPopup(inputPopup, editArea);
116:
117: inputPopup.insert(new JSeparator(), 2);
118: inputPopup
119: .insert(new AddWSSUsernameTokenAction(request), 3);
120: inputPopup.insert(new AddWSTimestampAction(request), 4);
121: }
122: }
123:
124: /**
125: * XmlSource editor for a WsdlMockRequest
126: *
127: * @author ole.matzura
128: */
129:
130: public static class WsdlMockRequestXmlSourceEditor extends
131: XmlSourceEditorView {
132: private final WsdlMockResponse mockResponse;
133:
134: public WsdlMockRequestXmlSourceEditor(XmlEditor xmlEditor,
135: WsdlMockResponse mockResponse) {
136: super (xmlEditor);
137: this .mockResponse = mockResponse;
138: }
139:
140: protected ValidationError[] validateXml(String xml) {
141: WsdlOperation operation = mockResponse.getMockOperation()
142: .getOperation();
143:
144: if (operation == null) {
145: return new ValidationError[] { new AssertionError(
146: "Missing operation for MockResponse") };
147: }
148:
149: WsdlValidator validator = new WsdlValidator(
150: ((WsdlInterface) operation.getInterface())
151: .getWsdlContext());
152: return validator.assertRequest(
153: new WsdlMockResultMessageExchange(mockResponse
154: .getMockResult()), false);
155: }
156:
157: protected void buildPopup(JPopupMenu inputPopup,
158: JXEditTextArea editArea) {
159: super .buildPopup(inputPopup, editArea);
160: inputPopup.insert(new JSeparator(), 2);
161: }
162: }
163:
164: /**
165: * XmlSource editor for a WsdlResponse
166: *
167: * @author ole.matzura
168: */
169:
170: public static class WsdlResponseXmlSourceEditor extends
171: XmlSourceEditorView {
172: private final WsdlRequest request;
173:
174: public WsdlResponseXmlSourceEditor(XmlEditor xmlEditor,
175: WsdlRequest request) {
176: super (xmlEditor);
177: this .request = request;
178: }
179:
180: protected ValidationError[] validateXml(String xml) {
181: if (request instanceof WsdlTestRequest) {
182: WsdlTestRequest testRequest = (WsdlTestRequest) request;
183: testRequest.assertResponse(new WsdlTestRunContext(
184: testRequest.getTestStep()));
185: }
186:
187: WsdlOperation operation = (WsdlOperation) request
188: .getOperation();
189: WsdlValidator validator = new WsdlValidator(
190: ((WsdlInterface) operation.getInterface())
191: .getWsdlContext());
192:
193: return validator.assertResponse(
194: new WsdlResponseMessageExchange(request), false);
195: }
196: }
197:
198: /**
199: * XmlSource editor for a WsdlMockResponse
200: *
201: * @author ole.matzura
202: */
203:
204: public static class WsdlMockResponseXmlSourceEditor extends
205: XmlSourceEditorView {
206: private final WsdlMockResponse mockResponse;
207:
208: public WsdlMockResponseXmlSourceEditor(XmlEditor xmlEditor,
209: WsdlMockResponse mockResponse) {
210: super (xmlEditor);
211: this .mockResponse = mockResponse;
212: }
213:
214: protected ValidationError[] validateXml(String xml) {
215: WsdlOperation operation = mockResponse.getMockOperation()
216: .getOperation();
217: if (operation == null) {
218: return new ValidationError[] { new AssertionError(
219: "Missing operation for MockResponse") };
220: }
221:
222: WsdlValidator validator = new WsdlValidator(
223: ((WsdlInterface) operation.getInterface())
224: .getWsdlContext());
225: return validator.assertResponse(
226: new WsdlMockResponseMessageExchange(mockResponse),
227: false);
228: }
229: }
230: }
|