Git Product home page Git Product logo

http-testserver's Introduction

Simulating remote HTTP servers for functional testing

This is a test fixture, which provides a very basic servlet that registers expected requests and logs access counts for each requested method/pathParts combination. If no expectation is registered for a particular method/pathParts, 404 is returned.

Usage is pretty simple:

For junit 4 Rule based

@Rule
public ExpectationServerRule serverRule = new ExpectationServerRule( "repos" );

@Test
public void run()
    throws Exception
{
    final ExpectationServer server = serverRule.getServer();
    final String pathParts = "/repos/pathParts/to/something.txt";
    final String content = "this is the content";
    final String url = server.formatUrl( pathParts );
    server.expect( url, 200, content );
    // Do any assertions....
    .......
}

For junit 5 Extension Based:

@ExtendWith(ExpectationServerExtension.class)
public class ExpectaionTest{

    @Expected("repos")
    public ExpectationServer server;
 
    @Test
    public void run()
        throws Exception
    {
        final String pathParts = "/repos/pathParts/to/something.txt";
        final String content = "this is the content";
        final String url = server.formatUrl( pathParts );
        server.expect( url, 200, content );
        // Do any assertions....
        .......
    }
}

or:

public class ExpectaionTest{

    @RegisterExtension
    public ExpectationServerExtension extension = new ExpectationServerExtension("repos");
 
    @Test
    public void run()
        throws Exception
    {
        final ExpectationServer server = extension.getServer();
        final String pathParts = "/repos/pathParts/to/something.txt";
        final String content = "this is the content";
        final String url = server.formatUrl( pathParts );
        server.expect( url, 200, content );
        // Do any assertions....
        .......
    }
}

Quarkus Based Test

There are some limitations to let junit5 @ExtendWith work together with @QuarkusTest, see quarkusio/quarkus#24911 (comment)
So to make it work, here brings the new annotation to make it work.

@QuarkusTest
public class ExpectaionTest{

    @InjectExpected("repos")
    ExpectationServer server;
 
    @Test
    public void run()
        throws Exception
    {
        final String pathParts = "/repos/pathParts/to/something.txt";
        final String content = "this is the content";
        final String url = server.formatUrl( pathParts );
        server.expect( url, 200, content );
        // Do any assertions....
        .......
    }
}

http-testserver's People

Contributors

ligangty avatar jdcasey avatar commonjava-bot avatar ruhan1 avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.