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 Globs method doGlob.
private static ImmutableList<String> doGlob(final Path path, final Path searchPath) {
final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + path);
try {
final ImmutableList.Builder<String> builder = ImmutableList.builder();
Files.walkFileTree(searchPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
if (matcher.matches(file)) {
builder.add(file.toString());
}
return FileVisitResult.CONTINUE;
}
});
return builder.build();
} catch (IOException e) {
throw new MocoException(e);
}
}
use of com.github.dreamhead.moco.MocoException in project moco by dreamhead.
the class MocoRequestAction method execute.
@Override
public final void execute(final Request request) {
try (CloseableHttpClient client = HttpClients.createDefault()) {
final HttpUriRequest actionRequest = prepareRequest(request);
dump(actionRequest);
final CloseableHttpResponse response = client.execute(actionRequest);
dump(response);
} catch (IOException e) {
throw new MocoException(e);
}
}
Aggregations