Best Webtau code snippet using org.testingisdocumenting.webtau.server.WebTauServerFacade.serve
Source:WebTauServerFacade.java
...12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package org.testingisdocumenting.webtau.server;17import org.testingisdocumenting.webtau.cfg.WebTauConfig;18import org.testingisdocumenting.webtau.server.route.WebTauRouter;19import java.nio.file.Path;20import java.nio.file.Paths;21import java.util.Collections;22import static org.testingisdocumenting.webtau.server.WebTauServerResponseBuilder.*;23public class WebTauServerFacade {24 public static final WebTauServerFacade server = new WebTauServerFacade();25 private WebTauServerFacade() {26 }27 public final WebTauServerResponseBuilder response = new WebTauServerResponseBuilder();28 /**29 * create response for a server based on the payload type. For String the response will be <code>plain/text</code> and for30 * map/list/beans it will be application/json.31 *32 * @see WebTauServerFacade#response33 * @see WebTauServerResponseBuilder#text34 * @param body body to serialzie as response35 * @return response instance36 */37 public WebTauServerResponse response(Object body) {38 return response(USE_DEFAULT_STATUS_CODE, body);39 }40 /**41 * create response for a server based on the payload type with a specified status code.42 * For String the response will be <code>plain/text</code> and for43 * map/list/beans it will be application/json.44 *45 * @see WebTauServerFacade#response46 * @see WebTauServerResponseBuilder#text47 * @param statusCode status code to return48 * @param body body to serialize as response49 * @return response instance50 */51 public WebTauServerResponse response(int statusCode, Object body) {52 if (body instanceof String) {53 return response.text(statusCode, body.toString());54 }55 if (body == null) {56 return response.text(statusCode, "");57 }58 return response.json(statusCode, body);59 }60 /**61 * creates response for a server with empty response, empty content type and empty header62 * @param statusCode status code to return63 * @return response instance64 */65 public WebTauServerResponse statusCode(int statusCode) {66 return new WebTauServerResponse(statusCode, "", new byte[0], Collections.emptyMap());67 }68 /**69 * creates static content server and starts it on a random part70 * @param serverId unique server id71 * @param path static content path72 * @return server instance73 */74 public WebTauServer serve(String serverId, String path) {75 return serve(serverId, path, 0);76 }77 /**78 * creates static content server and starts it on a random part79 * @param serverId unique server id80 * @param path static content path81 * @return server instance82 */83 public WebTauServer serve(String serverId, Path path) {84 return serve(serverId, path, 0);85 }86 /**87 * creates static content server and starts it on the specified part88 * @param serverId unique server id89 * @param path static content path90 * @param port server port91 * @return server instance92 */93 public WebTauServer serve(String serverId, String path, int port) {94 return serve(serverId, Paths.get(path), port);95 }96 /**97 * creates static content server and starts it on the specified part98 * @param serverId unique server id99 * @param path static content path100 * @param port server port101 * @return server instance102 */103 public WebTauServer serve(String serverId, Path path, int port) {104 WebTauStaticServer server = new WebTauStaticServer(serverId, WebTauConfig.getCfg().fullPath(path), port);105 server.start();106 return server;107 }108 /**109 * creates proxy server and starts it on the specified part110 * @param serverId unique server id111 * @param urlToProxy url to proxy to112 * @param port server port113 * @return server instance114 */115 public WebTauProxyServer proxy(String serverId, String urlToProxy, int port) {116 WebTauProxyServer server = new WebTauProxyServer(serverId, urlToProxy, port);117 server.start();118 return server;119 }120 /**121 * creates proxy server and starts it on a random part122 * @param serverId unique server id123 * @param urlToProxy url to proxy to124 * @return server instance125 */126 public WebTauProxyServer proxy(String serverId, String urlToProxy) {127 return proxy(serverId, urlToProxy, 0);128 }129 /**130 * creates a fake server and starts it on the specified port131 * @param serverId unique server id132 * @param port server port133 * @return server instance134 * @see WebTauRouter135 */136 public WebTauServer fake(String serverId, int port) {137 WebTauFakeRestServer server = new WebTauFakeRestServer(serverId, port);138 server.start();139 return server;140 }141 /**142 * creates a fake server and starts it on a random port143 * @param serverId unique server id144 * @return server instance145 * @see WebTauRouter146 */147 public WebTauServer fake(String serverId) {148 return fake(serverId, 0);149 }150 /**151 * creates a fake server and starts it on the specified port using provided router to defined responses152 * @param serverId unique server id153 * @param port server port154 * @param router responses definition155 * @return server instance156 * @see WebTauRouter157 */158 public WebTauServer fake(String serverId, int port, WebTauRouter router) {159 WebTauFakeRestServer server = new WebTauFakeRestServer(serverId, port, router);160 server.start();161 return server;162 }163 /**164 * creates a fake server and starts it on a random port using provided router to defined responses165 * @param serverId unique server id166 * @param router responses definition167 * @return server instance168 * @see WebTauRouter169 */170 public WebTauServer fake(String serverId, WebTauRouter router) {171 return fake(serverId, 0, router);172 }173 /**174 * creates an instance of router to define or override responses175 * @param id unique router id176 * @return router instance177 * @see WebTauRouter178 */179 public WebTauRouter router(String id) {180 return new WebTauRouter(id);181 }182 /**183 * creates an instance of router to define or override responses assigning default router id184 * @return router instance185 * @see WebTauRouter...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!