Giter Site home page Giter Site logo

codeite / javastubserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tarttelin/javastubserver

0.0 2.0 0.0 166 KB

An HTTP server used in tests to provide canned responses to expected requests.

Home Page: http://tarttelin.github.io/JavaStubServer/

License: Other

Groovy 4.75% Java 95.25%

javastubserver's Introduction

JavaStubServer Build Status

Stub server is intended to give a mockito-esque feel to a stubbed HTTP server. This allows you to test an application that hits external HTTP interfaces as a proper black box. Take this example

You have a web application that hits a ReST api to retrieve customer information. In the web app code, you have a gateway that calls the ReST api using a real HTTP request. In a test environment, you don't want to, or cannot depend on the real ReST api, so you want to have a fake server that provides canned data back. This is what StubServer is intended to simplify for you.

Example test:
Deploy your web app with a config file that declares that the ReST api is accessible on http://localhost:21435

  StubServer server = new StubServer(21435); // matching port
  server.start();
  server.expect(get("/api/customer/Bob")).thenReturn(200, "application/xml","<customer><name>Bob</name></customer>");
  // can have multiple expectations. The url is actually a regex
  try {
     selenium.open("http://localhost:8080/users/?name=Bob");
     //assertions that Bob has the right values as returned from the external ReST api
     server.verify(); // check that all expectations were called
  } finally {
     server.stop();
  }

With this approach, it feels more like a unit test, but it allows you to totally black box the system under test.

Build / dependency

  • The project is built with gradle. To build from source, install gradle and run gradle clean build

The library is available from maven central as:

groupId: com.pyruby artifactId: java-stub-server

javastubserver's People

Contributors

chris-h-barrett avatar happysathya avatar tarttelin avatar thecodeite avatar

Watchers

 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.