Easy Setup Stub Server

Related tags

Testing 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
Java DSL for easy testing of REST services

Testing and validation of REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of usi

REST Assured 6.2k Dec 31, 2022
AssertJ is a library providing easy to use rich typed assertions

AssertJ - Fluent assertions for java AssertJ provides a rich and intuitive set of strongly-typed assertions to use for unit testing (with JUnit, TestN

AssertJ 2.3k Dec 30, 2022
Java DSL for easy testing of REST services

Testing and validation of REST services in Java is harder than in dynamic languages such as Ruby and Groovy. REST Assured brings the simplicity of usi

REST Assured 6.2k Dec 25, 2022
AssertJ is a library providing easy to use rich typed assertions

AssertJ - Fluent assertions for java AssertJ provides a rich and intuitive set of strongly-typed assertions to use for unit testing (with JUnit, TestN

AssertJ 2.3k Jan 8, 2023
MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Rub

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).

Mock-Server 4k Jan 4, 2023
JUnit 5 extension for easy-random

Easy Random/Faker JUnit 5 extension The simple, stupid random Java™ beans generator for JUnit 5 The easy random extension provides a test with randoml

Libing Chen 8 Nov 9, 2022
🟪 DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses.

DeepfakeHTTP – Your 100% static dynamic backend DeepfakeHTTP is a web server that uses HTTP dumps as a source for responses. What are people using it

null 445 Dec 30, 2022
A Minestom extension that opens the port that the Minestom server is running on!

OpenPortStom A project that uses weupnp to forward the port for you when starting your server, it will also attempt to close the port. Yes this is a s

null 4 Apr 24, 2022
Gatling is a load test tool. It officially supports HTTP, WebSocket, Server-Sent-Events and JMS.

Gatling What is Gatling ? Gatling is a load test tool. It officially supports HTTP, WebSocket, Server-Sent-Events and JMS. Motivation Finding fancy GU

Gatling 5.8k Dec 27, 2022
This mod gives the option to server admins to disable chat reporting, in a non-intrusive way

Simply No Report This mod gives the option to server admins to disable chat reporting, in a non-intrusive way. It is disabled by default to let everyo

Amber Bertucci 17 Aug 20, 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