How to use start method of ui.MockRunner class

Best Karate code snippet using ui.MockRunner.start

Source:MockAsWarServlet.java Github

copy

Full Screen

...89 if (StringUtils.hasContent(mockServiceEndpoint)) {90 ((WsdlMockService) mockService).setMockServiceEndpoint(mockServiceEndpoint);91 }9293 mockService.start();94 }9596 for (MockService mockService : project.getRestMockServiceList()) {97 logger.info("Starting REST mock service [" + mockService.getName() + "]");98 mockService.start();99 }100 } catch (Exception ex) {101 logger.log(Level.SEVERE, null, ex);102 }103 }104105 protected void initProject(String path) throws XmlException, IOException, SoapUIException {106 project = (WsdlProject) ProjectFactoryRegistry.getProjectFactory("wsdl").createNew(path);107 }108109 protected String initMockServiceParameters() {110 try {111 if (StringUtils.hasContent(getInitParameter("listeners"))) {112 logger.info("Init listeners");113 try {114 System.setProperty("soapui.ext.listeners", getServletContext().getRealPath(getInitParameter("listeners")));115 } catch (Exception e) {116 logger.info("Listeners not set! Reason : " + e.getMessage());117 }118 } else {119 logger.info("Listeners not set!");120 }121122 if (StringUtils.hasContent(getInitParameter("actions"))) {123 logger.info("Init actions");124 try {125 System.setProperty("soapui.ext.actions", getServletContext().getRealPath(getInitParameter("actions")));126 } catch (Exception e) {127 logger.info("Actions not set! Reason : " + e.getMessage());128 }129 } else {130 logger.info("Actions not set!");131 }132133 if (SoapUI.getSoapUICore() == null) {134 if (StringUtils.hasContent(getInitParameter("soapUISettings"))) {135 logger.info("Init settings");136 SoapUI.setSoapUICore(137 new MockServletSoapUICore(getServletContext(), getInitParameter("soapUISettings")), true);138 } else {139 logger.info("Settings not set!");140 SoapUI.setSoapUICore(new MockServletSoapUICore(getServletContext()), true);141 }142 } else {143 logger.info("SoapUI core already exists, reusing existing one");144 }145146 if (StringUtils.hasContent(getInitParameter("enableWebUI"))) {147 if ("true".equals(getInitParameter("enableWebUI"))) {148 logger.info("WebUI ENABLED");149 enableWebUI = true;150 } else {151 logger.info("WebUI DISABLED");152 enableWebUI = false;153 }154 }155156 }catch (Exception e){157 logger.info("Property set with error!"+e.getMessage());158 }159 try {160 maxResults = Integer.parseInt(getInitParameter("maxResults"));161 } catch (NumberFormatException ex) {162 maxResults = 1000;163 }164165 SoapUI.ensureGroovyLog().addAppender(new GroovyLogAppender());166167 return getInitParameter("mockServiceEndpoint");168 }169170 public void destroy() {171 super.destroy();172 getMockServletCore().stop();173 }174175 protected MockAsWarCoreInterface getMockServletCore() {176 return (MockAsWarCoreInterface) SoapUI.getSoapUICore();177 }178179 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,180 IOException {181 try {182 getMockServletCore().dispatchRequest(request, response);183 } catch (DispatchException ex) {184 logger.log(Level.SEVERE, null, ex);185 }186 }187188 private void printResult(PrintWriter out, MockResult result) {189190 out.print("<h4>Details for MockResult at " + new java.util.Date(result.getTimestamp()) + " ("191 + result.getTimeTaken() + "ms)</h4>");192193 out.println("<hr/><p><b>Request Headers</b>:</p>");194 out.print("<table border=\"1\"><tr><td>Header</td><td>Value</td></tr>");195 StringToStringsMap headers = result.getMockRequest().getRequestHeaders();196 for (String name : headers.getKeys()) {197 for (String value : headers.get(name)) {198 out.println("<tr><td>" + name + "</td><td>" + value + "</td></tr>");199 }200 }201 out.println("</table>");202203 out.println("<hr/><b>Incoming Request</b>:<br/><pre>"204 + XmlUtils.entitize(result.getMockRequest().getRequestContent()) + "</pre>");205206 out.println("<hr/><p><b>Response Headers</b>:</p>");207 out.print("<table border\"1\"><tr><td>Header</td><td>Value</td></tr>");208 headers = result.getResponseHeaders();209 for (String name : headers.getKeys()) {210 for (String value : headers.get(name)) {211 out.println("<tr><td>" + name + "</td><td>" + value + "</td></tr>");212 }213 }214 out.println("</table>");215216 out.println("<hr/><b>Returned Response</b>:<pre>" + XmlUtils.entitize(result.getResponseContent()) + "</pre>");217 }218219 class MockServletSoapUICore extends DefaultSoapUICore implements MockEngine, MockAsWarCoreInterface {220 private final ServletContext servletContext;221 private List<MockRunner> mockRunners = new ArrayList<MockRunner>();222223 public MockServletSoapUICore(ServletContext servletContext, String soapUISettings) {224 super(servletContext.getRealPath("/"), servletContext.getRealPath(soapUISettings));225 this.servletContext = servletContext;226 }227228 /*229 * (non-Javadoc)230 *231 * @see232 * com.eviware.soapui.mockaswar.MockAsWarCoreInterface#dispatchRequest233 * (javax.servlet.http.HttpServletRequest,234 * javax.servlet.http.HttpServletResponse)235 */236 @Override237 public void dispatchRequest(HttpServletRequest request, HttpServletResponse response) throws DispatchException,238 IOException {239 String pathInfo = request.getPathInfo();240 if (pathInfo == null) {241 pathInfo = "";242 }243244 MockRunner mockRunner = getMatchedMockRunner(getMockRunners(), pathInfo);245246 if (mockRunner != null) {247 MockResult result = mockRunner.dispatchRequest(request, response);248249 if (maxResults > 0) {250 synchronized (results) {251 while (maxResults > 0 && results.size() > maxResults) {252 results.remove(0);253 }254 if (result != null) {255 results.add(result);256 }257 }258 }259 return;260 }261262 if (enableWebUI) {263 String realPath = servletContext.getRealPath(pathInfo);264 File file = realPath == null ? null : new File(realPath);265 if (file != null && file.exists() && file.isFile()) {266 FileInputStream in = new FileInputStream(file);267 response.setStatus(HttpServletResponse.SC_OK);268 long length = file.length();269 response.setContentLength((int) length);270 response.setContentType(ContentTypeHandler.getContentTypeFromFilename(file.getName()));271 Tools.readAndWrite(in, length, response.getOutputStream());272 in.close();273 } else if (pathInfo.equals("/master")) {274 printMaster(request, response, mockRunners);275 } else if (pathInfo.equals("/detail")) {276 printDetail(request, response);277 } else if (pathInfo.equals("/log")) {278 printLog(request, response);279 } else {280 printFrameset(request, response);281 }282 } else {283 printDisabledLogFrameset(request, response);284 }285 }286287 private MockRunner getMatchedMockRunner(MockRunner[] mockRunners, String pathInfo) {288289 MockRunner mockRunner = null;290 String bestMatchedRootPath = "";291292 for (MockRunner runner : mockRunners) {293 String mockServicePath = runner.getMockContext().getMockService().getPath();294 if (pathInfo.startsWith(mockServicePath) && mockServicePath.length() > bestMatchedRootPath.length()) {295 bestMatchedRootPath = mockServicePath;296 mockRunner = runner;297 }298 }299300 return mockRunner;301302 }303304 /*305 * (non-Javadoc)306 *307 * @see com.eviware.soapui.mockaswar.MockAsWarCoreInterface#stop()308 */309 @Override310 public void stop() {311 for (MockRunner mockRunner : getMockRunners()) {312 mockRunner.stop();313 }314 }315316 public MockServletSoapUICore(ServletContext servletContext) {317 super(servletContext.getRealPath("/"), null);318 this.servletContext = servletContext;319 }320321 @Override322 protected MockEngine buildMockEngine() {323 return this;324 }325326 public MockRunner[] getMockRunners() {327 return mockRunners.toArray(new MockRunner[mockRunners.size()]);328 }329330 public boolean hasRunningMock(MockService mockService) {331 for (MockRunner runner : mockRunners) {332 if (runner.getMockContext().getMockService() == mockService) {333 return true;334 }335 }336337 return false;338 }339340 public void startMockService(MockRunner runner) throws Exception {341 mockRunners.add(runner);342 }343344 public void stopMockService(MockRunner runner) {345 mockRunners.remove(runner);346 }347 }348349 public void printMaster(HttpServletRequest request, HttpServletResponse response, List<MockRunner> mockRunners)350 throws IOException {351 response.setStatus(HttpServletResponse.SC_OK);352 response.setContentType("text/html");353354 PrintWriter out = response.getWriter();355 startHtmlPage(out, "MockService Log Table", "15");356357 out.print("<img src=\"header_logo.png\"><h3>SoapUI MockServices Log for project [" + project.getName()358 + "]</h3>" + "<p style=\"text-align: left\">WSDLs:");359360 for (MockRunner mockRunner : mockRunners) {361 String overviewUrl = ((WsdlMockRunner) mockRunner).getOverviewUrl();362 if (overviewUrl.startsWith("/")) {363 overviewUrl = overviewUrl.substring(1);364 }365366 out.print(" [<a target=\"new\" href=\"" + overviewUrl + "\">" + mockRunner.getMockContext().getMockService().getName()367 + "</a>]");368 }369370 out.print("</p>");371372 out.print("<hr/><p><b>Processed Requests</b>: ");373 out.print("[<a href=\"master\">Refresh</a>] ");374 out.print("[<a href=\"master?clear\">Clear</a>]</p>");375376 if ("clear".equals(request.getQueryString())) {377 results.clear();378 }379380 out.print("<table border=\"1\">");381 out.print("<tr><td></td><td>Timestamp</td><td>Time Taken</td><td>MockOperation</td><td>MockResponse</td><td>MockService</td></tr>");382383 int cnt = 1;384385 for (MockResult result : results) {386387 if (result != null) {388 out.print("<tr><td>" + (cnt++) + "</td>");389 out.print("<td><a target=\"detail\" href=\"detail?" + result.hashCode() + "\">"390 + new java.util.Date(result.getTimestamp()) + "</a></td>");391 out.print("<td>" + result.getTimeTaken() + "</td>");392 out.print("<td>" + result.getMockOperation().getName() + "</td>");393 if (result.getMockResponse() != null) {394 out.print("<td>" + result.getMockResponse().getName() + "</td>");395 }396 out.print("<td>" + result.getMockOperation().getMockService().getName() + "</td></tr>");397 }398 }399400 out.print("</table>");401402 out.print("</body></html>");403 out.flush();404405 }406407 private void startHtmlPage(PrintWriter out, String title, String refresh) {408 out.print("<html><head>");409 out.print("<title>" + title + "</title>");410 if (refresh != null) {411 out.print("<meta http-equiv=\"refresh\" content=\"" + refresh + "\"/>");412 }413414 out.print("<link type=\"text/css\" rel=\"stylesheet\" href=\"stylesheet.css\" />");415 out.print("</head><body>");416 }417418 public void printDisabledLogFrameset(HttpServletRequest request, HttpServletResponse response) throws IOException {419 response.setStatus(HttpServletResponse.SC_OK);420 response.setContentType("text/html");421422 PrintWriter out = response.getWriter();423 out.print("<html><head><title>SoapUI MockServices Log for project [" + project.getName() + "]</title></head>");424 out.print("<body>");425 out.print("<h3>");426 out.print("Log is disabled.");427 out.print("</h3>");428 out.print("</body></html>");429 out.flush();430 }431432 public void printFrameset(HttpServletRequest request, HttpServletResponse response) throws IOException {433 response.setStatus(HttpServletResponse.SC_OK);434 response.setContentType("text/html");435436 PrintWriter out = response.getWriter();437 out.print("<html><head><title>SoapUI MockServices Log for project [" + project.getName() + "]</title></head>");438 out.print("<frameset rows=\"40%,40%,*\">");439 out.print("<frame src=\"master\"/>");440 out.print("<frame name=\"detail\" src=\"detail\"/>");441 out.print("<frame src=\"log\"/>");442 out.print("</frameset>");443 out.print("</html>");444 out.flush();445 }446447 public void printDetail(HttpServletRequest request, HttpServletResponse response) throws IOException {448 response.setStatus(HttpServletResponse.SC_OK);449 response.setContentType("text/html");450451 PrintWriter out = response.getWriter();452453 startHtmlPage(out, "MockService Detail", null);454455 int id = 0;456457 try {458 id = Integer.parseInt(request.getQueryString());459 } catch (NumberFormatException e) {460 }461462 if (id > 0) {463 for (MockResult result : results) {464 if (result.hashCode() == id) {465 id = 0;466 printResult(out, result);467 }468 }469 }470471 if (id > 0) {472 out.print("<p>Missing specified MockResult</p>");473 }474475 out.print("</body></html>");476 out.flush();477 }478479 private class GroovyLogAppender extends org.apache.log4j.AppenderSkeleton {480481 protected void append(LoggingEvent event) {482 events.add(event);483 }484485 public void close() {486 }487488 public boolean requiresLayout() {489 return false;490 }491 }492493 public void printLog(HttpServletRequest request, HttpServletResponse response) throws IOException {494 response.setStatus(HttpServletResponse.SC_OK);495 response.setContentType("text/html");496497 PrintWriter out = response.getWriter();498 startHtmlPage(out, "MockService Groovy Log", "15");499 out.print("<p><b>Groovy Log output</b>: ");500 out.print("[<a href=\"log\">Refresh</a>] ");501 out.print("[<a href=\"log?clear\">Clear</a>]</p>");502503 if ("clear".equals(request.getQueryString())) {504 events.clear();505 }506507 out.print("<table border=\"1\">");508 out.print("<tr><td></td><td>Timestamp</td><td>Message</td></tr>");509510 int cnt = 1;511512 for (LoggingEvent event : events) { ...

Full Screen

Full Screen

Source:AbstractMockService.java Github

copy

Full Screen

...55public abstract class AbstractMockService<MockOperationType extends MockOperation,56 MockServiceConfigType extends BaseMockServiceConfig>57 extends AbstractTestPropertyHolderWsdlModelItem<MockServiceConfigType>58 implements MockService, HasHelpUrl {59 public final static String START_SCRIPT_PROPERTY = AbstractMockService.class.getName() + "@startScript";60 public final static String STOP_SCRIPT_PROPERTY = AbstractMockService.class.getName() + "@stopScript";61 protected List<MockOperation> mockOperations = new ArrayList<MockOperation>();62 private Set<MockRunListener> mockRunListeners = new HashSet<MockRunListener>();63 private Set<MockServiceListener> mockServiceListeners = new HashSet<MockServiceListener>();64 private MockServiceIconAnimator iconAnimator;65 private WsdlMockRunner mockRunner;66 private SoapUIScriptEngine startScriptEngine;67 private SoapUIScriptEngine stopScriptEngine;68 private BeanPathPropertySupport docrootProperty;69 private ScriptEnginePool onRequestScriptEnginePool;70 private ScriptEnginePool afterRequestScriptEnginePool;71 protected AbstractMockService(MockServiceConfigType config, ModelItem parent, String icon) {72 super(config, parent, icon);73 if (!config.isSetPort() || config.getPort() < 1) {74 config.setPort(8080);75 }76 if (!config.isSetPath()) {77 config.setPath("/");78 }79 if (!config.isSetId()) {80 config.setId(ModelSupport.generateModelItemID());81 }82 initHost(config);83 docrootProperty = new BeanPathPropertySupport(this, "docroot");84 iconAnimator = new MockServiceIconAnimator();85 addMockRunListener(iconAnimator);86 }87 private void initHost(MockServiceConfigType config) {88 try {89 if (!config.isSetHost() || !StringUtils.hasContent(config.getHost())) {90 config.setHost(InetAddress.getLocalHost().getHostName());91 }92 } catch (UnknownHostException e) {93 SoapUI.logError(e);94 }95 }96 // Implements MockService97 @Override98 public WsdlProject getProject() {99 return (WsdlProject) getParent();100 }101 @Override102 public MockOperationType getMockOperationAt(int index) {103 return (MockOperationType) mockOperations.get(index);104 }105 @Override106 public MockOperation getMockOperationByName(String name) {107 for (MockOperation operation : mockOperations) {108 if (operation.getName() != null && operation.getName().equals(name)) {109 return operation;110 }111 }112 return null;113 }114 public void addMockOperation(MockOperationType mockOperation) {115 if (canIAddAMockOperation(mockOperation)) {116 mockOperations.add(mockOperation);117 } else {118 throw new IllegalStateException(mockOperation.getName() + " is not attached to service " + this.getName());119 }120 }121 protected String getProtocol() {122 try {123 boolean sslEnabled = SoapUI.getSettings().getBoolean(SSLSettings.ENABLE_MOCK_SSL);124 String protocol = sslEnabled ? "https://" : "http://";125 return protocol;126 } catch (Exception e) {127 return "http://";128 }129 }130 protected abstract boolean canIAddAMockOperation(MockOperationType mockOperation);131 @Override132 public int getMockOperationCount() {133 return mockOperations.size();134 }135 @Override136 public int getPort() {137 return getConfig().getPort();138 }139 @Override140 public String getPath() {141 return getConfig().getPath();142 }143 @Override144 public void removeMockOperation(MockOperation mockOperation) {145 int ix = mockOperations.indexOf(mockOperation);146 if (ix == -1) {147 throw new RuntimeException("Unknown MockOperation specified to removeMockOperation");148 }149 mockOperations.remove(ix);150 fireMockOperationRemoved(mockOperation);151 mockOperation.release();152 if (this instanceof WsdlMockService) {153 ((WsdlMockService) this).getConfig().removeMockOperation(ix);154 } else if (this instanceof RestMockService) {155 ((RestMockService) this).getConfig().removeRestMockAction(ix);156 }157 }158 public String getLocalEndpoint() {159 String host = getHost();160 if (StringUtils.isNullOrEmpty(host)) {161 host = "127.0.0.1";162 }163 return getProtocol() + host + ":" + getPort() + getPath();164 }165 @Override166 public String getHost() {167 return getConfig().getHost();168 }169 public void setHost(String host) {170 getConfig().setHost(host);171 }172 @Override173 public void setPort(int port) {174 int oldPort = getPort();175 getConfig().setPort(port);176 notifyPropertyChanged(PORT_PROPERTY, oldPort, port);177 }178 @Override179 public void setPath(String path) {180 String oldPath = getPath();181 getConfig().setPath(path);182 notifyPropertyChanged(PATH_PROPERTY, oldPath, path);183 }184 @Override185 public WsdlMockRunner start() throws Exception {186 return start(null);187 }188 @Override189 public void startIfConfigured() throws Exception {190 if (SoapUI.getSettings().getBoolean(HttpSettings.START_MOCK_SERVICE)) {191 start();192 }193 }194 @Override195 public boolean getBindToHostOnly() {196 return getConfig().getBindToHostOnly();197 }198 public void setBindToHostOnly(boolean bindToHostOnly) {199 getConfig().setBindToHostOnly(bindToHostOnly);200 }201 // TODO: think about naming - this does not start nothing.....202 public WsdlMockRunner start(WsdlTestRunContext context) throws Exception {203 String path = getPath();204 if (path == null || path.trim().length() == 0 || path.trim().charAt(0) != '/') {205 throw new Exception("Invalid path; must start with '/'");206 }207 mockRunner = new WsdlMockRunner(this, context);208 return mockRunner;209 }210 @Override211 public void addMockRunListener(MockRunListener listener) {212 mockRunListeners.add(listener);213 }214 @Override215 public void removeMockRunListener(MockRunListener listener) {216 mockRunListeners.remove(listener);217 }218 @Override219 public void addMockServiceListener(MockServiceListener listener) {220 mockServiceListeners.add(listener);221 }222 @Override223 public void removeMockServiceListener(MockServiceListener listener) {224 mockServiceListeners.remove(listener);225 }226 @Override227 public WsdlMockRunner getMockRunner() {228 return mockRunner;229 }230 public void setMockRunner(WsdlMockRunner mockRunner) {231 this.mockRunner = mockRunner;232 }233 @Override234 public MockRunListener[] getMockRunListeners() {235 return mockRunListeners.toArray(new MockRunListener[mockRunListeners.size()]);236 }237 public MockServiceListener[] getMockServiceListeners() {238 return mockServiceListeners.toArray(new MockServiceListener[mockServiceListeners.size()]);239 }240 @Override241 public List<MockOperation> getMockOperationList() {242 return Collections.unmodifiableList(new ArrayList<MockOperation>(mockOperations));243 }244 protected List<MockOperation> getMockOperations() {245 return mockOperations;246 }247 @Override248 public void fireMockOperationAdded(MockOperation mockOperation) {249 for (MockServiceListener listener : getMockServiceListeners()) {250 listener.mockOperationAdded(mockOperation);251 }252 }253 @Override254 public void fireMockOperationRemoved(MockOperation mockOperation) {255 for (MockServiceListener listener : getMockServiceListeners()) {256 listener.mockOperationRemoved(mockOperation);257 }258 }259 @Override260 public void fireMockResponseAdded(MockResponse mockResponse) {261 for (MockServiceListener listener : getMockServiceListeners()) {262 listener.mockResponseAdded(mockResponse);263 }264 }265 @Override266 public void fireMockResponseRemoved(MockResponse mockResponse) {267 for (MockServiceListener listener : getMockServiceListeners()) {268 listener.mockResponseRemoved(mockResponse);269 }270 }271 @Override272 public void release() {273 super.release();274 mockServiceListeners.clear();275 if (mockRunner != null) {276 if (mockRunner.isRunning()) {277 mockRunner.stop();278 }279 if (mockRunner != null) {280 mockRunner.release();281 }282 }283 if (onRequestScriptEnginePool != null) {284 onRequestScriptEnginePool.release();285 }286 if (afterRequestScriptEnginePool != null) {287 afterRequestScriptEnginePool.release();288 }289 if (startScriptEngine != null) {290 startScriptEngine.release();291 }292 if (stopScriptEngine != null) {293 stopScriptEngine.release();294 }295 }296 @Override297 public void setStartScript(String script) {298 String oldScript = getStartScript();299 if (!getConfig().isSetStartScript()) {300 getConfig().addNewStartScript();301 }302 getConfig().getStartScript().setStringValue(script);303 if (startScriptEngine != null) {304 startScriptEngine.setScript(script);305 }306 notifyPropertyChanged(START_SCRIPT_PROPERTY, oldScript, script);307 }308 @Override309 public String getStartScript() {310 return getConfig().isSetStartScript() ? getConfig().getStartScript().getStringValue() : null;311 }312 @Override313 public void setStopScript(String script) {314 String oldScript = getStopScript();315 if (!getConfig().isSetStopScript()) {316 getConfig().addNewStopScript();317 }318 getConfig().getStopScript().setStringValue(script);319 if (stopScriptEngine != null) {320 stopScriptEngine.setScript(script);321 }322 notifyPropertyChanged(STOP_SCRIPT_PROPERTY, oldScript, script);323 }324 @Override325 public String getStopScript() {326 return getConfig().isSetStopScript() ? getConfig().getStopScript().getStringValue() : null;327 }328 @Override329 public Object runStartScript(WsdlMockRunContext runContext, MockRunner runner) throws Exception {330 String script = getStartScript();331 if (StringUtils.isNullOrEmpty(script)) {332 return null;333 }334 if (startScriptEngine == null) {335 startScriptEngine = SoapUIScriptEngineRegistry.create(this);336 startScriptEngine.setScript(script);337 }338 startScriptEngine.setVariable("context", runContext);339 startScriptEngine.setVariable("mockRunner", runner);340 startScriptEngine.setVariable("log", SoapUI.ensureGroovyLog());341 return startScriptEngine.run();342 }343 @Override344 public Object runStopScript(WsdlMockRunContext runContext, MockRunner runner) throws Exception {345 String script = getStopScript();346 if (StringUtils.isNullOrEmpty(script)) {347 return null;348 }349 if (stopScriptEngine == null) {350 stopScriptEngine = SoapUIScriptEngineRegistry.create(this);351 stopScriptEngine.setScript(script);352 }353 stopScriptEngine.setVariable("context", runContext);354 stopScriptEngine.setVariable("mockRunner", runner);355 stopScriptEngine.setVariable("log", SoapUI.ensureGroovyLog());356 return stopScriptEngine.run();357 }358 @Override359 public void setOnRequestScript(String script) {360 String oldScript = getOnRequestScript();361 if (!getConfig().isSetOnRequestScript()) {362 getConfig().addNewOnRequestScript();363 }364 getConfig().getOnRequestScript().setStringValue(script);365 if (onRequestScriptEnginePool != null) {366 onRequestScriptEnginePool.setScript(script);367 }368 notifyPropertyChanged("onRequestScript", oldScript, script);369 }370 @Override371 public String getOnRequestScript() {372 return getConfig().isSetOnRequestScript() ? getConfig().getOnRequestScript().getStringValue() : null;373 }374 @Override375 public void setAfterRequestScript(String script) {376 String oldScript = getAfterRequestScript();377 if (!getConfig().isSetAfterRequestScript()) {378 getConfig().addNewAfterRequestScript();379 }380 getConfig().getAfterRequestScript().setStringValue(script);381 if (afterRequestScriptEnginePool != null) {382 afterRequestScriptEnginePool.setScript(script);383 }384 notifyPropertyChanged("afterRequestScript", oldScript, script);385 }386 @Override387 public String getAfterRequestScript() {388 return getConfig().isSetAfterRequestScript() ? getConfig().getAfterRequestScript().getStringValue() : null;389 }390 @Override391 public Object runOnRequestScript(WsdlMockRunContext runContext, MockRequest mockRequest) throws Exception {392 String script = getOnRequestScript();393 if (StringUtils.isNullOrEmpty(script)) {394 return null;395 }396 if (onRequestScriptEnginePool == null) {397 onRequestScriptEnginePool = new ScriptEnginePool(this);398 onRequestScriptEnginePool.setScript(script);399 }400 SoapUIScriptEngine scriptEngine = onRequestScriptEnginePool.getScriptEngine();401 try {402 scriptEngine.setVariable("context", runContext);403 scriptEngine.setVariable("mockRequest", mockRequest);404 scriptEngine.setVariable("mockRunner", getMockRunner());405 scriptEngine.setVariable("log", SoapUI.ensureGroovyLog());406 return scriptEngine.run();407 } finally {408 onRequestScriptEnginePool.returnScriptEngine(scriptEngine);409 }410 }411 @Override412 public Object runAfterRequestScript(WsdlMockRunContext runContext, MockResult mockResult) throws Exception {413 String script = getAfterRequestScript();414 if (StringUtils.isNullOrEmpty(script)) {415 return null;416 }417 if (afterRequestScriptEnginePool == null) {418 afterRequestScriptEnginePool = new ScriptEnginePool(this);419 afterRequestScriptEnginePool.setScript(script);420 }421 SoapUIScriptEngine scriptEngine = afterRequestScriptEnginePool.getScriptEngine();422 try {423 scriptEngine.setVariable("context", runContext);424 scriptEngine.setVariable("mockResult", mockResult);425 scriptEngine.setVariable("mockRunner", getMockRunner());426 scriptEngine.setVariable("log", SoapUI.ensureGroovyLog());427 return scriptEngine.run();428 } finally {429 afterRequestScriptEnginePool.returnScriptEngine(scriptEngine);430 }431 }432 public void setDocroot(String docroot) {433 docrootProperty.set(docroot, true);434 }435 public String getDocroot() {436 return docrootProperty.get();437 }438 @Override439 public void addExternalDependencies(List<ExternalDependency> dependencies) {440 super.addExternalDependencies(dependencies);441 //Disable since ProjectExporter.packageAll doesn't seem to handle folders442 //dependencies.add( new MockServiceExternalDependency( docrootProperty ) );443 }444 @Override445 public void resolve(ResolveContext<?> context) {446 super.resolve(context);447 docrootProperty.resolveFile(context, "Missing MockService docroot");448 }449 public boolean isDispatchResponseMessages() {450 return getConfig().getDispatchResponseMessages();451 }452 public void setDispatchResponseMessages(boolean dispatchResponseMessages) {453 boolean old = isDispatchResponseMessages();454 getConfig().setDispatchResponseMessages(dispatchResponseMessages);455 notifyPropertyChanged("dispatchResponseMessages", old, dispatchResponseMessages);456 }457 public abstract String getIconName();458 public void fireOnMockResult(Object result) {459 if (result != null && result instanceof MockResult) {460 for (MockRunListener listener : getMockRunListeners()) {461 listener.onMockResult((MockResult) result);462 }463 }464 }465 private class MockServiceIconAnimator466 extends IconAnimator<MockService>467 implements MockRunListener {468 public MockServiceIconAnimator() {469 super(AbstractMockService.this, getIconName(), getIconName(), 4);470 }471 public MockResult onMockRequest(MockRunner runner, HttpServletRequest request, HttpServletResponse response) {472 return null;473 }474 public void onMockResult(MockResult result) {475 }476 public void onMockRunnerStart(MockRunner mockRunner) {477 start();478 }479 public void onMockRunnerStop(MockRunner mockRunner) {480 stop();481 AbstractMockService.this.mockRunner = null;482 }483 }484}...

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2import java.awt.BorderLayout;3import java.awt.Dimension;4import java.awt.event.ActionEvent;5import java.awt.event.ActionListener;6import javax.swing.JButton;7import javax.swing.JFrame;8import javax.swing.JLabel;9import javax.swing.JPanel;10import javax.swing.JTextField;11import javax.swing.SwingUtilities;12import javax.swing.border.EmptyBorder;13public class MockRunner extends JFrame {14private static final long serialVersionUID = 1L;15private JPanel contentPane;16private JTextField textField;17private JTextField textField_1;18private JTextField textField_2;19private JTextField textField_3;20private JTextField textField_4;21private JTextField textField_5;22private JTextField textField_6;23private JTextField textField_7;24private JTextField textField_8;25private JTextField textField_9;26private JTextField textField_10;27private JTextField textField_11;28private JTextField textField_12;29private JTextField textField_13;30private JTextField textField_14;31private JTextField textField_15;32private JTextField textField_16;33private JTextField textField_17;34private JTextField textField_18;35private JTextField textField_19;36private JTextField textField_20;37private JTextField textField_21;38private JTextField textField_22;39private JTextField textField_23;40private JTextField textField_24;41private JTextField textField_25;42private JTextField textField_26;43private JTextField textField_27;44private JTextField textField_28;45private JTextField textField_29;46private JTextField textField_30;47private JTextField textField_31;48private JTextField textField_32;49private JTextField textField_33;50private JTextField textField_34;51private JTextField textField_35;52private JTextField textField_36;53private JTextField textField_37;54private JTextField textField_38;55private JTextField textField_39;56private JTextField textField_40;57private JTextField textField_41;58private JTextField textField_42;59private JTextField textField_43;60private JTextField textField_44;61private JTextField textField_45;62private JTextField textField_46;63private JTextField textField_47;64private JTextField textField_48;65private JTextField textField_49;66private JTextField textField_50;67private JTextField textField_51;68private JTextField textField_52;69private JTextField textField_53;70private JTextField textField_54;71private JTextField textField_55;72private JTextField textField_56;73private JTextField textField_57;74private JTextField textField_58;75private JTextField textField_59;76private JTextField textField_60;77private JTextField textField_61;78private JTextField textField_62;79private JTextField textField_63;80private JTextField textField_64;81private JTextField textField_65;82private JTextField textField_66;83private JTextField textField_67;

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2import javax.swing.SwingUtilities;3public class Main {4 public static void main(String[] args) {5 MockRunner runner = new MockRunner();6 SwingUtilities.invokeLater(runner);7 }8}9package ui;10import javax.swing.SwingUtilities;11public class Main {12 public static void main(String[] args) {13 MockRunner runner = new MockRunner();14 SwingUtilities.invokeLater(runner);15 }16}17package ui;18import javax.swing.SwingUtilities;19public class Main {20 public static void main(String[] args) {21 MockRunner runner = new MockRunner();22 SwingUtilities.invokeLater(runner);23 }24}25package ui;26import javax.swing.SwingUtilities;27public class Main {28 public static void main(String[] args) {29 MockRunner runner = new MockRunner();30 SwingUtilities.invokeLater(runner);31 }32}33package ui;34import javax.swing.SwingUtilities;35public class Main {36 public static void main(String[] args) {37 MockRunner runner = new MockRunner();38 SwingUtilities.invokeLater(runner);39 }40}41package ui;42import javax.swing.SwingUtilities;43public class Main {44 public static void main(String[] args) {45 MockRunner runner = new MockRunner();46 SwingUtilities.invokeLater(runner);47 }48}49package ui;50import javax.swing.SwingUtilities;51public class Main {52 public static void main(String[] args) {53 MockRunner runner = new MockRunner();54 SwingUtilities.invokeLater(runner);55 }56}57package ui;58import javax.swing.SwingUtilities;59public class Main {

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2public class MockRunner {3 public static void main(String[] args) {4 new MockRunner().start();5 }6 private void start() {7 System.out.println("MockRunner started");8 }9}10package ui;11public class MockRunner {12 public static void main(String[] args) {13 new MockRunner().start();14 }15 protected void start() {16 System.out.println("MockRunner started");17 }18}19package ui;20public class MockRunner {21 public static void main(String[] args) {22 new MockRunner().start();23 }24 private void start() {25 System.out.println("MockRunner started");26 }27}28package ui;29public class MockRunner {30 public static void main(String[] args) {31 new MockRunner().start();32 }33 private void start() {34 System.out.println("MockRunner started");35 }36}37package ui;38public class MockRunner {39 public static void main(String[] args) {40 new MockRunner().start();41 }42 private void start() {43 System.out.println("MockRunner started");44 }45}46package ui;47public class MockRunner {48 public static void main(String[] args) {49 new MockRunner().start();50 }51 private void start() {52 System.out.println("MockRunner started");53 }54}55package ui;56public class MockRunner {57 public static void main(String[] args) {58 new MockRunner().start();59 }60 private void start() {61 System.out.println("MockRunner started");62 }63}64package ui;65public class MockRunner {66 public static void main(String[] args) {67 new MockRunner().start();68 }69 private void start() {70 System.out.println("MockRunner started");71 }72}

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1import static org.junit.Assert.*;2import org.junit.*;3import org.junit.runner.*;4import org.junit.runner.notification.*;5import org.junit.runner.manipulation.*;6public class 4 {7 public void test() {8 Result result = JUnitCore.runClasses(MockRunner.class);9 assertEquals(1, result.getRunCount());10 assertEquals(1, result.getFailureCount());11 assertEquals(0, result.getIgnoreCount());12 }13}14import static org.junit.Assert.*;15import org.junit.*;16import org.junit.runner.*;17import org.junit.runner.notification.*;18import org.junit.runner.manipulation.*;19public class 5 {20 public void test() {21 Result result = JUnitCore.runClasses(MockRunner.class);22 assertEquals(1, result.getRunCount());23 assertEquals(1, result.getFailureCount());24 assertEquals(0, result.getIgnoreCount());25 }26}27import static org.junit.Assert.*;28import org.junit.*;29import org.junit.runner.*;30import org.junit.runner.notification.*;31import org.junit.runner.manipulation.*;32public class 6 {33 public void test() {34 Result result = JUnitCore.runClasses(MockRunner.class);35 assertEquals(1, result.getRunCount());36 assertEquals(1, result.getFailureCount());37 assertEquals(0, result.getIgnoreCount());38 }39}40import static org.junit.Assert.*;41import org.junit.*;42import org.junit.runner.*;43import org.junit.runner.notification.*;44import org.junit.runner.manipulation.*;45public class 7 {46 public void test() {47 Result result = JUnitCore.runClasses(MockRunner.class);48 assertEquals(1, result.getRunCount());49 assertEquals(1, result.getFailureCount());50 assertEquals(0, result.getIgnoreCount());51 }52}53import static org.junit.Assert.*;54import org.junit.*;55import org.junit.runner.*;56import org.junit.runner.notification.*;57import org.junit.runner.manipulation.*;58public class 8 {59 public void test() {60 Result result = JUnitCore.runClasses(MockRunner.class);61 assertEquals(1,

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2import java.lang.reflect.Method;3public class MockRunner {4 public static void main(String[] args) {5 try {6 Class<?> clazz = Class.forName("ui.Mock");7 Object obj = clazz.newInstance();8 Method method = clazz.getDeclaredMethod("start", new Class[] {});9 method.invoke(obj, new Object[] {});10 } catch (Exception e) {11 e.printStackTrace();12 }13 }14}15package ui;16public class Mock {17 public void start() {18 System.out.println("Hello World!");19 }20}21package ui;22import java.lang.reflect.Method;23public class MockRunner {24 public static void main(String[] args) {25 try {26 Class<?> clazz = Class.forName("ui.Mock");27 Object obj = clazz.newInstance();28 Method method = clazz.getDeclaredMethod("start", new Class[] {});29 method.invoke(obj, new Object[] {});30 } catch (Exception e) {31 e.printStackTrace();32 }33 }34}35package ui;36public class Mock {37 public void start() {38 System.out.println("Hello World!");39 }40}41package ui;42import java.lang.reflect.Method;43public class MockRunner {44 public static void main(String[] args) {45 try {46 Class<?> clazz = Class.forName("ui.Mock");47 Object obj = clazz.newInstance();48 Method method = clazz.getDeclaredMethod("start", new Class[] {});49 method.invoke(obj, new Object[] {});50 } catch (Exception e) {51 e.printStackTrace();52 }53 }54}55package ui;56public class Mock {57 public void start() {58 System.out.println("Hello World!");59 }60}61package ui;62import java.lang.reflect.Method;63public class MockRunner {64 public static void main(String[] args) {65 try {66 Class<?> clazz = Class.forName("ui.Mock");67 Object obj = clazz.newInstance();68 Method method = clazz.getDeclaredMethod("start", new Class[] {});

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2import java.io.*;3import java.util.*;4{5public static void main(String args[])6{7MockRunner m = new MockRunner();8m.start();9}10public void start()11{12System.out.println("Hello World");13}14}15package ui;16import java.io.*;17import java.util.*;18{19public static void main(String args[])20{21MockRunner m = new MockRunner();22m.start();23}24public void start()25{26System.out.println("Hello World");27}28}29package ui;30import java.io.*;31import java.util.*;32{33public static void main(String args[])34{35MockRunner m = new MockRunner();36m.start();37}38public void start()39{40System.out.println("Hello World");41}42}43package ui;44import java.io.*;45import java.util.*;46{47public static void main(String args[])48{49MockRunner m = new MockRunner();50m.start();51}52public void start()53{54System.out.println("Hello World");55}56}57package ui;58import java.io.*;59import java.util.*;60{61public static void main(String args[])62{63MockRunner m = new MockRunner();64m.start();65}66public void start()67{68System.out.println("Hello World");69}70}71package ui;72import java.io.*;73import java.util.*;74{75public static void main(String args[])76{77MockRunner m = new MockRunner();78m.start();79}80public void start()81{82System.out.println("Hello World");83}84}85package ui;86import java.io.*;87import java.util.*;88{89public static void main(String args[])90{91MockRunner m = new MockRunner();92m.start();93}94public void start()95{96System.out.println("Hello World");97}98}99package ui;100import java.io.*;101import

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2import java.awt.EventQueue;3public class MockRunner extends Thread {4 public void run() {5 EventQueue.invokeLater(new Runnable() {6 public void run() {7 try {8 Main window = new Main();9 window.frame.setVisible(true);10 } catch (Exception e) {11 e.printStackTrace();12 }13 }14 });15 }16}17package ui;18public class Main {19 public static void main(String[] args) {20 MockRunner mr = new MockRunner();21 mr.start();22 }23}24package ui;25import java.awt.EventQueue;26public class MockRunner extends Thread {27 public void run() {28 EventQueue.invokeLater(new Runnable() {29 public void run() {30 try {31 Main window = new Main();32 window.frame.setVisible(true);33 } catch (Exception e) {34 e.printStackTrace();35 }36 }37 });38 }39}40package ui;41public class Main {42 public static void main(String[] args) {43 MockRunner mr = new MockRunner();44 mr.start();45 }46}47package ui;48import java.awt.EventQueue;49public class MockRunner extends Thread {50 public void run() {51 EventQueue.invokeLater(new Runnable() {52 public void run() {53 try {54 Main window = new Main();55 window.frame.setVisible(true);56 } catch (Exception e) {57 e.printStackTrace();58 }59 }60 });61 }62}63package ui;64public class Main {65 public static void main(String[] args) {66 MockRunner mr = new MockRunner();67 mr.start();68 }69}70package ui;71import java.awt.EventQueue;72public class MockRunner extends Thread {73 public void run() {74 EventQueue.invokeLater(new Runnable() {75 public void run() {76 try {

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2import java.awt.*;3import java.awt.event.*;4import javax.swing.*;5import java.util.*;6import java.io.*;7import java.util.regex.*;8import java.lang.reflect.*;9import java.lang.annotation.*;10import java.lang.*;11import java.lang.reflect.*;12import java.lang.annotation.*;13import java.util.regex.*;14import java.util.*;15import java.util.concurrent.*;16import java.util.concurrent

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package ui;2import java.util.Arrays;3public class Main {4 public static void main(String[] args) {5 System.out.println(Arrays.toString(args));6 MockRunner runner = new MockRunner();7 runner.start(args);8 }9}10package ui;11import java.util.Arrays;12public class Main {13 public static void main(String[] args) {14 System.out.println(Arrays.toString(args));15 MockRunner runner = new MockRunner();16 runner.start(args);17 }18}19package ui;20import java.util.Arrays;21public class Main {22 public static void main(String[] args) {23 System.out.println(Arrays.toString(args));24 MockRunner runner = new MockRunner();25 runner.start(args);26 }27}28package ui;29import java.util.Arrays;30public class Main {31 public static void main(String[] args) {32 System.out.println(Arrays.toString(args));33 MockRunner runner = new MockRunner();34 runner.start(args);35 }36}37package ui;38import java.util.Arrays;39public class Main {40 public static void main(String[] args) {41 System.out.println(Arrays.toString(args));42 MockRunner runner = new MockRunner();43 runner.start(args);44 }45}46package ui;47import java.util.Arrays;48public class Main {49 public static void main(String[] args) {50 System.out.println(Arrays.toString(args));51 MockRunner runner = new MockRunner();52 runner.start(args);53 }54}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Karate automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in MockRunner

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful