CN110851468A - Method and device for making simulation response to test request of client - Google Patents

Method and device for making simulation response to test request of client Download PDF

Info

Publication number
CN110851468A
CN110851468A CN201810862773.9A CN201810862773A CN110851468A CN 110851468 A CN110851468 A CN 110851468A CN 201810862773 A CN201810862773 A CN 201810862773A CN 110851468 A CN110851468 A CN 110851468A
Authority
CN
China
Prior art keywords
request
response
predefined
database
client
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201810862773.9A
Other languages
Chinese (zh)
Inventor
杨立昆
许戈兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201810862773.9A priority Critical patent/CN110851468A/en
Publication of CN110851468A publication Critical patent/CN110851468A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

本发明公开了一种对客户端的测试请求做出模拟响应的方法和装置,涉及计算机技术领域。该方法的一具体实施方式包括:接收客户端发出的测试请求;在数据库中查找与测试请求匹配的预定义请求,数据库存储预定义的请求表和响应表以及请求‑响应关系表;当在数据库中找到与测试请求匹配的预定义请求时,根据匹配的预定义请求和请求‑响应关系表确定对应的预定义响应,根据所确定的预定义响应产生对测试请求的模拟响应并返回给客户端。本发明实现了请求‑响应数据持久化,配置灵活,无需硬编码,特别是按项目管理数据提高了系统处理的效率。

Figure 201810862773

The invention discloses a method and a device for making a simulated response to a test request of a client, and relates to the technical field of computers. A specific implementation of the method includes: receiving a test request sent by a client; searching a database for a predefined request matching the test request, and the database stores the predefined request table, response table and request-response relationship table; When a predefined request matching the test request is found, the corresponding predefined response is determined according to the matching predefined request and the request-response relationship table, and a simulated response to the test request is generated according to the determined predefined response and returned to the client . The invention realizes the persistence of request-response data, flexible configuration, no hard coding, and especially improves the efficiency of system processing by managing data according to items.

Figure 201810862773

Description

对客户端的测试请求做出模拟响应的方法和装置Method and apparatus for simulating response to client's test request

技术领域technical field

本发明涉及计算机技术领域,尤其涉及一种对客户端的测试请求做出模拟响应的方法和装置。The present invention relates to the field of computer technology, and in particular, to a method and device for making a simulated response to a test request of a client.

背景技术Background technique

在客户端/服务器系统应用实际开发过程中,经常会遇到客户端与服务器端研发耦合的问题。服务器端的相应接口常常滞后于客户端的开发,而客户端研发人员期望服务器端尽可能早的提供具备联调数据产出能力的接口,同时也期望接口响应数据的类型丰富、内容可以灵活配置,进而满足客户端对各种数据的适配。In the actual development process of client/server system applications, the problem of coupling between client and server R&D is often encountered. The corresponding interface on the server side often lags behind the development of the client side, and the client side developers expect the server side to provide the interface with the ability to produce joint debugging data as soon as possible, and also expect the interface to respond to a variety of data types and flexibly configure the content, and then Satisfy the client's adaptation to various data.

在目前的实践中,一种做法是,前后端研发在充分沟通的基础上,服务器研发以硬编码的方式提供模拟接口,或者客户端直接在JavaScript层面设定模拟数据。另一种做法是,使用一些开源的框架(比如MOCK SERVER)来模拟交互。In current practice, one approach is that the front-end and back-end R&D are based on sufficient communication, the server R&D provides a simulation interface in a hard-coded way, or the client directly sets the simulation data at the JavaScript level. Another way is to use some open source framework (such as MOCK SERVER) to simulate the interaction.

在实现本发明过程中,发明人发现现有技术中至少存在如下问题:In the process of realizing the present invention, the inventor found that there are at least the following problems in the prior art:

在服务器端临时设置模拟接口,虽然能在一定程度上缓解客户端对服务器端数据的依赖,但模拟数据类型的单一、不可灵活配置,仍然是个急需解决的问题。而且,开源的MOCK框架大多数不支持请求-响应持久化,仅支持将请求-响应映射存储在内存中,这意味着服务重启后,已定义的映射数据都消失了,再次使用的话,需要重新定义。Temporarily setting an analog interface on the server side can alleviate the client's dependence on server-side data to a certain extent, but the single and inflexible configuration of the analog data type is still an urgent problem to be solved. Moreover, most open source MOCK frameworks do not support request-response persistence, but only support request-response mapping in memory, which means that after the service is restarted, the defined mapping data will disappear. definition.

发明内容SUMMARY OF THE INVENTION

有鉴于此,本发明实施例提供一种对客户端的测试请求做出模拟响应的方法和装置,能够重复利用以往定义的请求-响应数据,提高开发工作的效率。In view of this, embodiments of the present invention provide a method and apparatus for making a simulated response to a client's test request, which can reuse previously defined request-response data and improve the efficiency of development work.

为实现上述目的,根据本发明实施例的一个方面,提供了一种对客户端的测试请求做出模拟响应的方法,所述方法包括:接收所述客户端发出的测试请求;在数据库中查找与所述测试请求匹配的预定义请求,所述数据库存储预定义的请求表和响应表以及请求-响应关系表,其中,当在所述数据库中找到与所述测试请求匹配的预定义请求时,根据匹配的预定义请求和所述请求-响应关系表确定对应的预定义响应,根据所确定的预定义响应产生对所述测试请求的模拟响应并返回给所述客户端。To achieve the above object, according to an aspect of the embodiments of the present invention, a method for simulating a response to a test request from a client is provided, the method comprising: receiving a test request sent by the client; A predefined request matching the test request, the database stores a predefined request table and a response table and a request-response relationship table, wherein when a predefined request matching the test request is found in the database, A corresponding predefined response is determined according to the matched predefined request and the request-response relationship table, and a simulated response to the test request is generated according to the determined predefined response and returned to the client.

可选地,所述数据库还包括项目表,用于指示数据库中预定义的请求和响应所属项目的项目标识,其中,所述测试请求中指定项目标识,并且在数据库中查找与所述测试请求匹配的预定义请求时,首先根据所述项目标识对预定义请求做筛选,使得仅对所述项目标识关联的预定义请求做匹配。Optionally, the database also includes a project table, which is used to indicate the project identifier of the project to which the predefined request and response belong in the database, wherein the project identifier is specified in the test request, and the test request is searched in the database with the test request. When matching predefined requests, the predefined requests are first filtered according to the item identifiers, so that only predefined requests associated with the item identifiers are matched.

可选地,所述预定义请求和预定义响应及其对应关系通过图形界面来定义。Optionally, the predefined requests and predefined responses and their corresponding relationships are defined through a graphical interface.

可选地,在所述预定义请求中包含创建人、创建时间、修改时间,用于数据维护和权限控制。Optionally, the predefined request includes the creator, creation time, and modification time, which are used for data maintenance and permission control.

可选地,根据所确定的预定义响应产生对所述测试请求的模拟响应包括:从所述响应表中查找与所确定的预定义响应相匹配的响应,并将找到的响应作为对所述测试请求的模拟响应。Optionally, generating a simulated response to the test request according to the determined predefined response includes: searching the response table for a response matching the determined predefined response, and using the found response as a response to the test request. Mock responses to test requests.

根据本发明的另一方面,提供一种对客户端的测试请求做出模拟响应的装置,所述装置包括:请求接收模块,用于接收所述客户端发出的测试请求;查找模块,用于在数据库中查找与所述测试请求匹配的预定义请求,其中所述数据库存储预定义的请求表和响应表以及请求-响应关系表;请求响应模块,用于当在所述数据库中找到与所述测试请求匹配的预定义请求时,根据匹配的预定义请求和所述请求-响应关系表确定对应的预定义响应,并且根据所确定的预定义响应产生对所述测试请求的模拟响应并返回给所述客户端。According to another aspect of the present invention, an apparatus for simulating a response to a test request from a client is provided, the apparatus comprising: a request receiving module for receiving a test request sent by the client; a search module for Find a predefined request matching the test request in a database, wherein the database stores a predefined request table and a response table and a request-response relationship table; When testing a predefined request matched by a request, a corresponding predefined response is determined according to the matched predefined request and the request-response relationship table, and a simulated response to the test request is generated according to the determined predefined response and returned to the client.

可选地,所述数据库还包括项目表,用于指示数据库中预定义的请求和响应所属项目的项目标识,其中,所述测试请求中指定项目标识,并且在数据库中查找与所述测试请求匹配的预定义请求时,首先根据所述项目标识对预定义请求做筛选,使得仅对所述项目标识关联的预定义请求做匹配。Optionally, the database also includes a project table, which is used to indicate the project identifier of the project to which the predefined request and response belong in the database, wherein the project identifier is specified in the test request, and the test request is searched in the database with the test request. When matching predefined requests, the predefined requests are first filtered according to the item identifiers, so that only predefined requests associated with the item identifiers are matched.

可选地,所述预定义请求和预定义响应及其对应关系通过图形界面来定义。Optionally, the predefined requests and predefined responses and their corresponding relationships are defined through a graphical interface.

可选地,在所述预定义请求中包含创建人、创建时间、修改时间,用于数据维护和权限控制。Optionally, the predefined request includes the creator, creation time, and modification time, which are used for data maintenance and permission control.

可选地,所述请求响应模块还用于:从所述响应表中查找与所确定的预定义响应相匹配的响应,并将找到的响应作为对所述测试请求的模拟响应。Optionally, the request-response module is further configured to: look up a response matching the determined predefined response from the response table, and use the found response as a simulated response to the test request.

根据本发明的又一方面,提供一种对客户端的测试请求做出模拟响应的电子设备,包括:一个或多个处理器;存储装置,用于存储一个或多个程序,当所述一个或多个程序被所述一个或多个处理器执行,使得所述一个或多个处理器实现本发明实施例所提供的对客户端的测试请求做出模拟响应的方法。According to yet another aspect of the present invention, there is provided an electronic device for making a simulated response to a test request from a client, comprising: one or more processors; and a storage device for storing one or more programs, when the one or more Multiple programs are executed by the one or more processors, so that the one or more processors implement the method for making a simulated response to a test request of a client provided by the embodiment of the present invention.

根据本发明的又一方面,提供一种计算机可读介质,其上存储有计算机程序,所述程序被处理器执行时实现本发明实施例所提供的对客户端的测试请求做出模拟响应的方法。According to another aspect of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for making a simulated response to a test request from a client provided by the embodiment of the present invention is implemented. .

上述发明中的一个实施例具有如下优点或有益效果:通过在数据库中查找与客户端发出的测试请求匹配的预定义请求,并且当在数据库中找到与该测试请求匹配的预定义请求时,根据匹配的该预定义请求和请求-响应关系表确定对应的预定义响应,根据所确定的预定义响应产生对测试请求的模拟响应并返回给客户端,实现了可以预先设置请求-响应映射,即便请求完全相同,也可以通过映射开关决定使用何种响应反馈本次请求,而且,响应内容可以是JSON、HTML、XML多种格式;无需硬编码,只需要在MOCK平台预定义期望的请求-响应映射,客户端发起HTTP请求时,MOCK平台会将请求和已存储的诸多映射逐一匹配,命中则响应;用户预定义的请求-响应映射关系会持久化到数据库中,寻找匹配映射时直接从数据库中检索、转换。本发明实现了请求-响应数据持久化,配置灵活,无需硬编码,特别是按项目管理数据提高了系统处理的效率。One embodiment of the above invention has the following advantages or beneficial effects: by searching the database for a predefined request matching the test request sent by the client, and when the predefined request matching the test request is found in the database, according to The matching predefined request and the request-response relationship table determine the corresponding predefined response, and generate a simulated response to the test request according to the determined predefined response and return it to the client, so that the request-response mapping can be preset, even if The request is exactly the same, and you can also decide which response to use to feed this request through the mapping switch. Moreover, the response content can be in JSON, HTML, XML formats; no hard coding is required, you only need to predefine the expected request-response on the MOCK platform Mapping, when the client initiates an HTTP request, the MOCK platform will match the request with the stored mappings one by one, and the hit will respond; the user-defined request-response mapping relationship will be persisted to the database, and the database will be directly retrieved from the database when looking for a matching mapping. Search and convert. The invention realizes the persistence of request-response data, has flexible configuration, does not need hard coding, and especially improves the efficiency of system processing by managing data according to items.

上述的非惯用的可选方式所具有的进一步效果将在下文中结合具体实施方式加以说明。Further effects of the above non-conventional alternatives will be described below in conjunction with specific embodiments.

附图说明Description of drawings

附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used for better understanding of the present invention and do not constitute an improper limitation of the present invention. in:

图1是本发明实施例的将请求-响应持久化的流程示意图;1 is a schematic flowchart of a request-response persistence process according to an embodiment of the present invention;

图2是本发明实施例的对请求的模拟响应的实现流程示意图;2 is a schematic flowchart of an implementation of a simulated response to a request according to an embodiment of the present invention;

图3是根据本发明实施例的对客户端的测试请求做出模拟响应的方法的主要流程的示意图;3 is a schematic diagram of the main flow of the method for making a simulated response to a test request of a client according to an embodiment of the present invention;

图4是根据本发明实施例的对客户端的测试请求做出模拟响应的装置的主要模块的示意图;4 is a schematic diagram of main modules of an apparatus for making a simulated response to a test request from a client according to an embodiment of the present invention;

图5是本发明实施例可以应用于其中的示例性系统架构图;5 is an exemplary system architecture diagram to which an embodiment of the present invention may be applied;

图6是适于用来实现本发明实施例的终端设备或服务器的计算机系统的结构示意图。FIG. 6 is a schematic structural diagram of a computer system suitable for implementing a terminal device or a server according to an embodiment of the present invention.

具体实施方式Detailed ways

以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding and should be considered as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted from the following description for clarity and conciseness.

为了解决前述的问题,本发明提出了一种针对客户端和服务器端研发解耦使得在系统研发和测试阶段对客户端的请求进行模拟响应的方法和系统,特别是基于开源框架MOCK SERVER的实现方案。其中,MOCK SERVER是一款功能强劲的基于HTTP/HTTPS的开源MOCK(模拟)框架,通过预先定义Expectations(期望值)来匹配实际请求,给予响应。下面详细说明本发明的实现细节。In order to solve the aforementioned problems, the present invention proposes a method and system for decoupling client-side and server-side R&D so that the client's request can be simulated and responded in the system R&D and testing stages, especially an implementation scheme based on the open source framework MOCK SERVER . Among them, MOCK SERVER is a powerful open source MOCK (simulation) framework based on HTTP/HTTPS, which matches actual requests and responds by pre-defining Expectations (expectations). The implementation details of the present invention are described in detail below.

1.预定义请求和与之对应的模拟响应1. Predefined requests and corresponding simulated responses

根据本发明,在应用的开发和测试阶段,为了在测试中对客户端的请求给出模拟响应,需要预先定义请求和与之对应的模拟响应,并且把定义的请求、响应和它们之间的对应关系持久保存在数据库中,使得在在测试中当客户端实际发出请求时,能够根据数据库中保存的数据对请求进行模拟响应。According to the present invention, in the development and testing stage of the application, in order to give a simulated response to the client's request during the test, the request and the corresponding simulated response need to be pre-defined, and the defined request, the response and the correspondence between them need to be defined in advance. The relationship is persisted in the database, so that when the client actually makes a request in the test, the request can be simulated according to the data stored in the database.

根据本发明的一个实施例,可利用图形用户界面来定义请求和相对应的响应,图形用户界面实现请求、响应及其关系的表示。例如,请求和对应的响应分别在画面的左右两部分定义。According to one embodiment of the present invention, requests and corresponding responses may be defined using a graphical user interface that enables the representation of requests, responses, and their relationships. For example, requests and corresponding responses are defined in the left and right parts of the screen, respectively.

请求的定义中包括:The definition of the request includes:

统一资源定位符URL(Uniform Resource Locator),用于定位资源;Uniform Resource Locator URL (Uniform Resource Locator), used to locate resources;

请求方法,例如包括超文本传输协议HTTP(HTTP,HyperText Transfer Protocol)协议的1.1版本常用的方法,例如包括GET(获取资源)、PUT(传输文件)、POST(传输实体主体)、DETELE(删除文件)等,以供选择;Request methods, such as those commonly used in version 1.1 of the HyperText Transfer Protocol HTTP (HTTP) protocol, such as GET (resource acquisition), PUT (file transfer), POST (transfer entity body), DETELE (delete file) ), etc. for selection;

请求头,常见的HTTP首部字段有:Accept-Charset(优先的字符集)、Accept-Encoding(优先的内容编码)、Host(请求资源所在的服务器)、User-Agent(HTTP客户端程序的信息)等,是可选的;Request header, common HTTP header fields are: Accept-Charset (preferred character set), Accept-Encoding (preferred content encoding), Host (server where the requested resource is located), User-Agent (HTTP client program information) etc., is optional;

请求参数以及请求体等部分,请求内容实体,通常包含业务相关的请求字段,比如用户名等,可选。Parts such as request parameters and request body, request content entity, usually include business-related request fields, such as user name, etc., optional.

响应的定义中包括:HTTP响应码、响应头、延迟响应和响应体等部分,其中响应头提供了常用的响应头供选择,响应头的形式一般包括了内容和类型,以内容/类型的形式提交响应头数据。响应头的形式例如包括:application/json、text/html、application/xml等。The definition of the response includes: HTTP response code, response header, delayed response and response body, among which the response header provides common response headers for selection, and the response header generally includes content and type, in the form of content/type Submit response header data. The form of the response header includes, for example, application/json, text/html, application/xml, and so on.

根据本发明的一个实施例,本发明的模拟响应利用现有的MOCK SERVER框架来实现。定义的请求、响应的字段与MOCK SERVER的期望值Expectation(例如:org.mockserver.mock.Expectation)属性一致,请求定义被映射到MOCK SERVER形式的HTTP请求(例如:org.mockserver.model.HttpRequest),响应定义被映射到MOCK SERVER形式的HTTP响应(例如:org.mockserver.model.HttpResponse),并且利用MOCK SERVER的工具完成有关的转换。According to one embodiment of the present invention, the simulated response of the present invention is implemented using the existing MOCK SERVER framework. The defined request and response fields are consistent with the expected value Expectation (for example: org.mockserver.mock.Expectation) property of MOCK SERVER, and the request definition is mapped to the HTTP request in the form of MOCK SERVER (for example: org.mockserver.model.HttpRequest), The response definition is mapped to the HTTP response in the form of MOCK SERVER (eg: org.mockserver.model.HttpResponse), and the related conversion is done using the tools of MOCK SERVER.

2.在数据库中持久存储的预定义的请求、响应及其对应关系2. Predefined requests, responses and their corresponding relationships that are persistently stored in the database

把预定义的请求、响应和他们的对应关系保存到数据库中,用于在客户端发出请求时,根据数据库中的数据进行模拟响应。原生的MOCK SERVER框架只能将请求-响应映射关系存储在内存中,这意味着重启之后,所有映射数据都消失了。本发明即是基于MOCKSERVER框架,将请求-映射关系持久化到数据库,利用其提供的工具类,实现持久化的请求、响应与MOCK SERVER匹配所需内容之间的转换。Predefined requests, responses and their corresponding relationships are saved in the database, which is used to simulate the response according to the data in the database when the client sends a request. The native MOCK SERVER framework can only store the request-response mapping relationship in memory, which means that after restarting, all mapping data disappears. The invention is based on the MOCKSERVER framework, persists the request-mapping relationship to the database, and uses the tool class provided by the invention to realize the conversion between the persistent request and response and the content required for matching the MOCK SERVER.

根据本发明的实施例,建立请求表和响应表分别保存定义的请求和响应。并且,建立请求-响应映射表来表示请求和响应之间的对应关系。According to an embodiment of the present invention, a request table and a response table are established to store defined requests and responses, respectively. And, a request-response mapping table is established to represent the correspondence between requests and responses.

根据本发明的优选实施例,为了提高处理效率,可以按照项目来分割数据。可通过建立项目表来表示请求和响应所属的项目。According to a preferred embodiment of the present invention, in order to improve processing efficiency, data may be divided by item. Items to which requests and responses belong can be represented by building an item table.

根据本发明的实施例,为了方便数据维护和权限控制,在预定义请求中还包含创建人、创建时间、修改时间等字段。According to the embodiment of the present invention, in order to facilitate data maintenance and permission control, the predefined request also includes fields such as creator, creation time, modification time, and the like.

根据本发明的一个实施例,基于MOCK SERVER框架,把请求、响应和其对应关系持久化到数据库。According to an embodiment of the present invention, based on the MOCK SERVER framework, requests, responses and their corresponding relationships are persisted to a database.

根据本发明的一个实施例,用户预定义的请求、响应的各属性与MOCK SERVER框架的Expectation属性保持一致。利用MOCK SERVER,把用户预定义的请求和响应反序列化为Expectation实例。According to an embodiment of the present invention, the attributes of the request and response predefined by the user are consistent with the Expectation attribute of the MOCK SERVER framework. Using MOCK SERVER, deserialize user-defined requests and responses into Expectation instances.

图1是本发明实施例的将请求-响应持久化的流程示意图。如图1所示,根据本发明的一个实施例,用户预定义的请求-响应映射的各个属性实际上与Expectation的属性保持一致,当MOCK平台收到用户的映射定义(例如:是JSON字符串形式的)时,会反序列化为Expectation实例。基于MOCK SERVER实现用户预定义请求-响应的持久化的过程如下:FIG. 1 is a schematic flowchart of request-response persistence according to an embodiment of the present invention. As shown in FIG. 1, according to an embodiment of the present invention, each attribute of the request-response mapping predefined by the user is actually consistent with the attribute of Expectation. When the MOCK platform receives the mapping definition from the user (for example: a JSON string) form), it will be deserialized into an Expectation instance. The process of implementing user-defined request-response persistence based on MOCK SERVER is as follows:

(1)把HTTP请求HttpRequest序列化为JSON字符串,作为请求的自定义类RequestPO的属性,即:使用HttpRequest构建RequestPO;(1) Serialize the HTTP request HttpRequest into a JSON string as an attribute of the requested custom class RequestPO, that is: use HttpRequest to build RequestPO;

(2)对HTTP响应HttpResponse,通过利用响应的自定义类ResponsePO完成类似处理,即:使用HttpResponse构建ResponsePO;(2) For the HTTP response HttpResponse, similar processing is done by using the custom class ResponsePO of the response, that is: using HttpResponse to build ResponsePO;

(3)把请求的自定义类RequestPO持久化存储至请求数据库表tb_req,把响应的自定义类ResponsePO持久化存储至响应数据库表tb_resp;(3) Persistently store the requested custom class RequestPO in the request database table tb_req, and persistently store the responding custom class ResponsePO in the response database table tb_resp;

(4)建立项目数据库表tb_project,用来确定预定义的请求和对应的响应属于哪个开发项目;(4) Establish a project database table tb_project to determine which development project a predefined request and a corresponding response belong to;

(5)建立请求-响应对应关系数据库表tb_req_resp以维护请求和与之对应的响应的对应关系。具体地,例如是通过请求-响应对应关系数据库表tb_req_resp来维护请求数据库表tb_req和响应数据库表tb_resp的映射关系;或者是过请求-响应对应关系数据库表tb_req_resp来维护请求数据库表tb_req、响应数据库表tb_resp,以及项目数据库表tb_project三者的映射关系。(5) Establish the request-response correspondence database table tb_req_resp to maintain the correspondence between the request and the corresponding response. Specifically, for example, the mapping relationship between the request database table tb_req and the response database table tb_resp is maintained through the request-response database table tb_req_resp; or the request-response database table tb_req_resp is used to maintain the request database table tb_req and the response database table. tb_resp, and the mapping relationship between the project database table tb_project.

3.请求的模拟响应3. Mock response to request

根据本发明,对于接收的客户端发出的请求,本发明的模拟响应系统在数据库中查找与该请求匹配的请求-响应关系,当找到匹配的请求-响应关系时,根据该关系产生相应的模拟响应,然后返回该模拟响应给客户端。According to the present invention, for the received request sent by the client, the simulation response system of the present invention searches the database for a request-response relationship matching the request, and when a matching request-response relationship is found, a corresponding simulation is generated according to the relationship. response, and then return that mock response to the client.

根据本发明的实施例,请求-响应之间的匹配基于MOCK SERVER的匹配机制。请求-响应映射可以是按照项目(project)划分的。不同的项目具有自己的预定义的请求-响应关系。注意,不同项目可以拥有完全相同的请求-响应关系。客户端在发出请求时,需要同时指定项目标识(project-ID)或名称(project-Name),使得系统仅处理该项目下的请求-响应关系以提高数据处理效率。在一个实施例中,客户端在发出请求时,可在URL路径中设置项目标识project-ID,以URL路径“http://mock.aa.com/mock/id-train/users.html”为例,其中的部分“/mock/id-train”便是用于提示MOCK平台,需以MOCK的方式请求获取“id-train”这个项目下的映射关系。According to an embodiment of the present invention, the matching between request-response is based on the matching mechanism of MOCK SERVER. The request-response mapping can be divided by project. Different projects have their own predefined request-response relationships. Note that different projects can have the exact same request-response relationship. When a client sends a request, it needs to specify a project ID (project-ID) or a name (project-Name) at the same time, so that the system only processes the request-response relationship under the project to improve data processing efficiency. In one embodiment, the client can set the project identifier project-ID in the URL path when making a request, and the URL path "http://mock.aa.com/mock/id-train/users.html" is For example, part of "/mock/id-train" is used to prompt the MOCK platform, and it is necessary to request the mapping relationship under the item "id-train" in the form of MOCK.

图2是本发明实施例的对请求的模拟响应的实现流程示意图。如图2所示,根据本发明的一个实施例,一种对请求的模拟响应的实现基于MOCK SERVER,具体过程如下:FIG. 2 is a schematic flowchart of an implementation of a simulated response to a request according to an embodiment of the present invention. As shown in Figure 2, according to an embodiment of the present invention, a simulation response to a request is implemented based on MOCK SERVER, and the specific process is as follows:

(1)接收客户端发出的HTTP请求HttpServletRequest,该HTTP请求可包括相应的项目名称;(1) Receive the HTTP request HttpServletRequest sent by the client, and the HTTP request may include the corresponding project name;

(2)使用MOCK SERVER的映射工具(mappers),例如:使用“org.mockserver.mappers.HttpServletRequestToMockServerRequestDecoder”这个工具类,把该HTTP请求HttpServletRequest转换为MOCK SERVER形式的HTTP请求org.mockserver.model.HttpRequest,简记为:MOCK SERVER形式的HTTP请求HttpRequest;(2) Use the mapping tool (mappers) of MOCK SERVER, for example: use the tool class "org.mockserver.mappers.HttpServletRequestToMockServerRequestDecoder" to convert the HTTP request HttpServletRequest into the HTTP request org.mockserver.model.HttpRequest in the form of MOCK SERVER, Abbreviated as: HTTP request HttpRequest in the form of MOCK SERVER;

(3)根据项目名称,从数据库的请求-响应关系数据库表tb_req_resp中取出与该项目名称有关的所有的关系,并且把取出的每一个关系中的请求RequestPO转换(解析)为MOCK SERVER形式的HTTP请求,使得形成转换后的关系集合S;(3) According to the project name, take out all the relations related to the project name from the request-response relational database table tb_req_resp of the database, and convert (parse) the request RequestPO in each relation taken out into HTTP in the form of MOCK SERVER request, so that the transformed relation set S is formed;

(4)使用匹配工具如org.mockserver.matchers.HttpRequestMatcher把步骤(2)得到的MOCK SERVER形式的HTTP请求HttpRequest与步骤(3)获取的关系集合S中的关系逐个进行匹配,若命中(即:关系集合S中的某个关系对应的MOCK SERVER形式的HTTP请求与步骤(2)得到的MOCK SERVER形式的HTTP请求相同),则转到下面的步骤(5),否则,取S中的下一个关系进行匹配,并且当S中没有找到匹配的关系时,返回错误码;(4) Use matching tools such as org.mockserver.matchers.HttpRequestMatcher to match the HTTP request HttpRequest in the form of MOCK SERVER obtained in step (2) with the relationships in the relationship set S obtained in step (3) one by one. If it hits (ie: The HTTP request in the form of MOCK SERVER corresponding to a relation in the relation set S is the same as the HTTP request in the form of MOCK SERVER obtained in step (2), then go to the following step (5), otherwise, take the next one in S The relationship is matched, and when no matching relationship is found in S, an error code is returned;

(5)根据命中的关系,根据该关系确定与之对应的响应ResponsePO,并将确定的响应ResponsePO转换(解析)为MOCK SERVER形式的HTTP响应HttpResponse;(5) According to the relationship of the hit, determine the corresponding response ResponsePO according to the relationship, and convert (parse) the determined response ResponsePO into the HTTP response HttpResponse in the form of MOCK SERVER;

(6)使用MOCK SERVER的映射工具(例如:使用“org.mockserver.mappers.MockServerResponseToHttpServletResponseEncoder”这个工具类)把步骤(5)中确定的MOCKSERVER形式的HTTP响应HttpResponse转换为所需的模拟响应HttpServletResponse并返回到客户端。(6) Use the mapping tool of MOCK SERVER (for example: use the tool class "org.mockserver.mappers.MockServerResponseToHttpServletResponseEncoder") to convert the HTTP response HttpResponse in the form of MOCKSERVER determined in step (5) into the required mock response HttpServletResponse and return it to the client.

本发明的有益效果包括可以预先设置请求-响应映射,即便请求完全相同,也可以通过映射开关决定使用何种响应反馈本次请求,而且,响应内容可以是JSON、HTML、XML多种格式;无需硬编码,只需要在MOCK平台预定义期望的请求-响应映射,客户端发起HTTP请求时,MOCK平台会将请求和已存储的诸多映射逐一匹配,命中则响应;用户预定义的请求-响应映射关系会持久化到数据库中,寻找匹配映射时直接从数据库中检索、转换。The beneficial effects of the present invention include that the request-response mapping can be preset, and even if the requests are completely the same, the mapping switch can be used to decide which response is used to feed back this request, and the response content can be in various formats of JSON, HTML, and XML; Hard-coded, you only need to pre-define the desired request-response mapping on the MOCK platform. When the client initiates an HTTP request, the MOCK platform will match the request with the stored mappings one by one, and respond if they hit; user-defined request-response mapping Relationships are persisted to the database, and are retrieved and transformed directly from the database when looking for matching mappings.

另外,在本发明的实施例中,还可以通过对HTTP接口响应的某些头部属性进行设置以达到跨域访问的目的。具体可以设置的头部属性以及对应的属性值例如:In addition, in the embodiment of the present invention, some header attributes of the HTTP interface response can also be set to achieve the purpose of cross-domain access. The specific header attributes that can be set and the corresponding attribute values are for example:

将头部属性“Access-Control-Allow-Origin(入口管理可用起点)”的属性值设置为“*”;Set the attribute value of the header attribute "Access-Control-Allow-Origin" to "*";

将头部属性“Access-Control-Allow-Methods(入口管理可用方法)”的属性值设置为“CONNECT、DELETE、GET、HEAD、OPTIONS、POST、PUT、TRACE”;Set the attribute value of the header attribute "Access-Control-Allow-Methods" to "CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, TRACE";

将头部属性“Access-Control-Allow-Headers(入口管理可用头部)”或“Access-Control-Expose-Headers(入口管理可暴露头部)”的属性值设置为“Allow、Content-Encoding、Content-Length、Content-Type、ETag、Expires、Last-Modified、Location、Server、Vary”;Set the attribute value of the header attribute "Access-Control-Allow-Headers (entry management available headers)" or "Access-Control-Expose-Headers (entry management exposed headers)" to "Allow, Content-Encoding, Content-Length, Content-Type, ETag, Expires, Last-Modified, Location, Server, Vary";

将头部属性“Access-Control-Max-Age(入口管理最大年限)”的属性值设置为“1”;Set the attribute value of the header attribute "Access-Control-Max-Age (maximum age of entry management)" to "1";

将头部属性“X-CORS(CORS,Cross-Origin Resource Sharing,跨域资源共享)”的属性值设置为“MockServer CORS support enabled by default、to disable ConfigurationProperties.enableCORSForAPI(false)or-Dmockserver.disableCORS=false”,等。Set the attribute value of the header attribute "X-CORS (CORS, Cross-Origin Resource Sharing, Cross-Origin Resource Sharing)" to "MockServer CORS support enabled by default, to disable ConfigurationProperties.enableCORSForAPI(false)or-Dmockserver.disableCORS= false", etc.

图3是根据本发明实施例的对客户端的测试请求做出模拟响应的方法的主要流程的示意图。如图3所示,本发明实施例的对客户端的测试请求做出模拟响应的方法主要包括如下步骤:FIG. 3 is a schematic diagram of the main flow of a method for making a simulated response to a test request of a client according to an embodiment of the present invention. As shown in FIG. 3 , the method for making a simulated response to a test request of a client according to an embodiment of the present invention mainly includes the following steps:

S301:接收客户端发出的测试请求;S301: Receive the test request sent by the client;

S302:在数据库中查找与该测试请求匹配的预定义请求,数据库存储预定义的请求表和响应表以及请求-响应关系表;S302: Find a predefined request matching the test request in the database, and the database stores the predefined request table, response table and request-response relationship table;

S303:当在数据库中找到与该测试请求匹配的预定义请求时,根据匹配的该预定义请求和请求-响应关系表确定对应的预定义响应,根据所确定的预定义响应产生对测试请求的模拟响应并返回给客户端。S303: When a predefined request matching the test request is found in the database, determine a corresponding predefined response according to the matched predefined request and the request-response relationship table, and generate a response to the test request according to the predefined predefined response. Mock the response and return it to the client.

根据本发明的优选实施例,数据库中还可以包括项目表,用于指示数据库中预定义的请求和响应所属项目的项目标识,其中,测试请求中指定项目标识,并且在数据库中查找与该测试请求匹配的预定义请求时,首先根据该项目标识对预定义请求做筛选,使得仅对该项目标识关联的预定义请求做匹配。According to a preferred embodiment of the present invention, the database may further include an item table, which is used to indicate the item identifiers of the items to which the predefined requests and responses belong in the database, wherein the item identifiers are specified in the test request, and the database related to the test is looked up in the database. When a matching predefined request is requested, the predefined request is first filtered according to the item ID, so that only the predefined request associated with the item ID is matched.

根据本发明的优选实施例,预定义请求和预定义响应及其对应关系通过图形界面来定义。According to a preferred embodiment of the present invention, the predefined requests and predefined responses and their corresponding relationships are defined through a graphical interface.

根据本发明的优选实施例,在预定义请求中还可以包含创建人、创建时间、修改时间,用于数据维护和权限控制。According to a preferred embodiment of the present invention, the predefined request may also include the creator, creation time, and modification time, which are used for data maintenance and permission control.

根据本发明的优选实施例,根据所确定的预定义响应产生对测试请求的模拟响应包括:从响应表中查找与所确定的预定义响应相匹配的响应,并将找到的响应作为对测试请求的模拟响应。According to a preferred embodiment of the present invention, generating a simulated response to the test request according to the determined predefined response includes: searching a response table for a response matching the determined predefined response, and using the found response as a response to the test request simulated response.

图4是根据本发明实施例的对客户端的测试请求做出模拟响应的装置的主要模块的示意图。如图4所示,本发明实施例的对客户端的测试请求做出模拟响应的装置400主要包括:FIG. 4 is a schematic diagram of main modules of an apparatus for making a simulated response to a test request of a client according to an embodiment of the present invention. As shown in FIG. 4 , the apparatus 400 for making a simulated response to a test request of a client according to an embodiment of the present invention mainly includes:

请求接收模块401,用于接收客户端发出的测试请求;A request receiving module 401, configured to receive a test request sent by a client;

请求查找模块402,用于在数据库中查找与测试请求匹配的预定义请求,其中数据库存储预定义的请求表和响应表以及请求-响应关系表;A request lookup module 402, configured to look up a predefined request matching the test request in a database, wherein the database stores a predefined request table, a response table and a request-response relationship table;

请求响应模块403,用于当在数据库中找到与该测试请求匹配的预定义请求时,根据匹配的该预定义请求和所述请求-响应关系表确定对应的预定义响应,并且根据所确定的预定义响应产生对测试请求的模拟响应并返回给客户端。The request response module 403 is configured to determine a corresponding predefined response according to the matched predefined request and the request-response relationship table when a predefined request matching the test request is found in the database, and according to the determined The predefined response produces a mock response to the test request and returns it to the client.

上述模块是示意性的,这些模块可以分成子模块,不同的模块可以组合成一个模块。The above modules are illustrative, these modules can be divided into sub-modules, and different modules can be combined into one module.

根据本发明的优选实施例,数据库中还可以包括项目表,用于指示数据库中预定义的请求和响应所属项目的项目标识,其中,测试请求中指定项目标识,并且在数据库中查找与该测试请求匹配的预定义请求时,首先根据该项目标识对预定义请求做筛选,使得仅对该项目标识关联的预定义请求做匹配。According to a preferred embodiment of the present invention, the database may further include an item table, which is used to indicate the item identifiers of the items to which the predefined requests and responses belong in the database, wherein the item identifiers are specified in the test request, and the database related to the test is looked up in the database. When a matching predefined request is requested, the predefined request is first filtered according to the item ID, so that only the predefined request associated with the item ID is matched.

根据本发明的优选实施例,预定义请求和预定义响应及其对应关系通过图形界面来定义。According to a preferred embodiment of the present invention, the predefined requests and predefined responses and their corresponding relationships are defined through a graphical interface.

根据本发明的优选实施例,在预定义请求中还可以包含创建人、创建时间、修改时间,用于数据维护和权限控制。According to a preferred embodiment of the present invention, the predefined request may also include the creator, creation time, and modification time, which are used for data maintenance and permission control.

根据本发明的优选实施例,请求响应模块403还可以用于:According to the preferred embodiment of the present invention, the request-response module 403 can also be used for:

从响应表中查找与所确定的预定义响应相匹配的响应,并将找到的响应作为对测试请求的模拟响应。Find a response from the response table that matches the determined predefined response, and use the found response as a mock response to the test request.

根据本发明实施例的技术方案,通过在数据库中查找与客户端发出的测试请求匹配的预定义请求,并且当在数据库中找到与该测试请求匹配的预定义请求时,根据匹配的该预定义请求和请求-响应关系表确定对应的预定义响应,根据所确定的预定义响应产生对测试请求的模拟响应并返回给客户端,实现了可以预先设置请求-响应映射,即便请求完全相同,也可以通过映射开关决定使用何种响应反馈本次请求,而且,响应内容可以是JSON、HTML、XML多种格式;无需硬编码,只需要在MOCK平台预定义期望的请求-响应映射,客户端发起HTTP请求时,MOCK平台会将请求和已存储的诸多映射逐一匹配,命中则响应;用户预定义的请求-响应映射关系会持久化到数据库中,寻找匹配映射时直接从数据库中检索、转换。According to the technical solution of the embodiment of the present invention, the predefined request matching the test request sent by the client is searched in the database, and when the predefined request matching the test request is found in the database, according to the matching predefined request The request and request-response relationship table determines the corresponding predefined response, and generates a simulated response to the test request according to the determined predefined response and returns it to the client, so that the request-response mapping can be set in advance. You can decide which response to use to feed this request through the mapping switch, and the response content can be in JSON, HTML, XML formats; no hard coding is required, you only need to predefine the desired request-response mapping on the MOCK platform, and the client initiates When an HTTP request is made, the MOCK platform will match the request with the stored mappings one by one, and respond when it hits; the user-defined request-response mapping relationship will be persisted to the database, and the matching mapping will be retrieved and converted directly from the database.

图5示出了可以应用本发明实施例的对客户端的测试请求做出模拟响应的方法或相应装置的示例性系统架构500。FIG. 5 shows an exemplary system architecture 500 of a method or corresponding apparatus for making a simulated response to a client's test request to which an embodiment of the present invention can be applied.

如图5所示,系统架构500可以包括终端设备501、502、503,网络504和服务器505。网络504用以在终端设备501、502、503和服务器505之间提供通信链路的介质。网络504可以包括各种连接类型,例如有线、无线通信链路或者光纤电缆等等。As shown in FIG. 5 , the system architecture 500 may include terminal devices 501 , 502 , and 503 , a network 504 and a server 505 . The network 504 is a medium used to provide a communication link between the terminal devices 501 , 502 , 503 and the server 505 . Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.

用户可以使用终端设备501、502、503通过网络504与服务器505交互,以接收或发送消息等。终端设备501、502、503上可以安装有各种通讯客户端应用,例如购物类应用、网页浏览器应用、搜索类应用、即时通信工具、邮箱客户端、社交平台软件等(仅为示例)。The user can use the terminal devices 501, 502, 503 to interact with the server 505 through the network 504 to receive or send messages and the like. Various communication client applications may be installed on the terminal devices 501 , 502 and 503 , such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

终端设备501、502、503可以是具有显示屏并且支持网页浏览的各种电子设备,包括但不限于智能手机、平板电脑、膝上型便携计算机和台式计算机等等。The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

服务器505可以是提供各种服务的服务器,例如对用户利用终端设备501、502、503所浏览的购物类网站提供支持的后台管理服务器(仅为示例)。后台管理服务器可以对接收到的产品信息查询请求等数据进行分析等处理,并将处理结果(例如目标推送信息、产品信息--仅为示例)反馈给终端设备。The server 505 may be a server that provides various services, for example, a background management server that provides support for shopping websites browsed by the terminal devices 501 , 502 , and 503 (just an example). The background management server can analyze and process the received product information query request and other data, and feed back the processing results (such as target push information, product information—just an example) to the terminal device.

需要说明的是,本发明实施例所提供的对客户端的测试请求做出模拟响应方法一般由服务器505执行,相应地,对客户端的测试请求做出模拟响应装置一般设置于服务器505中。It should be noted that the method for making a simulated response to a client's test request provided by the embodiment of the present invention is generally executed by the server 505 .

应该理解,图5中的终端设备、网络和服务器的数目仅仅是示意性的。根据实现需要,可以具有任意数目的终端设备、网络和服务器。It should be understood that the numbers of terminal devices, networks and servers in FIG. 5 are only illustrative. There can be any number of terminal devices, networks and servers according to implementation needs.

下面参考图6,其示出了适于用来实现本发明实施例的终端设备的计算机系统600的结构示意图。图6示出的终端设备仅仅是一个示例,不应对本发明实施例的功能和使用范围带来任何限制。Referring to FIG. 6 below, it shows a schematic structural diagram of a computer system 600 suitable for implementing a terminal device according to an embodiment of the present invention. The terminal device shown in FIG. 6 is only an example, and should not impose any limitations on the functions and scope of use of the embodiments of the present invention.

如图6所示,计算机系统600包括中央处理单元(CPU)601,其可以根据存储在只读存储器(ROM)602中的程序或者从存储部分608加载到随机访问存储器(RAM)603中的程序而执行各种适当的动作和处理。在RAM 603中,还存储有系统600操作所需的各种程序和数据。CPU 601、ROM 602以及RAM 603通过总线604彼此相连。输入/输出(I/O)接口605也连接至总线604。As shown in FIG. 6, a computer system 600 includes a central processing unit (CPU) 601, which can be loaded into a random access memory (RAM) 603 according to a program stored in a read only memory (ROM) 602 or a program from a storage section 608 Instead, various appropriate actions and processes are performed. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601 , the ROM 602 , and the RAM 603 are connected to each other through a bus 604 . An input/output (I/O) interface 605 is also connected to bus 604 .

以下部件连接至I/O接口605:包括键盘、鼠标等的输入部分606;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分607;包括硬盘等的存储部分608;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分609。通信部分609经由诸如因特网的网络执行通信处理。驱动器610也根据需要连接至I/O接口605。可拆卸介质611,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器610上,以便于从其上读出的计算机程序根据需要被安装入存储部分608。The following components are connected to the I/O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc. ; and a communication section 609 including a network interface card such as a LAN card, a modem, and the like. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I/O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is mounted on the drive 610 as needed so that a computer program read therefrom is installed into the storage section 608 as needed.

特别地,根据本发明公开的实施例,上文参考流程图描述的过程可以被实现为计算机软件程序。例如,本发明公开的实施例包括一种计算机程序产品,其包括承载在计算机可读介质上的计算机程序,该计算机程序包含用于执行流程图所示的方法的程序代码。在这样的实施例中,该计算机程序可以通过通信部分609从网络上被下载和安装,和/或从可拆卸介质611被安装。在该计算机程序被中央处理单元(CPU)601执行时,执行本发明的系统中限定的上述功能。In particular, the processes described above with reference to the flowcharts may be implemented as computer software programs in accordance with the disclosed embodiments of the present invention. For example, embodiments disclosed herein include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the method illustrated in the flowchart. In such an embodiment, the computer program may be downloaded and installed from the network via the communication portion 609 and/or installed from the removable medium 611 . When the computer program is executed by the central processing unit (CPU) 601, the above-described functions defined in the system of the present invention are executed.

需要说明的是,本发明所示的计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质或者是上述两者的任意组合。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子可以包括但不限于:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机访问存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本发明中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。而在本发明中,计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。计算机可读介质上包含的程序代码可以用任何适当的介质传输,包括但不限于:无线、电线、光缆、RF等等,或者上述的任意合适的组合。It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium, or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus or device, or a combination of any of the above. More specific examples of computer readable storage media may include, but are not limited to, electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable Programmable read only memory (EPROM or flash memory), fiber optics, portable compact disk read only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. In the present invention, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, however, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code therein. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device . Program code embodied on a computer readable medium may be transmitted using any suitable medium including, but not limited to, wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

附图中的流程图和框图,图示了按照本发明各种实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段、或代码的一部分,上述模块、程序段、或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个接连地表示的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图或流程图中的每个方框、以及框图或流程图中的方框的组合,可以用执行规定的功能或操作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code that contains one or more logical functions for implementing the specified functions executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It is also noted that each block of the block diagrams or flowchart illustrations, and combinations of blocks in the block diagrams or flowchart illustrations, can be implemented in special purpose hardware-based systems that perform the specified functions or operations, or can be implemented using A combination of dedicated hardware and computer instructions is implemented.

描述于本发明实施例中所涉及到的单元(或“模块”)可以通过软件的方式实现,也可以通过硬件的方式来实现。所描述的单元(或“模块”)也可以设置在处理器中,例如,可以描述为:一种处理器包括请求接收模块、请求查找模块和请求响应模块。其中,这些单元的名称在某种情况下并不构成对该单元本身的限定,例如,请求接收模块还可以被描述为“用于接收所述客户端发出的测试请求的模块”。The units (or "modules") involved in the embodiments of the present invention may be implemented in a software manner, and may also be implemented in a hardware manner. The described unit (or "module") can also be provided in the processor, for example, it can be described as: a processor includes a request receiving module, a request finding module and a request responding module. Wherein, the names of these units do not constitute a limitation of the unit itself in some cases, for example, the request receiving module may also be described as "a module for receiving a test request sent by the client".

作为另一方面,本发明还提供了一种计算机可读介质,该计算机可读介质可以是上述实施例中描述的设备中所包含的;也可以是单独存在,而未装配入该设备中。上述计算机可读介质承载有一个或者多个程序,当上述一个或者多个程序被一个该设备执行时,使得该设备包括:接收所述客户端发出的测试请求;在数据库中查找与所述测试请求匹配的预定义请求,所述数据库存储预定义的请求表和响应表以及请求-响应关系表,其中,当在所述数据库中找到与所述测试请求匹配的预定义请求时,根据匹配的预定义请求和所述请求-响应关系表确定对应的预定义响应,根据所确定的预定义响应产生对所述测试请求的模拟响应并返回给所述客户端。As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or may exist alone without being assembled into the device. The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by a device, the device includes: receiving a test request sent by the client; Requests matching predefined requests, the database stores predefined request tables and response tables and a request-response relationship table, wherein when a predefined request matching the test request is found in the database, according to the matching predefined request The predefined request and the request-response relationship table determine a corresponding predefined response, and generate a simulated response to the test request according to the determined predefined response and return it to the client.

根据本发明实施例的技术方案,通过在数据库中查找与客户端发出的测试请求匹配的预定义请求,并且当在数据库中找到与该测试请求匹配的预定义请求时,根据匹配的该预定义请求和请求-响应关系表确定对应的预定义响应,根据所确定的预定义响应产生对测试请求的模拟响应并返回给客户端,实现了可以预先设置请求-响应映射,即便请求完全相同,也可以通过映射开关决定使用何种响应反馈本次请求,而且,响应内容可以是JSON、HTML、XML多种格式;无需硬编码,只需要在MOCK平台预定义期望的请求-响应映射,客户端发起HTTP请求时,MOCK平台会将请求和已存储的诸多映射逐一匹配,命中则响应;用户预定义的请求-响应映射关系会持久化到数据库中,寻找匹配映射时直接从数据库中检索、转换。本发明实现了请求-响应数据持久化,配置灵活,无需硬编码,特别是按项目管理数据提高了系统处理的效率。According to the technical solution of the embodiment of the present invention, the predefined request matching the test request sent by the client is searched in the database, and when the predefined request matching the test request is found in the database, according to the matching predefined request The request and request-response relationship table determines the corresponding predefined response, and generates a simulated response to the test request according to the determined predefined response and returns it to the client, so that the request-response mapping can be set in advance. You can decide which response to use to feed this request through the mapping switch, and the response content can be in JSON, HTML, XML formats; no hard coding is required, you only need to predefine the desired request-response mapping on the MOCK platform, and the client initiates When an HTTP request is made, the MOCK platform will match the request with the stored mappings one by one, and respond when it hits; the user-defined request-response mapping relationship will be persisted to the database, and the matching mapping will be retrieved and converted directly from the database. The invention realizes the persistence of request-response data, has flexible configuration, does not need hard coding, and especially improves the efficiency of system processing by managing data according to items.

上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above-mentioned specific embodiments do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.

Claims (12)

1. A method for simulated response to a test request from a client, comprising:
receiving a test request sent by the client;
searching a predefined request matched with the test request in a database, wherein the database stores a predefined request table, a predefined response table and a request-response relation table;
when the predefined request matched with the test request is found in the database, determining a corresponding predefined response according to the matched predefined request and the request-response relation table, generating a simulated response to the test request according to the determined predefined response, and returning the simulated response to the client.
2. The method of claim 1, wherein the database further comprises an item table for indicating item identifications of items to which predefined requests and responses in the database belong,
wherein, the test request specifies the item identification, and when the predefined request matched with the test request is searched in the database, the predefined request is screened according to the item identification, so that only the predefined request associated with the item identification is matched.
3. The method of claim 1, wherein the predefined request and the predefined response and their correspondence are defined through a graphical interface.
4. The method of claim 1, wherein the predefined request includes a creator, a creation time, a modification time, for data maintenance and rights control.
5. The method of claim 1, wherein generating a simulated response to the test request according to the determined predefined response comprises:
looking up a response from the response table that matches the determined predefined response and using the found response as a simulated response to the test request.
6. An apparatus for simulated response to a test request from a client, comprising:
the request receiving module is used for receiving a test request sent by the client;
the request searching module is used for searching a predefined request matched with the test request in a database, wherein the database stores a predefined request table, a predefined response table and a request-response relation table;
and the request response module is used for determining a corresponding predefined response according to the matched predefined request and the request-response relation table when the predefined request matched with the test request is found in the database, generating a simulated response to the test request according to the determined predefined response and returning the simulated response to the client.
7. The apparatus of claim 6, wherein the database further comprises an item table for indicating item identifications of items to which predefined requests and responses in the database belong,
wherein, the test request specifies the item identification, and when the predefined request matched with the test request is searched in the database, the predefined request is screened according to the item identification, so that only the predefined request associated with the item identification is matched.
8. The apparatus of claim 6, wherein the predefined request and the predefined response and their correspondence are defined through a graphical interface.
9. The apparatus of claim 6, wherein the predefined request comprises a creator, a creation time, a modification time, for data maintenance and rights control.
10. The apparatus of claim 6, wherein the request response module is further configured to:
looking up a response from the response table that matches the determined predefined response and using the found response as a simulated response to the test request.
11. An electronic device for simulated response to a test request from a client, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-5.
12. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-5.
CN201810862773.9A 2018-08-01 2018-08-01 Method and device for making simulation response to test request of client Pending CN110851468A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810862773.9A CN110851468A (en) 2018-08-01 2018-08-01 Method and device for making simulation response to test request of client

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810862773.9A CN110851468A (en) 2018-08-01 2018-08-01 Method and device for making simulation response to test request of client

Publications (1)

Publication Number Publication Date
CN110851468A true CN110851468A (en) 2020-02-28

Family

ID=69594482

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810862773.9A Pending CN110851468A (en) 2018-08-01 2018-08-01 Method and device for making simulation response to test request of client

Country Status (1)

Country Link
CN (1) CN110851468A (en)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111695328A (en) * 2020-06-16 2020-09-22 深圳前海微众银行股份有限公司 Method, device, equipment and storage medium for generating simulation test message
CN111752837A (en) * 2020-06-24 2020-10-09 北京百度网讯科技有限公司 View base system test method, device, equipment and storage medium
CN111917603A (en) * 2020-07-22 2020-11-10 广州虎牙信息科技有限公司 Client test method and device, computer equipment and storage medium
CN111953659A (en) * 2020-07-21 2020-11-17 北京思特奇信息技术股份有限公司 Method and system for simulating http request
CN112306858A (en) * 2020-05-21 2021-02-02 北京字节跳动网络技术有限公司 Test method and device and electronic equipment
CN112925711A (en) * 2021-02-26 2021-06-08 平安普惠企业管理有限公司 Local joint debugging test method and related device
CN113381911A (en) * 2021-06-09 2021-09-10 上海臣星软件技术有限公司 Test method, device, equipment and storage medium
WO2022134895A1 (en) * 2020-12-25 2022-06-30 华为云计算技术有限公司 Mock response method and related device
CN114741285A (en) * 2022-03-30 2022-07-12 阿波罗智联(北京)科技有限公司 Method, device, electronic equipment and computer program product for processing data

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106802859A (en) * 2015-11-25 2017-06-06 北京京东尚科信息技术有限公司 A kind of method and device of client software test
CN106970873A (en) * 2017-01-10 2017-07-21 阿里巴巴集团控股有限公司 Mock method of testings, apparatus and system on line
CN107547312A (en) * 2017-09-21 2018-01-05 广州四三九九信息科技有限公司 Applied program testing method and system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106802859A (en) * 2015-11-25 2017-06-06 北京京东尚科信息技术有限公司 A kind of method and device of client software test
CN106970873A (en) * 2017-01-10 2017-07-21 阿里巴巴集团控股有限公司 Mock method of testings, apparatus and system on line
CN107547312A (en) * 2017-09-21 2018-01-05 广州四三九九信息科技有限公司 Applied program testing method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
郑有庆: "Java面向对象程序设计教学做一体化教程", 30 November 2016, 安徽大学出版社, pages: 306 *

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112306858A (en) * 2020-05-21 2021-02-02 北京字节跳动网络技术有限公司 Test method and device and electronic equipment
CN111695328A (en) * 2020-06-16 2020-09-22 深圳前海微众银行股份有限公司 Method, device, equipment and storage medium for generating simulation test message
CN111695328B (en) * 2020-06-16 2023-01-24 深圳前海微众银行股份有限公司 Simulation test message generation method, device, equipment and storage medium
CN111752837A (en) * 2020-06-24 2020-10-09 北京百度网讯科技有限公司 View base system test method, device, equipment and storage medium
CN111752837B (en) * 2020-06-24 2024-01-12 北京百度网讯科技有限公司 View library system test method, device, equipment and storage medium
CN111953659A (en) * 2020-07-21 2020-11-17 北京思特奇信息技术股份有限公司 Method and system for simulating http request
CN111917603A (en) * 2020-07-22 2020-11-10 广州虎牙信息科技有限公司 Client test method and device, computer equipment and storage medium
WO2022134895A1 (en) * 2020-12-25 2022-06-30 华为云计算技术有限公司 Mock response method and related device
CN112925711A (en) * 2021-02-26 2021-06-08 平安普惠企业管理有限公司 Local joint debugging test method and related device
CN113381911A (en) * 2021-06-09 2021-09-10 上海臣星软件技术有限公司 Test method, device, equipment and storage medium
CN114741285A (en) * 2022-03-30 2022-07-12 阿波罗智联(北京)科技有限公司 Method, device, electronic equipment and computer program product for processing data

Similar Documents

Publication Publication Date Title
CN110851468A (en) Method and device for making simulation response to test request of client
CN110019350B (en) Data query method and device based on configuration information
WO2021027615A1 (en) Test method and device for web service interface having authentication authorization
CN112866310B (en) CDN back-to-source verification method and verification server, CDN cluster
CN110019211A (en) The methods, devices and systems of association index
WO2021023149A1 (en) Method and apparatus for dynamically returning message
CN113536748B (en) A method and device for generating chart data
US11243921B2 (en) Database expansion system, equipment, and method of expanding database
US20160028833A1 (en) Tenant aware session manager
CN113839977A (en) Message pushing method and device, computer equipment and storage medium
CN109218041B (en) Request processing method and device for server system
TW201818317A (en) Business realization method, payment method, business realization apparatus and payment server
CN112052152A (en) A method and device for simulating testing
CN113282489B (en) Interface testing method and device
CN113541987B (en) A method and device for updating configuration data
US20190223004A1 (en) Implementation method, apparatus and system for remote access
CN112929453B (en) Method and device for sharing session data
CN110728009A (en) Simulation method, apparatus and system
CN112306791B (en) Performance monitoring method and device
CN114996554A (en) Database query method and device, storage medium and electronic equipment
CN110019671B (en) Method and system for processing real-time message
CN113778847A (en) Test report generation method and device
CN113704080B (en) Automatic test method and device
CN111258572A (en) Method and device for generating business code framework
CN113760886B (en) Method, apparatus, device and computer readable medium for providing data service

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination