Code Monkey home page Code Monkey logo

mockserver-client-1c's Introduction

MockServer client for 1C:Enterprise Platform

Quality Gate Status Maintainability Rating

русский

MockServer-client-1c is designed to controll MoskServer using 1C:Enterprise Platform. This client is distributed as cfe and implemented as DataProcessor that interacts with the MockServer via the REST API. MockServer supports OpenAPI v3 specifications in either JSON or YAML format.

How it works

 Mock = DataProcessors.MockServerClient.Create();
 Mock.Server("http://localhost", "1080")
  .When(
   Mock.Request()
    .WithMetod("GET")
    .WithPath("/some/path")
    .Headers()
      .WithHeader("foo", "boo")
  ).Respond(
   Mock.Response()
    .WithStatusCode(200)
  );

That's all! Mock is created!

// @unit-test
Procedure Verify(Context) Export
  // given
  Mock = DataProcessors.MockServerClient.Create();
  Mock.Server( "http://localhost", "1080", true );
  HTTPConnector.Get( "http://localhost:1080/some/path" );
  HTTPConnector.Get( "http://localhost:1080/some/path" );
  // when
  Mock.When(
      Mock.Request()
        .WithPath("/some/path")
    ).Verify(
      Mock.Times()
        .AtLeast(2)
    );
  // then
  Assert.IsTrue(Mock.IsOk());
EndProcedure

Tested!

Code Examples

Public API

Getting Started

Overview

The typical sequence for using MockServer is as follows:

Start MockServer

Running MockServer documentation

For example, start the MockServer docker container:

docker run -d --rm -p 1080:1080 --name mockserver-1c-integration mockserver/mockserver -logLevel DEBUG -serverPort 1080

Or run docker-compose.yml from root directory of the project:

docker-compose -f "docker-compose.yml" up -d --build

Create an instance of the client

Connect to the default server:

Mock = DataProcessors.MockServerClient.Create();

Connect to the server at the specified host and port:

Mock = DataProcessors.MockServerClient.Create();
Mock = Mock.Server( "http://server" );
# or
Mock = DataProcessors.MockServerClient.Create();
Mock = Mock.Server( "http://server", "1099" );

Connect to the server at the specified host and port with a completely MockServer reset:

Mock = DataProcessors.MockServerClient.Create();
Mock = Mock.Server( "http://server", "1099", True );

Setup Expectations

Setup expectation (and verify requests) consists of two stages: preparing conditions (JSON) and sending an action (PUT JSON).

There are two types of methods: intermediate (returns self-object) and terminal (perform action). Some object's methods as parameters can accept a reference to themselves with preparing conditions or a JSON-format string. Before executing the action, the necessary JSON will be automatically generated depending on the selected terminal operation and preconditions.

Use method chaining style (fluent interface):

  # full JSON without auto-generating
  Mock.Server( "localhost", "1080" )
    .When( "{""name"":""value""}" )
    .Respond();

  # httpRequest property in JSON-style
  Mock.Server( "localhost", "1080" )
    .When(
      Mock.Request( """name"":""value""" )
    )
    .Respond();

  # combined style
  Mock.Server( "localhost", "1080" )
    .When(
      Mock.Request()
        .WithMethod( "GET" )
        .WithPath( "some/path" )
    )
    .Respond(
        Mock.Response( """statusCode"": 404" )
    );

Dependencies

The project built with:

  1. 1C:Enterprise 8.3.16.1502+ (8.3.16 compatibility mode)
  2. 1C:Enterprise Development Tools 2020.4 RC1
  3. 1Unit 0.4.0+
  4. vanessa-automation
  5. dt.bslls.validator
  6. BSL Language Server

Working with HTTP is implemented using the following libraries:

mockserver-client-1c's People

Contributors

astrizhachuk avatar

Watchers

James Cloos 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.