美文网首页
mock工具

mock工具

作者: 酷酷的美猴王 | 来源:发表于2018-09-12 19:56 被阅读0次

    1:Mockable

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface Mockable {
    
        /**
         * 接口的Mock级别,默认为 带参Mock
         */
        MockLevel mockLevel() default MockLevel.MOCK_WITH_PARAMS;
    }
    

    2:MockLevel

    public enum MockLevel {
        //带参数Mock
        MOCK_WITH_PARAMS,
        //不带参数Mock
        MOCK_WITHOUT_PARAMS,
        //强制Mock异常
        MOCK_WITH_EXCEPTION,
        //强制Mock错误
        MOCK_WITH_ERROR;
    }
    

    3:MockResultConfig

    @Data
    public class MockResultConfig {
        private Long id;
        private String interfaceMethodParamKey;
        private String resultContent;
        private String hashCode;
        private String resultType;
        private int status;
    

    4:MockResultDesc

    public enum MockResultDesc {
        METHOD_MOCK_RESULT_CONFIG_LESS("NOT FOUND MOCK RESULT CONFIG"),
        METHOD_MOCK_RESULT_BUILD_FAIL("MOCK RESULT BUILD FAIL");
    
        private String desc;
        MockResultDesc(String desc) {
            this.desc = desc;
        }
        public String getDesc() {
            return desc;
        }
    }
    

    5:MockResultDynamicReplaceMapping

    @Data
    public class MockResultDynamicReplaceMapping {
    
        private Long id;
        private String interfaceMethodParamKey;
        private int hashCode;
        private String paramKey;
        private String propertyKey;
    
    }
    

    6:MockResultConfigMapper

    @Repository
    public interface MockResultConfigMapper {
    
        //查询有效状态的mock标记
        MockResultConfig queryConfigsValidateByHashCode(@Param("hashCode") String hashCode);
    
        MockResultConfig queryConfigsValidateByInterFace(@Param("interFace") String interFace);
    
        void saveMockResultConfig(@Param("mockResultConfig") MockResultConfig mockResultConfig);
    }
    

    7:MockResultDynamicReplaceMappingMapper

    @Repository
    public interface MockResultDynamicReplaceMappingMapper {
    
        //查询有效状态的mock标记
        List<MockResultDynamicReplaceMapping> queryMappingByHashCode(@Param("hashCode") String hashCode);
    
        List<MockResultDynamicReplaceMapping> queryMappings();
    }
    

    相关文章

      网友评论

          本文标题:mock工具

          本文链接:https://www.haomeiwen.com/subject/ehubgftx.html