All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.cweijan.mock.Mocker Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package io.github.cweijan.mock;

import feign.RequestInterceptor;
import io.github.cweijan.mock.context.HttpMockContext;
import io.github.cweijan.mock.feign.FeignMockerContext;

/**
 * @author cweijan
 * @since 2020/05/21 17:30
 */
public class Mocker {

    /**
     * 调用controller方法时会发送请求到本地spring boot应用
     * 调用该方法会创建3个核心对象: feign接口, feign接口代理, controller代理
     *
     * @param controllerClass 目标controller
     * @param port            springboot应用端口
     */
    public static  T api(Class controllerClass, Integer port) {
        return api(controllerClass, new HttpMockContext("http", "127.0.0.1", port));
    }

    /**
     * 调用controller方法时会发送请求到本地spring boot应用
     * 调用该方法会创建3个核心对象: feign接口, feign接口代理, controller代理
     *
     * @param controllerClass 目标controller
     * @param context 目标web应用上下文
     */
    public static  T api(Class controllerClass, HttpMockContext context) {

        return FeignMockerContext.getFeignClientWrapper(controllerClass, context);
    }


    public static void apiInterceptor(RequestInterceptor requestInterceptor) {
        FeignMockerContext.addInterceptor(requestInterceptor);
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy