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();
}
网友评论