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

io.github.smart.cloud.starter.mock.condition.MockCondition Maven / Gradle / Ivy

/*
 * Copyright © 2019 collin ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.github.smart.cloud.starter.mock.condition;

import io.github.smart.cloud.starter.configure.constants.ConfigureConstant;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 判断mock配置是否生效
 *
 * @author collin
 * @date 2019-04-27
 */
public class MockCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        Boolean mockApi = environment.getProperty(ConfigureConstant.MOCK_API_CONDITION_PROPERTY, Boolean.class);
        Boolean mockMethod = environment.getProperty(ConfigureConstant.MOCK_METHOD_CONDITION_PROPERTY, Boolean.class);
        return (mockApi != null && mockApi) || (mockMethod != null && mockMethod);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy