Search in sources :

Example 1 with IBehaviorMatchBuilder

use of com.shulie.instrument.simulator.api.listener.ext.IBehaviorMatchBuilder in project LinkAgent by shulieTech.

the class MockPlugin method enhanceClassMethod.

public Map<String, EventWatcher> enhanceClassMethod(Map<String, Set<MockConfig>> configs) {
    if (configs == null || configs.isEmpty()) {
        return Collections.EMPTY_MAP;
    }
    Map<String, EventWatcher> watchers = new HashMap<String, EventWatcher>();
    for (Map.Entry<String, Set<MockConfig>> entry : configs.entrySet()) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("pre enhance class:{} ,configs:{}", entry.getKey(), entry.getValue());
        }
        for (MockConfig mockConfig : entry.getValue()) {
            IClassMatchBuilder buildingForClass = new EventWatchBuilder(moduleEventWatcher).onClass(entry.getKey());
            IBehaviorMatchBuilder buildingForBehavior = buildingForClass.onAnyBehavior(mockConfig.getMethodName());
            if (mockConfig.getMethodArgClasses() != null && !mockConfig.getMethodArgClasses().isEmpty()) {
                buildingForBehavior.withParameterTypes(mockConfig.getMethodArgClasses().toArray(new String[mockConfig.getMethodArgClasses().size()]));
            }
            buildingForBehavior.onListener(Listeners.of(MockAdviceListener.class, new Object[] { mockConfig.getCodeScript() }));
            watchers.put(mockConfig.getKey(), buildingForClass.onWatch());
        }
    }
    return watchers;
}
Also used : IClassMatchBuilder(com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder) MockAdviceListener(com.pamirs.attach.plugin.mock.interceptor.MockAdviceListener) EventWatcher(com.shulie.instrument.simulator.api.listener.ext.EventWatcher) IBehaviorMatchBuilder(com.shulie.instrument.simulator.api.listener.ext.IBehaviorMatchBuilder) MockConfig(com.pamirs.pradar.internal.config.MockConfig) EventWatchBuilder(com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)

Aggregations

MockAdviceListener (com.pamirs.attach.plugin.mock.interceptor.MockAdviceListener)1 MockConfig (com.pamirs.pradar.internal.config.MockConfig)1 EventWatchBuilder (com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)1 EventWatcher (com.shulie.instrument.simulator.api.listener.ext.EventWatcher)1 IBehaviorMatchBuilder (com.shulie.instrument.simulator.api.listener.ext.IBehaviorMatchBuilder)1 IClassMatchBuilder (com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder)1