use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class MocoServer method start.
public int start(final int port, final ChannelInitializer<? extends Channel> pipelineFactory) {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(group).channel(NioServerSocketChannel.class).childHandler(pipelineFactory);
try {
future = bootstrap.bind(port).sync();
SocketAddress socketAddress = future.channel().localAddress();
return ((InetSocketAddress) socketAddress).getPort();
} catch (InterruptedException e) {
throw new MocoException(e);
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class JsonRequestMatcher method doMatch.
private boolean doMatch(final Request request, final byte[] content) {
try {
JsonNode requestNode = mapper.readTree(content);
JsonNode resourceNode = mapper.readTree(expected.readFor(of(request)).getContent());
return requestNode.equals(resourceNode);
} catch (JsonProcessingException jpe) {
return false;
} catch (IOException e) {
throw new MocoException(e);
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class XmlRequestMatcher method extractDocument.
private Document extractDocument(final InputSource inputSource, final DocumentBuilder builder) throws SAXException {
try {
Document document = builder.parse(inputSource);
document.normalizeDocument();
trimNode(document);
return document;
} catch (IOException e) {
throw new MocoException(e);
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class DefaultFailoverExecutor method onCompleteResponse.
@Override
public void onCompleteResponse(final HttpRequest request, final HttpResponse httpResponse) {
try {
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
Session targetSession = Session.newSession(request, httpResponse);
writer.writeValue(this.file, prepareTargetSessions(targetSession));
} catch (IOException e) {
throw new MocoException(e);
}
}
Aggregations