Easy Setup Stub Server

Related tags

HTTP Clients moco
Overview

Moco Build Status

Moco is an easy setup stub framework.

Latest Release

  • 1.1.0

More details in Release Notes

User Voice

Why

Integration, especially based on HTTP protocol, e.g. web service, REST etc, is wildly used in most of our development.

In the old days, we just deployed another WAR to an application server, e.g. Jetty or Tomcat etc. As we all know, it's so boring to develop a WAR and deploy it to any application server, even if we use an embeded server. And the WAR needs to be reassembled even if we just want to change a little bit.

Quick Start

  • Download Standalone Moco Runner
  • Write your own configuration file to describe your Moco server configuration as follow:
[
  {
    "response" :
      {
        "text" : "Hello, Moco"
      }
  }
]

(foo.json)

  • Run Moco HTTP server with the configuration file.
java -jar moco-runner-<version>-standalone.jar http -p 12306 -c foo.json

Documents

Build

Make sure you have JDK and Gradle installed.

  • Clone Moco
git clone [email protected]:dreamhead/moco.git
  • Build Moco
./gradlew build
  • Build uberjar
./gradlew uberjar
  • Check code before commit
./gradlew check

Contributing

Check out what you can help here if you do not have any existing idea.

Copyright and license

Copyright 2012-2020 ZHENG Ye

Licensed under MIT License (the "License"); You may obtain a copy of the License in the LICENSE file, or at:

https://raw.github.com/dreamhead/moco/master/MIT-LICENSE.txt

Powered By

Comments
  • Java API - Let Moco choose an available port

    Java API - Let Moco choose an available port

    When writing tests using the Java API, it would be nice to let Moco choose a port that is free on the OS and then provide a mechanism for querying that port. This would make tests written using Moco more robust when run on different environments.

    opened by garrettheel 14
  • Feature Request: Namespacing for stubbing multiple apps with one Moco instance

    Feature Request: Namespacing for stubbing multiple apps with one Moco instance

    I think it would be useful for Moco to allow multiple config files to be loaded into a single instance, each with a different namespace.

    This would avoid needing to spin up multiple instances of Moco when you want to run a few different stubs at the same time (for example during a build pipeline).

    Here's a rough example of how this could work:

    Runner runner = new NamespacedRunner(8080);
    runner.addConfig("myApp1", "/path/to/myConfig1.json");
    runner.addConfig("myApp2", "/path/to/myConfig2.json");
    runner.run()
    

    After doing this, the matchers in myConfig1.json will all be implicitly prepended with the path myApp1.

    E.g if myConfig1.json defines a matcher to catch all GET requests, it will catch requests to localhost:8080/myApp1**, but not localhost:8080/somethingElse.

    Do you agree that this would be a useful feature? I would be happy to help in implementation.

    Thanks, Garrett

    opened by garrettheel 14
  • (Blocker) Moco fails to start when executed in a test suite and dealing with large files

    (Blocker) Moco fails to start when executed in a test suite and dealing with large files

    What steps will reproduce the problem?

    1. Prepare a large json response file
    2. Simulate a test suite execution by running the following test (I wrote this in MocoTest class):
    @Test
        public void should_return_expected_response_from_a_large_file_and_run_a_new_server_without_exceptions() throws Exception {
            server.response(file("src/test/resources/large.response"));
    
            running(server, new Runnable() {
                @Override
                public void run() throws IOException {
                    assertThat(helper.get(root()), Matchers.notNullValue());
                }
            });
            server = httpserver(port());
            running(server, new Runnable() {
                @Override
                public void run() throws IOException {
                    assertThat(helper.get(root()), Matchers.notNullValue());
                }
            });
        }
    

    What is the expected output? What do you see instead? Moco will fail to start on the second attempt

    What version of the product are you using? On what operating system? Moco 0.9, Windows

    Workaround: We used Awaitility and wrote such piece of code that seems to wait until a port is free and we call after each running method:

    await().until(mocoShutsDownCompletelyAtPort(PORT));
    
    private Callable<Boolean> mocoShutsDownCompletelyAtPort(final int port) {
            return new Callable<Boolean>() {
                @Override
                public Boolean call() throws Exception {
                    System.out.println("Waiting until port is available");
                    String url = "http://localhost:"+ port;
    
                    try {                   
                        final URLConnection connection = new URL(url).openConnection();
                        connection.connect();
                        return true;
                    } catch (final MalformedURLException e) {
                        throw new IllegalStateException("Bad URL: " + url, e);
                    } catch (final IOException e) {
                        e.printStackTrace();
                        return false;
                    } 
                }
            };
        }   
    

    Please provide any additional information below. We have this issue when starting moco server when junit executes a test method in which we start a new Moco server. The problem is such that when we want to start a new server some big portion of data "blocks" still blocks closing of the previous server. We are working also with CXF and we are sending a lot of data so sometimes we see that the connection to Moco has been suddenly shutdown and we have errors like "Unexpected end of file" or sth like "error writting request body".

    opened by marcingrzejszczak 13
  • Allow response/request files to be loaded from classpath

    Allow response/request files to be loaded from classpath

    Currently, when using a file as the source of a request or response, the files are obtained via the java.io.File constructor.

    It would be useful if files could be loaded from the classpath to simplify the paths that go into configs. This could be implemented as a new static method on Moco which attempts to load a file using the ClassLoader.

    opened by garrettheel 12
  • Need change response in runtime

    Need change response in runtime

    In some scenarios, we need changing the response of an API in runtime. I think there are 2 ways to achieve it.

    1. Config response as an array and iterate it
    2. Provide an API to toggle it manually

    I see below feature on plan page, does it mean the same thing?

    • Runtime configuration change
    opened by seabornlee 9
  • Making it possible to configure Moco through Groovy script

    Making it possible to configure Moco through Groovy script

    Together with @kurlenda we created a bash script that allows to configure and run Moco server through Groovy script. In addition it downloads groovy if one doesn't have GDK already installed on his drive.

    opened by marcingrzejszczak 9
  • HTTPS Support

    HTTPS Support

    Hi, I really enjoy using Moco, however on my current project we needed HTTPS support, so I tried to put something together. Please let me know, if you think it's good enough to be merged in. If not, I'm happy to change it as necessary.

    Thanks!

    opened by msvab 8
  • Date variables for working with dates in template mock response

    Date variables for working with dates in template mock response

    Hi,

    first of all I want to say thaks for such a great tool! We need that in our mock responses are dates for specific periods (for example wee need date in the response which is 2 months from today or 4 months from today), so I have added 2 variable to the templates - "now" and "dateUtils" which can be used in such cases.

    opened by andrey-gr 8
  • HEAD request returns body

    HEAD request returns body

    Result are with latest version 0.10.1

    Why does a HEAD request yield a body?

    [
        {
            "request": {
                "uri": {
                    "startsWith": "/prefix"
                }
            },
            "response": {
                "text": {
                    "template": "${req}"
                },
                "headers": {
                    "header": "1.0",
                    "Date": "Mon, 02 Mar 2015 21:27:38 GMT"
                }
            }
        }
    ]
    
    ↳ curl -i -X HEAD http://localhost:5001/prefix
    HTTP/1.1 200 OK
    Date: Mon, 02 Mar 2015 21:27:38 GMT
    Content-Length: 165
    header: 1.0
    Content-Type: text/plain; charset=UTF-8
    
    HTTP Request{uri=/prefix, version=HTTP/1.1, method=HEAD, queries={}, headers={User-Agent=curl/7.37.1, Host=localhost:5001, Accept=*/*, Content-Length=0}, content=}%
    
    opened by arnm 7
  • Adds a call to get method of Future task.

    Adds a call to get method of Future task.

    Adds a call to get method of Future task so the threads are closed in sync. Resolves issue #71. I have not developed any test because stop method is called several times in tests.

    opened by lordofthejars 7
  • Use URI path parameters on the response template

    Use URI path parameters on the response template

    Is it possible to use URL parameters in path and insert them in the response template, as URL queries?

    For some mocks, I see the need to insert values coming from the URL path.

    For example:

    • URI: /v1/test/.*/example
    • Request: GET /v1/test/dummy/example
    • Response: dummy

    Maybe something like the following:

        {
            "request": {
                "uri": {
                    "match": "/v1/test/.*/example"
                },
                "method": "get",
            },
            "response": {
                "status": 200,
                "text": {
                    "template": "{$req.uri.param[0]}"
                },
                "headers": {
                    "Content-Type": "application/json"
                }
            }
        },
    

    Thanks.

    opened by wapcrazut 6
Owner
Zheng Ye
Zheng Ye
Tiny, easily embeddable HTTP server in Java.

NanoHTTPD – a tiny web server in Java NanoHTTPD is a light-weight HTTP server designed for embedding in other applications, released under a Modified

NanoHttpd 6.5k Jan 5, 2023
http-kit is a minimalist, event-driven, high-performance Clojure HTTP server/client library with WebSocket and asynchronous support

HTTP Kit A simple, high-performance event-driven HTTP client+server for Clojure CHANGELOG | API | current Break Version: [http-kit "2.5.3"] ; Publish

HTTP Client/Server for Clojure 2.3k Dec 31, 2022
A Java event based WebSocket and HTTP server

Webbit - A Java event based WebSocket and HTTP server Getting it Prebuilt JARs are available from the central Maven repository or the Sonatype Maven r

null 808 Jan 3, 2023
Allows you to duplicate items via the server kicking you. (Credits to TheTroll2001)

CloseConnection Dupe (1.12.2-1.17.1) Allows you to duplicate items via the server kicking you. (Credits to TheTroll2001) Usage Type .dupe <method> <pa

null 20 Nov 15, 2022
Easy Setup Stub Server

Moco Moco is an easy setup stub framework. Latest Release 1.1.0 More details in Release Notes User Voice Let me know if you are using Moco. Join Moco

Zheng Ye 4.1k Jan 4, 2023
Connection Pool Test Setup

Connection Pool Test Setup Setup to test the behavior of http connection pools with the following setup server-apache apache server with proxy-pass to

Johannes Wendig 1 Jan 21, 2022
Section B of Assignment 1. Setup project and collaborate on GitHub by writing test fixtures.

Task Each member (including the team leader) should create a branch (use student number as the branch name) and include a small program in the branch

Quinn Frost 1 Apr 6, 2022
A template for a Forge + Fabric project setup using a Common source set.

MultiLoader Template This project provides a Gradle project template that can compile mods for both Forge and Fabric using a common sourceset. This pr

Jared 130 Jan 5, 2023
This bare project template includes a minimal setup for using unimodules with React Native tvOS.

What This is a clone of expo's bare minimal template which includes a minimal setup for using unimodules with React Native. Additionally, this templat

Abdullah Musab Ceylan 4 Dec 25, 2022
Easy-es - easy use for elastich search

Born To Simplify Development What is Easy-Es? Easy-Es is a powerfully enhanced toolkit of RestHighLevelClient for simplify development. This toolkit p

null 777 Jan 6, 2023
💡极致性能的企业级Java服务器框架,RPC,游戏服务器框架,web应用服务器框架。(Extreme fast enterprise Java server framework, can be RPC, game server framework, web server framework.)

?? 为性能而生的万能服务器框架 ?? Ⅰ. zfoo简介 ?? 性能炸裂,天生异步,Actor设计思想,无锁化设计,基于Spring的MVC式用法的万能RPC框架 极致序列化,原生集成的目前二进制序列化和反序列化速度最快的 zfoo protocol 作为网络通讯协议 高可拓展性,单台服务器部署,

null 1k Jan 1, 2023
Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API

Swagger Core NOTE: If you're looking for Swagger Core 1.5.X and OpenAPI 2.0, please refer to 1.5 branch. NOTE: Since version 2.1.7 Swagger Core suppor

Swagger 7.1k Jan 5, 2023
A simple Plugin to allow server admins and user with Permissions to change fast and easy thier own Gamemode

A simple Plugin to allow server admins and user with Permissions to change fast and easy thier own Gamemode

Qubik Studios 1 Jan 17, 2022
Essentials - Minecraft server command mod - Adds over 100 commands for use in-game to help manage a server

Essentials Development Readme The official repository is at: https://github.com/essentials/Essentials We use NetBeans 7.3 for development. Recommended

Essentials 811 Jan 7, 2023
The most powerfull forge server software (not yet) which aims for high capacity and performance on 1.16.5 modded server.

GoldenForge The most powerfull forge server software (not yet) which aims for high capacity and performance on 1.16.5 modded server. Current work Asyn

null 20 Sep 3, 2022
Sonic-server - sonic-server

?? Sonic Cloud Real Machine Testing Platform English | 简体中文 Official Website Sonic Official Website Background What is sonic ? Nowadays, automatic tes

null 1.7k Jan 4, 2023
SlimeVR-Server - Server app for SlimeVR ecosystem

SlimeVR Server Server app for SlimeVR ecosystem Server orchestrates communication between multiple sensors and integrations, like SteamVR. Sensors imp

null 362 Dec 31, 2022
Control a VNC server from a Minecraft server today!

MakiDesktop ?? Controlling VNC through a Minecraft server How does it work Load jar plugin onto 1.17.1 Paper server It will connect to IP:PORT specifi

null 5 May 1, 2022
A simple Discord bot, which shows the server status of the Lost Ark server Beatrice

Beatrice A simple Discord bot, which shows the server status of the Lost Ark server Beatrice. Example Usage Clone the repository. Edit the property fi

Leon 3 Mar 9, 2022
A Minecraft server proxy with unparalleled server support, scalability, and flexibility

Velocity A Minecraft server proxy with unparalleled server support, scalability, and flexibility. Velocity is licensed under the GPLv3 license. Goals

PaperMC 1.2k Jan 8, 2023