Search in sources :

Example 6 with MocoException

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);
    }
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) MocoException(com.github.dreamhead.moco.MocoException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 7 with MocoException

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);
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) MocoException(com.github.dreamhead.moco.MocoException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 8 with MocoException

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);
    }
}
Also used : IOException(java.io.IOException) MocoException(com.github.dreamhead.moco.MocoException) Document(org.w3c.dom.Document)

Example 9 with MocoException

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);
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) MocoException(com.github.dreamhead.moco.MocoException) Session(com.github.dreamhead.moco.model.Session)

Aggregations

MocoException (com.github.dreamhead.moco.MocoException)9 IOException (java.io.IOException)6 Session (com.github.dreamhead.moco.model.Session)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 MessageContent (com.github.dreamhead.moco.model.MessageContent)1 ImmutableList (com.google.common.collect.ImmutableList)1 ParseException (freemarker.core.ParseException)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1