├── .github └── workflows │ └── sonar-scanner.yml ├── .gitignore ├── COPYING.md ├── README.md ├── docker-compose.yml ├── docs ├── en │ ├── Examples.md │ └── PublicAPI.md └── ru │ ├── Examples.md │ ├── PublicAPI.md │ └── README.md ├── mockserver-client.Tests ├── .project ├── .settings │ └── org.eclipse.core.resources.prefs ├── DT-INF │ └── PROJECT.PMF ├── features │ ├── all │ │ ├── Tests_CallWrapperRu.feature │ │ ├── Tests_CreateMock.feature │ │ ├── Tests_Exceptions.feature │ │ ├── Tests_Integration.feature │ │ ├── Tests_OpenAPI.feature │ │ ├── Tests_Request.feature │ │ ├── Tests_RequestMatchers.feature │ │ ├── Tests_Reset.feature │ │ ├── Tests_Respond.feature │ │ ├── Tests_Response.feature │ │ ├── Tests_ResponseAction.feature │ │ ├── Tests_Times.feature │ │ ├── Tests_TimesMethods.feature │ │ ├── Tests_Verify.feature │ │ └── Tests_When.feature │ ├── dev │ │ ├── Tests_RequestMatchers.feature │ │ └── Tests_ResponseAction.feature │ ├── integration │ │ └── Tests_Integration.feature │ └── prepare │ │ └── Tests_Integration.feature └── src │ ├── CommonModules │ ├── Assert │ │ ├── Assert.mdo │ │ └── Module.bsl │ ├── Tests_CallWrapperRu │ │ ├── Module.bsl │ │ └── Tests_CallWrapperRu.mdo │ ├── Tests_CreateMock │ │ ├── Module.bsl │ │ └── Tests_CreateMock.mdo │ ├── Tests_Exceptions │ │ ├── Module.bsl │ │ └── Tests_Exceptions.mdo │ ├── Tests_Integration │ │ ├── Module.bsl │ │ └── Tests_Integration.mdo │ ├── Tests_OpenAPI │ │ ├── Module.bsl │ │ └── Tests_OpenAPI.mdo │ ├── Tests_Request │ │ ├── Module.bsl │ │ └── Tests_Request.mdo │ ├── Tests_RequestMatchers │ │ ├── Module.bsl │ │ └── Tests_RequestMatchers.mdo │ ├── Tests_Reset │ │ ├── Module.bsl │ │ └── Tests_Reset.mdo │ ├── Tests_Respond │ │ ├── Module.bsl │ │ └── Tests_Respond.mdo │ ├── Tests_Response │ │ ├── Module.bsl │ │ └── Tests_Response.mdo │ ├── Tests_ResponseAction │ │ ├── Module.bsl │ │ └── Tests_ResponseAction.mdo │ ├── Tests_Times │ │ ├── Module.bsl │ │ └── Tests_Times.mdo │ ├── Tests_TimesMethods │ │ ├── Module.bsl │ │ └── Tests_TimesMethods.mdo │ ├── Tests_Verify │ │ ├── Module.bsl │ │ └── Tests_Verify.mdo │ └── Tests_When │ │ ├── Module.bsl │ │ └── Tests_When.mdo │ └── Configuration │ ├── CommandInterface.cmi │ ├── Configuration.mdo │ └── MainSectionCommandInterface.cmi ├── mockserver-client.cfe ├── .project ├── .settings │ └── org.eclipse.core.resources.prefs ├── DT-INF │ └── PROJECT.PMF └── src │ ├── CommonModules │ ├── HTTPConnector │ │ ├── HTTPConnector.mdo │ │ └── Module.bsl │ └── HTTPStatusCodesClientServerCached │ │ ├── HTTPStatusCodesClientServerCached.mdo │ │ └── Module.bsl │ ├── Configuration │ ├── CommandInterface.cmi │ ├── Configuration.mdo │ └── MainSectionCommandInterface.cmi │ └── DataProcessors │ └── MockServerClient │ ├── MockServerClient.mdo │ └── ObjectModule.bsl ├── mockserver-client ├── .project ├── .settings │ └── org.eclipse.core.resources.prefs ├── DT-INF │ └── PROJECT.PMF └── src │ └── Configuration │ └── Configuration.mdo ├── sonar-project.properties └── test └── stub.dt /.github/workflows/sonar-scanner.yml: -------------------------------------------------------------------------------- 1 | name: sonar-scanner 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - master 7 | push: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | SonarScanner: 13 | if: github.repository == 'astrizhachuk/mockserver-client-1c' 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout 17 | uses: actions/checkout@v1 18 | - name: Setup SonarQube scanner 19 | uses: warchant/setup-sonar-scanner@v1 20 | - name: Run SonarQube on push 21 | if: github.event_name == 'push' 22 | run: sonar-scanner 23 | -Dsonar.login=${{ secrets.SONAR_TOKEN }} 24 | -Dsonar.projectVersion=$(grep -oPm1 "(?<=)[^<]+" mockserver-client/src/Configuration/Configuration.mdo) 25 | -Dsonar.host.url=https://sonar.openbsl.ru 26 | -Dsonar.branch.name=${GITHUB_REF#refs/heads/} 27 | - name: Run SonarQube on pull request 28 | if: github.event_name == 'pull_request' 29 | run: sonar-scanner 30 | -Dsonar.login=${{ secrets.SONAR_TOKEN }} 31 | -Dsonar.host.url=https://sonar.openbsl.ru 32 | -Dsonar.projectVersion=$(grep -oPm1 "(?<=)[^<]+" mockserver-client/src/Configuration/Configuration.mdo) 33 | -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} 34 | -Dsonar.pullrequest.branch=${{ github.event.pull_request.head.ref }} 35 | -Dsonar.pullrequest.base=${{ github.event.pull_request.base.ref }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MockServer client for 1C:Enterprise Platform 2 | 3 | [![Quality Gate Status](https://sonar.openbsl.ru/api/project_badges/measure?project=mockserver-client-1c&metric=alert_status)](https://sonar.openbsl.ru/dashboard?id=mockserver-client-1c) 4 | [![Maintainability Rating](https://sonar.openbsl.ru/api/project_badges/measure?project=mockserver-client-1c&metric=sqale_rating)](https://sonar.openbsl.ru/dashboard?id=mockserver-client-1c) 5 | 6 | [русский](https://github.com/astrizhachuk/mockserver-client-1c/blob/master/docs/ru/README.md) 7 | 8 | *[MockServer](https://www.mock-server.com/#what-is-mockserver)-client-1c* is designed to [manage](https://www.mock-server.com/mock_server/mockserver_clients.html) MoskServer using 1C:Enterprise Platform. This *client* is distributed as *cfe* and implemented as *DataProcessor* that interacts with the MockServer via the [REST API](https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.11.x). MockServer supports OpenAPI v3 specifications in either JSON or YAML format. 9 | 10 | ## How it works 11 | 12 | ```text 13 | Mock = DataProcessors.MockServerClient.Create(); 14 | Mock.Server("http://localhost", "1080") 15 | .When( 16 | Mock.Request() 17 | .WithMetod("GET") 18 | .WithPath("/some/path") 19 | .Headers() 20 | .WithHeader("foo", "boo") 21 | ).Respond( 22 | Mock.Response() 23 | .WithStatusCode(200) 24 | ); 25 | ``` 26 | 27 | That's all! Mock is created! 28 | 29 | ```text 30 | // @unit-test 31 | Procedure Verify(Context) Export 32 | // given 33 | Mock = DataProcessors.MockServerClient.Create(); 34 | Mock.Server( "http://localhost", "1080", true ); 35 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 36 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 37 | // when 38 | Mock.When( 39 | Mock.Request() 40 | .WithPath("/some/path") 41 | ).Verify( 42 | Mock.Times() 43 | .AtLeast(2) 44 | ); 45 | // then 46 | Assert.IsTrue(Mock.IsOk()); 47 | EndProcedure 48 | ``` 49 | 50 | Tested! 51 | 52 | [Code Examples](https://github.com/astrizhachuk/mockserver-client-1c/blob/master/docs/en/Examples.md) 53 | 54 | [Public API](https://github.com/astrizhachuk/mockserver-client-1c/blob/master/docs/en/PublicAPI.md) 55 | 56 | ## Getting Started 57 | 58 | [Overview](https://www.mock-server.com/mock_server/getting_started.html) 59 | 60 | The typical sequence for using MockServer is as follows: 61 | 62 | * [Start MockServer](#StartMockServer) 63 | * [Create an instance of the client](#CreateInstance) 64 | * [Setup Expectations](#SetupExpectations) 65 | * Run Your Test Scenarios 66 | * Verify Requests 67 | 68 | ### Start MockServer 69 | 70 | [Running MockServer documentation](https://www.mock-server.com/mock_server/running_mock_server.html) 71 | 72 | For example, start the MockServer docker container: 73 | 74 | ```text 75 | docker run -d --rm -p 1080:1080 --name mockserver-1c-integration mockserver/mockserver -logLevel DEBUG -serverPort 1080 76 | ``` 77 | 78 | Or run docker-compose.yml from root directory of the project: 79 | 80 | ```text 81 | docker-compose -f "docker-compose.yml" up -d --build 82 | ``` 83 | 84 | ### Create an instance of the client 85 | 86 | Connect to the default server: 87 | 88 | ```text 89 | Mock = DataProcessors.MockServerClient.Create(); 90 | ``` 91 | 92 | Connect to the server at the specified host and port: 93 | 94 | ```text 95 | Mock = DataProcessors.MockServerClient.Create(); 96 | Mock = Mock.Server( "http://server" ); 97 | # or 98 | Mock = DataProcessors.MockServerClient.Create(); 99 | Mock = Mock.Server( "http://server", "1099" ); 100 | ``` 101 | 102 | Connect to the server at the specified host and port with a completely MockServer [reset](https://www.mock-server.com/mock_server/clearing_and_resetting.html): 103 | 104 | ```text 105 | Mock = DataProcessors.MockServerClient.Create(); 106 | Mock = Mock.Server( "http://server", "1099", True ); 107 | ``` 108 | 109 | ### Setup Expectations 110 | 111 | Setup expectation (and verify requests) consists of two stages: preparing conditions (JSON) and sending an action (PUT JSON). 112 | 113 | 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. 114 | 115 | Use method chaining style (fluent interface): 116 | 117 | ```text 118 | # full JSON without auto-generating 119 | Mock.Server( "localhost", "1080" ) 120 | .When( "{""name"":""value""}" ) 121 | .Respond(); 122 | 123 | # httpRequest property in JSON-style 124 | Mock.Server( "localhost", "1080" ) 125 | .When( 126 | Mock.Request( """name"":""value""" ) 127 | ) 128 | .Respond(); 129 | 130 | # combined style 131 | Mock.Server( "localhost", "1080" ) 132 | .When( 133 | Mock.Request() 134 | .WithMethod( "GET" ) 135 | .WithPath( "some/path" ) 136 | ) 137 | .Respond( 138 | Mock.Response( """statusCode"": 404" ) 139 | ); 140 | 141 | ``` 142 | 143 | ## Dependencies 144 | 145 | The project built with: 146 | 147 | 1. [1C:Enterprise](https://1c-dn.com) 8.3.16.1502+ (8.3.16 compatibility mode) 148 | 2. [1C:Enterprise Development Tools](https://edt.1c.ru) 2020.4 RC1 149 | 3. [1Unit](https://github.com/DoublesunRUS/ru.capralow.dt.unit.launcher) 0.4.0+ 150 | 4. [vanessa-automation](https://github.com/Pr-Mex/vanessa-automation) 151 | 5. [dt.bslls.validator](https://github.com/DoublesunRUS/ru.capralow.dt.bslls.validator) 152 | 6. [BSL Language Server](https://github.com/1c-syntax/bsl-language-server) 153 | 154 | Working with HTTP is implemented using the following libraries: 155 | 156 | * [HTTPConnector](https://github.com/vbondarevsky/Connector) 157 | * [HTTPStatusCodes](https://github.com/astrizhachuk/HTTPStatusCodes) 158 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | 5 | mock: 6 | image: mockserver/mockserver 7 | command: -logLevel DEBUG -serverPort 1080 8 | ports: 9 | - "1080:1080" 10 | # volumes: 11 | # - ./api-receiver.yaml:/tmp/receiver.yaml -------------------------------------------------------------------------------- /docs/en/Examples.md: -------------------------------------------------------------------------------- 1 | # Code Examples 2 | 3 | ## Clearing & Resetting 4 | 5 | ### reset everything 6 | 7 | ```text 8 | Mock.Server("http://localhost", "1080").Reset(); 9 | ``` 10 | 11 | ## Request Properties Matcher 12 | 13 | ### match request by path 14 | 15 | ```text 16 | Mock.When( 17 | Mock.Request() 18 | .WithPath("/some/path") 19 | ).Respond( 20 | Mock.Response() 21 | .WithBody("some_response_body") 22 | ); 23 | ``` 24 | 25 | ### match request by method regex 26 | 27 | ```text 28 | Mock.When( 29 | Mock.Request() 30 | .WithMethod("P.*{2,3}") 31 | ).Respond( 32 | Mock.Response() 33 | .WithBody("some_response_body") 34 | ); 35 | ``` 36 | 37 | ### match request by not matching method 38 | 39 | ```text 40 | Mock.When( 41 | Mock.Request() 42 | .WithMethod("!GET") 43 | ).Respond( 44 | Mock.Response() 45 | .WithBody("some_response_body") 46 | ); 47 | ``` 48 | 49 | ### match request by query parameter with regex value 50 | 51 | ```text 52 | Mock.When( 53 | Mock.Request() 54 | .WithPath("/some/path") 55 | .WithQueryStringParameter("cartId", "[A-Z0-9\\-]+") 56 | .WithQueryStringParameter("anotherId", "[A-Z0-9\\-]+") 57 | ).Respond( 58 | Mock.Response() 59 | .WithBody("some_response_body") 60 | ); 61 | ``` 62 | 63 | ### match request by headers 64 | 65 | ```text 66 | Mock.When( 67 | Mock.Request() 68 | .WithMethod("GET") 69 | .WithPath("/some/path") 70 | .Headers() 71 | .WithHeader("Accept", "application/json") 72 | .WithHeader("Accept-Encoding", "gzip, deflate, br") 73 | ).Respond( 74 | Mock.Response() 75 | .WithBody("some_response_body") 76 | ); 77 | ``` 78 | 79 | ## Response Action 80 | 81 | ### literal response with body only 82 | 83 | ```text 84 | Mock.Respond( 85 | Mock.Response() 86 | .WithBody("some_response_body") 87 | ); 88 | ``` 89 | 90 | ### literal response with status code and reason phrase 91 | 92 | ```text 93 | Mock.When( 94 | Mock.Request() 95 | .WithMethod("GET") 96 | .WithPath("/some/path") 97 | ).Respond( 98 | Mock.Response() 99 | .WithStatusCode(418) 100 | .WithReasonPhrase("I'm a teapot") 101 | ); 102 | ``` 103 | 104 | ## Verifying Repeating Requests 105 | 106 | ### verify requests received at least twice 107 | 108 | ```text 109 | Mock.When( 110 | Mock.Request() 111 | .WithPath("/some/path") 112 | ).Verify( 113 | Mock.Times() 114 | .AtLeast(2) 115 | ); 116 | ``` 117 | 118 | ### verify requests received at most twice 119 | 120 | ```text 121 | Mock.When( 122 | Mock.Request() 123 | .WithPath("/some/path") 124 | ).Verify( 125 | Mock.Times() 126 | .AtMost(2) 127 | ); 128 | ``` 129 | 130 | ### verify requests received exactly twice 131 | 132 | ```text 133 | Mock.When( 134 | Mock.Request() 135 | .WithPath("/some/path") 136 | ).Verify( 137 | Mock.Times() 138 | .Exactly(2) 139 | ); 140 | ``` 141 | 142 | ### verify requests received at least twice by openapi 143 | 144 | ```text 145 | Mock.When( 146 | Mock.OpenAPI() 147 | .WithSource("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 148 | ).Verify( 149 | Mock.Times() 150 | .AtLeast(2) 151 | ); 152 | ``` 153 | 154 | ### verify requests received at exactly once by openapi and operation 155 | 156 | ```text 157 | Mock.When( 158 | Mock.OpenAPI() 159 | .WithSource("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 160 | .WithOperationId("listPets") 161 | ).Verify( 162 | Mock.Times() 163 | .Once() 164 | ); 165 | ``` 166 | 167 | ### verify requests received at exactly once 168 | 169 | ```text 170 | Mock.When( 171 | Mock.Request() 172 | .WithPath("/some/path") 173 | ).Verify( 174 | Mock.Times() 175 | .Once() 176 | ); 177 | ``` 178 | 179 | ### verify requests received between n and m times 180 | 181 | ```text 182 | Mock.When( 183 | Mock.Request() 184 | .WithPath("/some/path") 185 | ).Verify( 186 | Mock.Times() 187 | .Between(2, 3) 188 | ); 189 | ``` 190 | 191 | ### verify requests never received 192 | 193 | ```text 194 | Mock.When( 195 | Mock.Request() 196 | .WithPath("/some/path") 197 | ).Verify( 198 | Mock.Times() 199 | .Exactly(0) 200 | ); 201 | ``` 202 | -------------------------------------------------------------------------------- /docs/en/PublicAPI.md: -------------------------------------------------------------------------------- 1 | # Public API 2 | 3 | Auto generated by [BSl LS](https://github.com/1c-syntax/bsl-language-server) 4 | 5 | ## ObjectModule 6 | 7 | ### Server 8 | 9 | ```bsl 10 | // Initializes the client to communicate with the MockServer on the specified host and port. 11 | // 12 | // Parameters: 13 | // URL - String - URL; 14 | // Port - String - port; 15 | // Reset - Boolean - True - reset MockServer, otherwise - False (default); 16 | // 17 | // Returns: 18 | // DataProcessorObject.MockServerClient - instance of mock-object; 19 | // 20 | // Example: 21 | // Mock = DataProcessors.MockServerClient.Create().Server("http://server"); 22 | // Mock = DataProcessors.MockServerClient.Create().Server("http://server", "1090"); 23 | // Mock = DataProcessors.MockServerClient.Create().Server("http://server", "1090", True); 24 | // 25 | Функция Server(Знач URL, Знач Port = Undefined, Знач Reset = False) Экспорт 26 | ``` 27 | 28 | ### When 29 | 30 | ```bsl 31 | // Presets any conditions or accepts fully prepared JSON for subsequent sending data to MockServer. 32 | // 33 | // Parameters: 34 | // What - DataProcessorObject.MockServerClient - instance of mock-object with a predefined conditions; 35 | // - String - JSON to send to MockServer; 36 | // 37 | // Returns: 38 | // DataProcessorObject.MockServerClient - instance of mock-object; 39 | // 40 | // Example: 41 | // Mock.When( Mock.WithPath("/фуу/foo") ).Respond(); 42 | // Mock.When("{""sample"": ""any""}").Respond(); 43 | // 44 | Функция When(Знач What) Экспорт 45 | ``` 46 | 47 | ### Request 48 | 49 | ```bsl 50 | // Prepares a set of request properties in "httpRequest" node. 51 | // 52 | // Parameters: 53 | // Request - String - a request properties in JSON-format; 54 | // - Undefined - an empty collection will be added to the conditions collection for the 'httpRequest' node; 55 | // 56 | // Returns: 57 | // DataProcessorObject.MockServerClient - instance of mock-object with a new collection of properties; 58 | // 59 | // Example: 60 | // Mock.When( Mock.Request().WithPath("/фуу/foo") ).Respond( Mock.Response().WithBody("some_response_body") ); 61 | // Mock.When( Mock.Request("""method"": ""GET""") ).Respond( Mock.Response().WithBody("some_response_body") ); 62 | // 63 | Функция Request(Знач Request = Undefined) Экспорт 64 | ``` 65 | 66 | ### Response 67 | 68 | ```bsl 69 | // Prepares a set of response properties in "httpResponse" node. 70 | // 71 | // Parameters: 72 | // Response - String - a response properties in JSON-format; 73 | // - Undefined - an empty collection will be added to the conditions collection for the 'httpResponse' node; 74 | // 75 | // Returns: 76 | // DataProcessorObject.MockServerClient - instance of mock-object with a new collection of properties; 77 | // 78 | // Example: 79 | // Mock.When( Mock.Request().WithPath("/фуу/foo") ).Respond( Mock.Response().WithBody("some_response_body") ); 80 | // Mock.When( Mock.Request().WithPath("/фуу/foo") ).Respond( Mock.Response("""statusCode"": 200 ") ); 81 | // 82 | Функция Response(Знач Response = Undefined) Экспорт 83 | ``` 84 | 85 | ### OpenAPI 86 | 87 | ```bsl 88 | // Prepares a set of OpenAPI properties in "httpResponse" node. 89 | // 90 | // Parameters: 91 | // OpenAPI - String - OpenAPI properties in JSON-format; 92 | // - Undefined - an empty collection will be added to the conditions collection for the 'httpResponse' node; 93 | // 94 | // Returns: 95 | // DataProcessorObject.MockServerClient - instance of mock-object with a new collection of properties; 96 | // 97 | // Example: 98 | // Mock.When( 99 | // Mock.OpenAPI() 100 | // .WithSource("http://example.com/openapi_petstore_example.json") 101 | // .WithOperationId("some_id") 102 | // ).Verify( 103 | // Mock.Times() 104 | // .Once() 105 | // ); 106 | // 107 | Функция OpenAPI(Знач OpenAPI = Undefined) Экспорт 108 | ``` 109 | 110 | ### Times 111 | 112 | ```bsl 113 | // Sets conditions that a requests has been received by MockServer a specific number of time. 114 | // 115 | // Parameters: 116 | // Condition - String - a conditions in JSON-format string; 117 | // - Undefined - an empty collection will be added to the conditions collection for the 'times' node; 118 | // 119 | // Returns: 120 | // DataProcessorObject.MockServerClient - instance of mock-object with a new collection of properties; 121 | // 122 | // Example: 123 | // Mock.When( Mock.Request().WithMethod("GET") ).Verify( Mock.Times().AtMost(3) ); 124 | // Result = Mock.Times().AtMost(3).AtLeast(3); 125 | // Result = Mock.Times("""atLeast"": 3, ""atMost"": 3"); 126 | // 127 | Функция Times(Знач Condition = Undefined) Экспорт 128 | ``` 129 | 130 | ### AtLeast 131 | 132 | ```bsl 133 | // Adds condition that a request has been received by MockServer at least n-times. 134 | // 135 | // Parameters: 136 | // Count - Number - n-times; 137 | // 138 | // Returns: 139 | // DataProcessorObject.MockServerClient - instance of mock-object; 140 | // 141 | Функция AtLeast(Знач Count) Экспорт 142 | ``` 143 | 144 | ### AtMost 145 | 146 | ```bsl 147 | // Adds condition that a request has been received by MockServer at most n-times. 148 | // 149 | // Parameters: 150 | // Count - Number - number of times; 151 | // 152 | // Returns: 153 | // DataProcessorObject.MockServerClient - instance of mock-object; 154 | // 155 | Функция AtMost(Знач Count) Экспорт 156 | ``` 157 | 158 | ### Exactly 159 | 160 | ```bsl 161 | // Adds condition that a request has been received by MockServer exactly n-times. 162 | // 163 | // Parameters: 164 | // Count - Number - number of times; 165 | // 166 | // Returns: 167 | // DataProcessorObject.MockServerClient - instance of mock-object; 168 | // 169 | Функция Exactly(Знач Count) Экспорт 170 | ``` 171 | 172 | ### Once 173 | 174 | ```bsl 175 | // Adds condition that a request has been received by MockServer only once. 176 | // 177 | // Returns: 178 | // DataProcessorObject.MockServerClient - instance of mock-object; 179 | // 180 | Функция Once() Экспорт 181 | ``` 182 | 183 | ### Between 184 | 185 | ```bsl 186 | // Adds condition that a request has been received by MockServer between n and m times. 187 | // 188 | // Parameters: 189 | // AtLeast - Number - at least n-times; 190 | // AtMost - Number - at most m-times; 191 | // 192 | // Returns: 193 | // DataProcessorObject.MockServerClient - instance of mock-object; 194 | // 195 | Функция Between(Знач AtLeast, Знач AtMost) Экспорт 196 | ``` 197 | 198 | ### Reset 199 | 200 | ```bsl 201 | // Resets the MockServer completely (terminal operation). 202 | // 203 | Процедура Reset() Экспорт 204 | ``` 205 | 206 | ### Respond 207 | 208 | ```bsl 209 | // Sets requests expectation (terminal operation). 210 | // 211 | // Parameters: 212 | // Self - DataProcessorObject.MockServerClient - a reference to object with preparing conditions; 213 | // 214 | // Example: 215 | // Mock.When( Mock.Request().WithMethod("GET") ).Respond( Mock.Response().WithBody("some_response_body") ); 216 | // Mock.Respond( Mock.Response().WithBody("some_response_body") ); 217 | // Mock.Respond( Mock.Response("""statusCode"": 404") ); 218 | // 219 | Процедура Respond(Знач Self = Undefined) Экспорт 220 | ``` 221 | 222 | ### Verify 223 | 224 | ```bsl 225 | // Verifies a request has been sent (terminal operation). 226 | // 227 | // Parameters: 228 | // Self - DataProcessorObject.MockServerClient - a reference to object with preparing conditions; 229 | // 230 | // Example: 231 | // Mock.When( Mock.Request().WithMethod("GET") ).Verify( Mock.Times().AtMost(3) ); 232 | // Mock.Verify( Mock.Times().AtMost(3) ); 233 | // Mock.Verify( Mock.Times("""atMost"": 3") ); 234 | // 235 | Процедура Verify(Знач Self = Undefined) Экспорт 236 | ``` 237 | 238 | ### OpenAPIExpectation 239 | 240 | ```bsl 241 | // Sets the expectations according to the OpenAPI specification (terminal operation). 242 | // 243 | // Parameters: 244 | // Source - String - the path to the OpenAPI document or the data itself in accordance with the OpenAPI specification; 245 | // Operations - String - operation id and response status code for the selected operation as a JSON-format string; 246 | // 247 | // Example: 248 | // Mock.OpenAPIExpectation( "file:/Users/me/openapi.json" ); 249 | // Mock.OpenAPIExpectation( "http://example.com/mock/openapi.json", """some_operation_id"": ""200""" ); 250 | // Mock.OpenAPIExpectation( "---\n"" 251 | // + """openapi: 3.0.0\n""" 252 | // + """info:\n""" 253 | // ... 254 | // + """...OpenAPI specification here""" " ); 255 | // 256 | Процедура OpenAPIExpectation(Знач Source, Знач Operations = "") Экспорт 257 | ``` 258 | 259 | ### IsOk 260 | 261 | ```bsl 262 | // Returns the result of executing the PUT method for the last action. 263 | // 264 | // Returns: 265 | // Boolean - true - operation was successful, otherwise - false; 266 | // 267 | Функция IsOk() Экспорт 268 | ``` 269 | 270 | ### WithMethod 271 | 272 | ```bsl 273 | // Adds the "method" property. 274 | // See also: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 275 | // 276 | // Parameters: 277 | // Method - String - property matcher; 278 | // 279 | // Returns: 280 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 281 | // 282 | // Example: 283 | // 284 | // Mock.When( 285 | // Mock.Request() 286 | // .WithMethod("!GET") 287 | // ).Respond( 288 | // Mock.Response() 289 | // .WithBody("some_response_body") 290 | // ); 291 | // 292 | Функция WithMethod(Знач Method) Экспорт 293 | ``` 294 | 295 | ### WithPath 296 | 297 | ```bsl 298 | // Adds the "path" property. 299 | // See also: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 300 | // 301 | // Parameters: 302 | // Path - String - property matcher; 303 | // 304 | // Returns: 305 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 306 | // 307 | // Example: 308 | // 309 | // Mock.When( 310 | // Mock.Request() 311 | // .WithMethod("!GET") 312 | // ).Respond( 313 | // Mock.Response() 314 | // .WithBody("some_response_body") 315 | // ); 316 | // 317 | Функция WithPath(Знач Path) Экспорт 318 | ``` 319 | 320 | ### WithQueryStringParameter 321 | 322 | ```bsl 323 | // Adds the "queryStringParameters" property. 324 | // See also: https://www.mock-server.com/mock_server/getting_started.html#request_key_to_multivalue_matchers 325 | // 326 | // Parameters: 327 | // Key - String - key of query parameter; 328 | // Value - String - value of query parameter; 329 | // 330 | // Returns: 331 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 332 | // 333 | // Example: 334 | // 335 | // Mock.When( 336 | // Mock.Request() 337 | // .WithPath("/some/path") 338 | // .WithQueryStringParameter("cartId", "[A-Z0-9\\-]+") 339 | // .WithQueryStringParameter("anotherId", "[A-Z0-9\\-]+") 340 | // ).Respond( 341 | // Mock.Response() 342 | // .WithBody("some_response_body") 343 | // ); 344 | // 345 | Функция WithQueryStringParameter(Знач Key, Знач Value) Экспорт 346 | ``` 347 | 348 | ### Headers 349 | 350 | ```bsl 351 | // Prepares a set of headers properties in "headers" node. 352 | // 353 | // Parameters: 354 | // Headers - Map - a headers (key = header, value = array of strings); 355 | // - Undefined - an empty collection will be added to the 'header' node; 356 | // 357 | // Returns: 358 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 359 | // 360 | // Example: 361 | // 362 | // 1: 363 | // 364 | // Mock.When( 365 | // Mock.Request() 366 | // .WithMethod("GET") 367 | // .WithPath("/some/path") 368 | // .Headers() 369 | // .WithHeader("Accept", "application/json") 370 | // .WithHeader("Accept-Encoding", "gzip, deflate, br") 371 | // ).Respond( 372 | // Mock.Response() 373 | // .WithBody("some_response_body") 374 | // ); 375 | // 376 | // 2: 377 | // 378 | // Header_1 = New Array(); 379 | // Header_1.Add("11"); 380 | // Header_1.Add("12"); 381 | // Header_2 = New Array(); 382 | // Header_2.Add("21"); 383 | // Header_2.Add("22"); 384 | // Headers = New Map(); 385 | // Headers.Insert("Header_1", Header_1); 386 | // Headers.Insert("Header_2", Header_2); 387 | // 388 | // Mock.When( Mock.Request().Headers(Headers) ).Respond(); 389 | // 390 | Функция Headers(Знач Headers = Undefined) Экспорт 391 | ``` 392 | 393 | ### WithHeader 394 | 395 | ```bsl 396 | // Adds the "header" property to the "headers" node. 397 | // See also: https://www.mock-server.com/mock_server/getting_started.html#request_key_to_multivalue_matchers 398 | // 399 | // Parameters: 400 | // Key - String - key of header; 401 | // Value - String - value of header; 402 | // 403 | // Returns: 404 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 405 | // 406 | // Example: 407 | // 408 | // Mock.When( 409 | // Mock.Request() 410 | // .WithMethod("GET") 411 | // .WithPath("/some/path") 412 | // .Headers() 413 | // .WithHeader("Accept", "application/json") 414 | // .WithHeader("Accept-Encoding", "gzip, deflate, br") 415 | // ).Respond( 416 | // Mock.Response() 417 | // .WithBody("some_response_body") 418 | // ); 419 | // 420 | Функция WithHeader(Знач Key, Знач Value) Экспорт 421 | ``` 422 | 423 | ### WithBody 424 | 425 | ```bsl 426 | // Adds the "body" property. 427 | // See also: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 428 | // 429 | // Parameters: 430 | // Body - String - property matcher; 431 | // 432 | // Returns: 433 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 434 | // 435 | // Example: 436 | // 437 | // Mock.When( 438 | // Mock.Request() 439 | // .WithMethod("!GET") 440 | // ).Respond( 441 | // Mock.Response() 442 | // .WithBody("some_response_body") 443 | // ); 444 | // 445 | Функция WithBody(Знач Body) Экспорт 446 | ``` 447 | 448 | ### WithStatusCode 449 | 450 | ```bsl 451 | // Adds the "statusCode" property. 452 | // See also: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 453 | // 454 | // Parameters: 455 | // StatusCode - Numeric - numeric status code; 456 | // 457 | // Returns: 458 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 459 | // 460 | // Example: 461 | // 462 | // Mock.When( 463 | // Mock.Request() 464 | // .WithMethod("GET") 465 | // .WithPath("/some/path") 466 | // ).Respond( 467 | // Mock.Response() 468 | // .WithStatusCode(418) 469 | // .WithReasonPhrase("I'm a teapot") 470 | // ); 471 | // 472 | Функция WithStatusCode(Знач StatusCode) Экспорт 473 | ``` 474 | 475 | ### WithReasonPhrase 476 | 477 | ```bsl 478 | // Adds the "reasonPhrase" property. 479 | // See also: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 480 | // 481 | // Parameters: 482 | // ReasonPhrase - String - reason phrase; 483 | // 484 | // Returns: 485 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 486 | // 487 | // Example: 488 | // 489 | // Mock.When( 490 | // Mock.Request() 491 | // .WithMethod("GET") 492 | // .WithPath("/some/path") 493 | // ).Respond( 494 | // Mock.Response() 495 | // .WithStatusCode(418) 496 | // .WithReasonPhrase("I'm a teapot") 497 | // ); 498 | // 499 | Функция WithReasonPhrase(Знач ReasonPhrase) Экспорт 500 | ``` 501 | 502 | ### WithSource 503 | 504 | ```bsl 505 | // Adds the "specUrlOrPayload" property describing the data source or the data itself in OpenAPI format. 506 | // 507 | // Parameters: 508 | // Source - String - the path to the OpenAPI document or the data itself in accordance with the OpenAPI specification; 509 | // 510 | // Returns: 511 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 512 | // 513 | // Example: 514 | // 515 | // Mock.When( 516 | // Mock.OpenAPI() 517 | // .WithSource("https://example.com/openapi.json") 518 | // ).Verify( 519 | // Mock.Times() 520 | // .AtLeast(2) 521 | // ); 522 | // 523 | // Result = Mock.OpenAPI().WithSource( "file:/Users/me/openapi.json" ); 524 | // 525 | Функция WithSource(Знач Source) Экспорт 526 | ``` 527 | 528 | ### WithOperationId 529 | 530 | ```bsl 531 | // Adds the "operationId" property that specifies which operations of OpenAPI are included. 532 | // 533 | // Parameters: 534 | // OperationId - String - the operation in the OpenAPI specification; 535 | // 536 | // Returns: 537 | // DataProcessorObject.MockServerClient - instance of mock-object with added property; 538 | // 539 | // Example: 540 | // 541 | // Mock.When( 542 | // Mock.OpenAPI() 543 | // .WithSource("https://example.com/openapi.json") 544 | // .WithOperationId("listPets") 545 | // ).Verify( 546 | // Mock.Times() 547 | // .AtLeast(2) 548 | // ); 549 | // 550 | // Result = Mock.OpenAPI().WithSource( "file:/Users/me/openapi.json" ).WithOperationId("listPets"); 551 | // 552 | Функция WithOperationId(Знач OperationId) Экспорт 553 | ``` -------------------------------------------------------------------------------- /docs/ru/Examples.md: -------------------------------------------------------------------------------- 1 | # Примеры кода 2 | 3 | ## Сброс и очистка 4 | 5 | ### Сбросить все 6 | 7 | ```text 8 | Мок.Сервер("http://localhost", "1080").Сбросить(); 9 | ``` 10 | 11 | ## Сопоставление свойств запросов 12 | 13 | ### запрос совпадает по относительному пути 14 | 15 | ```text 16 | Мок.Когда( 17 | Мок.Запрос() 18 | .Путь("/some/path") 19 | ).Ответить( 20 | Мок.Ответ() 21 | .Тело("some_response_body") 22 | ); 23 | ``` 24 | 25 | ### запрос совпадает по методу через регулярные выражения 26 | 27 | ```text 28 | Мок.Когда( 29 | Мок.Запрос() 30 | .Метод("P.*{2,3}") 31 | ).Ответить( 32 | Мок.Ответ() 33 | .Тело("some_response_body") 34 | ); 35 | ``` 36 | 37 | ### запрос совпадает по неподходящему методу 38 | 39 | ```text 40 | Мок.Когда( 41 | Мок.Запрос() 42 | .Метод("!GET") 43 | ).Ответить( 44 | Мок.Ответ() 45 | .Тело("some_response_body") 46 | ); 47 | ``` 48 | 49 | ### запрос совпадает по параметрам запроса через регулярные выражения 50 | 51 | ```text 52 | Мок.Когда( 53 | Мок.Запрос() 54 | .Путь("/some/path") 55 | .ПараметрСтрокиЗапроса("cartId", "[A-Z0-9\\-]+") 56 | .ПараметрСтрокиЗапроса("anotherId", "[A-Z0-9\\-]+") 57 | ).Ответить( 58 | Мок.Ответ() 59 | .Тело("some_response_body") 60 | ); 61 | ``` 62 | 63 | ### запрос совпадает по заголовкам 64 | 65 | ```text 66 | Мок.Когда( 67 | Мок.Запрос() 68 | .Метод("GET") 69 | .Путь("/some/path") 70 | .Заголовки() 71 | .Заголовок("Accept", "application/json") 72 | .Заголовок("Accept-Encoding", "gzip, deflate, br") 73 | ).Ответить( 74 | Мок.Ответ() 75 | .Тело("some_response_body") 76 | ); 77 | ``` 78 | 79 | ## Ответы сервера 80 | 81 | ### только текстовое тело ответа 82 | 83 | ```text 84 | Мок.Ответить( 85 | Мок.Ответ() 86 | .Тело("some_response_body") 87 | ); 88 | ``` 89 | ### с кодом ответа и причиной 90 | 91 | ```text 92 | Мок.Когда( 93 | Мок.Запрос() 94 | .Метод("GET") 95 | .Путь("/some/path") 96 | ).Ответить( 97 | Мок.Ответ() 98 | .КодОтвета(418) 99 | .Причина("I'm a teapot") 100 | ); 101 | ``` 102 | 103 | ## Проверка повторений запросов 104 | 105 | ### проверить, что запросы получены не менее двух раз 106 | 107 | ```text 108 | Мок.Когда( 109 | Мок.Запрос() 110 | .Путь("/some/path") 111 | ).Проверить( 112 | Мок.Повторений() 113 | .НеМенее(2) 114 | ); 115 | ``` 116 | 117 | ### проверить, что запросы получены не более двух раз 118 | 119 | ```text 120 | Мок.Когда( 121 | Мок.Запрос() 122 | .Путь("/some/path") 123 | ).Проверить( 124 | Мок.Повторений() 125 | .НеБолее(2) 126 | ); 127 | ``` 128 | 129 | ### проверить, что запросы получены точно два раза 130 | 131 | ```text 132 | Мок.Когда( 133 | Мок.Запрос() 134 | .Путь("/some/path") 135 | ).Проверить( 136 | Мок.Повторений() 137 | .Точно(2) 138 | ); 139 | ``` 140 | 141 | ### проверить, что запросы получены не менее двух раз в соответствии с OpenAPI 142 | 143 | ```text 144 | Мок.Когда( 145 | Мок.OpenAPI() 146 | .Источник("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 147 | ).Проверить( 148 | Мок.Повторений() 149 | .НеМенее(2) 150 | ); 151 | ``` 152 | 153 | ### проверить, что запрос получен только один раз в соответствии с OpenAPI для некоторой операции 154 | 155 | ```text 156 | Мок.Когда( 157 | Мок.OpenAPI() 158 | .Источник("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 159 | .Операция("listPets") 160 | ).Проверить( 161 | Мок.Повторений() 162 | .Однократно() 163 | ); 164 | ``` 165 | 166 | ### проверить, что запрос получен только один раз 167 | 168 | ```text 169 | Мок.Когда( 170 | Мок.Запрос() 171 | .Путь("/some/path") 172 | ).Проверить( 173 | Мок.Повторений() 174 | .Однократно() 175 | ); 176 | ``` 177 | 178 | ### проверить, что запросы получены в диапазоне между n и m раз 179 | 180 | ```text 181 | Мок.Когда( 182 | Мок.Запрос() 183 | .Путь("/some/path") 184 | ).Проверить( 185 | Мок.Повторений() 186 | .Между(2, 3) 187 | ); 188 | ``` 189 | 190 | ### проверить, что запросов не было 191 | 192 | ```text 193 | Мок.Когда( 194 | Мок.Запрос() 195 | .Путь("/some/path") 196 | ).Проверить( 197 | Мок.Повторений() 198 | .Точно(0) 199 | ); 200 | ``` 201 | -------------------------------------------------------------------------------- /docs/ru/PublicAPI.md: -------------------------------------------------------------------------------- 1 | # Программный интерфейс 2 | 3 | Автоматически сгенерировано [BSl LS](https://github.com/1c-syntax/bsl-language-server) 4 | 5 | ## Модуль объекта 6 | 7 | ### Сервер 8 | 9 | ```bsl 10 | // Инициализирует клиента для связи с MockServer на указанном хосте и порту. 11 | // 12 | // Параметры: 13 | // URL - Строка - URL; 14 | // Порт - Строка - порт; 15 | // Сбросить - Булево - Истина - предварительно сбросить сервер MockServer, иначе - Ложь (по умолчанию); 16 | // 17 | // Возвращаемое значение: 18 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта; 19 | // 20 | // Пример: 21 | // Мок = Обработки.MockServerClient.Создать().Сервер("http://server"); 22 | // Мок = Обработки.MockServerClient.Создать().Сервер("http://server", "1090"); 23 | // Мок = Обработки.MockServerClient.Создать().Сервер("http://server", "1090", Истина); 24 | // 25 | Функция Сервер(URL, Порт = Undefined, Сбросить = Undefined) Экспорт 26 | ``` 27 | 28 | ### Когда 29 | 30 | ```bsl 31 | // Предварительно устанавливает любые условия или принимает полностью готовый JSON 32 | // для последующей отправки данных на MockServer. 33 | // 34 | // Параметры: 35 | // Запрос - ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с предустановленными условиями; 36 | // - Строка - JSON для отправки на MockServer; 37 | // 38 | // Возвращаемое значение: 39 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта; 40 | // 41 | // Пример: 42 | // Мок.Когда( Мок.Путь("/фуу/foo") ).Ответить(); 43 | // Мок.Когда("{""sample"": ""any""}").Ответить(); 44 | // 45 | Функция Когда(Запрос) Экспорт 46 | ``` 47 | 48 | ### Запрос 49 | 50 | ```bsl 51 | // Подготавливает коллекцию свойств запроса в узле "httpRequest". 52 | // 53 | // Параметры: 54 | // Запрос - Строка - свойства запроса в виде строки в формате JSON; 55 | // - Неопределено - в коллекцию условий для узла 'httpRequest' будет добавлена пустая коллекция; 56 | // 57 | // Возвращаемое значение: 58 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с новой коллекцией условий; 59 | // 60 | // Пример: 61 | // Мок.Когда( Мок.Запрос().Путь("/фуу/foo") ).Ответить( Мок.Ответ().Тело("some_response_body") ); 62 | // Мок.Когда( Мок.Запрос("""method"": ""GET""") ).Ответить( Мок.Ответ().Тело("some_response_body") ); 63 | // 64 | Функция Запрос(Запрос = Undefined) Экспорт 65 | ``` 66 | 67 | ### Ответ 68 | 69 | ```bsl 70 | // Подготавливает коллекцию свойств ответа в узле "httpResponse". 71 | // 72 | // Параметры: 73 | // Ответ - Строка - свойства ответа в виде строки в формате JSON; 74 | // - Неопределено - в коллекцию условий для узла 'httpResponse' будет добавлена пустая коллекция; 75 | // 76 | // Возвращаемое значение: 77 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с новой коллекцией условий; 78 | // 79 | // Пример: 80 | // Мок.Когда( Мок.Запрос().Путь("/фуу/foo") ).Ответить( Мок.Ответ().Тело("some_response_body") ); 81 | // Мок.Когда( Мок.Запрос().Путь("/фуу/foo") ).Ответить( Мок.Ответ("""body"": ""some_response_body""") ); 82 | // 83 | Функция Ответ(Ответ = Undefined) Экспорт 84 | ``` 85 | 86 | ### Повторений 87 | 88 | ```bsl 89 | // Устанавливает условия на проверку количества запросов к MockServer. 90 | // 91 | // Параметры: 92 | // Условие - Строка - условие проверки на количество запросов в виде строки в формате JSON; 93 | // - Неопределено - в коллекцию условий для узла 'times' будет добавлена пустая коллекция; 94 | // 95 | // Возвращаемое значение: 96 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с новой коллекцией условий; 97 | // 98 | // Пример: 99 | // Мок.Когда( Мок.Запрос().Метод("GET") ).Проверить( Мок.Повторений().НеБолее(3) ); 100 | // Результат = Мок.Проверить().НеМенее(3).НеБолее(3); 101 | // Результат = Мок.Проверить( """atLeast"": 3, ""atMost"": 3" ); 102 | // 103 | Функция Повторений(Условие = Undefined) Экспорт 104 | ``` 105 | 106 | ### НеМенее 107 | 108 | ```bsl 109 | // Добавляет условие, что количество запросов к MockServer было не менее n раз. 110 | // 111 | // Параметры: 112 | // Повторений - Число - количество повторений запросов; 113 | // 114 | // Возвращаемое значение: 115 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта; 116 | // 117 | Функция НеМенее(Знач Повторений) Экспорт 118 | ``` 119 | 120 | ### НеБолее 121 | 122 | ```bsl 123 | // Добавляет условие, что количество запросов к MockServer было не более n раз. 124 | // 125 | // Параметры: 126 | // Повторений - Число - количество повторений запросов; 127 | // 128 | // Возвращаемое значение: 129 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта; 130 | // 131 | Функция НеБолее(Знач Повторений) Экспорт 132 | ``` 133 | 134 | ### Точно 135 | 136 | ```bsl 137 | // Добавляет условие, что количество запросов к MockServer было ровно n раз. 138 | // 139 | // Параметры: 140 | // Повторений - Число - количество повторений запросов; 141 | // 142 | // Возвращаемое значение: 143 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта; 144 | // 145 | Функция Точно(Знач Повторений) Экспорт 146 | ``` 147 | 148 | ### Однократно 149 | 150 | ```bsl 151 | // Добавляет условие, что запрос к MockServer был только один раз. 152 | // 153 | // Возвращаемое значение: 154 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта; 155 | // 156 | Функция Однократно() Экспорт 157 | ``` 158 | 159 | ### Между 160 | 161 | ```bsl 162 | // Добавляет условие, что количество запросов к MockServer было от n до m раз. 163 | // 164 | // Параметры: 165 | // От - Число - не менее n раз; 166 | // До - Число - не более m раз; 167 | // 168 | // Возвращаемое значение: 169 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта; 170 | // 171 | Функция Между(Знач От, Знач До) Экспорт 172 | ``` 173 | 174 | ### Сбросить 175 | 176 | ```bsl 177 | // Полностью сбрасывает MockServer (терминальная операция). 178 | // 179 | Процедура Сбросить() Экспорт 180 | ``` 181 | 182 | ### Ответить 183 | 184 | ```bsl 185 | // Устанавливает ожидание запроса (терминальная операция). 186 | // 187 | // Пример: 188 | // Объект - ОбработкаОбъект.MockServerClient - объект с предварительно установленными условиями; 189 | // 190 | // Example: 191 | // Мок.Когда( Мок.Запрос().Метод("GET") ).Ответить( Мок.Ответ().Тело("some_response_body") ); 192 | // Мок.Ответить( Мок.Ответ().Тело("some_response_body") ); 193 | // Мок.Ответить( Мок.Ответ("""statusCode"": 404") ); 194 | // 195 | Процедура Ответить(Объект = Undefined) Экспорт 196 | ``` 197 | 198 | ### Проверить 199 | 200 | ```bsl 201 | // Проверяет наличие отправленного на сервер запроса (терминальная операция). 202 | // 203 | // Параметры: 204 | // Объект - ОбработкаОбъект.MockServerClient - объект с предварительно установленными условиями; 205 | // 206 | // Пример: 207 | // Мок.Когда( Мок.Запрос().Метод("GET") ).Проверить( Мок.Повторений().НеБолее(3) ); 208 | // Мок.Проверить( Мок.Повторений().НеБолее(3) ); 209 | // Мок.Проверить( Мок.Повторений("""atMost"": 3") ); 210 | // 211 | Процедура Проверить(Объект = Undefined) Экспорт 212 | ``` 213 | 214 | ### ОжидатьOpenAPI 215 | 216 | ```bsl 217 | // Устанавливает ожидание в соответствии с OpenAPI спецификацией (терминальная операция). 218 | // 219 | // Параметры: 220 | // Источник - Строка - путь к документу с описанием данных или сами данные в соответствии с OpenAPI спецификацией; 221 | // Операции - Строка - id операции и код статуса ответа для выбранной операции в виде строки в формате JSON; 222 | // 223 | // Пример: 224 | // Мок.ОжидатьOpenAPI( "file:/Users/me/openapi.json" ); 225 | // Мок.ОжидатьOpenAPI( "http://example.com/mock/openapi.json", """some_operation_id"": ""200""" ); 226 | // Мок.ОжидатьOpenAPI( "---\n"" 227 | // + """openapi: 3.0.0\n""" 228 | // + """info:\n""" 229 | // ... 230 | // + """...OpenAPI specification here""" " ); 231 | // 232 | Процедура ОжидатьOpenAPI(Знач Источник, Знач Операции = "") Экспорт 233 | ``` 234 | 235 | ### Успешно 236 | 237 | ```bsl 238 | // Возвращает результат выполнения PUT-метода для последней терминальной операции (действия). 239 | // 240 | // Возвращаемое значение: 241 | // Булево - Истина - операция выполнена успешно, иначе - Ложь; 242 | // 243 | Функция Успешно() Экспорт 244 | ``` 245 | 246 | ### Метод 247 | 248 | ```bsl 249 | // Добавляет свойство "method". 250 | // См. также: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 251 | // 252 | // Параметры: 253 | // Метод - Строка - имя метода; 254 | // 255 | // Возвращаемое значение: 256 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 257 | // 258 | // Пример: 259 | // 260 | // Мок.Когда( 261 | // Мок.Запрос() 262 | // .Метод("!GET") 263 | // ).Ответить( 264 | // Мок.Ответ() 265 | // .Тело("some_response_body") 266 | // ); 267 | // 268 | Функция Метод(Метод) Экспорт 269 | ``` 270 | 271 | ### Путь 272 | 273 | ```bsl 274 | // Добавляет свойство "path". 275 | // См. также: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 276 | // 277 | // Параметры: 278 | // Путь - Строка - относительный путь; 279 | // 280 | // Возвращаемое значение: 281 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 282 | // 283 | // Пример: 284 | // 285 | // Мок.Когда( 286 | // Мок.Запрос() 287 | // .Путь("/some/path") 288 | // ).Ответить( 289 | // Мок.Ответ() 290 | // .Тело("some_response_body") 291 | // ); 292 | // 293 | Функция Путь(Путь) Экспорт 294 | ``` 295 | 296 | ### ПараметрСтрокиЗапроса 297 | 298 | ```bsl 299 | // Добавляет свойство "queryStringParameters". 300 | // См. также: https://www.mock-server.com/mock_server/getting_started.html#request_key_to_multivalue_matchers 301 | // 302 | // Параметры: 303 | // Ключ - Строка - ключ параметра строки запроса; 304 | // Значение - Строка - значение параметра строки запроса; 305 | // 306 | // Возвращаемое значение: 307 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 308 | // 309 | // Пример: 310 | // 311 | // Мок.Когда( 312 | // Мок.Запрос() 313 | // .Путь("/some/path") 314 | // .ПараметрСтрокиЗапроса("cartId", "[A-Z0-9\\-]+") 315 | // .ПараметрСтрокиЗапроса("anotherId", "[A-Z0-9\\-]+") 316 | // ).Ответить( 317 | // Мок.Ответ() 318 | // .Тело("some_response_body") 319 | // ); 320 | // 321 | Функция ПараметрСтрокиЗапроса(Ключ, Значение) Экспорт 322 | ``` 323 | 324 | ### Заголовки 325 | 326 | ```bsl 327 | // Добавляет коллекцию свойств в узле "headers" или создает пустую коллекцию. 328 | // 329 | // Параметры: 330 | // Заголовки - Соответствие - коллекция заголовков (Ключ = имя заголовка, Значение = массив строк); 331 | // - Неопределено - в коллекцию условий для узла 'headers' будет добавлена пустая коллекция; 332 | // 333 | // Возвращаемое значение: 334 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 335 | // 336 | // Пример: 337 | // 338 | // Вариант 1: 339 | // 340 | // Мок.Когда( 341 | // Мок.Запрос() 342 | // .Метод("GET") 343 | // .Путь("/some/path") 344 | // .Заголовки() 345 | // .Заголовок("Accept", "application/json") 346 | // .Заголовок("Accept-Encoding", "gzip, deflate, br") 347 | // ).Ответить( 348 | // Мок.Ответ() 349 | // .Тело("some_response_body") 350 | // ); 351 | // 352 | // Вариант 2: 353 | // 354 | // Заголовок_1 = Новый Массив(); 355 | // Заголовок_1.Добавить("11"); 356 | // Заголовок_1.Добавить("12"); 357 | // Заголовок_2 = Новый Массив(); 358 | // Заголовок_2.Добавить("21"); 359 | // Заголовок_2.Добавить("22"); 360 | // Заголовки = Новый Соответствие(); 361 | // Заголовки.Вставить("Заголовок_1", Заголовок_1); 362 | // Заголовки.Вставить("Заголовок_2", Заголовок_2); 363 | // 364 | // Мок.Когда( Мок.Запрос().Заголовки(Заголовки) ).Ответить(); 365 | // 366 | Функция Заголовки(Заголовки = Undefined) Экспорт 367 | ``` 368 | 369 | ### Заголовок 370 | 371 | ```bsl 372 | // Добавляет свойство "header" в коллекцию свойств "headers". 373 | // См. также: https://www.mock-server.com/mock_server/getting_started.html#request_key_to_multivalue_matchers 374 | // 375 | // Параметры: 376 | // Ключ - Строка - ключ заголовка; 377 | // Значение - Строка - значение заголовка; 378 | // 379 | // Возвращаемое значение: 380 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 381 | // 382 | // Пример: 383 | // 384 | // Мок.Когда( 385 | // Мок.Запрос() 386 | // .Метод("GET") 387 | // .Путь("/some/path") 388 | // .Заголовки() 389 | // .Заголовок("Accept", "application/json") 390 | // .Заголовок("Accept-Encoding", "gzip, deflate, br") 391 | // ).Ответить( 392 | // Мок.Ответ() 393 | // .Тело("some_response_body") 394 | // ); 395 | // 396 | Функция Заголовок(Ключ, Значение) Экспорт 397 | ``` 398 | 399 | ### Тело 400 | 401 | ```bsl 402 | // Добавляет свойство "body". 403 | // См. также: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 404 | // 405 | // Параметры: 406 | // Тело - Строка - строковое значение тела; 407 | // 408 | // Возвращаемое значение: 409 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 410 | // 411 | // Пример: 412 | // 413 | // Мок.Ответить( 414 | // Мок.Ответ() 415 | // .Тело("some_response_body") 416 | // ); 417 | // 418 | Функция Тело(Тело) Экспорт 419 | ``` 420 | 421 | ### КодОтвета 422 | 423 | ```bsl 424 | // Добавляет свойство "statusCode". 425 | // См. также: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 426 | // 427 | // Параметры: 428 | // КодОтвета - Число - числовой код статуса ответа; 429 | // 430 | // Возвращаемое значение: 431 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 432 | // 433 | // Пример: 434 | // 435 | // Мок.Когда( 436 | // Мок.Запрос() 437 | // .Метод("GET") 438 | // .Путь("/some/path") 439 | // ).Ответить( 440 | // Мок.Ответ() 441 | // .КодОтвета(418) 442 | // .Причина("I'm a teapot") 443 | // ); 444 | // 445 | Функция КодОтвета(КодОтвета) Экспорт 446 | ``` 447 | 448 | ### Причина 449 | 450 | ```bsl 451 | // Добавляет свойство "reasonPhrase". 452 | // См. также: https://www.mock-server.com/mock_server/creating_expectations.html#request_property_matchers 453 | // 454 | // Параметры: 455 | // Причина - Строка - причина; 456 | // 457 | // Возвращаемое значение: 458 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 459 | // 460 | // Пример: 461 | // 462 | // Мок.Когда( 463 | // Мок.Запрос() 464 | // .Метод("GET") 465 | // .Путь("/some/path") 466 | // ).Ответить( 467 | // Мок.Ответ() 468 | // .КодОтвета(418) 469 | // .Причина("I'm a teapot") 470 | // ); 471 | // 472 | Функция Причина(Причина) Экспорт 473 | ``` 474 | 475 | ### Источник 476 | 477 | ```bsl 478 | // Добавляет свойство "specUrlOrPayload", которое описывает источник данных или сами данные в формате OpenAPI. 479 | // 480 | // Параметры: 481 | // Источник - Строка - путь к документу с описанием данных или сами данные в соответствии с OpenAPI спецификацией; 482 | // 483 | // Возвращаемое значение: 484 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 485 | // 486 | // Пример: 487 | // 488 | // Мок.Когда( 489 | // Мок.OpenAPI() 490 | // .Источник("https://example.com/openapi.json") 491 | // ).Проверить( 492 | // Мок.Повторений() 493 | // .НеМенее(2) 494 | // ); 495 | // 496 | // Результат = Мок.OpenAPI().Источник( "file:/Users/me/openapi.json" ); 497 | // 498 | Функция Источник(Источник) Экспорт 499 | ``` 500 | 501 | ### Операция 502 | 503 | ```bsl 504 | // Добавляет свойство "operationId", указывающее на операцию из спецификации документа OpenAPI; 505 | // 506 | // Параметры: 507 | // Операция - Строка - операция из документа OpenAPI; 508 | // 509 | // Возвращаемое значение: 510 | // ОбработкаОбъект.MockServerClient - текущий экземпляр мок-объекта с добавленным свойством; 511 | // 512 | // Пример: 513 | // 514 | // Мок.Когда( 515 | // Мок.OpenAPI() 516 | // .Источник("https://example.com/openapi.json") 517 | // .Операция("listPets") 518 | // ).Проверить( 519 | // Мок.Повторений() 520 | // .НеМенее(2) 521 | // ); 522 | // 523 | // Результат = Мок.OpenAPI().Источник( "file:/Users/me/openapi.json" ).Операция("listPets"); 524 | // 525 | Функция Операция(Операция) Экспорт 526 | ``` 527 | 528 | -------------------------------------------------------------------------------- /docs/ru/README.md: -------------------------------------------------------------------------------- 1 | # MockServer клиент для 1C:Предприятие 8 2 | 3 | [![Quality Gate Status](https://sonar.openbsl.ru/api/project_badges/measure?project=mockserver-client-1c&metric=alert_status)](https://sonar.openbsl.ru/dashboard?id=mockserver-client-1c) 4 | [![Maintainability Rating](https://sonar.openbsl.ru/api/project_badges/measure?project=mockserver-client-1c&metric=sqale_rating)](https://sonar.openbsl.ru/dashboard?id=mockserver-client-1c) 5 | 6 | [english](https://github.com/astrizhachuk/mockserver-client-1c/blob/master/README.md) 7 | 8 | *[MockServer](https://www.mock-server.com/#what-is-mockserver)-client-1c* создан для [управления](https://www.mock-server.com/mock_server/mockserver_clients.html) MoskServer с помощью 1C:Предприятие 8. *Клиент* поставляется в виде расширения конфигурации и реализован в виде обработки, взаимодействующей с MockServer через [REST API](https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.11.x). MockServer поддерживает OpenAPI v3 спецификацию как в JSON, так и в YAML форматах. 9 | 10 | ## Как это работает 11 | 12 | ```text 13 | Мок = Обработки.MockServerClient.Создать(); 14 | Мок.Сервер("localhost", "1080") 15 | .Когда( 16 | Мок.Запрос() 17 | .Метод("GET") 18 | .Путь("/some/path") 19 | .Заголовки() 20 | .Заголовок("foo", "boo") 21 | ).Ответить( 22 | Мок.Ответ() 23 | .КодОтвета(200) 24 | ); 25 | ``` 26 | 27 | Вот и все! Мок создан! 28 | 29 | ```text 30 | // @unit-test 31 | Процедура Пример(Фреймворк) Экспорт 32 | // given 33 | Мок = Обработки.MockServerClient.Создать(); 34 | Мок.Сервер( "localhost", "1080", Истина ); 35 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 36 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 37 | // when 38 | Мок.Когда( 39 | Мок.Запрос() 40 | .Путь("/some/path") 41 | ).Проверить( 42 | Мок.Повторений() 43 | .НеМенее(2) 44 | ); 45 | // then 46 | Проверка.ЭтоИстина(Мок.Успешно()); 47 | КонецПроцедуры 48 | ``` 49 | 50 | Протестировано! 51 | 52 | [Примеры кода](https://github.com/astrizhachuk/mockserver-client-1c/blob/master/docs/ru/Examples.md) 53 | 54 | [Программный интерфейс](https://github.com/astrizhachuk/mockserver-client-1c/blob/master/docs/ru/PublicAPI.md) 55 | 56 | ## Начало работы 57 | 58 | [Руководство пользователя (англ.)](https://www.mock-server.com/mock_server/getting_started.html) 59 | 60 | Обычная последовательность действий при работе с MockServer: 61 | 62 | * [Запустить MockServer](#StartMockServer) 63 | * [Создать экземпляр клиента](#CreateInstance) 64 | * [Установить ожидаемое поведение](#SetupExpectations) 65 | * Запустить тестовые сценарии 66 | * Проверить запросы 67 | 68 | ### Запуск MockServer 69 | 70 | [Документация по запуску MockServer](https://www.mock-server.com/mock_server/running_mock_server.html) 71 | 72 | Пример запуска docker-контейнера с MockServer: 73 | 74 | ```text 75 | docker run -d --rm -p 1080:1080 --name mockserver-1c-integration mockserver/mockserver -logLevel DEBUG -serverPort 1080 76 | ``` 77 | 78 | Или запуск docker-compose.yml из корня текущего проекта: 79 | 80 | ```text 81 | docker-compose -f "docker-compose.yml" up -d --build 82 | ``` 83 | 84 | ### Создание экземпляра клиента 85 | 86 | Подключение к серверу по умолчанию: 87 | 88 | ```text 89 | Мок = Обработки.MockServerClient.Создать(); 90 | ``` 91 | 92 | Подключение к серверу с некоторым адресом и портом подключения: 93 | 94 | ```text 95 | Мок = Обработки.MockServerClient.Создать(); 96 | Мок = Мок.Server( "http://server" ); 97 | # или 98 | Мок = Обработки.MockServerClient.Создать(); 99 | Мок = Мок.Сервер( "http://server", "1099" ); 100 | ``` 101 | 102 | Подключение к серверу с некоторым адресом и портом подключения с предварительной [очисткой](https://www.mock-server.com/mock_server/clearing_and_resetting.html) MockServer: 103 | 104 | ```text 105 | Мок = Обработки.MockServerClient.Создать(); 106 | Мок = Мок.Сервер( "http://server", "1099", Истина ); 107 | ``` 108 | 109 | ### Установка ожидания поведения 110 | 111 | Установка ожидания поведения (и проверка запросов) состоит из двух стадий: подготовка условий (в формате JSON) и выполнение действия для этих условий (отправка JSON на сервер). 112 | 113 | Для клиента доступны два вида методов: **промежуточные** (возвращающие ссылки на объект клиента) и **терминальные** (выполняющие некоторое действие). Некоторые методы принимать в качестве параметров как ссылки на объекты с установленными предварительными условиями, так и строки в формате JSON. Перед отправкой сообщения на сервер будет автоматически сгенерирован необходимый JSON в зависимости от выбранной терминальной операции и предварительных условий. 114 | 115 | Текущая реализация клиента позволяет использовать вызовы методов в виде цепочки действий, завершающихся терминальной операцией (fluent interface): 116 | 117 | ```text 118 | # передача готового JSON без автоматической генерации 119 | Мок.Сервер( "localhost", "1080" ) 120 | .Когда( "{""name"":""value""}" ) 121 | .Ответить(); 122 | 123 | # передача свойства httpRequest в JSON-формате 124 | Мок.Server( "localhost", "1080" ) 125 | .Когда( 126 | Мок.Запрос( """name"":""value""" ) 127 | ) 128 | .Ответить(); 129 | 130 | # комбинированный вариант 131 | Мок.Сервер( "localhost", "1080" ) 132 | .Когда( 133 | Мок.Запрос() 134 | .Метод( "GET" ) 135 | .Путь( "some/path" ) 136 | ) 137 | .Ответить( 138 | Мок.Ответ( """statusCode"": 404" ) 139 | ); 140 | 141 | ``` 142 | 143 | ## Зависимости 144 | 145 | Проект создан с помощью: 146 | 147 | 1. [1C:Enterprise](https://1c-dn.com) 8.3.16.1502+ (8.3.16 compatibility mode) 148 | 2. [1C:Enterprise Development Tools](https://edt.1c.ru) 2020.4 RC1 149 | 3. [1Unit](https://github.com/DoublesunRUS/ru.capralow.dt.unit.launcher) 0.4.0+ 150 | 4. [vanessa-automation](https://github.com/Pr-Mex/vanessa-automation) 151 | 5. [dt.bslls.validator](https://github.com/DoublesunRUS/ru.capralow.dt.bslls.validator) 152 | 6. [BSL Language Server](https://github.com/1c-syntax/bsl-language-server) 153 | 154 | Работа с HTTP реализована с помощью следующих библиотек: 155 | 156 | * [HTTPConnector](https://github.com/vbondarevsky/Connector) 157 | * [HTTPStatusCodes](https://github.com/astrizhachuk/HTTPStatusCodes) 158 | 159 | -------------------------------------------------------------------------------- /mockserver-client.Tests/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mockserver-client.Tests 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.xtext.ui.shared.xtextNature 16 | com._1c.g5.v8.dt.core.V8ExtensionNature 17 | 18 | 19 | -------------------------------------------------------------------------------- /mockserver-client.Tests/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /mockserver-client.Tests/DT-INF/PROJECT.PMF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Runtime-Version: 8.3.16 3 | Base-Project: mockserver-client 4 | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_CallWrapperRu.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_CallWrapperRu 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: Server 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_CallWrapperRu.Server(Context());' | 15 | 16 | @OnServer 17 | Scenario: Reset 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_CallWrapperRu.Reset(Context());' | 20 | 21 | @OnServer 22 | Scenario: When 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_CallWrapperRu.When(Context());' | 25 | 26 | @OnServer 27 | Scenario: Request 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_CallWrapperRu.Request(Context());' | 30 | 31 | @OnServer 32 | Scenario: Headers 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_CallWrapperRu.Headers(Context());' | 35 | 36 | @OnServer 37 | Scenario: WithHeader 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_CallWrapperRu.WithHeader(Context());' | 40 | 41 | @OnServer 42 | Scenario: WithMethod 43 | And I execute 1C:Enterprise script at server 44 | | 'Tests_CallWrapperRu.WithMethod(Context());' | 45 | 46 | @OnServer 47 | Scenario: WithPath 48 | And I execute 1C:Enterprise script at server 49 | | 'Tests_CallWrapperRu.WithPath(Context());' | 50 | 51 | @OnServer 52 | Scenario: WithQueryStringParameter 53 | And I execute 1C:Enterprise script at server 54 | | 'Tests_CallWrapperRu.WithQueryStringParameter(Context());' | 55 | 56 | @OnServer 57 | Scenario: Response 58 | And I execute 1C:Enterprise script at server 59 | | 'Tests_CallWrapperRu.Response(Context());' | 60 | 61 | @OnServer 62 | Scenario: WithStatusCode 63 | And I execute 1C:Enterprise script at server 64 | | 'Tests_CallWrapperRu.WithStatusCode(Context());' | 65 | 66 | @OnServer 67 | Scenario: WithReasonPhrase 68 | And I execute 1C:Enterprise script at server 69 | | 'Tests_CallWrapperRu.WithReasonPhrase(Context());' | 70 | 71 | @OnServer 72 | Scenario: Respond 73 | And I execute 1C:Enterprise script at server 74 | | 'Tests_CallWrapperRu.Respond(Context());' | 75 | 76 | @OnServer 77 | Scenario: Times 78 | And I execute 1C:Enterprise script at server 79 | | 'Tests_CallWrapperRu.Times(Context());' | 80 | 81 | @OnServer 82 | Scenario: AtLeast 83 | And I execute 1C:Enterprise script at server 84 | | 'Tests_CallWrapperRu.AtLeast(Context());' | 85 | 86 | @OnServer 87 | Scenario: AtMost 88 | And I execute 1C:Enterprise script at server 89 | | 'Tests_CallWrapperRu.AtMost(Context());' | 90 | 91 | @OnServer 92 | Scenario: Exactly 93 | And I execute 1C:Enterprise script at server 94 | | 'Tests_CallWrapperRu.Exactly(Context());' | 95 | 96 | @OnServer 97 | Scenario: Once 98 | And I execute 1C:Enterprise script at server 99 | | 'Tests_CallWrapperRu.Once(Context());' | 100 | 101 | @OnServer 102 | Scenario: Between 103 | And I execute 1C:Enterprise script at server 104 | | 'Tests_CallWrapperRu.Between(Context());' | 105 | 106 | @OnServer 107 | Scenario: Verify 108 | And I execute 1C:Enterprise script at server 109 | | 'Tests_CallWrapperRu.Verify(Context());' | 110 | 111 | @OnServer 112 | Scenario: WithSource 113 | And I execute 1C:Enterprise script at server 114 | | 'Tests_CallWrapperRu.WithSource(Context());' | 115 | 116 | @OnServer 117 | Scenario: WithOperationId 118 | And I execute 1C:Enterprise script at server 119 | | 'Tests_CallWrapperRu.WithOperationId(Context());' | 120 | 121 | @OnServer 122 | Scenario: OpenAPIExpectation 123 | And I execute 1C:Enterprise script at server 124 | | 'Tests_CallWrapperRu.OpenAPIExpectation(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_CreateMock.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_CreateMock 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: CreateNewClientsWithoutServer 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_CreateMock.CreateNewClientsWithoutServer(Context());' | 15 | 16 | @OnServer 17 | Scenario: CreateNewClientsWithServer 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_CreateMock.CreateNewClientsWithServer(Context());' | 20 | 21 | @OnServer 22 | Scenario: CreateClientNotDefaultURL 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_CreateMock.CreateClientNotDefaultURL(Context());' | 25 | 26 | @OnServer 27 | Scenario: CreateClientOnlyServerName 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_CreateMock.CreateClientOnlyServerName(Context());' | 30 | 31 | @OnServer 32 | Scenario: CreateClientServerNameAndPort 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_CreateMock.CreateClientServerNameAndPort(Context());' | 35 | 36 | @OnServer 37 | Scenario: CreateClientAndResetAfter 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_CreateMock.CreateClientAndResetAfter(Context());' | 40 | 41 | @OnServer 42 | Scenario: CreateFluence 43 | And I execute 1C:Enterprise script at server 44 | | 'Tests_CreateMock.CreateFluence(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Exceptions.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Exceptions 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: CurrentStageEmptySelfException 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Exceptions.CurrentStageEmptySelfException(Context());' | 15 | 16 | @OnServer 17 | Scenario: RequestEmptyMapException 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Exceptions.RequestEmptyMapException(Context());' | 20 | 21 | @OnServer 22 | Scenario: ResponseEmptyMapException 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Exceptions.ResponseEmptyMapException(Context());' | 25 | 26 | @OnServer 27 | Scenario: RequestBlankException 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_Exceptions.RequestBlankException(Context());' | 30 | 31 | @OnServer 32 | Scenario: ResponseBlankException 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_Exceptions.ResponseBlankException(Context());' | 35 | 36 | @OnServer 37 | Scenario: ConstructorPropertyByStageException 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_Exceptions.ConstructorPropertyByStageException(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Integration.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Integration 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: MockServerDockerUp 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Integration.MockServerDockerUp(Context());' | 15 | 16 | @OnServer 17 | Scenario: ExpectationFail 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Integration.ExpectationFail(Context());' | 20 | 21 | @OnServer 22 | Scenario: RequestAndResponseJSONFormat 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Integration.RequestAndResponseJSONFormat(Context());' | 25 | 26 | @OnServer 27 | Scenario: Resetting 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_Integration.Resetting(Context());' | 30 | 31 | @OnServer 32 | Scenario: MatchRequestByPath 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_Integration.MatchRequestByPath(Context());' | 35 | 36 | @OnServer 37 | Scenario: MatchRequestByMethodRegex 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_Integration.MatchRequestByMethodRegex(Context());' | 40 | 41 | @OnServer 42 | Scenario: MatchRequestByNotMatchingMethod 43 | And I execute 1C:Enterprise script at server 44 | | 'Tests_Integration.MatchRequestByNotMatchingMethod(Context());' | 45 | 46 | @OnServer 47 | Scenario: MatchRequestByQueryParameterWithRegexValue 48 | And I execute 1C:Enterprise script at server 49 | | 'Tests_Integration.MatchRequestByQueryParameterWithRegexValue(Context());' | 50 | 51 | @OnServer 52 | Scenario: MatchRequestByHeaders 53 | And I execute 1C:Enterprise script at server 54 | | 'Tests_Integration.MatchRequestByHeaders(Context());' | 55 | 56 | @OnServer 57 | Scenario: LiteralResponseWithBodyOnly 58 | And I execute 1C:Enterprise script at server 59 | | 'Tests_Integration.LiteralResponseWithBodyOnly(Context());' | 60 | 61 | @OnServer 62 | Scenario: LiteralResponseWithStatusCodeAndReasonPhrase 63 | And I execute 1C:Enterprise script at server 64 | | 'Tests_Integration.LiteralResponseWithStatusCodeAndReasonPhrase(Context());' | 65 | 66 | @OnServer 67 | Scenario: OpenAPIExpectationOnlySource 68 | And I execute 1C:Enterprise script at server 69 | | 'Tests_Integration.OpenAPIExpectationOnlySource(Context());' | 70 | 71 | @OnServer 72 | Scenario: OpenAPIExpectationSourceAndOperations 73 | And I execute 1C:Enterprise script at server 74 | | 'Tests_Integration.OpenAPIExpectationSourceAndOperations(Context());' | 75 | 76 | @OnServer 77 | Scenario: VerifyRequestsReceivedAtLeastTwice 78 | And I execute 1C:Enterprise script at server 79 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwice(Context());' | 80 | 81 | @OnServer 82 | Scenario: VerifyRequestsReceivedAtLeastTwiceFail 83 | And I execute 1C:Enterprise script at server 84 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwiceFail(Context());' | 85 | 86 | @OnServer 87 | Scenario: VerifyRequestsReceivedAtMostTwice 88 | And I execute 1C:Enterprise script at server 89 | | 'Tests_Integration.VerifyRequestsReceivedAtMostTwice(Context());' | 90 | 91 | @OnServer 92 | Scenario: VerifyRequestsReceivedAtMostTwiceFail 93 | And I execute 1C:Enterprise script at server 94 | | 'Tests_Integration.VerifyRequestsReceivedAtMostTwiceFail(Context());' | 95 | 96 | @OnServer 97 | Scenario: VerifyRequestsReceivedExactlyTwice 98 | And I execute 1C:Enterprise script at server 99 | | 'Tests_Integration.VerifyRequestsReceivedExactlyTwice(Context());' | 100 | 101 | @OnServer 102 | Scenario: VerifyRequestsReceivedExactlyTwiceFail 103 | And I execute 1C:Enterprise script at server 104 | | 'Tests_Integration.VerifyRequestsReceivedExactlyTwiceFail(Context());' | 105 | 106 | @OnServer 107 | Scenario: VerifyRequestsReceivedAtLeastTwiceByOpenAPI 108 | And I execute 1C:Enterprise script at server 109 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwiceByOpenAPI(Context());' | 110 | 111 | @OnServer 112 | Scenario: VerifyRequestsReceivedAtLeastTwiceByOpenAPIFailed 113 | And I execute 1C:Enterprise script at server 114 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwiceByOpenAPIFailed(Context());' | 115 | 116 | @OnServer 117 | Scenario: VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperation 118 | And I execute 1C:Enterprise script at server 119 | | 'Tests_Integration.VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperation(Context());' | 120 | 121 | @OnServer 122 | Scenario: VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperationFail 123 | And I execute 1C:Enterprise script at server 124 | | 'Tests_Integration.VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperationFail(Context());' | 125 | 126 | @OnServer 127 | Scenario: VerifyRequestsReceivedOnce 128 | And I execute 1C:Enterprise script at server 129 | | 'Tests_Integration.VerifyRequestsReceivedOnce(Context());' | 130 | 131 | @OnServer 132 | Scenario: VerifyRequestsReceivedOnceFail 133 | And I execute 1C:Enterprise script at server 134 | | 'Tests_Integration.VerifyRequestsReceivedOnceFail(Context());' | 135 | 136 | @OnServer 137 | Scenario: VerifyRequestsReceivedBetween 138 | And I execute 1C:Enterprise script at server 139 | | 'Tests_Integration.VerifyRequestsReceivedBetween(Context());' | 140 | 141 | @OnServer 142 | Scenario: VerifyRequestsReceivedBetweenLessFail 143 | And I execute 1C:Enterprise script at server 144 | | 'Tests_Integration.VerifyRequestsReceivedBetweenLessFail(Context());' | 145 | 146 | @OnServer 147 | Scenario: VerifyRequestsReceivedBetweenMoreFail 148 | And I execute 1C:Enterprise script at server 149 | | 'Tests_Integration.VerifyRequestsReceivedBetweenMoreFail(Context());' | 150 | 151 | @OnServer 152 | Scenario: VerifyRequestsNeverReceived 153 | And I execute 1C:Enterprise script at server 154 | | 'Tests_Integration.VerifyRequestsNeverReceived(Context());' | 155 | 156 | @OnServer 157 | Scenario: VerifyRequestsNeverReceivedFail 158 | And I execute 1C:Enterprise script at server 159 | | 'Tests_Integration.VerifyRequestsNeverReceivedFail(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_OpenAPI.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_OpenAPI 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: OpenAPIUndefinedConstructor 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_OpenAPI.OpenAPIUndefinedConstructor(Context());' | 15 | 16 | @OnServer 17 | Scenario: OpenAPIStringJSON 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_OpenAPI.OpenAPIStringJSON(Context());' | 20 | 21 | @OnServer 22 | Scenario: OpenAPIWhenOpenAPIMap 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_OpenAPI.OpenAPIWhenOpenAPIMap(Context());' | 25 | 26 | @OnServer 27 | Scenario: OpenAPIExpectationOnlySource 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_OpenAPI.OpenAPIExpectationOnlySource(Context());' | 30 | 31 | @OnServer 32 | Scenario: OpenAPIExpectationSourceAndOperations 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_OpenAPI.OpenAPIExpectationSourceAndOperations(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Request.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Request 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: RequestUndefinedConstructor 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Request.RequestUndefinedConstructor(Context());' | 15 | 16 | @OnServer 17 | Scenario: RequestReInitWrongConstructor 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Request.RequestReInitWrongConstructor(Context());' | 20 | 21 | @OnServer 22 | Scenario: RequestStringJSON 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Request.RequestStringJSON(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_RequestMatchers.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_RequestMatchers 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: PropertyByStage 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_RequestMatchers.PropertyByStage(Context());' | 15 | 16 | @OnServer 17 | Scenario: HeadersWithoutParams 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_RequestMatchers.HeadersWithoutParams(Context());' | 20 | 21 | @OnServer 22 | Scenario: HeadersWithParams 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_RequestMatchers.HeadersWithParams(Context());' | 25 | 26 | @OnServer 27 | Scenario: HeadersByStage 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_RequestMatchers.HeadersByStage(Context());' | 30 | 31 | @OnServer 32 | Scenario: WithHeader 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_RequestMatchers.WithHeader(Context());' | 35 | 36 | @OnServer 37 | Scenario: WithHeaderArrayValue 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_RequestMatchers.WithHeaderArrayValue(Context());' | 40 | 41 | @OnServer 42 | Scenario: WithHeaderWithoutHeaders 43 | And I execute 1C:Enterprise script at server 44 | | 'Tests_RequestMatchers.WithHeaderWithoutHeaders(Context());' | 45 | 46 | @OnServer 47 | Scenario: WithHeaderTwoHeader 48 | And I execute 1C:Enterprise script at server 49 | | 'Tests_RequestMatchers.WithHeaderTwoHeader(Context());' | 50 | 51 | @OnServer 52 | Scenario: WithMethodNotEmpty 53 | And I execute 1C:Enterprise script at server 54 | | 'Tests_RequestMatchers.WithMethodNotEmpty(Context());' | 55 | 56 | @OnServer 57 | Scenario: WithMethodRewrite 58 | And I execute 1C:Enterprise script at server 59 | | 'Tests_RequestMatchers.WithMethodRewrite(Context());' | 60 | 61 | @OnServer 62 | Scenario: WithPathNotEmpty 63 | And I execute 1C:Enterprise script at server 64 | | 'Tests_RequestMatchers.WithPathNotEmpty(Context());' | 65 | 66 | @OnServer 67 | Scenario: WithQueryStringParameterNotEmpty 68 | And I execute 1C:Enterprise script at server 69 | | 'Tests_RequestMatchers.WithQueryStringParameterNotEmpty(Context());' | 70 | 71 | @OnServer 72 | Scenario: WithQueryStringParameterTwoParams 73 | And I execute 1C:Enterprise script at server 74 | | 'Tests_RequestMatchers.WithQueryStringParameterTwoParams(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Reset.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Reset 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: ResetIntermediateException 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Reset.ResetIntermediateException(Context());' | 15 | 16 | @OnServer 17 | Scenario: ResetTerminalException 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Reset.ResetTerminalException(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Respond.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Respond 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: RespondURLException 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Respond.RespondURLException(Context());' | 15 | 16 | @OnServer 17 | Scenario: RespondWhenFullJSON 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Respond.RespondWhenFullJSON(Context());' | 20 | 21 | @OnServer 22 | Scenario: RespondWhenRequestJSON 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Respond.RespondWhenRequestJSON(Context());' | 25 | 26 | @OnServer 27 | Scenario: RespondWhenRequestMap 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_Respond.RespondWhenRequestMap(Context());' | 30 | 31 | @OnServer 32 | Scenario: RespondWhenRespondJSON 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_Respond.RespondWhenRespondJSON(Context());' | 35 | 36 | @OnServer 37 | Scenario: RespondWhenResponseJSON 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_Respond.RespondWhenResponseJSON(Context());' | 40 | 41 | @OnServer 42 | Scenario: RespondWhenResponseMap 43 | And I execute 1C:Enterprise script at server 44 | | 'Tests_Respond.RespondWhenResponseMap(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Response.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Response 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: ResponseUndefinedConstructor 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Response.ResponseUndefinedConstructor(Context());' | 15 | 16 | @OnServer 17 | Scenario: ResponseReInitWrongConstructor 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Response.ResponseReInitWrongConstructor(Context());' | 20 | 21 | @OnServer 22 | Scenario: ResponseRequestExists 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Response.ResponseRequestExists(Context());' | 25 | 26 | @OnServer 27 | Scenario: ResponseStringJSON 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_Response.ResponseStringJSON(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_ResponseAction.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_ResponseAction 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: WithBody 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_ResponseAction.WithBody(Context());' | 15 | 16 | @OnServer 17 | Scenario: WithStatusCode 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_ResponseAction.WithStatusCode(Context());' | 20 | 21 | @OnServer 22 | Scenario: WithStatusCodeRewrite 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_ResponseAction.WithStatusCodeRewrite(Context());' | 25 | 26 | @OnServer 27 | Scenario: WithReasonPhrase 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_ResponseAction.WithReasonPhrase(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Times.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Times 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: TimesUndefinedConstructor 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Times.TimesUndefinedConstructor(Context());' | 15 | 16 | @OnServer 17 | Scenario: TimesReInitWrongConstructor 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Times.TimesReInitWrongConstructor(Context());' | 20 | 21 | @OnServer 22 | Scenario: TimesRequestExists 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Times.TimesRequestExists(Context());' | 25 | 26 | @OnServer 27 | Scenario: TimesStringJSON 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_Times.TimesStringJSON(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_TimesMethods.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_TimesMethods 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: AtLeast 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_TimesMethods.AtLeast(Context());' | 15 | 16 | @OnServer 17 | Scenario: AtMost 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_TimesMethods.AtMost(Context());' | 20 | 21 | @OnServer 22 | Scenario: Exactly 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_TimesMethods.Exactly(Context());' | 25 | 26 | @OnServer 27 | Scenario: Once 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_TimesMethods.Once(Context());' | 30 | 31 | @OnServer 32 | Scenario: Between 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_TimesMethods.Between(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_Verify.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Verify 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: VerifyURLException 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Verify.VerifyURLException(Context());' | 15 | 16 | @OnServer 17 | Scenario: VerifyWhenFullJSON 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Verify.VerifyWhenFullJSON(Context());' | 20 | 21 | @OnServer 22 | Scenario: VerifyWhenRequestJSON 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Verify.VerifyWhenRequestJSON(Context());' | 25 | 26 | @OnServer 27 | Scenario: VerifyWhenRequestMap 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_Verify.VerifyWhenRequestMap(Context());' | 30 | 31 | @OnServer 32 | Scenario: VerifyWhenVerifyJSON 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_Verify.VerifyWhenVerifyJSON(Context());' | 35 | 36 | @OnServer 37 | Scenario: VerifyWhenTimesNode 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_Verify.VerifyWhenTimesNode(Context());' | 40 | 41 | @OnServer 42 | Scenario: VerifydWhenTimesMap 43 | And I execute 1C:Enterprise script at server 44 | | 'Tests_Verify.VerifydWhenTimesMap(Context());' | 45 | 46 | @OnServer 47 | Scenario: VerifydWhenRequestAndTimes 48 | And I execute 1C:Enterprise script at server 49 | | 'Tests_Verify.VerifydWhenRequestAndTimes(Context());' | 50 | 51 | @OnServer 52 | Scenario: VerifydWhenRequestInWhenAndTimesInVerify 53 | And I execute 1C:Enterprise script at server 54 | | 'Tests_Verify.VerifydWhenRequestInWhenAndTimesInVerify(Context());' | 55 | 56 | @OnServer 57 | Scenario: VerifyWhenOpenAPIWithSource 58 | And I execute 1C:Enterprise script at server 59 | | 'Tests_Verify.VerifyWhenOpenAPIWithSource(Context());' | 60 | 61 | @OnServer 62 | Scenario: VerifyWhenOpenAPIWithOperationId 63 | And I execute 1C:Enterprise script at server 64 | | 'Tests_Verify.VerifyWhenOpenAPIWithOperationId(Context());' | 65 | 66 | @OnServer 67 | Scenario: VerifyWhenOpenAPI 68 | And I execute 1C:Enterprise script at server 69 | | 'Tests_Verify.VerifyWhenOpenAPI(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/all/Tests_When.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_When 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: WhenParamsString 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_When.WhenParamsString(Context());' | 15 | 16 | @OnServer 17 | Scenario: WhenParamsRequestAction 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_When.WhenParamsRequestAction(Context());' | 20 | 21 | @OnServer 22 | Scenario: WhenWrongParams 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_When.WhenWrongParams(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/dev/Tests_RequestMatchers.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_RequestMatchers 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: WithMethodRewrite 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_RequestMatchers.WithMethodRewrite(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/dev/Tests_ResponseAction.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_ResponseAction 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: WithStatusCodeRewrite 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_ResponseAction.WithStatusCodeRewrite(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/integration/Tests_Integration.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Integration 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: ExpectationFail 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Integration.ExpectationFail(Context());' | 15 | 16 | @OnServer 17 | Scenario: RequestAndResponseJSONFormat 18 | And I execute 1C:Enterprise script at server 19 | | 'Tests_Integration.RequestAndResponseJSONFormat(Context());' | 20 | 21 | @OnServer 22 | Scenario: Resetting 23 | And I execute 1C:Enterprise script at server 24 | | 'Tests_Integration.Resetting(Context());' | 25 | 26 | @OnServer 27 | Scenario: MatchRequestByPath 28 | And I execute 1C:Enterprise script at server 29 | | 'Tests_Integration.MatchRequestByPath(Context());' | 30 | 31 | @OnServer 32 | Scenario: MatchRequestByMethodRegex 33 | And I execute 1C:Enterprise script at server 34 | | 'Tests_Integration.MatchRequestByMethodRegex(Context());' | 35 | 36 | @OnServer 37 | Scenario: MatchRequestByNotMatchingMethod 38 | And I execute 1C:Enterprise script at server 39 | | 'Tests_Integration.MatchRequestByNotMatchingMethod(Context());' | 40 | 41 | @OnServer 42 | Scenario: MatchRequestByQueryParameterWithRegexValue 43 | And I execute 1C:Enterprise script at server 44 | | 'Tests_Integration.MatchRequestByQueryParameterWithRegexValue(Context());' | 45 | 46 | @OnServer 47 | Scenario: MatchRequestByHeaders 48 | And I execute 1C:Enterprise script at server 49 | | 'Tests_Integration.MatchRequestByHeaders(Context());' | 50 | 51 | @OnServer 52 | Scenario: LiteralResponseWithBodyOnly 53 | And I execute 1C:Enterprise script at server 54 | | 'Tests_Integration.LiteralResponseWithBodyOnly(Context());' | 55 | 56 | @OnServer 57 | Scenario: LiteralResponseWithStatusCodeAndReasonPhrase 58 | And I execute 1C:Enterprise script at server 59 | | 'Tests_Integration.LiteralResponseWithStatusCodeAndReasonPhrase(Context());' | 60 | 61 | @OnServer 62 | Scenario: OpenAPIExpectationOnlySource 63 | And I execute 1C:Enterprise script at server 64 | | 'Tests_Integration.OpenAPIExpectationOnlySource(Context());' | 65 | 66 | @OnServer 67 | Scenario: OpenAPIExpectationSourceAndOperations 68 | And I execute 1C:Enterprise script at server 69 | | 'Tests_Integration.OpenAPIExpectationSourceAndOperations(Context());' | 70 | 71 | @OnServer 72 | Scenario: VerifyRequestsReceivedAtLeastTwice 73 | And I execute 1C:Enterprise script at server 74 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwice(Context());' | 75 | 76 | @OnServer 77 | Scenario: VerifyRequestsReceivedAtLeastTwiceFail 78 | And I execute 1C:Enterprise script at server 79 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwiceFail(Context());' | 80 | 81 | @OnServer 82 | Scenario: VerifyRequestsReceivedAtMostTwice 83 | And I execute 1C:Enterprise script at server 84 | | 'Tests_Integration.VerifyRequestsReceivedAtMostTwice(Context());' | 85 | 86 | @OnServer 87 | Scenario: VerifyRequestsReceivedAtMostTwiceFail 88 | And I execute 1C:Enterprise script at server 89 | | 'Tests_Integration.VerifyRequestsReceivedAtMostTwiceFail(Context());' | 90 | 91 | @OnServer 92 | Scenario: VerifyRequestsReceivedExactlyTwice 93 | And I execute 1C:Enterprise script at server 94 | | 'Tests_Integration.VerifyRequestsReceivedExactlyTwice(Context());' | 95 | 96 | @OnServer 97 | Scenario: VerifyRequestsReceivedExactlyTwiceFail 98 | And I execute 1C:Enterprise script at server 99 | | 'Tests_Integration.VerifyRequestsReceivedExactlyTwiceFail(Context());' | 100 | 101 | @OnServer 102 | Scenario: VerifyRequestsReceivedAtLeastTwiceByOpenAPI 103 | And I execute 1C:Enterprise script at server 104 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwiceByOpenAPI(Context());' | 105 | 106 | @OnServer 107 | Scenario: VerifyRequestsReceivedAtLeastTwiceByOpenAPIFailed 108 | And I execute 1C:Enterprise script at server 109 | | 'Tests_Integration.VerifyRequestsReceivedAtLeastTwiceByOpenAPIFailed(Context());' | 110 | 111 | @OnServer 112 | Scenario: VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperation 113 | And I execute 1C:Enterprise script at server 114 | | 'Tests_Integration.VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperation(Context());' | 115 | 116 | @OnServer 117 | Scenario: VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperationFail 118 | And I execute 1C:Enterprise script at server 119 | | 'Tests_Integration.VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperationFail(Context());' | 120 | 121 | @OnServer 122 | Scenario: VerifyRequestsReceivedOnce 123 | And I execute 1C:Enterprise script at server 124 | | 'Tests_Integration.VerifyRequestsReceivedOnce(Context());' | 125 | 126 | @OnServer 127 | Scenario: VerifyRequestsReceivedOnceFail 128 | And I execute 1C:Enterprise script at server 129 | | 'Tests_Integration.VerifyRequestsReceivedOnceFail(Context());' | 130 | 131 | @OnServer 132 | Scenario: VerifyRequestsReceivedBetween 133 | And I execute 1C:Enterprise script at server 134 | | 'Tests_Integration.VerifyRequestsReceivedBetween(Context());' | 135 | 136 | @OnServer 137 | Scenario: VerifyRequestsReceivedBetweenLessFail 138 | And I execute 1C:Enterprise script at server 139 | | 'Tests_Integration.VerifyRequestsReceivedBetweenLessFail(Context());' | 140 | 141 | @OnServer 142 | Scenario: VerifyRequestsReceivedBetweenMoreFail 143 | And I execute 1C:Enterprise script at server 144 | | 'Tests_Integration.VerifyRequestsReceivedBetweenMoreFail(Context());' | 145 | 146 | @OnServer 147 | Scenario: VerifyRequestsNeverReceived 148 | And I execute 1C:Enterprise script at server 149 | | 'Tests_Integration.VerifyRequestsNeverReceived(Context());' | 150 | 151 | @OnServer 152 | Scenario: VerifyRequestsNeverReceivedFail 153 | And I execute 1C:Enterprise script at server 154 | | 'Tests_Integration.VerifyRequestsNeverReceivedFail(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/features/prepare/Tests_Integration.feature: -------------------------------------------------------------------------------- 1 | # language: en 2 | 3 | @tree 4 | @classname=ModuleExceptionPath 5 | 6 | Feature: mockserver-client.Tests.Tests_Integration 7 | As Developer 8 | I want the returns value to be equal to expected value 9 | That I can guarantee the execution of the method 10 | 11 | @OnServer 12 | Scenario: MockServerDockerUp 13 | And I execute 1C:Enterprise script at server 14 | | 'Tests_Integration.MockServerDockerUp(Context());' | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Assert/Assert.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Assert 4 | 5 | en 6 | Assert 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Assert/Module.bsl: -------------------------------------------------------------------------------- 1 | // From "OpenSubsystemsLibrary" Assert by Ingvar Vilkman 2 | // https://github.com/zeegin/OpenSubsystemsLibrary/ 3 | 4 | #Region Public 5 | 6 | Procedure AreEqual(Expected, Actual, Message = "") Export 7 | 8 | If Expected <> Actual Then 9 | Raise AssertError(Expected, Actual, Message); 10 | EndIf; 11 | 12 | EndProcedure 13 | 14 | Procedure AreNotEqual(NotExpected, Actual, Message = "") Export 15 | 16 | If NotExpected = Actual Then 17 | Raise AssertError(NotExpected, Actual, Message); 18 | EndIf; 19 | 20 | EndProcedure 21 | 22 | Procedure IsTrue(Condition, Message = "") Export 23 | 24 | If Not Condition Then 25 | Raise AssertError(True, Condition, Message); 26 | EndIf; 27 | 28 | EndProcedure 29 | 30 | Procedure IsFalse(Condition, Message = "") Export 31 | 32 | If Condition Then 33 | Raise AssertError(False, Not Condition, Message); 34 | EndIf; 35 | 36 | EndProcedure 37 | 38 | Procedure IsInstanceOfType(ExpectedType, Value, Message = "") Export 39 | 40 | If TypeOf(Value) <> Type(ExpectedType) Then 41 | Raise AssertError(Type(ExpectedType), TypeOf(Value), Message); 42 | EndIf; 43 | 44 | EndProcedure 45 | 46 | Procedure IsUndefined(Value, Message = "") Export 47 | 48 | If Value <> Undefined Then 49 | Raise AssertError(Undefined, Value, Message); 50 | EndIf; 51 | 52 | EndProcedure 53 | 54 | Procedure IsNotUndefined(Value, Message = "") Export 55 | 56 | If Value = Undefined Then 57 | Raise AssertError(Undefined, Value, Message); 58 | EndIf; 59 | 60 | EndProcedure 61 | 62 | Procedure IsNull(Value, Message = "") Export 63 | 64 | If Value <> Null Then 65 | Raise AssertError(Null, Value, Message); 66 | EndIf; 67 | 68 | EndProcedure 69 | 70 | Procedure IsNotNull(Value, Message = "") Export 71 | 72 | If Value = Null Then 73 | Raise AssertError(Null, Value, Message); 74 | EndIf; 75 | 76 | EndProcedure 77 | 78 | Procedure IsLegalException(LegalErrorFragment, ErrorInfo, Message = "") Export 79 | 80 | ErrorDescription = DetailErrorDescription(ErrorInfo); 81 | 82 | If Not StrFind(ErrorDescription, LegalErrorFragment) Then 83 | Raise AssertError(LegalErrorFragment, ErrorDescription, Message); 84 | EndIf; 85 | 86 | EndProcedure 87 | 88 | Procedure AreCollectionEmpty(Value, Message = "") Export 89 | 90 | If Value.Count() <> 0 Then 91 | Raise AssertError( 92 | NStr("ru = 'Не пустая коллекция.'; en = 'Collection isn't empty.'"), 93 | Value, 94 | Message); 95 | EndIf; 96 | 97 | EndProcedure 98 | 99 | Procedure AreCollectionNotEmpty(Value, Message = "") Export 100 | 101 | If Value.Count() = 0 Then 102 | Raise AssertError( 103 | NStr("ru = 'Пустая коллекция.'; en = 'Collection is empty'"), 104 | Value, 105 | Message); 106 | EndIf; 107 | 108 | EndProcedure 109 | 110 | Function AssertError(Expected, Actual, Message = "") Export 111 | 112 | ErrorText = StrTemplate( 113 | "[AssertError] 114 | |[Expected] 115 | |%1 116 | |[Actual] 117 | |%2", 118 | Expected, 119 | Actual 120 | ); 121 | 122 | If Not IsBlankString(Message) Then 123 | ErrorText = ErrorText + Chars.LF + "[Message]" + Chars.LF + Message; 124 | EndIf; 125 | 126 | Return ErrorText; 127 | 128 | EndFunction 129 | 130 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_CallWrapperRu/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure Server(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Result = Mock.Сервер("example.org", "1090", Ложь); 10 | // then 11 | Assert.AreEqual(Result.URL, "example.org:1090"); 12 | 13 | EndProcedure 14 | 15 | // @unit-test 16 | Procedure Reset(Context) Export 17 | 18 | // given 19 | Mock = DataProcessors.MockServerClient.Create(); 20 | Mock.Server("this.is.error.url", "1080"); 21 | // when 22 | Mock.Сбросить(); 23 | // then 24 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 25 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 26 | 27 | EndProcedure 28 | 29 | // @unit-test 30 | Procedure When(Context) Export 31 | 32 | // given 33 | Mock = DataProcessors.MockServerClient.Create(); 34 | // when 35 | Result = Mock.Когда("{""sample"": ""any""}"); 36 | // then 37 | Assert.IsUndefined(Result.Constructor); 38 | Assert.AreEqual(Result.JSON, "{""sample"": ""any""}"); 39 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 40 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 41 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 42 | 43 | EndProcedure 44 | 45 | // @unit-test 46 | Procedure Request(Context) Export 47 | 48 | // given 49 | Mock = DataProcessors.MockServerClient.Create(); 50 | // when 51 | Result = Mock.Запрос("""method"": ""GET"""); 52 | // then 53 | Assert.IsTrue(IsBlankString(Result.JSON)); 54 | Assert.IsFalse(IsBlankString(Result.HttpRequestNode)); 55 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 56 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 57 | Assert.IsUndefined(Result.Constructor); 58 | 59 | EndProcedure 60 | 61 | // @unit-test 62 | Procedure Headers(Context) Export 63 | 64 | // given 65 | Mock = DataProcessors.MockServerClient.Create(); 66 | Mock.Server("this.is.error.url", "1080"); 67 | // when 68 | Mock.When(Mock.Request().Заголовки()).Respond(); 69 | // then 70 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 71 | Assert.AreEqual(Mock.CurrentStage, ""); 72 | Assert.AreEqual(Mock.Constructor["httpRequest"].Count(), 1); 73 | Assert.IsInstanceOfType("Map", Mock.Constructor["httpRequest"]["headers"]); 74 | Assert.AreEqual(Mock.JSON, "{ 75 | | ""httpRequest"": { 76 | | ""headers"": {} 77 | | } 78 | |}"); 79 | 80 | EndProcedure 81 | 82 | // @unit-test 83 | Procedure WithHeader(Context) Export 84 | 85 | // given 86 | Mock = DataProcessors.MockServerClient.Create(); 87 | Mock.Server("this.is.error.url", "1080"); 88 | // when 89 | Mock.When(Mock.Request().Headers().Заголовок("key", "value")).Respond(); 90 | // then 91 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 92 | Assert.AreEqual(Mock.CurrentStage, ""); 93 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"]["key"][0], "value"); 94 | Assert.AreEqual(Mock.JSON, "{ 95 | | ""httpRequest"": { 96 | | ""headers"": { 97 | | ""key"": [ 98 | | ""value"" 99 | | ] 100 | | } 101 | | } 102 | |}" ); 103 | 104 | EndProcedure 105 | 106 | // @unit-test 107 | Procedure WithMethod(Context) Export 108 | 109 | // given 110 | Mock = DataProcessors.MockServerClient.Create(); 111 | Mock.Server("this.is.error.url", "1080"); 112 | // when 113 | Mock.When(Mock.Request().Метод("GET")).Respond(); 114 | // then 115 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 116 | Assert.AreEqual(Mock.CurrentStage, ""); 117 | Assert.AreEqual(Mock.Constructor["httpRequest"]["method"], "GET"); 118 | Assert.AreEqual(Mock.JSON, "{ 119 | | ""httpRequest"": { 120 | | ""method"": ""GET"" 121 | | } 122 | |}"); 123 | 124 | EndProcedure 125 | 126 | // @unit-test 127 | Procedure WithPath(Context) Export 128 | 129 | // given 130 | Mock = DataProcessors.MockServerClient.Create(); 131 | Mock.Server("this.is.error.url", "1080"); 132 | // when 133 | Mock.When(Mock.Request().Путь("/фуу/foo")).Respond(); 134 | // then 135 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 136 | Assert.AreEqual(Mock.CurrentStage, ""); 137 | Assert.AreEqual(Mock.Constructor["httpRequest"]["path"], "/фуу/foo"); 138 | Assert.AreEqual(Mock.JSON, "{ 139 | | ""httpRequest"": { 140 | | ""path"": ""/фуу/foo"" 141 | | } 142 | |}"); 143 | 144 | EndProcedure 145 | 146 | // @unit-test 147 | Procedure WithQueryStringParameter(Context) Export 148 | 149 | // given 150 | Mock = DataProcessors.MockServerClient.Create(); 151 | Mock.Server("this.is.error.url", "1080"); 152 | // when 153 | Mock.When(Mock.Request().ПараметрСтрокиЗапроса("cartId", "[A-Z0-9\\-]+")).Respond(); 154 | // then 155 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 156 | Assert.AreEqual(Mock.CurrentStage, ""); 157 | Assert.AreEqual(Mock.Constructor["httpRequest"]["queryStringParameters"]["cartId"][0], "[A-Z0-9\\-]+"); 158 | Assert.AreEqual(Mock.JSON, "{ 159 | | ""httpRequest"": { 160 | | ""queryStringParameters"": { 161 | | ""cartId"": [ 162 | | ""[A-Z0-9\\\\-]+"" 163 | | ] 164 | | } 165 | | } 166 | |}"); 167 | 168 | EndProcedure 169 | 170 | // @unit-test 171 | Procedure Response(Context) Export 172 | 173 | // given 174 | Mock = DataProcessors.MockServerClient.Create(); 175 | // when 176 | Result = Mock.Ответ("""statusCode"": 200 "); 177 | // then 178 | Assert.IsTrue(IsBlankString(Result.JSON)); 179 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 180 | Assert.IsFalse(IsBlankString(Result.HttpResponseNode)); 181 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 182 | Assert.IsUndefined(Result.Constructor); 183 | 184 | EndProcedure 185 | 186 | // @unit-test 187 | Procedure WithStatusCode(Context) Export 188 | 189 | // given 190 | Mock = DataProcessors.MockServerClient.Create(); 191 | Mock.Server("this.is.error.url", "1080"); 192 | // when 193 | Mock.Respond(Mock.Response().КодОтвета(404)); 194 | // then 195 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 196 | Assert.AreEqual(Mock.CurrentStage, ""); 197 | Assert.AreEqual(Mock.Constructor["httpResponse"]["statusCode"], 404); 198 | Assert.AreEqual(Mock.JSON, "{ 199 | | ""httpResponse"": { 200 | | ""statusCode"": 404 201 | | } 202 | |}"); 203 | 204 | EndProcedure 205 | 206 | // @unit-test 207 | Procedure WithReasonPhrase(Context) Export 208 | 209 | // given 210 | Mock = DataProcessors.MockServerClient.Create(); 211 | Mock.Server("this.is.error.url", "1080"); 212 | // when 213 | Mock.Respond(Mock.Response().Причина("I'm a teapot")); 214 | // then 215 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 216 | Assert.AreEqual(Mock.CurrentStage, ""); 217 | Assert.AreEqual(Mock.Constructor["httpResponse"]["reasonPhrase"], "I'm a teapot"); 218 | Assert.AreEqual(Mock.JSON, "{ 219 | | ""httpResponse"": { 220 | | ""reasonPhrase"": ""I'm a teapot"" 221 | | } 222 | |}"); 223 | 224 | EndProcedure 225 | 226 | // @unit-test 227 | Procedure Respond(Context) Export 228 | 229 | // given 230 | Mock = DataProcessors.MockServerClient.Create(); 231 | Mock.Server("this.is.error.url", "1080"); 232 | // when 233 | Mock.When("{""name"":""value""}").Ответить(); 234 | // then 235 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 236 | Assert.AreEqual(Mock.CurrentStage, ""); 237 | Assert.AreEqual(Mock.JSON, "{""name"":""value""}"); 238 | 239 | EndProcedure 240 | 241 | // @unit-test 242 | Procedure Times(Context) Export 243 | 244 | // given 245 | Mock = DataProcessors.MockServerClient.Create(); 246 | // when 247 | Result = Mock.Повторений(); 248 | // then 249 | Assert.AreEqual(Mock.CurrentStage, "times"); 250 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 251 | Assert.AreCollectionEmpty(Result.Constructor["times"]); 252 | 253 | EndProcedure 254 | 255 | // @unit-test 256 | Procedure AtLeast(Context) Export 257 | 258 | // given 259 | Mock = DataProcessors.MockServerClient.Create(); 260 | // when 261 | Result = Mock.Повторений().НеМенее(2); 262 | // then 263 | Assert.AreEqual(Mock.CurrentStage, "times"); 264 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 2); 265 | 266 | EndProcedure 267 | 268 | // @unit-test 269 | Procedure AtMost(Context) Export 270 | 271 | // given 272 | Mock = DataProcessors.MockServerClient.Create(); 273 | // when 274 | Result = Mock.Повторений().НеБолее(2); 275 | // then 276 | Assert.AreEqual(Mock.CurrentStage, "times"); 277 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 2); 278 | 279 | EndProcedure 280 | 281 | // @unit-test 282 | Procedure Exactly(Context) Export 283 | 284 | // given 285 | Mock = DataProcessors.MockServerClient.Create(); 286 | // when 287 | Result = Mock.Повторений().Точно(2); 288 | // then 289 | Assert.AreEqual(Mock.CurrentStage, "times"); 290 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 2); 291 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 2); 292 | 293 | EndProcedure 294 | 295 | // @unit-test 296 | Procedure Once(Context) Export 297 | 298 | // given 299 | Mock = DataProcessors.MockServerClient.Create(); 300 | // when 301 | Result = Mock.Повторений().Однократно(); 302 | // then 303 | Assert.AreEqual(Mock.CurrentStage, "times"); 304 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 1); 305 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 1); 306 | 307 | EndProcedure 308 | 309 | // @unit-test 310 | Procedure Between(Context) Export 311 | 312 | // given 313 | Mock = DataProcessors.MockServerClient.Create(); 314 | // when 315 | Result = Mock.Повторений().Между(2, 3); 316 | // then 317 | Assert.AreEqual(Mock.CurrentStage, "times"); 318 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 2); 319 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 3); 320 | 321 | EndProcedure 322 | 323 | // @unit-test 324 | Procedure Verify(Context) Export 325 | 326 | // given 327 | Mock = DataProcessors.MockServerClient.Create(); 328 | Mock.Server("this.is.error.url", "1080"); 329 | // when 330 | Mock.When( Mock.Request().Метод("GET") ).Проверить( Mock.Times().AtMost(3) ); 331 | // then 332 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 333 | Assert.AreEqual(Mock.JSON, "{ 334 | | ""httpRequest"": { 335 | | ""method"": ""GET"" 336 | | }, 337 | | ""times"": { 338 | | ""atMost"": 3 339 | | } 340 | |}"); 341 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 342 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 343 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 344 | 345 | EndProcedure 346 | 347 | // @unit-test 348 | Procedure WithSource(Context) Export 349 | 350 | // given 351 | Mock = DataProcessors.MockServerClient.Create(); 352 | Mock.Server("this.is.error.url", "1080"); 353 | // when 354 | Mock.When( Mock.OpenAPI().Источник("http://...") ).Verify(); 355 | // then 356 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 357 | Assert.AreEqual(Mock.CurrentStage, ""); 358 | Assert.IsNotUndefined(Mock.Constructor); 359 | Assert.AreEqual(Mock.JSON, "{ 360 | | ""httpRequest"": { 361 | | ""specUrlOrPayload"": ""http://..."" 362 | | } 363 | |}"); 364 | 365 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 366 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 367 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 368 | 369 | EndProcedure 370 | 371 | // @unit-test 372 | Procedure WithOperationId(Context) Export 373 | 374 | // given 375 | Mock = DataProcessors.MockServerClient.Create(); 376 | Mock.Server("this.is.error.url", "1080"); 377 | // when 378 | Mock.When( Mock.OpenAPI().Операция("operation_id") ).Verify(); 379 | // then 380 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 381 | Assert.AreEqual(Mock.CurrentStage, ""); 382 | Assert.IsNotUndefined(Mock.Constructor); 383 | Assert.AreEqual(Mock.JSON, "{ 384 | | ""httpRequest"": { 385 | | ""operationId"": ""operation_id"" 386 | | } 387 | |}"); 388 | 389 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 390 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 391 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 392 | 393 | EndProcedure 394 | 395 | // @unit-test 396 | Procedure OpenAPIExpectation(Context) Export 397 | 398 | // given 399 | Mock = DataProcessors.MockServerClient.Create(); 400 | Mock.Server("this.is.error.url", "1080"); 401 | // when 402 | Mock.ОжидатьOpenAPI( "http://..." ); 403 | // then 404 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 405 | Assert.AreEqual(Mock.CurrentStage, ""); 406 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 407 | 408 | Assert.AreEqual(Mock.JSON, "{ 409 | | ""specUrlOrPayload"": ""http://..."" 410 | |}"); 411 | 412 | EndProcedure 413 | 414 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_CallWrapperRu/Tests_CallWrapperRu.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_CallWrapperRu 4 | 5 | en 6 | Russian 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_CreateMock/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure CreateNewClientsWithoutServer(Context) Export 5 | 6 | // given 7 | Mock_1 = DataProcessors.MockServerClient.Create(); 8 | Mock_2 = DataProcessors.MockServerClient.Create(); 9 | // when 10 | // then 11 | Assert.AreEqual(Mock_1.URL, "localhost:1080"); 12 | Assert.AreEqual(Mock_2.URL, "localhost:1080"); 13 | 14 | EndProcedure 15 | 16 | // @unit-test 17 | Procedure CreateNewClientsWithServer(Context) Export 18 | 19 | // given 20 | Mock_1 = DataProcessors.MockServerClient.Create(); 21 | Mock_2 = DataProcessors.MockServerClient.Create(); 22 | // when 23 | Result_1 = Mock_1.Server("http://localhost:1080"); 24 | Result_2 = Mock_2.Server("http://localhost:1090"); 25 | // then 26 | Assert.AreEqual(Result_1.URL, "http://localhost:1080"); 27 | Assert.AreEqual(Result_2.URL, "http://localhost:1090"); 28 | 29 | EndProcedure 30 | 31 | // @unit-test 32 | Procedure CreateClientNotDefaultURL(Context) Export 33 | 34 | // given 35 | Mock = DataProcessors.MockServerClient.Create(); 36 | // when 37 | Result = Mock.Server("http://example.org"); 38 | // then 39 | Assert.AreEqual(Result.URL, "http://example.org"); 40 | Assert.IsUndefined(Result.MockServerResponse); 41 | 42 | EndProcedure 43 | 44 | // @unit-test 45 | Procedure CreateClientOnlyServerName(Context) Export 46 | 47 | // given 48 | Mock = DataProcessors.MockServerClient.Create(); 49 | // when 50 | Result = Mock.Server("example.org"); 51 | // then 52 | Assert.AreEqual(Result.URL, "example.org"); 53 | Assert.IsUndefined(Result.MockServerResponse); 54 | 55 | EndProcedure 56 | 57 | // @unit-test 58 | Procedure CreateClientServerNameAndPort(Context) Export 59 | 60 | // given 61 | Mock = DataProcessors.MockServerClient.Create(); 62 | // when 63 | Result = Mock.Server("example.org", "1090"); 64 | // then 65 | Assert.AreEqual(Result.URL, "example.org:1090"); 66 | Assert.IsUndefined(Result.MockServerResponse); 67 | 68 | EndProcedure 69 | 70 | // @unit-test 71 | Procedure CreateClientAndResetAfter(Context) Export 72 | 73 | // given 74 | Mock = DataProcessors.MockServerClient.Create(); 75 | // when 76 | Result = Mock.Server("this.is.error.url", "1080", true); 77 | // then 78 | Assert.AreEqual(Result.URL, "this.is.error.url:1080"); 79 | Assert.AreEqual(Result.MockServerResponse.КодСостояния, 500); 80 | 81 | EndProcedure 82 | 83 | // @unit-test 84 | Procedure CreateFluence(Context) Export 85 | 86 | // when 87 | Result = DataProcessors.MockServerClient.Create().Server("this.is.error.url", "1080", true); 88 | // then 89 | Assert.AreEqual(Result.URL, "this.is.error.url:1080"); 90 | Assert.AreEqual(Result.MockServerResponse.КодСостояния, 500); 91 | 92 | EndProcedure 93 | 94 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_CreateMock/Tests_CreateMock.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_CreateMock 4 | 5 | en 6 | Create mock 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Exceptions/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure CurrentStageEmptySelfException(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | Try 9 | // when 10 | Result = Mock.WithMethod("GET"); 11 | Except 12 | // then 13 | Assert.IsLegalException("[RuntimeError]", ErrorInfo()); 14 | Assert.AreEqual(Mock.CurrentStage, ""); 15 | EndTry; 16 | 17 | EndProcedure 18 | 19 | // @unit-test 20 | Procedure RequestEmptyMapException(Context) Export 21 | 22 | // given 23 | Mock = DataProcessors.MockServerClient.Create(); 24 | Mock.CurrentStage = "foo"; 25 | Mock.Constructor = New Map(); 26 | Try 27 | // when 28 | Result = Mock.WithMethod("GET"); 29 | Except 30 | // then 31 | Assert.IsLegalException("[RuntimeError]", ErrorInfo()); 32 | Assert.AreEqual(Mock.CurrentStage, "foo"); 33 | EndTry; 34 | 35 | EndProcedure 36 | 37 | // @unit-test 38 | Procedure ResponseEmptyMapException(Context) Export 39 | 40 | // given 41 | Mock = DataProcessors.MockServerClient.Create(); 42 | Mock.CurrentStage = "foo"; 43 | Mock.Constructor = New Map(); 44 | Try 45 | // when 46 | Result = Mock.WithStatusCode(404); 47 | Except 48 | // then 49 | Assert.IsLegalException("[RuntimeError]", ErrorInfo()); 50 | Assert.AreEqual(Mock.CurrentStage, "foo"); 51 | EndTry; 52 | 53 | EndProcedure 54 | 55 | // @unit-test 56 | Procedure RequestBlankException(Context) Export 57 | 58 | // given 59 | Mock = DataProcessors.MockServerClient.Create(); 60 | Mock.Constructor = New Map(); 61 | Mock.Constructor.Insert("httpRequest", ""); 62 | Try 63 | // when 64 | Result = Mock.WithMethod("GET"); 65 | Except 66 | // then 67 | Assert.IsLegalException("[RuntimeError]", ErrorInfo()); 68 | EndTry; 69 | 70 | EndProcedure 71 | 72 | // @unit-test 73 | Procedure ResponseBlankException(Context) Export 74 | 75 | // given 76 | Mock = DataProcessors.MockServerClient.Create(); 77 | Mock.Constructor = New Map(); 78 | Mock.Constructor.Insert("httpResponse", ""); 79 | Try 80 | // when 81 | Result = Mock.WithStatusCode(404); 82 | Except 83 | // then 84 | Assert.IsLegalException("[RuntimeError]", ErrorInfo()); 85 | EndTry; 86 | 87 | EndProcedure 88 | 89 | // @unit-test 90 | Procedure ConstructorPropertyByStageException(Context) Export 91 | 92 | // given 93 | Mock = DataProcessors.MockServerClient.Create(); 94 | Try 95 | // when 96 | Result = Mock.Response(); 97 | Mock.CurrentStage = "foo"; 98 | Result = Result.КодОтвета(404); 99 | Except 100 | // then 101 | Assert.IsLegalException("[RuntimeError]", ErrorInfo()); 102 | EndTry; 103 | 104 | EndProcedure 105 | 106 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Exceptions/Tests_Exceptions.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Exceptions 4 | 5 | en 6 | Exceptions 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Integration/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test:prepare 4 | Procedure MockServerDockerUp(Context) Export 5 | 6 | ExitStatus = Undefined; 7 | RunApp("docker kill mockserver-1c-integration", , True, ExitStatus); 8 | RunApp("docker run -d --rm -p 1080:1080" 9 | + " --name mockserver-1c-integration mockserver/mockserver" 10 | + " -logLevel DEBUG -serverPort 1080", 11 | , 12 | True, 13 | ExitStatus); 14 | 15 | If ExitStatus <> 0 Then 16 | 17 | Raise NStr("en = 'Container mockserver-1c-integration isn't created.'"); 18 | 19 | EndIf; 20 | 21 | Wait(5); 22 | 23 | EndProcedure 24 | 25 | // @unit-test:integration 26 | Procedure ExpectationFail(Context) Export 27 | 28 | // given 29 | Mock = DataProcessors.MockServerClient.Create(); 30 | // when 31 | Mock.Server("localhost", "1080", true).When("{}").Respond(); 32 | // then 33 | Assert.IsFalse(Mock.IsOk()); 34 | 35 | EndProcedure 36 | 37 | // @unit-test:integration 38 | Procedure RequestAndResponseJSONFormat(Context) Export 39 | 40 | // given 41 | Mock = DataProcessors.MockServerClient.Create(); 42 | // when 43 | Mock.Server("localhost", "1080", true) 44 | .When( 45 | Mock.Request("""path"": ""/some/path""") 46 | ).Respond( 47 | Mock.Response("""body"": ""some_response_body""") 48 | ); 49 | // then 50 | Assert.IsTrue(Mock.IsOk()); 51 | 52 | EndProcedure 53 | 54 | #Region ClearingAndResetting 55 | 56 | // @unit-test:integration 57 | Procedure Resetting(Context) Export 58 | 59 | // given 60 | Mock = DataProcessors.MockServerClient.Create(); 61 | // when 62 | Mock.Server("localhost", "1080").Reset(); 63 | // then 64 | Assert.IsTrue(Mock.IsOk()); 65 | 66 | EndProcedure 67 | 68 | #EndRegion 69 | 70 | #Region RequestPropertiesMatcher 71 | 72 | // match request by path 73 | // 74 | // @unit-test:integration 75 | Procedure MatchRequestByPath(Context) Export 76 | 77 | // given 78 | Mock = DataProcessors.MockServerClient.Create(); 79 | // when 80 | Mock.Server("localhost", "1080", true) 81 | .When( 82 | Mock.Request() 83 | .WithPath("/some/path") 84 | ).Respond( 85 | Mock.Response() 86 | .WithBody("some_response_body") 87 | ); 88 | // then 89 | Assert.IsTrue(Mock.IsOk()); 90 | 91 | EndProcedure 92 | 93 | // match request by method regex 94 | // 95 | // @unit-test:integration 96 | Procedure MatchRequestByMethodRegex(Context) Export 97 | 98 | // given 99 | Mock = DataProcessors.MockServerClient.Create(); 100 | // when 101 | Mock.Server("localhost", "1080", true) 102 | .When( 103 | Mock.Request() 104 | .WithMethod("P.*{2,3}") 105 | ).Respond( 106 | Mock.Response() 107 | .WithBody("some_response_body") 108 | ); 109 | // then 110 | Assert.IsTrue(Mock.IsOk()); 111 | 112 | EndProcedure 113 | 114 | // match request by not matching method 115 | // 116 | // @unit-test:integration 117 | Procedure MatchRequestByNotMatchingMethod(Context) Export 118 | 119 | // given 120 | Mock = DataProcessors.MockServerClient.Create(); 121 | // when 122 | Mock.Server("localhost", "1080", true) 123 | .When( 124 | Mock.Request() 125 | .WithMethod("!GET") 126 | ).Respond( 127 | Mock.Response() 128 | .WithBody("some_response_body") 129 | ); 130 | // then 131 | Assert.IsTrue(Mock.IsOk()); 132 | 133 | EndProcedure 134 | 135 | // match request by query parameter with regex value 136 | // 137 | // @unit-test:integration 138 | Procedure MatchRequestByQueryParameterWithRegexValue(Context) Export 139 | 140 | // given 141 | Mock = DataProcessors.MockServerClient.Create(); 142 | // when 143 | Mock.Server("localhost", "1080", true) 144 | .When( 145 | Mock.Request() 146 | .WithPath("/some/path") 147 | .WithQueryStringParameter("cartId", "[A-Z0-9\\-]+") 148 | .WithQueryStringParameter("anotherId", "[A-Z0-9\\-]+") 149 | ).Respond( 150 | Mock.Response() 151 | .WithBody("some_response_body") 152 | ); 153 | // then 154 | Assert.IsTrue(Mock.IsOk()); 155 | 156 | EndProcedure 157 | 158 | // match request by headers 159 | // 160 | // @unit-test:integration 161 | Procedure MatchRequestByHeaders(Context) Export 162 | 163 | // given 164 | Mock = DataProcessors.MockServerClient.Create(); 165 | // when 166 | Mock.Server("localhost", "1080", true) 167 | .When( 168 | Mock.Request() 169 | .WithMethod("GET") 170 | .WithPath("/some/path") 171 | .Headers() 172 | .WithHeader("Accept", "application/json") 173 | .WithHeader("Accept-Encoding", "gzip, deflate, br") 174 | ).Respond( 175 | Mock.Response() 176 | .WithBody("some_response_body") 177 | ); 178 | // then 179 | Assert.IsTrue(Mock.IsOk()); 180 | 181 | EndProcedure 182 | 183 | #EndRegion 184 | 185 | #Region ResponseAction 186 | 187 | // literal response with body only 188 | // 189 | // @unit-test:integration 190 | Procedure LiteralResponseWithBodyOnly(Context) Export 191 | 192 | // given 193 | Mock = DataProcessors.MockServerClient.Create(); 194 | // when 195 | Mock.Server("localhost", "1080", true) 196 | .Respond( 197 | Mock.Response() 198 | .WithBody("some_response_body") 199 | ); 200 | // then 201 | Assert.IsTrue(Mock.IsOk()); 202 | 203 | EndProcedure 204 | 205 | // literal response with status code and reason phrase 206 | // 207 | // @unit-test:integration 208 | Procedure LiteralResponseWithStatusCodeAndReasonPhrase(Context) Export 209 | 210 | // given 211 | Mock = DataProcessors.MockServerClient.Create(); 212 | // when 213 | Mock.Server("localhost", "1080", true) 214 | .When( 215 | Mock.Request() 216 | .WithPath("/some/path") 217 | .WithMethod("POST") 218 | ).Respond( 219 | Mock.Response() 220 | .WithStatusCode(418) 221 | .WithReasonPhrase("I'm a teapot") 222 | ); 223 | // then 224 | Assert.IsTrue(Mock.IsOk()); 225 | 226 | EndProcedure 227 | 228 | #EndRegion 229 | 230 | #Region OpenAPI 231 | 232 | // @unit-test:integration 233 | Procedure OpenAPIExpectationOnlySource(Context) Export 234 | 235 | // given 236 | Mock = DataProcessors.MockServerClient.Create(); 237 | Mock.Server("localhost", "1080", true); 238 | // when 239 | Mock.OpenAPIExpectation( "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json" ); 240 | // then 241 | Assert.IsTrue(Mock.IsOk()); 242 | Assert.IsTrue(Mock.Успешно()); 243 | 244 | EndProcedure 245 | 246 | // @unit-test:integration 247 | Procedure OpenAPIExpectationSourceAndOperations(Context) Export 248 | 249 | // given 250 | Mock = DataProcessors.MockServerClient.Create(); 251 | Mock.Server("localhost", "1080", true); 252 | // when 253 | Mock.OpenAPIExpectation( "https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json", 254 | """listPets"": ""200""" ); 255 | // then 256 | Assert.IsTrue(Mock.IsOk()); 257 | Assert.IsTrue(Mock.Успешно()); 258 | 259 | EndProcedure 260 | 261 | #EndRegion 262 | 263 | #Region VerifyingRepeatingRequests 264 | 265 | // verify requests received at least twice 266 | // 267 | // @unit-test:integration 268 | Procedure VerifyRequestsReceivedAtLeastTwice(Context) Export 269 | 270 | // given 271 | Mock = DataProcessors.MockServerClient.Create(); 272 | Mock.Server("localhost", "1080", true); 273 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 274 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 275 | // when 276 | Mock.When( 277 | Mock.Request() 278 | .WithPath("/some/path") 279 | ).Verify( 280 | Mock.Times() 281 | .AtLeast(2) 282 | ); 283 | // then 284 | Assert.IsTrue(Mock.IsOk()); 285 | Assert.IsTrue(Mock.Успешно()); 286 | 287 | EndProcedure 288 | 289 | // @unit-test:integration 290 | Procedure VerifyRequestsReceivedAtLeastTwiceFail(Context) Export 291 | 292 | // given 293 | Mock = DataProcessors.MockServerClient.Create(); 294 | Mock.Server("localhost", "1080", true); 295 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 296 | // when 297 | Mock.When( 298 | Mock.Request() 299 | .WithPath("/some/path") 300 | ).Verify( 301 | Mock.Times() 302 | .AtLeast(2) 303 | ); 304 | // then 305 | Assert.IsFalse(Mock.IsOk()); 306 | Assert.IsFalse(Mock.Успешно()); 307 | 308 | EndProcedure 309 | 310 | // verify requests received at most twice 311 | // 312 | // @unit-test:integration 313 | Procedure VerifyRequestsReceivedAtMostTwice(Context) Export 314 | 315 | // given 316 | Mock = DataProcessors.MockServerClient.Create(); 317 | Mock.Server("localhost", "1080", true); 318 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 319 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 320 | HTTPConnector.Get( "http://localhost:1080/some/another" ); 321 | // when 322 | Mock.When( 323 | Mock.Request() 324 | .WithPath("/some/path") 325 | ).Verify( 326 | Mock.Times() 327 | .AtMost(2) 328 | ); 329 | // then 330 | Assert.IsTrue(Mock.IsOk()); 331 | Assert.IsTrue(Mock.Успешно()); 332 | 333 | EndProcedure 334 | 335 | // @unit-test:integration 336 | Procedure VerifyRequestsReceivedAtMostTwiceFail(Context) Export 337 | 338 | // given 339 | Mock = DataProcessors.MockServerClient.Create(); 340 | Mock.Server("localhost", "1080", true); 341 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 342 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 343 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 344 | // when 345 | Mock.When( 346 | Mock.Request() 347 | .WithPath("/some/path") 348 | ).Verify( 349 | Mock.Times() 350 | .AtMost(2) 351 | ); 352 | // then 353 | Assert.IsFalse(Mock.IsOk()); 354 | Assert.IsFalse(Mock.Успешно()); 355 | 356 | EndProcedure 357 | 358 | // verify requests received exactly twice 359 | // 360 | // @unit-test:integration 361 | Procedure VerifyRequestsReceivedExactlyTwice(Context) Export 362 | 363 | // given 364 | Mock = DataProcessors.MockServerClient.Create(); 365 | Mock.Server("localhost", "1080", true); 366 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 367 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 368 | HTTPConnector.Get( "http://localhost:1080/some/another" ); 369 | // when 370 | Mock.When( 371 | Mock.Request() 372 | .WithPath("/some/path") 373 | ).Verify( 374 | Mock.Times() 375 | .Exactly(2) 376 | ); 377 | // then 378 | Assert.IsTrue(Mock.IsOk()); 379 | Assert.IsTrue(Mock.Успешно()); 380 | 381 | EndProcedure 382 | 383 | // @unit-test:integration 384 | Procedure VerifyRequestsReceivedExactlyTwiceFail(Context) Export 385 | 386 | // given 387 | Mock = DataProcessors.MockServerClient.Create(); 388 | Mock.Server("localhost", "1080", true); 389 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 390 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 391 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 392 | // when 393 | Mock.When( 394 | Mock.Request() 395 | .WithPath("/some/path") 396 | ).Verify( 397 | Mock.Times() 398 | .Exactly(2) 399 | ); 400 | // then 401 | Assert.IsFalse(Mock.IsOk()); 402 | Assert.IsFalse(Mock.Успешно()); 403 | 404 | EndProcedure 405 | 406 | // verify requests received at least twice by openapi 407 | // 408 | // @unit-test:integration 409 | Procedure VerifyRequestsReceivedAtLeastTwiceByOpenAPI(Context) Export 410 | 411 | // given 412 | Mock = DataProcessors.MockServerClient.Create(); 413 | Mock.Server("localhost", "1080", true); 414 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 415 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 416 | HTTPConnector.Get( "http://localhost:1080/some/another" ); 417 | // when 418 | Mock.When( 419 | Mock.OpenAPI() 420 | .WithSource("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 421 | ).Verify( 422 | Mock.Times() 423 | .AtLeast(2) 424 | ); 425 | // then 426 | Assert.IsTrue(Mock.IsOk()); 427 | Assert.IsTrue(Mock.Успешно()); 428 | 429 | EndProcedure 430 | 431 | // @unit-test:integration 432 | Procedure VerifyRequestsReceivedAtLeastTwiceByOpenAPIFailed(Context) Export 433 | 434 | // given 435 | Mock = DataProcessors.MockServerClient.Create(); 436 | Mock.Server("localhost", "1080", true); 437 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 438 | // when 439 | Mock.When( 440 | Mock.OpenAPI() 441 | .WithSource("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 442 | ).Verify( 443 | Mock.Times() 444 | .AtLeast(2) 445 | ); 446 | // then 447 | Assert.IsFalse(Mock.IsOk()); 448 | Assert.IsFalse(Mock.Успешно()); 449 | 450 | EndProcedure 451 | 452 | // verify requests received at exactly once by openapi and operation 453 | // 454 | // @unit-test:integration 455 | Procedure VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperation(Context) Export 456 | 457 | // given 458 | Mock = DataProcessors.MockServerClient.Create(); 459 | Mock.Server("localhost", "1080", true); 460 | HTTPConnector.Get( "http://localhost:1080/pets" ); 461 | // when 462 | Mock.When( 463 | Mock.OpenAPI() 464 | .WithSource("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 465 | .WithOperationId("listPets") 466 | ).Verify( 467 | Mock.Times() 468 | .Once() 469 | ); 470 | // then 471 | Assert.IsTrue(Mock.IsOk()); 472 | Assert.IsTrue(Mock.Успешно()); 473 | 474 | EndProcedure 475 | 476 | // @unit-test:integration 477 | Procedure VerifyRequestsReceivedAtExactlyOnceByOpenAPIAndOperationFail(Context) Export 478 | 479 | // given 480 | Mock = DataProcessors.MockServerClient.Create(); 481 | Mock.Server("localhost", "1080", true); 482 | HTTPConnector.Get( "http://localhost:1080/pets" ); 483 | HTTPConnector.Get( "http://localhost:1080/pets" ); 484 | // when 485 | Mock.When( 486 | Mock.OpenAPI() 487 | .WithSource("https://raw.githubusercontent.com/mock-server/mockserver/master/mockserver-integration-testing/src/main/resources/org/mockserver/mock/openapi_petstore_example.json") 488 | .WithOperationId("listPets") 489 | ).Verify( 490 | Mock.Times() 491 | .Once() 492 | ); 493 | // then 494 | Assert.IsFalse(Mock.IsOk()); 495 | Assert.IsFalse(Mock.Успешно()); 496 | 497 | EndProcedure 498 | 499 | // verify requests received at exactly once 500 | // 501 | // @unit-test:integration 502 | Procedure VerifyRequestsReceivedOnce(Context) Export 503 | 504 | // given 505 | Mock = DataProcessors.MockServerClient.Create(); 506 | Mock.Server("localhost", "1080", true); 507 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 508 | HTTPConnector.Get( "http://localhost:1080/some/another" ); 509 | // when 510 | Mock.When( 511 | Mock.Request() 512 | .WithPath("/some/path") 513 | ).Verify( 514 | Mock.Times() 515 | .Once() 516 | ); 517 | // then 518 | Assert.IsTrue(Mock.IsOk()); 519 | Assert.IsTrue(Mock.Успешно()); 520 | 521 | EndProcedure 522 | 523 | // @unit-test:integration 524 | Procedure VerifyRequestsReceivedOnceFail(Context) Export 525 | 526 | // given 527 | Mock = DataProcessors.MockServerClient.Create(); 528 | Mock.Server("localhost", "1080", true); 529 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 530 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 531 | // when 532 | Mock.When( 533 | Mock.Request() 534 | .WithPath("/some/path") 535 | ).Verify( 536 | Mock.Times() 537 | .Once() 538 | ); 539 | // then 540 | Assert.IsFalse(Mock.IsOk()); 541 | Assert.IsFalse(Mock.Успешно()); 542 | 543 | EndProcedure 544 | 545 | // verify requests received between n and m times 546 | // 547 | // @unit-test:integration 548 | Procedure VerifyRequestsReceivedBetween(Context) Export 549 | 550 | // given 551 | Mock = DataProcessors.MockServerClient.Create(); 552 | Mock.Server("localhost", "1080", true); 553 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 554 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 555 | // when 556 | Mock.When( 557 | Mock.Request() 558 | .WithPath("/some/path") 559 | ).Verify( 560 | Mock.Times() 561 | .Between(2, 3) 562 | ); 563 | // then 564 | Assert.IsTrue(Mock.IsOk()); 565 | Assert.IsTrue(Mock.Успешно()); 566 | 567 | EndProcedure 568 | 569 | // @unit-test:integration 570 | Procedure VerifyRequestsReceivedBetweenLessFail(Context) Export 571 | 572 | // given 573 | Mock = DataProcessors.MockServerClient.Create(); 574 | Mock.Server("localhost", "1080", true); 575 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 576 | // when 577 | Mock.When( 578 | Mock.Request() 579 | .WithPath("/some/path") 580 | ).Verify( 581 | Mock.Times() 582 | .Between(2, 3) 583 | ); 584 | // then 585 | Assert.IsFalse(Mock.IsOk()); 586 | Assert.IsFalse(Mock.Успешно()); 587 | 588 | EndProcedure 589 | 590 | // @unit-test:integration 591 | Procedure VerifyRequestsReceivedBetweenMoreFail(Context) Export 592 | 593 | // given 594 | Mock = DataProcessors.MockServerClient.Create(); 595 | Mock.Server("localhost", "1080", true); 596 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 597 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 598 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 599 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 600 | // when 601 | Mock.When( 602 | Mock.Request() 603 | .WithPath("/some/path") 604 | ).Verify( 605 | Mock.Times() 606 | .Between(2, 3) 607 | ); 608 | // then 609 | Assert.IsFalse(Mock.IsOk()); 610 | Assert.IsFalse(Mock.Успешно()); 611 | 612 | EndProcedure 613 | 614 | // verify requests never received 615 | // 616 | // @unit-test:integration 617 | Procedure VerifyRequestsNeverReceived(Context) Export 618 | 619 | // given 620 | Mock = DataProcessors.MockServerClient.Create(); 621 | Mock.Server("localhost", "1080", true); 622 | // when 623 | Mock.When( 624 | Mock.Request() 625 | .WithPath("/some/path") 626 | ).Verify( 627 | Mock.Times() 628 | .Exactly(0) 629 | ); 630 | // then 631 | Assert.IsTrue(Mock.IsOk()); 632 | Assert.IsTrue(Mock.Успешно()); 633 | 634 | EndProcedure 635 | 636 | // @unit-test:integration 637 | Procedure VerifyRequestsNeverReceivedFail(Context) Export 638 | 639 | // given 640 | Mock = DataProcessors.MockServerClient.Create(); 641 | Mock.Server("localhost", "1080", true); 642 | HTTPConnector.Get( "http://localhost:1080/some/path" ); 643 | // when 644 | Mock.When( 645 | Mock.Request() 646 | .WithPath("/some/path") 647 | ).Verify( 648 | Mock.Times() 649 | .Exactly(0) 650 | ); 651 | // then 652 | Assert.IsFalse(Mock.IsOk()); 653 | Assert.IsFalse(Mock.Успешно()); 654 | 655 | EndProcedure 656 | 657 | #EndRegion 658 | 659 | #EndRegion 660 | 661 | #Region Private 662 | 663 | Procedure Wait( Val Wait) Export 664 | 665 | End = CurrentDate() + Wait; 666 | 667 | While (True) Do 668 | 669 | If CurrentDate() >= End Then 670 | Return; 671 | EndIf; 672 | 673 | EndDo; 674 | 675 | EndProcedure 676 | 677 | #EndRegion 678 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Integration/Tests_Integration.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Integration 4 | 5 | en 6 | Integration 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_OpenAPI/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure OpenAPIUndefinedConstructor(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Result = Mock.OpenAPI(); 10 | // then 11 | Assert.AreEqual(Mock.CurrentStage, "httpRequest"); 12 | Assert.IsTrue(IsBlankString(Result.JSON)); 13 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 14 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 15 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 16 | Assert.IsInstanceOfType("Map", Result.Constructor); 17 | Assert.AreEqual(Result.Constructor.Count(), 1); 18 | Assert.IsInstanceOfType("Map", Result.Constructor["httpRequest"]); 19 | Assert.AreCollectionEmpty(Result.Constructor["httpRequest"]); 20 | 21 | EndProcedure 22 | 23 | // @unit-test 24 | Procedure OpenAPIStringJSON(Context) Export 25 | 26 | // given 27 | Mock = DataProcessors.MockServerClient.Create(); 28 | // when 29 | Result = Mock.OpenAPI("""specUrlOrPayload"": ""http://..."", ""operationId"": ""operation_id"""); 30 | // then 31 | Assert.AreEqual(Mock.CurrentStage, "httpRequest"); 32 | Assert.IsTrue(IsBlankString(Result.JSON)); 33 | Assert.IsFalse(IsBlankString(Result.HttpRequestNode)); 34 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 35 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 36 | Assert.IsUndefined(Result.Constructor); 37 | 38 | Assert.AreEqual(Mock.HttpRequestNode, """specUrlOrPayload"": ""http://..."", ""operationId"": ""operation_id"""); 39 | 40 | EndProcedure 41 | 42 | // @unit-test 43 | Procedure OpenAPIWhenOpenAPIMap(Context) Export 44 | 45 | // given 46 | Mock = DataProcessors.MockServerClient.Create(); 47 | Mock.Server("this.is.error.url", "1080"); 48 | // when 49 | Mock.When( Mock.OpenAPI().WithSource("http://...").WithOperationId("operation_id") ).Verify(); 50 | // then 51 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 52 | Assert.AreEqual(Mock.CurrentStage, ""); 53 | Assert.IsNotUndefined(Mock.Constructor); 54 | Assert.AreEqual(Mock.JSON, "{ 55 | | ""httpRequest"": { 56 | | ""specUrlOrPayload"": ""http://..."", 57 | | ""operationId"": ""operation_id"" 58 | | } 59 | |}"); 60 | 61 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 62 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 63 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 64 | 65 | EndProcedure 66 | 67 | // @unit-test 68 | Procedure OpenAPIExpectationOnlySource(Context) Export 69 | 70 | // given 71 | Mock = DataProcessors.MockServerClient.Create(); 72 | Mock.Server("this.is.error.url", "1080"); 73 | // when 74 | Mock.OpenAPIExpectation( "http://..." ); 75 | // then 76 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 77 | Assert.AreEqual(Mock.CurrentStage, ""); 78 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 79 | 80 | Assert.AreEqual(Mock.JSON, "{ 81 | | ""specUrlOrPayload"": ""http://..."" 82 | |}"); 83 | 84 | EndProcedure 85 | 86 | // @unit-test 87 | Procedure OpenAPIExpectationSourceAndOperations(Context) Export 88 | 89 | // given 90 | Mock = DataProcessors.MockServerClient.Create(); 91 | Mock.Server("this.is.error.url", "1080"); 92 | // when 93 | Mock.OpenAPIExpectation( "http://...", """operation"": ""200""" ); 94 | // then 95 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 96 | Assert.AreEqual(Mock.CurrentStage, ""); 97 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 98 | 99 | Assert.IsUndefined(Mock.Constructor); 100 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 101 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 102 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 103 | Assert.AreEqual(Mock.JSON, "{ 104 | | ""specUrlOrPayload"": ""http://..."", 105 | | ""operationsAndResponses"": { 106 | | ""operation"": ""200"" 107 | | } 108 | |}"); 109 | 110 | EndProcedure 111 | 112 | #EndRegion 113 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_OpenAPI/Tests_OpenAPI.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_OpenAPI 4 | 5 | en 6 | Open API 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Request/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure RequestUndefinedConstructor(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Result = Mock.Request(); 10 | // then 11 | Assert.AreEqual(Mock.CurrentStage, "httpRequest"); 12 | Assert.IsTrue(IsBlankString(Result.JSON)); 13 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 14 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 15 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 16 | Assert.IsInstanceOfType("Map", Result.Constructor); 17 | Assert.AreEqual(Result.Constructor.Count(), 1); 18 | Assert.IsInstanceOfType("Map", Result.Constructor["httpRequest"]); 19 | Assert.AreCollectionEmpty(Result.Constructor["httpRequest"]); 20 | 21 | EndProcedure 22 | 23 | // @unit-test 24 | Procedure RequestReInitWrongConstructor(Context) Export 25 | 26 | // given 27 | Mock = DataProcessors.MockServerClient.Create(); 28 | Mock.Constructor = New Array(); 29 | // when 30 | Result = Mock.Request(); 31 | // then 32 | Assert.AreEqual(Mock.CurrentStage, "httpRequest"); 33 | Assert.IsTrue(IsBlankString(Result.JSON)); 34 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 35 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 36 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 37 | Assert.IsInstanceOfType("Map", Result.Constructor); 38 | Assert.AreEqual(Result.Constructor.Count(), 1); 39 | Assert.IsInstanceOfType("Map", Result.Constructor["httpRequest"]); 40 | Assert.AreCollectionEmpty(Result.Constructor["httpRequest"]); 41 | 42 | EndProcedure 43 | 44 | // @unit-test 45 | Procedure RequestStringJSON(Context) Export 46 | 47 | // given 48 | Mock = DataProcessors.MockServerClient.Create(); 49 | // when 50 | Result = Mock.Request("""method"": ""GET"""); 51 | // then 52 | Assert.AreEqual(Mock.CurrentStage, "httpRequest"); 53 | Assert.IsTrue(IsBlankString(Result.JSON)); 54 | Assert.IsFalse(IsBlankString(Result.HttpRequestNode)); 55 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 56 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 57 | Assert.IsUndefined(Result.Constructor); 58 | 59 | EndProcedure 60 | 61 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Request/Tests_Request.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Request 4 | 5 | en 6 | Request 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_RequestMatchers/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure PropertyByStage(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | Mock.Server("this.is.error.url", "1080"); 9 | // when 10 | Mock.When(Mock.Request().Метод("GET")).Respond(Mock.Response().Метод("POST")); 11 | // then 12 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 13 | Assert.AreEqual(Mock.CurrentStage, ""); 14 | Assert.AreEqual(Mock.Constructor["httpRequest"]["method"], "GET"); 15 | Assert.AreEqual(Mock.Constructor["httpResponse"]["method"], "POST"); 16 | Assert.AreEqual(Mock.JSON, "{ 17 | | ""httpRequest"": { 18 | | ""method"": ""GET"" 19 | | }, 20 | | ""httpResponse"": { 21 | | ""method"": ""POST"" 22 | | } 23 | |}"); 24 | 25 | EndProcedure 26 | 27 | // @unit-test 28 | Procedure HeadersWithoutParams(Context) Export 29 | 30 | // given 31 | Mock = DataProcessors.MockServerClient.Create(); 32 | Mock.Server("this.is.error.url", "1080"); 33 | // when 34 | Mock.When(Mock.Request().Headers()).Respond(); 35 | // then 36 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 37 | Assert.AreEqual(Mock.CurrentStage, ""); 38 | Assert.AreEqual(Mock.Constructor["httpRequest"].Count(), 1); 39 | Assert.IsInstanceOfType("Map", Mock.Constructor["httpRequest"]["headers"]); 40 | Assert.AreEqual(Mock.JSON, "{ 41 | | ""httpRequest"": { 42 | | ""headers"": {} 43 | | } 44 | |}"); 45 | 46 | EndProcedure 47 | 48 | // @unit-test 49 | Procedure HeadersWithParams(Context) Export 50 | 51 | // given 52 | Mock = DataProcessors.MockServerClient.Create(); 53 | Mock.Server("this.is.error.url", "1080"); 54 | 55 | Value1 = New Array(); 56 | Value1.Add("array1_1"); 57 | Value1.Add("array1_2"); 58 | Value2 = New Array(); 59 | Value2.Add("array2_1"); 60 | Value2.Add("array2_2"); 61 | Headers = New Map(); 62 | Headers.Insert("header1", Value1); 63 | Headers.Insert("header2", Value2); 64 | // when 65 | Mock.When(Mock.Request().Headers(Headers)).Respond(); 66 | // then 67 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 68 | Assert.AreEqual(Mock.CurrentStage, ""); 69 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"].Count(), 2); 70 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"]["header1"].Count(), 2); 71 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"]["header1"][0], "array1_1"); 72 | Assert.AreEqual(Mock.JSON, "{ 73 | | ""httpRequest"": { 74 | | ""headers"": { 75 | | ""header1"": [ 76 | | ""array1_1"", 77 | | ""array1_2"" 78 | | ], 79 | | ""header2"": [ 80 | | ""array2_1"", 81 | | ""array2_2"" 82 | | ] 83 | | } 84 | | } 85 | |}" ); 86 | 87 | EndProcedure 88 | 89 | // @unit-test 90 | Procedure HeadersByStage(Context) Export 91 | 92 | // given 93 | Mock = DataProcessors.MockServerClient.Create(); 94 | Mock.Server("this.is.error.url", "1080"); 95 | // when 96 | Mock.When(Mock.Request().Headers()).Respond(Mock.Response().Headers()); 97 | // then 98 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 99 | Assert.AreEqual(Mock.CurrentStage, ""); 100 | Assert.IsInstanceOfType("Map", Mock.Constructor["httpRequest"]["headers"]); 101 | Assert.IsInstanceOfType("Map", Mock.Constructor["httpResponse"]["headers"]); 102 | Assert.AreEqual(Mock.JSON, "{ 103 | | ""httpRequest"": { 104 | | ""headers"": {} 105 | | }, 106 | | ""httpResponse"": { 107 | | ""headers"": {} 108 | | } 109 | |}"); 110 | 111 | EndProcedure 112 | 113 | // @unit-test 114 | Procedure WithHeader(Context) Export 115 | 116 | // given 117 | Mock = DataProcessors.MockServerClient.Create(); 118 | Mock.Server("this.is.error.url", "1080"); 119 | // when 120 | Mock.When(Mock.Request().Headers().WithHeader("key", "value")).Respond(); 121 | // then 122 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 123 | Assert.AreEqual(Mock.CurrentStage, ""); 124 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"]["key"][0], "value"); 125 | Assert.AreEqual(Mock.JSON, "{ 126 | | ""httpRequest"": { 127 | | ""headers"": { 128 | | ""key"": [ 129 | | ""value"" 130 | | ] 131 | | } 132 | | } 133 | |}" ); 134 | 135 | EndProcedure 136 | 137 | // @unit-test 138 | Procedure WithHeaderArrayValue(Context) Export 139 | 140 | // given 141 | Mock = DataProcessors.MockServerClient.Create(); 142 | Mock.Server("this.is.error.url", "1080"); 143 | Array = New Array(); 144 | Array.Add("value1"); 145 | Array.Add("value2"); 146 | // when 147 | Mock.When(Mock.Request().Headers().WithHeader("key", Array)).Respond(); 148 | // then 149 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 150 | Assert.AreEqual(Mock.CurrentStage, ""); 151 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"]["key"][0], "value1"); 152 | Assert.AreEqual(Mock.JSON, "{ 153 | | ""httpRequest"": { 154 | | ""headers"": { 155 | | ""key"": [ 156 | | ""value1"", 157 | | ""value2"" 158 | | ] 159 | | } 160 | | } 161 | |}" ); 162 | 163 | EndProcedure 164 | 165 | // @unit-test 166 | Procedure WithHeaderWithoutHeaders(Context) Export 167 | 168 | // given 169 | Mock = DataProcessors.MockServerClient.Create(); 170 | Mock.Server("this.is.error.url", "1080"); 171 | // when 172 | Mock.When(Mock.Request().WithHeader("key", "value")).Respond(); 173 | // then 174 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 175 | Assert.AreEqual(Mock.CurrentStage, ""); 176 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"]["key"][0], "value"); 177 | Assert.AreEqual(Mock.JSON, "{ 178 | | ""httpRequest"": { 179 | | ""headers"": { 180 | | ""key"": [ 181 | | ""value"" 182 | | ] 183 | | } 184 | | } 185 | |}" ); 186 | 187 | EndProcedure 188 | 189 | // @unit-test 190 | Procedure WithHeaderTwoHeader(Context) Export 191 | 192 | // given 193 | Mock = DataProcessors.MockServerClient.Create(); 194 | Mock.Server("this.is.error.url", "1080"); 195 | // when 196 | Mock.When(Mock.Request().Headers().WithHeader("key1", "value1").WithHeader("key2", "value2")).Respond(); 197 | // then 198 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 199 | Assert.AreEqual(Mock.CurrentStage, ""); 200 | Assert.AreEqual(Mock.Constructor["httpRequest"]["headers"]["key1"][0], "value1"); 201 | Assert.AreEqual(Mock.JSON, "{ 202 | | ""httpRequest"": { 203 | | ""headers"": { 204 | | ""key1"": [ 205 | | ""value1"" 206 | | ], 207 | | ""key2"": [ 208 | | ""value2"" 209 | | ] 210 | | } 211 | | } 212 | |}" ); 213 | 214 | EndProcedure 215 | 216 | // @unit-test 217 | Procedure WithMethodNotEmpty(Context) Export 218 | 219 | // given 220 | Mock = DataProcessors.MockServerClient.Create(); 221 | Mock.Server("this.is.error.url", "1080"); 222 | // when 223 | Mock.When(Mock.Request().WithMethod("GET")).Respond(); 224 | // then 225 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 226 | Assert.AreEqual(Mock.CurrentStage, ""); 227 | Assert.AreEqual(Mock.Constructor["httpRequest"]["method"], "GET"); 228 | Assert.AreEqual(Mock.JSON, "{ 229 | | ""httpRequest"": { 230 | | ""method"": ""GET"" 231 | | } 232 | |}"); 233 | 234 | EndProcedure 235 | 236 | // @unit-test:dev 237 | Procedure WithMethodRewrite(Context) Export 238 | 239 | // given 240 | Mock = DataProcessors.MockServerClient.Create(); 241 | Mock.Server("this.is.error.url", "1080"); 242 | // when 243 | Mock.When(Mock.Request().WithMethod("GET")).Respond(); 244 | Mock.When(Mock.Request().WithMethod("POST")).Respond(); 245 | // then 246 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 247 | Assert.AreEqual(Mock.CurrentStage, ""); 248 | Assert.AreEqual(Mock.Constructor["httpRequest"].Count(), 1); 249 | Assert.AreEqual(Mock.Constructor["httpRequest"]["method"], "POST"); 250 | Assert.AreEqual(Mock.JSON, "{ 251 | | ""httpRequest"": { 252 | | ""method"": ""POST"" 253 | | } 254 | |}"); 255 | 256 | EndProcedure 257 | 258 | // @unit-test 259 | Procedure WithPathNotEmpty(Context) Export 260 | 261 | // given 262 | Mock = DataProcessors.MockServerClient.Create(); 263 | Mock.Server("this.is.error.url", "1080"); 264 | // when 265 | Mock.When(Mock.Request().WithPath("/фуу/foo")).Respond(); 266 | // then 267 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 268 | Assert.AreEqual(Mock.CurrentStage, ""); 269 | Assert.AreEqual(Mock.Constructor["httpRequest"]["path"], "/фуу/foo"); 270 | Assert.AreEqual(Mock.JSON, "{ 271 | | ""httpRequest"": { 272 | | ""path"": ""/фуу/foo"" 273 | | } 274 | |}"); 275 | 276 | EndProcedure 277 | 278 | // @unit-test 279 | Procedure WithQueryStringParameterNotEmpty(Context) Export 280 | 281 | // given 282 | Mock = DataProcessors.MockServerClient.Create(); 283 | Mock.Server("this.is.error.url", "1080"); 284 | // when 285 | Mock.When(Mock.Request().WithQueryStringParameter("cartId", "[A-Z0-9\\-]+")).Respond(); 286 | // then 287 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 288 | Assert.AreEqual(Mock.CurrentStage, ""); 289 | Assert.AreEqual(Mock.Constructor["httpRequest"]["queryStringParameters"]["cartId"][0], "[A-Z0-9\\-]+"); 290 | Assert.AreEqual(Mock.JSON, "{ 291 | | ""httpRequest"": { 292 | | ""queryStringParameters"": { 293 | | ""cartId"": [ 294 | | ""[A-Z0-9\\\\-]+"" 295 | | ] 296 | | } 297 | | } 298 | |}"); 299 | 300 | EndProcedure 301 | 302 | // @unit-test 303 | Procedure WithQueryStringParameterTwoParams(Context) Export 304 | 305 | // given 306 | Mock = DataProcessors.MockServerClient.Create(); 307 | Mock.Server("this.is.error.url", "1080"); 308 | // when 309 | Mock.When( 310 | Mock.Request() 311 | .WithQueryStringParameter("cartId", "[A-Z0-9\\-]+") 312 | .WithQueryStringParameter("anotherId", "[A-Z0-9\\-]+") 313 | ).Respond(); 314 | // then 315 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 316 | Assert.AreEqual(Mock.CurrentStage, ""); 317 | Assert.AreEqual(Mock.Constructor["httpRequest"]["queryStringParameters"]["cartId"][0], "[A-Z0-9\\-]+"); 318 | Assert.AreEqual(Mock.JSON, "{ 319 | | ""httpRequest"": { 320 | | ""queryStringParameters"": { 321 | | ""cartId"": [ 322 | | ""[A-Z0-9\\\\-]+"" 323 | | ], 324 | | ""anotherId"": [ 325 | | ""[A-Z0-9\\\\-]+"" 326 | | ] 327 | | } 328 | | } 329 | |}"); 330 | 331 | EndProcedure 332 | 333 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_RequestMatchers/Tests_RequestMatchers.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_RequestMatchers 4 | 5 | en 6 | Request Matchers 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Reset/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure ResetIntermediateException(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Mock.Server("this.is.error.url", "1080", true); 10 | // then 11 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 12 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 13 | 14 | EndProcedure 15 | 16 | // @unit-test 17 | Procedure ResetTerminalException(Context) Export 18 | 19 | // given 20 | Mock = DataProcessors.MockServerClient.Create(); 21 | Mock.Server("this.is.error.url", "1080"); 22 | // when 23 | Mock.Reset(); 24 | // then 25 | Assert.AreEqual(Mock.CurrentStage, ""); 26 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 27 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 28 | 29 | EndProcedure 30 | 31 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Reset/Tests_Reset.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Reset 4 | 5 | en 6 | Reset 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Respond/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure RespondURLException(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | Mock.Server("this.is.error.url", "1080"); 9 | // when 10 | Mock.Respond(); 11 | // then 12 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 13 | Assert.AreEqual(Mock.CurrentStage, ""); 14 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 15 | 16 | EndProcedure 17 | 18 | // @unit-test 19 | Procedure RespondWhenFullJSON(Context) Export 20 | 21 | // given 22 | Mock = DataProcessors.MockServerClient.Create(); 23 | Mock.Server("this.is.error.url", "1080"); 24 | // when 25 | Mock.When("{""name"":""value""}").Respond(); 26 | // then 27 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 28 | Assert.AreEqual(Mock.CurrentStage, ""); 29 | Assert.IsUndefined(Mock.Constructor); 30 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 31 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 32 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 33 | Assert.AreEqual(Mock.JSON, "{""name"":""value""}"); 34 | 35 | EndProcedure 36 | 37 | // @unit-test 38 | Procedure RespondWhenRequestJSON(Context) Export 39 | 40 | // given 41 | Mock = DataProcessors.MockServerClient.Create(); 42 | Mock.Server("this.is.error.url", "1080"); 43 | // when 44 | Mock.When( Mock.Request("""name"":""value""") ).Respond(); 45 | // then 46 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 47 | Assert.AreEqual(Mock.CurrentStage, ""); 48 | Assert.IsUndefined(Mock.Constructor); 49 | Assert.AreEqual(Mock.JSON, "{ 50 | | ""httpRequest"": { 51 | |""name"":""value"" 52 | | } 53 | |}"); 54 | Assert.AreEqual(Mock.HttpRequestNode, """name"":""value"""); 55 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 56 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 57 | 58 | EndProcedure 59 | 60 | // @unit-test 61 | Procedure RespondWhenRequestMap(Context) Export 62 | 63 | // given 64 | Mock = DataProcessors.MockServerClient.Create(); 65 | Mock.Server("this.is.error.url", "1080"); 66 | // when 67 | Mock.When( Mock.Request().WithMethod("GET") ).Respond(); 68 | // then 69 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 70 | Assert.AreEqual(Mock.CurrentStage, ""); 71 | Assert.IsNotUndefined(Mock.Constructor); 72 | Assert.AreEqual(Mock.JSON, "{ 73 | | ""httpRequest"": { 74 | | ""method"": ""GET"" 75 | | } 76 | |}"); 77 | 78 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 79 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 80 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 81 | 82 | EndProcedure 83 | 84 | // @unit-test 85 | Procedure RespondWhenRespondJSON(Context) Export 86 | 87 | // given 88 | Mock = DataProcessors.MockServerClient.Create(); 89 | Mock.Server("this.is.error.url", "1080"); 90 | // when 91 | Mock.Respond("{""name"":""value""}"); 92 | // then 93 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 94 | 95 | Assert.AreEqual(Mock.CurrentStage, ""); 96 | Assert.IsUndefined(Mock.Constructor); 97 | Assert.AreEqual(Mock.JSON, "{ 98 | |}"); 99 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 100 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 101 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 102 | 103 | EndProcedure 104 | 105 | // @unit-test 106 | Procedure RespondWhenResponseJSON(Context) Export 107 | 108 | // given 109 | Mock = DataProcessors.MockServerClient.Create(); 110 | Mock.Server("this.is.error.url", "1080"); 111 | // when 112 | Mock.Respond( Mock.Response("""statusCode"":404") ); 113 | // then 114 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 115 | Assert.AreEqual(Mock.CurrentStage, ""); 116 | Assert.IsUndefined(Mock.Constructor); 117 | Assert.AreEqual(Mock.JSON, "{ 118 | | ""httpResponse"": { 119 | |""statusCode"":404 120 | | } 121 | |}"); 122 | Assert.AreEqual(Mock.HttpResponseNode, """statusCode"":404"); 123 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 124 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 125 | 126 | EndProcedure 127 | 128 | // @unit-test 129 | Procedure RespondWhenResponseMap(Context) Export 130 | 131 | // given 132 | Mock = DataProcessors.MockServerClient.Create(); 133 | Mock.Server("this.is.error.url", "1080"); 134 | // when 135 | Mock.Respond( Mock.Response().WithStatusCode(404) ); 136 | // then 137 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 138 | Assert.AreEqual(Mock.JSON, "{ 139 | | ""httpResponse"": { 140 | | ""statusCode"": 404 141 | | } 142 | |}"); 143 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 144 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 145 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 146 | 147 | EndProcedure 148 | 149 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Respond/Tests_Respond.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Respond 4 | 5 | en 6 | Respond 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Response/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure ResponseUndefinedConstructor(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Result = Mock.Response(); 10 | // then 11 | Assert.AreEqual(Mock.CurrentStage, "httpResponse"); 12 | Assert.IsTrue(IsBlankString(Result.JSON)); 13 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 14 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 15 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 16 | Assert.IsInstanceOfType("Map", Result.Constructor); 17 | Assert.AreEqual(Result.Constructor.Count(), 1); 18 | Assert.IsInstanceOfType("Map", Result.Constructor["httpResponse"]); 19 | Assert.AreCollectionEmpty(Result.Constructor["httpResponse"]); 20 | 21 | EndProcedure 22 | 23 | // @unit-test 24 | Procedure ResponseReInitWrongConstructor(Context) Export 25 | 26 | // given 27 | Mock = DataProcessors.MockServerClient.Create(); 28 | Mock.Constructor = New Array(); 29 | // when 30 | Result = Mock.Response(); 31 | // then 32 | Assert.AreEqual(Mock.CurrentStage, "httpResponse"); 33 | Assert.IsTrue(IsBlankString(Result.JSON)); 34 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 35 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 36 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 37 | Assert.IsInstanceOfType("Map", Result.Constructor); 38 | Assert.AreEqual(Result.Constructor.Count(), 1); 39 | Assert.IsInstanceOfType("Map", Result.Constructor["httpResponse"]); 40 | Assert.AreCollectionEmpty(Result.Constructor["httpResponse"]); 41 | 42 | EndProcedure 43 | 44 | // @unit-test 45 | Procedure ResponseRequestExists(Context) Export 46 | 47 | // given 48 | Mock = DataProcessors.MockServerClient.Create(); 49 | Mock.Constructor = New Map(); 50 | Mock.Constructor.Insert( "httpRequest", New Map() ); 51 | // when 52 | Result = Mock.Response(); 53 | // then 54 | Assert.AreEqual(Mock.CurrentStage, "httpResponse"); 55 | Assert.IsTrue(IsBlankString(Result.JSON)); 56 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 57 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 58 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 59 | Assert.IsInstanceOfType("Map", Result.Constructor); 60 | Assert.AreEqual(Result.Constructor.Count(), 2); 61 | Assert.IsNotUndefined(Result.Constructor["httpRequest"]); 62 | Assert.IsInstanceOfType("Map", Result.Constructor["httpResponse"]); 63 | Assert.AreCollectionEmpty(Result.Constructor["httpResponse"]); 64 | 65 | EndProcedure 66 | 67 | // @unit-test 68 | Procedure ResponseStringJSON(Context) Export 69 | 70 | // given 71 | Mock = DataProcessors.MockServerClient.Create(); 72 | // when 73 | Result = Mock.Response("""statusCode"": 200 "); 74 | // then 75 | Assert.AreEqual(Mock.CurrentStage, "httpResponse"); 76 | Assert.IsTrue(IsBlankString(Result.JSON)); 77 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 78 | Assert.IsFalse(IsBlankString(Result.HttpResponseNode)); 79 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 80 | Assert.IsUndefined(Result.Constructor); 81 | 82 | EndProcedure 83 | 84 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Response/Tests_Response.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Response 4 | 5 | en 6 | Response 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_ResponseAction/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure WithBody(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | Mock.Server("this.is.error.url", "1080"); 9 | // when 10 | Mock.Respond(Mock.Response().WithBody("some body")); 11 | // then 12 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 13 | Assert.AreEqual(Mock.CurrentStage, ""); 14 | Assert.AreEqual(Mock.Constructor["httpResponse"]["body"], "some body"); 15 | Assert.AreEqual(Mock.JSON, "{ 16 | | ""httpResponse"": { 17 | | ""body"": ""some body"" 18 | | } 19 | |}"); 20 | 21 | EndProcedure 22 | 23 | // @unit-test 24 | Procedure WithStatusCode(Context) Export 25 | 26 | // given 27 | Mock = DataProcessors.MockServerClient.Create(); 28 | Mock.Server("this.is.error.url", "1080"); 29 | // when 30 | Mock.Respond(Mock.Response().WithStatusCode(404)); 31 | // then 32 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 33 | Assert.AreEqual(Mock.CurrentStage, ""); 34 | Assert.AreEqual(Mock.Constructor["httpResponse"]["statusCode"], 404); 35 | Assert.AreEqual(Mock.JSON, "{ 36 | | ""httpResponse"": { 37 | | ""statusCode"": 404 38 | | } 39 | |}"); 40 | 41 | EndProcedure 42 | 43 | // @unit-test:dev 44 | Procedure WithStatusCodeRewrite(Context) Export 45 | 46 | // given 47 | Mock = DataProcessors.MockServerClient.Create(); 48 | Mock.Server("this.is.error.url", "1080"); 49 | // when 50 | Mock.Respond(Mock.Response().WithStatusCode(404)); 51 | Mock.Respond(Mock.Response().WithStatusCode(400)); 52 | // then 53 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 54 | Assert.AreEqual(Mock.CurrentStage, ""); 55 | Assert.AreEqual(Mock.Constructor["httpResponse"].Count(), 1); 56 | Assert.AreEqual(Mock.Constructor["httpResponse"]["statusCode"], 400); 57 | Assert.AreEqual(Mock.JSON, "{ 58 | | ""httpResponse"": { 59 | | ""statusCode"": 400 60 | | } 61 | |}"); 62 | 63 | EndProcedure 64 | 65 | // @unit-test 66 | Procedure WithReasonPhrase(Context) Export 67 | 68 | // given 69 | Mock = DataProcessors.MockServerClient.Create(); 70 | Mock.Server("this.is.error.url", "1080"); 71 | // when 72 | Mock.Respond(Mock.Response().WithReasonPhrase("I'm a teapot")); 73 | // then 74 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 75 | Assert.AreEqual(Mock.CurrentStage, ""); 76 | Assert.AreEqual(Mock.Constructor["httpResponse"]["reasonPhrase"], "I'm a teapot"); 77 | Assert.AreEqual(Mock.JSON, "{ 78 | | ""httpResponse"": { 79 | | ""reasonPhrase"": ""I'm a teapot"" 80 | | } 81 | |}"); 82 | 83 | EndProcedure 84 | 85 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_ResponseAction/Tests_ResponseAction.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_ResponseAction 4 | 5 | en 6 | Response Action 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Times/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure TimesUndefinedConstructor(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Result = Mock.Times(); 10 | // then 11 | Assert.AreEqual(Mock.CurrentStage, "times"); 12 | Assert.IsTrue(IsBlankString(Result.JSON)); 13 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 14 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 15 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 16 | Assert.IsInstanceOfType("Map", Result.Constructor); 17 | Assert.AreEqual(Result.Constructor.Count(), 1); 18 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 19 | Assert.AreCollectionEmpty(Result.Constructor["times"]); 20 | 21 | EndProcedure 22 | 23 | // @unit-test 24 | Procedure TimesReInitWrongConstructor(Context) Export 25 | 26 | // given 27 | Mock = DataProcessors.MockServerClient.Create(); 28 | Mock.Constructor = New Array(); 29 | // when 30 | Result = Mock.Times(); 31 | // then 32 | Assert.AreEqual(Mock.CurrentStage, "times"); 33 | Assert.IsTrue(IsBlankString(Result.JSON)); 34 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 35 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 36 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 37 | Assert.IsInstanceOfType("Map", Result.Constructor); 38 | Assert.AreEqual(Result.Constructor.Count(), 1); 39 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 40 | Assert.AreCollectionEmpty(Result.Constructor["times"]); 41 | 42 | EndProcedure 43 | 44 | // @unit-test 45 | Procedure TimesRequestExists(Context) Export 46 | 47 | // given 48 | Mock = DataProcessors.MockServerClient.Create(); 49 | Mock.Constructor = New Map(); 50 | Mock.Constructor.Insert( "httpRequest", New Map() ); 51 | // when 52 | Result = Mock.Times(); 53 | // then 54 | Assert.AreEqual(Mock.CurrentStage, "times"); 55 | Assert.IsTrue(IsBlankString(Result.JSON)); 56 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 57 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 58 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 59 | Assert.IsInstanceOfType("Map", Result.Constructor); 60 | Assert.AreEqual(Result.Constructor.Count(), 2); 61 | Assert.IsNotUndefined(Result.Constructor["httpRequest"]); 62 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 63 | Assert.AreCollectionEmpty(Result.Constructor["times"]); 64 | 65 | EndProcedure 66 | 67 | // @unit-test 68 | Procedure TimesStringJSON(Context) Export 69 | 70 | // given 71 | Mock = DataProcessors.MockServerClient.Create(); 72 | // when 73 | Result = Mock.Times("""atLeast"": 2, ""atMost"": 2"); 74 | // then 75 | Assert.AreEqual(Mock.CurrentStage, "times"); 76 | Assert.IsTrue(IsBlankString(Result.JSON)); 77 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 78 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 79 | Assert.IsFalse(IsBlankString(Result.TimesNode)); 80 | Assert.IsUndefined(Result.Constructor); 81 | 82 | EndProcedure 83 | 84 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Times/Tests_Times.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Times 4 | 5 | en 6 | Times 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_TimesMethods/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure AtLeast(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Result = Mock.Times().AtLeast(2); 10 | // then 11 | Assert.AreEqual(Mock.CurrentStage, "times"); 12 | Assert.IsTrue(IsBlankString(Result.JSON)); 13 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 14 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 15 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 16 | Assert.IsInstanceOfType("Map", Result.Constructor); 17 | Assert.AreEqual(Result.Constructor.Count(), 1); 18 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 19 | Assert.AreEqual(Result.Constructor["times"].Count(), 1); 20 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 2); 21 | 22 | EndProcedure 23 | 24 | // @unit-test 25 | Procedure AtMost(Context) Export 26 | 27 | // given 28 | Mock = DataProcessors.MockServerClient.Create(); 29 | // when 30 | Result = Mock.Times().AtMost(2); 31 | // then 32 | Assert.AreEqual(Mock.CurrentStage, "times"); 33 | Assert.IsTrue(IsBlankString(Result.JSON)); 34 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 35 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 36 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 37 | Assert.IsInstanceOfType("Map", Result.Constructor); 38 | Assert.AreEqual(Result.Constructor.Count(), 1); 39 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 40 | Assert.AreEqual(Result.Constructor["times"].Count(), 1); 41 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 2); 42 | 43 | EndProcedure 44 | 45 | // @unit-test 46 | Procedure Exactly(Context) Export 47 | 48 | // given 49 | Mock = DataProcessors.MockServerClient.Create(); 50 | // when 51 | Result = Mock.Times().Exactly(2); 52 | // then 53 | Assert.AreEqual(Mock.CurrentStage, "times"); 54 | Assert.IsTrue(IsBlankString(Result.JSON)); 55 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 56 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 57 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 58 | Assert.IsInstanceOfType("Map", Result.Constructor); 59 | Assert.AreEqual(Result.Constructor.Count(), 1); 60 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 61 | Assert.AreEqual(Result.Constructor["times"].Count(), 2); 62 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 2); 63 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 2); 64 | 65 | EndProcedure 66 | 67 | // @unit-test 68 | Procedure Once(Context) Export 69 | 70 | // given 71 | Mock = DataProcessors.MockServerClient.Create(); 72 | // when 73 | Result = Mock.Times().Once(); 74 | // then 75 | Assert.AreEqual(Mock.CurrentStage, "times"); 76 | Assert.IsTrue(IsBlankString(Result.JSON)); 77 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 78 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 79 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 80 | Assert.IsInstanceOfType("Map", Result.Constructor); 81 | Assert.AreEqual(Result.Constructor.Count(), 1); 82 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 83 | Assert.AreEqual(Result.Constructor["times"].Count(), 2); 84 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 1); 85 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 1); 86 | 87 | EndProcedure 88 | 89 | // @unit-test 90 | Procedure Between(Context) Export 91 | 92 | // given 93 | Mock = DataProcessors.MockServerClient.Create(); 94 | // when 95 | Result = Mock.Times().Between(2, 3); 96 | // then 97 | Assert.AreEqual(Mock.CurrentStage, "times"); 98 | Assert.IsTrue(IsBlankString(Result.JSON)); 99 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 100 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 101 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 102 | Assert.IsInstanceOfType("Map", Result.Constructor); 103 | Assert.AreEqual(Result.Constructor.Count(), 1); 104 | Assert.IsInstanceOfType("Map", Result.Constructor["times"]); 105 | Assert.AreEqual(Result.Constructor["times"].Count(), 2); 106 | Assert.AreEqual(Mock.Constructor["times"]["atLeast"], 2); 107 | Assert.AreEqual(Mock.Constructor["times"]["atMost"], 3); 108 | 109 | EndProcedure 110 | 111 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_TimesMethods/Tests_TimesMethods.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_TimesMethods 4 | 5 | en 6 | Times methods 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Verify/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure VerifyURLException(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | Mock.Server("this.is.error.url", "1080"); 9 | // when 10 | Mock.Verify(); 11 | // then 12 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 13 | Assert.AreEqual(Mock.CurrentStage, ""); 14 | Assert.IsFalse(IsBlankString(Mock.MockServerResponse.ТекстОшибки)); 15 | 16 | EndProcedure 17 | 18 | // @unit-test 19 | Procedure VerifyWhenFullJSON(Context) Export 20 | 21 | // given 22 | Mock = DataProcessors.MockServerClient.Create(); 23 | Mock.Server("this.is.error.url", "1080"); 24 | // when 25 | Mock.When("{""name"":""value""}").Verify(); 26 | // then 27 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 28 | Assert.AreEqual(Mock.CurrentStage, ""); 29 | Assert.IsUndefined(Mock.Constructor); 30 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 31 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 32 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 33 | Assert.AreEqual(Mock.JSON, "{""name"":""value""}"); 34 | 35 | EndProcedure 36 | 37 | // @unit-test 38 | Procedure VerifyWhenRequestJSON(Context) Export 39 | 40 | // given 41 | Mock = DataProcessors.MockServerClient.Create(); 42 | Mock.Server("this.is.error.url", "1080"); 43 | // when 44 | Mock.When( Mock.Request("""name"":""value""") ).Verify(); 45 | // then 46 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 47 | Assert.AreEqual(Mock.CurrentStage, ""); 48 | Assert.IsUndefined(Mock.Constructor); 49 | Assert.AreEqual(Mock.JSON, "{ 50 | | ""httpRequest"": { 51 | |""name"":""value"" 52 | | } 53 | |}"); 54 | Assert.AreEqual(Mock.HttpRequestNode, """name"":""value"""); 55 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 56 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 57 | 58 | EndProcedure 59 | 60 | // @unit-test 61 | Procedure VerifyWhenRequestMap(Context) Export 62 | 63 | // given 64 | Mock = DataProcessors.MockServerClient.Create(); 65 | Mock.Server("this.is.error.url", "1080"); 66 | // when 67 | Mock.When( Mock.Request().WithMethod("GET") ).Verify(); 68 | // then 69 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 70 | Assert.AreEqual(Mock.CurrentStage, ""); 71 | Assert.IsNotUndefined(Mock.Constructor); 72 | Assert.AreEqual(Mock.JSON, "{ 73 | | ""httpRequest"": { 74 | | ""method"": ""GET"" 75 | | } 76 | |}"); 77 | 78 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 79 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 80 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 81 | 82 | EndProcedure 83 | 84 | // @unit-test 85 | Procedure VerifyWhenVerifyJSON(Context) Export 86 | 87 | // given 88 | Mock = DataProcessors.MockServerClient.Create(); 89 | Mock.Server("this.is.error.url", "1080"); 90 | // when 91 | Mock.Verify("{""name"":""value""}"); 92 | // then 93 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 94 | 95 | Assert.AreEqual(Mock.CurrentStage, ""); 96 | Assert.IsUndefined(Mock.Constructor); 97 | Assert.AreEqual(Mock.JSON, "{ 98 | |}"); 99 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 100 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 101 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 102 | 103 | EndProcedure 104 | 105 | // @unit-test 106 | Procedure VerifyWhenTimesNode(Context) Export 107 | 108 | // given 109 | Mock = DataProcessors.MockServerClient.Create(); 110 | Mock.Server("this.is.error.url", "1080"); 111 | // when 112 | Mock.Verify( Mock.Times("""atMost"": 2") ); 113 | // then 114 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 115 | Assert.AreEqual(Mock.CurrentStage, ""); 116 | Assert.IsUndefined(Mock.Constructor); 117 | Assert.AreEqual(Mock.JSON, "{ 118 | | ""times"": { 119 | |""atMost"": 2 120 | | } 121 | |}"); 122 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 123 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 124 | Assert.AreEqual(Mock.TimesNode, """atMost"": 2"); 125 | 126 | EndProcedure 127 | 128 | // @unit-test 129 | Procedure VerifydWhenTimesMap(Context) Export 130 | 131 | // given 132 | Mock = DataProcessors.MockServerClient.Create(); 133 | Mock.Server("this.is.error.url", "1080"); 134 | // when 135 | Mock.Verify( Mock.Times().AtMost(3) ); 136 | // then 137 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 138 | Assert.AreEqual(Mock.JSON, "{ 139 | | ""times"": { 140 | | ""atMost"": 3 141 | | } 142 | |}"); 143 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 144 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 145 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 146 | 147 | EndProcedure 148 | 149 | // @unit-test 150 | Procedure VerifydWhenRequestAndTimes(Context) Export 151 | 152 | // given 153 | Mock = DataProcessors.MockServerClient.Create(); 154 | Mock.Server("this.is.error.url", "1080"); 155 | // when 156 | Mock.Verify( Mock.Request().WithMethod("GET").Times().AtMost(3) ); 157 | // then 158 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 159 | Assert.AreEqual(Mock.JSON, "{ 160 | | ""httpRequest"": { 161 | | ""method"": ""GET"" 162 | | }, 163 | | ""times"": { 164 | | ""atMost"": 3 165 | | } 166 | |}"); 167 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 168 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 169 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 170 | 171 | EndProcedure 172 | 173 | // @unit-test 174 | Procedure VerifydWhenRequestInWhenAndTimesInVerify(Context) Export 175 | 176 | // given 177 | Mock = DataProcessors.MockServerClient.Create(); 178 | Mock.Server("this.is.error.url", "1080"); 179 | // when 180 | Mock.When( Mock.Request().WithMethod("GET") ).Verify( Mock.Times().AtMost(3) ); 181 | // then 182 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 183 | Assert.AreEqual(Mock.JSON, "{ 184 | | ""httpRequest"": { 185 | | ""method"": ""GET"" 186 | | }, 187 | | ""times"": { 188 | | ""atMost"": 3 189 | | } 190 | |}"); 191 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 192 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 193 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 194 | 195 | EndProcedure 196 | 197 | // @unit-test 198 | Procedure VerifyWhenOpenAPIWithSource(Context) Export 199 | 200 | // given 201 | Mock = DataProcessors.MockServerClient.Create(); 202 | Mock.Server("this.is.error.url", "1080"); 203 | // when 204 | Mock.When( Mock.OpenAPI().WithSource("http...") ).Verify( Mock.Times().AtMost(3) ); 205 | // then 206 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 207 | Assert.AreEqual(Mock.JSON, "{ 208 | | ""httpRequest"": { 209 | | ""specUrlOrPayload"": ""http..."" 210 | | }, 211 | | ""times"": { 212 | | ""atMost"": 3 213 | | } 214 | |}"); 215 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 216 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 217 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 218 | 219 | EndProcedure 220 | 221 | // @unit-test 222 | Procedure VerifyWhenOpenAPIWithOperationId(Context) Export 223 | 224 | // given 225 | Mock = DataProcessors.MockServerClient.Create(); 226 | Mock.Server("this.is.error.url", "1080"); 227 | // when 228 | Mock.When( Mock.OpenAPI().WithOperationId("operation") ).Verify( Mock.Times().AtMost(3) ); 229 | // then 230 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 231 | Assert.AreEqual(Mock.JSON, "{ 232 | | ""httpRequest"": { 233 | | ""operationId"": ""operation"" 234 | | }, 235 | | ""times"": { 236 | | ""atMost"": 3 237 | | } 238 | |}"); 239 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 240 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 241 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 242 | 243 | EndProcedure 244 | 245 | // @unit-test 246 | Procedure VerifyWhenOpenAPI(Context) Export 247 | 248 | // given 249 | Mock = DataProcessors.MockServerClient.Create(); 250 | Mock.Server("this.is.error.url", "1080"); 251 | // when 252 | Mock.When( Mock.OpenAPI().WithSource("http...").WithOperationId("operation") ).Verify( Mock.Times().AtMost(3) ); 253 | // then 254 | Assert.AreEqual(Mock.MockServerResponse.КодСостояния, 500); 255 | Assert.AreEqual(Mock.JSON, "{ 256 | | ""httpRequest"": { 257 | | ""specUrlOrPayload"": ""http..."", 258 | | ""operationId"": ""operation"" 259 | | }, 260 | | ""times"": { 261 | | ""atMost"": 3 262 | | } 263 | |}"); 264 | Assert.IsTrue(IsBlankString(Mock.HttpRequestNode)); 265 | Assert.IsTrue(IsBlankString(Mock.HttpResponseNode)); 266 | Assert.IsTrue(IsBlankString(Mock.TimesNode)); 267 | 268 | EndProcedure 269 | 270 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_Verify/Tests_Verify.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_Verify 4 | 5 | en 6 | Verify 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_When/Module.bsl: -------------------------------------------------------------------------------- 1 | #Region Internal 2 | 3 | // @unit-test 4 | Procedure WhenParamsString(Context) Export 5 | 6 | // given 7 | Mock = DataProcessors.MockServerClient.Create(); 8 | // when 9 | Result = Mock.When("{""sample"": ""any""}"); 10 | // then 11 | Assert.AreEqual(Mock.CurrentStage, ""); 12 | Assert.IsUndefined(Result.Constructor); 13 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 14 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 15 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 16 | Assert.AreEqual(Result.JSON, "{""sample"": ""any""}"); 17 | 18 | EndProcedure 19 | 20 | // @unit-test 21 | Procedure WhenParamsRequestAction(Context) Export 22 | 23 | // given 24 | Mock = DataProcessors.MockServerClient.Create(); 25 | // when 26 | Result = Mock.When( Mock.Request() ); 27 | // then 28 | Assert.AreEqual(Mock.CurrentStage, ""); 29 | Assert.IsTrue(IsBlankString(Result.JSON)); 30 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 31 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 32 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 33 | Assert.IsInstanceOfType("Map", Result.Constructor["httpRequest"]); 34 | Assert.AreCollectionEmpty(Result.Constructor["httpRequest"]); 35 | 36 | EndProcedure 37 | 38 | // @unit-test 39 | Procedure WhenWrongParams(Context) Export 40 | 41 | // given 42 | Mock = DataProcessors.MockServerClient.Create(); 43 | // when 44 | Result = Mock.When( new Array() ); 45 | // then 46 | Assert.AreEqual(Mock.CurrentStage, ""); 47 | Assert.IsTrue(IsBlankString(Result.JSON)); 48 | Assert.IsTrue(IsBlankString(Result.HttpRequestNode)); 49 | Assert.IsTrue(IsBlankString(Result.HttpResponseNode)); 50 | Assert.IsTrue(IsBlankString(Result.TimesNode)); 51 | Assert.IsUndefined(Result.Constructor); 52 | 53 | EndProcedure 54 | 55 | #EndRegion -------------------------------------------------------------------------------- /mockserver-client.Tests/src/CommonModules/Tests_When/Tests_When.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests_When 4 | 5 | en 6 | When 7 | 8 | true 9 | 10 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/Configuration/CommandInterface.cmi: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/Configuration/Configuration.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Tests 4 | 5 | ru 6 | Tests 7 | 8 | Adopted 9 | 10 | Checked 11 | Checked 12 | Extended 13 | Extended 14 | Checked 15 | Checked 16 | Checked 17 | Extended 18 | Extended 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | true 27 | Tests_ 28 | 8.3.16 29 | Customization 30 | ManagedApplication 31 | PersonalComputer 32 | 1.0.0 33 | Language.English 34 | Managed 35 | NotAutoFree 36 | DontUse 37 | DontUse 38 | 8.3.16 39 | 40 | English 41 | 42 | en 43 | English 44 | 45 | Adopted 46 | 47 | Checked 48 | 49 | en 50 | 51 | CommonModule.Assert 52 | CommonModule.Tests_Integration 53 | CommonModule.Tests_Exceptions 54 | CommonModule.Tests_CreateMock 55 | CommonModule.Tests_When 56 | CommonModule.Tests_Request 57 | CommonModule.Tests_RequestMatchers 58 | CommonModule.Tests_Response 59 | CommonModule.Tests_ResponseAction 60 | CommonModule.Tests_Respond 61 | CommonModule.Tests_Verify 62 | CommonModule.Tests_Reset 63 | CommonModule.Tests_Times 64 | CommonModule.Tests_TimesMethods 65 | CommonModule.Tests_OpenAPI 66 | CommonModule.Tests_CallWrapperRu 67 | 68 | -------------------------------------------------------------------------------- /mockserver-client.Tests/src/Configuration/MainSectionCommandInterface.cmi: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /mockserver-client.cfe/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mockserver-client.mockserver-client.cfe 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.xtext.ui.shared.xtextNature 16 | com._1c.g5.v8.dt.core.V8ExtensionNature 17 | 18 | 19 | -------------------------------------------------------------------------------- /mockserver-client.cfe/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /mockserver-client.cfe/DT-INF/PROJECT.PMF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Runtime-Version: 8.3.16 3 | Base-Project: mockserver-client 4 | -------------------------------------------------------------------------------- /mockserver-client.cfe/src/CommonModules/HTTPConnector/HTTPConnector.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | HTTPConnector 4 | 5 | en 6 | HTTPConnector 7 | 8 | 9 | ru 10 | HTTPConnector 11 | 12 | true 13 | true 14 | true 15 | 16 | -------------------------------------------------------------------------------- /mockserver-client.cfe/src/CommonModules/HTTPStatusCodesClientServerCached/HTTPStatusCodesClientServerCached.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | HTTPStatusCodesClientServerCached 4 | 5 | en 6 | HTTP Status Codes (client-server, cached) 7 | 8 | 9 | ru 10 | Коды состояния HTTP (клиент-сервер, кэш) 11 | 12 | true 13 | true 14 | true 15 | true 16 | DuringSession 17 | 18 | -------------------------------------------------------------------------------- /mockserver-client.cfe/src/Configuration/CommandInterface.cmi: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /mockserver-client.cfe/src/Configuration/Configuration.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | MockServerClient 4 | 5 | ru 6 | mockserver-client 7 | 8 | Adopted 9 | 10 | Checked 11 | Checked 12 | Extended 13 | Extended 14 | Checked 15 | Checked 16 | Checked 17 | Extended 18 | Extended 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | true 27 | Mock_ 28 | 8.3.16 29 | Customization 30 | ManagedApplication 31 | PersonalComputer 32 | 1.0.1 33 | Language.English 34 | Managed 35 | NotAutoFree 36 | DontUse 37 | DontUse 38 | 8.3.16 39 | 40 | English 41 | 42 | en 43 | English 44 | 45 | Adopted 46 | 47 | Checked 48 | 49 | en 50 | 51 | 52 | Русский 53 | 54 | ru 55 | Русский 56 | 57 | Adopted 58 | 59 | Checked 60 | 61 | ru 62 | 63 | CommonModule.HTTPConnector 64 | CommonModule.HTTPStatusCodesClientServerCached 65 | DataProcessor.MockServerClient 66 | 67 | -------------------------------------------------------------------------------- /mockserver-client.cfe/src/Configuration/MainSectionCommandInterface.cmi: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /mockserver-client.cfe/src/DataProcessors/MockServerClient/MockServerClient.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | MockServerClient 8 | 9 | en 10 | mockserver-client 11 | 12 | 13 | ru 14 | mockserver-client 15 | 16 | true 17 | 18 | URL 19 | 20 | en 21 | URL 22 | 23 | 24 | ru 25 | URL 26 | 27 | 28 | String 29 | 30 | 31 | 32 | 33 | CurrentStage 34 | 35 | en 36 | Current stage 37 | 38 | 39 | ru 40 | Current stage 41 | 42 | 43 | String 44 | 45 | 46 | 47 | 48 | Constructor 49 | 50 | en 51 | Constructor 52 | 53 | 54 | ru 55 | Constructor 56 | 57 | 58 | Arbitrary 59 | 60 | 61 | 62 | JSON 63 | 64 | en 65 | JSON 66 | 67 | 68 | ru 69 | JSON 70 | 71 | 72 | String 73 | 74 | 75 | 76 | 77 | HttpRequestNode 78 | 79 | en 80 | HttpRequestNode 81 | 82 | 83 | ru 84 | HttpRequestNode 85 | 86 | 87 | Arbitrary 88 | 89 | 90 | 91 | HttpResponseNode 92 | 93 | en 94 | HttpResponseNode 95 | 96 | 97 | ru 98 | HttpResponseNode 99 | 100 | 101 | Arbitrary 102 | 103 | 104 | 105 | TimesNode 106 | 107 | en 108 | TimesNode 109 | 110 | 111 | ru 112 | TimesNode 113 | 114 | 115 | Arbitrary 116 | 117 | 118 | 119 | IsActionOk 120 | 121 | ru 122 | Action status 123 | 124 | 125 | Boolean 126 | 127 | 128 | 129 | MockServerResponse 130 | 131 | en 132 | MockServerResponse 133 | 134 | 135 | ru 136 | MockServerResponse 137 | 138 | 139 | Arbitrary 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /mockserver-client/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mockserver-client 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.xtext.ui.shared.xtextBuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.xtext.ui.shared.xtextNature 16 | com._1c.g5.v8.dt.core.V8ConfigurationNature 17 | 18 | 19 | -------------------------------------------------------------------------------- /mockserver-client/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /mockserver-client/DT-INF/PROJECT.PMF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Runtime-Version: 8.3.16 3 | -------------------------------------------------------------------------------- /mockserver-client/src/Configuration/Configuration.mdo: -------------------------------------------------------------------------------- 1 | 2 | 3 | Конфигурация 4 | 5 | 6 | 7 | 8 | 9 | 10 | 8.3.16 11 | ManagedApplication 12 | PersonalComputer 13 | 1.0.0 14 | 15 | AllowOSBackup 16 | true 17 | 18 | Language.English 19 | Managed 20 | NotAutoFree 21 | DontUse 22 | DontUse 23 | 8.3.16 24 | 25 | Русский 26 | 27 | ru 28 | Русский 29 | 30 | ru 31 | 32 | 33 | English 34 | 35 | ru 36 | English 37 | 38 | en 39 | 40 | 41 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectName=mockserver-client-1c 2 | sonar.projectKey=mockserver-client-1c 3 | 4 | sonar.sourceEncoding=UTF-8 5 | 6 | sonar.sources=mockserver-client.cfe 7 | sonar.exclusions=mockserver-client.Tests/* 8 | 9 | sonar.scm.enabled=true 10 | sonar.scm.provider=git 11 | 12 | sonar.bsl.languageserver.diagnosticLanguage=en -------------------------------------------------------------------------------- /test/stub.dt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astrizhachuk/mockserver-client-1c/e3cf8278229d96c93081bfccf1841f1722f4fc81/test/stub.dt --------------------------------------------------------------------------------