com.github.dreamhead.moco.parser.model.PostSetting Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of moco-runner Show documentation
Show all versions of moco-runner Show documentation
Moco is an easy setup stub framework, mainly focusing on testing and integration.
package com.github.dreamhead.moco.parser.model;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.github.dreamhead.moco.Moco;
import com.github.dreamhead.moco.MocoEventAction;
import com.github.dreamhead.moco.resource.ContentResource;
import com.google.common.base.MoreObjects;
import java.util.Map;
import java.util.Optional;
import static com.github.dreamhead.moco.Moco.post;
import static java.util.Optional.empty;
import static java.util.Optional.of;
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public final class PostSetting extends BaseActionSetting {
private TextContainer url;
private Map headers;
private TextContainer content;
private Object json;
public MocoEventAction createAction() {
Optional postContent = postContent();
final ContentResource content = postContent.orElseThrow(() ->
new IllegalArgumentException("content or json should be setup for post event"));
return doCreateAction(content);
}
private MocoEventAction doCreateAction(final ContentResource content) {
ContentResource url = this.url.asResource();
return post(url, content, asHeaders(this.headers));
}
private Optional postContent() {
if (content != null) {
return of(content.asResource());
}
if (json != null) {
return of(Moco.json(json));
}
return empty();
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.omitNullValues()
.add("url", url)
.add("headers", headers)
.add("content", content)
.add("json", json)
.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy