com.arextest.schedule.model.invocation.GeneralInvocation Maven / Gradle / Ivy
package com.arextest.schedule.model.invocation;
import com.arextest.schedule.extension.invoker.ReplayExtensionInvoker;
import com.arextest.schedule.extension.invoker.ReplayInvocation;
import java.util.HashMap;
import java.util.Map;
import lombok.Setter;
import org.apache.commons.collections4.MapUtils;
public class GeneralInvocation implements ReplayInvocation {
protected String url;
@Setter
protected ReplayExtensionInvoker invoker;
protected Map attributes = new HashMap<>();
public GeneralInvocation(String url, Map attributes) {
this.url = url;
if (MapUtils.isNotEmpty(attributes)) {
this.attributes.putAll(attributes);
}
}
@Override
public String getUrl() {
return url;
}
@Override
public Map getAttributes() {
return attributes;
}
@Override
public ReplayExtensionInvoker getInvoker() {
return invoker;
}
@Override
public void put(String key, Object value) {
this.attributes.put(key, value);
}
@Override
public T get(String key, Class clazz) {
Object value = attributes.get(key);
if (value == null) {
return null;
}
if (!clazz.isAssignableFrom(value.getClass())) {
throw new IllegalArgumentException("Invalid value type, expected " + clazz.getSimpleName()
+ ", but got " + value.getClass().getSimpleName());
}
return clazz.cast(value);
}
@Override
public Object get(String key) {
return attributes.get(key);
}
}