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

The invention discloses a method and a device for making a simulation response to a test request of a client, and relates to the technical field of computers. One embodiment of the method comprises: receiving a test request sent by a 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; and 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 test request to the client. The invention realizes the request-response data persistence, has flexible configuration, does not need hard coding, and particularly manages the data according to the project so as to improve the system processing efficiency.

Description

Method and device for making simulation response to test request of client
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for making a simulation response to a test request of a client.
Background
In the practical development process of the client/server system application, the problem of research and development coupling of the client and the server is often encountered. The corresponding interface of the server is usually lagged behind the development of the client, and the client research personnel expect that the server provides an interface with joint debugging data output capacity as early as possible, and also expect that the type of interface response data is rich and the content can be flexibly configured, so that the adaptation of the client to various data is met.
In current practice, one way is that, the front-end and the back-end research and development provide an analog interface in a hard coding mode on the basis of sufficient communication, or the client directly sets analog data on a JavaScript level. Alternatively, some open-source framework (such as MOCK SERVER) is used to simulate the interaction.
In the process of implementing the invention, the inventor finds that at least the following problems exist in the prior art:
the simulation interface is temporarily arranged at the server side, so that the dependence of the client on the server side data can be relieved to a certain extent, but the problem that the simulation data type is single and cannot be flexibly configured still needs to be solved urgently. Furthermore, most open-source MOCK frameworks do not support request-response persistence, but only store request-response mappings in memory, which means that after a service restart, the defined mapping data disappears and needs to be redefined if used again.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for performing a simulated response to a test request of a client, which can reuse previously defined request-response data and improve efficiency of development work.
To achieve the above object, according to an aspect of the embodiments of the present invention, there is provided a method for making a simulated response to a test request of a client, the method including: receiving a test request sent by the client; and searching a predefined request matched with the test request in a database, wherein the database stores a predefined request table, a 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.
Optionally, the database further includes an item table, configured to indicate predefined requests in the database and item identifiers corresponding to items to which the requests belong, where the item identifiers are specified in the test request, and when a predefined request matching the test request is searched in the database, the predefined request is first filtered according to the item identifiers, so that only the predefined request associated with the item identifier is matched.
Optionally, the predefined request and the predefined response and their corresponding relationship are defined by a graphical interface.
Optionally, the pre-defined request comprises a creator, a creation time and a modification time, and is used for data maintenance and authority control.
Optionally, 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.
According to another aspect of the present invention, there is provided an apparatus for making a simulated response to a test request of a client, the apparatus comprising: the request receiving module is used for receiving a test request sent by the client; the 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.
Optionally, the database further includes an item table, configured to indicate predefined requests in the database and item identifiers corresponding to items to which the requests belong, where the item identifiers are specified in the test request, and when a predefined request matching the test request is searched in the database, the predefined request is first filtered according to the item identifiers, so that only the predefined request associated with the item identifier is matched.
Optionally, the predefined request and the predefined response and their corresponding relationship are defined by a graphical interface.
Optionally, the pre-defined request comprises a creator, a creation time and a modification time, and is used for data maintenance and authority control.
Optionally, 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.
According to still another aspect of the present invention, there is provided an electronic device for making a simulated response to a test request of a client, including: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method for responding to the test request of the client in a simulation mode, which is provided by the embodiment of the invention.
According to a further aspect of the present invention, there is provided a computer readable medium, on which a computer program is stored, which when executed by a processor, implements the method for simulating a response to a test request of a client provided by an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: the method comprises the steps of searching a predefined request matched with a test request sent by a client in a database, determining a corresponding predefined response according to the matched predefined request and a 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 test request to the client, realizing preset request-response mapping, deciding which response to use to feed back the request through a mapping switch even if the requests are completely the same, and enabling the response content to be in multiple formats of JSON, HTML and XML; the method has the advantages that hard coding is not needed, only the expected request-response mapping is predefined on the MOCK platform, when the client side initiates the HTTP request, the MOCK platform can match the request with the stored mapping one by one, and the response is performed when the HTTP request is hit; the request-response mapping relation predefined by the user can be persisted into the database, and when the matching mapping is searched, the matching mapping is directly retrieved and converted from the database. The invention realizes the request-response data persistence, has flexible configuration, does not need hard coding, and particularly manages the data according to the project so as to improve the system processing efficiency.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a flow diagram of a request-response persistence of an embodiment of the invention;
FIG. 2 is a flow chart illustrating the implementation of a simulated response to a request according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the main flow of a method of simulated response to a test request of a client according to an embodiment of the invention;
FIG. 4 is a schematic diagram of the main modules of an apparatus for simulated response to a test request of a client according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 6 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. 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 in the following description for clarity and conciseness.
In order to solve the foregoing problems, the present invention provides a method and a system for decoupling the development of a client and a SERVER so as to perform a simulated response to a request of the client in the system development and test phases, and in particular, an implementation scheme based on an open source framework (MOCK) SERVER. The MOCK SERVER is a powerful open source MOCK (simulation) framework based on HTTP/HTTPS, and responses are given by matching actual requests through predefining expected values. The details of the implementation of the present invention are described below.
1. Predefined requests and simulated responses corresponding thereto
According to the present invention, in the development and test stage of an application, in order to give a simulated response to a request of a client in a test, it is necessary to define the request and the simulated response corresponding thereto in advance, and to store the defined request, response, and correspondence therebetween in a database for a long time, so that when the client actually issues a request in the test, a simulated response can be made to the request based on data stored in the database.
According to one embodiment of the invention, the requests and corresponding responses may be defined using a graphical user interface that enables representation of the requests, responses, and their relationships. For example, the request and the corresponding response are defined in the left and right parts of the screen, respectively.
The definition of the request includes:
a uniform Resource locator url (uniform Resource locator) for locating a Resource;
request methods, for example, include methods commonly used in version 1.1 of the HyperText Transfer Protocol HTTP (HTTP), for example, GET (GET resource), PUT (Transfer file), POST (Transfer entity body), delete (delete file), and the like, for selection;
request header, common HTTP header fields are: Accept-Charset (preferential character set), Accept-Encoding (preferential content Encoding), Host (server where the request resource is located), User-Agent (information of HTTP client program), and the like, which are optional;
request parameters, a request body and the like, and a request content entity, generally containing service-related request fields, such as a user name and the like, are optional.
The definition of the response includes: the HTTP response code, the response head, the delayed response and the response body, wherein the response head provides a common response head for selection, the form of the response head generally comprises content and type, and the response head data is submitted in the form of content/type. Forms of the response head include, for example: application/json, text/html, application/xml, and the like.
According to one embodiment of the invention, the simulation response of the present invention is implemented using the existing MOCK SERVER framework. The defined request, field of response is consistent with expected value Expectation (e.g. org. MOCK. Expectation) attribute of the MOCK SERVER, the request defines HTTP request (e.g. org. MOCK. SERVER. model. HTTP request) mapped to MOCK SERVER form, the response defines HTTP response (e.g. org. MOCK. SERVER. model. HTTP response) mapped to MOCK SERVER form, and the related transformation is done using MOCK SERVER's tool.
2. Predefined requests, responses and their correspondences persistently stored in a database
And storing the predefined request, the predefined response and the corresponding relation of the predefined request and the predefined response in a database, and performing simulated response according to the data in the database when the client sends the request. The native MOCK SERVER framework can only store request-response mappings in memory, which means that after a reboot, all the mapping data disappears. The method is based on a MOCKSERVER framework, the request-mapping relation is persisted to a database, and the conversion between the persisted request and response and the content required by MOCK SERVER matching is realized by utilizing the tool class provided by the database.
According to an embodiment of the invention, a request table and a response table are created to hold defined requests and responses, respectively. And, a request-response mapping table is established to represent the correspondence between the request and the response.
According to a preferred embodiment of the present invention, in order to improve processing efficiency, data may be divided by items. The items to which the requests and responses belong may be represented by building an item table.
According to the embodiment of the invention, in order to facilitate data maintenance and authority control, fields such as creator, creation time, modification time and the like are also included in the predefined request.
According to one embodiment of the invention, requests, responses and their correspondences are persisted to a database based on the MOCK SERVER framework.
According to one embodiment of the invention, the attributes of the user-predefined request and response are consistent with the expecteration attribute of the MOCK SERVER framework. With the MOCK SERVER, user-predefined requests and responses are deserialized into an Expectation instance.
FIG. 1 is a flow diagram illustrating the persistence of a request-response according to an embodiment of the present invention. As shown in FIG. 1, according to one embodiment of the present invention, the various attributes of the user-defined request-response mapping are virtually identical to the attributes of Expectation, and when the MOCK platform receives the user's mapping definition (e.g., in the form of a JSON string), it is deserialized into an Expectation instance. The process of implementing persistence of user predefined request-response based on the MOCK SERVER is as follows:
(1) serializing the HTTP request HttpRequest into a JSON character string as the attribute of the custom class RequestPO of the request, namely: construction of RequestPO using HttpRequest;
(2) for the HTTP response HttpResponse, a similar process is done by using the custom class ResponsePO of the response, namely: constructing ResponsePO by using HttpResponse;
(3) storing the requested custom class RequestPO into a request database table tb _ req in a persistent mode, and storing the responded custom class ResponsePO into a response database table tb _ resp in a persistent mode;
(4) establishing a project database table tb _ project for determining to which development project the predefined request and corresponding response belong;
(5) a request-response correspondence database table tb _ req _ resp is established to maintain the correspondence of requests and responses corresponding thereto. Specifically, the mapping relationship of the request database table tb _ req and the response database table tb _ resp is maintained by, for example, the request-response correspondence database table tb _ req _ resp; or the mapping relationships among the request database table tb _ req, the response database table tb _ resp, and the project database table tb _ project are maintained through the request-response correspondence database table tb _ req _ resp.
3. Simulated response of requests
According to the invention, for the received request sent by the client, the simulation response system searches the request-response relation matched with the request in the database, generates the corresponding simulation response according to the relation when the matched request-response relation is found, and then returns the simulation response to the client.
According to an embodiment of the invention, the matching between request-response is based on the matching mechanism of the MOCK SERVER. The request-response mapping may be partitioned by project (project). Different items have their own predefined request-response relationships. Note that different items may have exactly the same request-response relationship. When a client sends a request, a project identifier (project-ID) or a Name (project-Name) needs to be specified at the same time, so that the system only processes the request-response relationship under the project to improve the data processing efficiency. In one embodiment, when a client sends a request, a project-ID can be set in a URL path, for example, the URL path "http:// MOCK. aa. com/MOCK/ID-train/users. html", where part of "/MOCK/ID-train" is used to prompt a MOCK platform and a mapping relation under the project of "ID-train" needs to be obtained in a MOCK manner.
FIG. 2 is a flow chart illustrating the implementation of simulated responses to requests according to an embodiment of the present invention. As shown in fig. 2, according to an embodiment of the present invention, an implementation of a simulated response to a request is based on a MOCK SERVER, and the specific process is as follows:
(1) receiving an HTTP request (HttpServletRequest) sent by a client, wherein the HTTP request can comprise a corresponding item name;
(2) mapping tools using MOCK SERVER (mappers), for example: using the tool class "org. mockserver. mappers. HTTP request to mockserverrrequestdecoder", the HTTP request is converted into a MOCK SERVER form HTTP request org. mockserver. model. HTTP request, abbreviated: HTTP request HTTP in the form of MOCK SERVER;
(3) according to the project name, all the relations related to the project name are taken out from a request-response relation database table tb _ req _ resp of the database, and the request requestPO in each taken-out relation is converted (resolved) into an HTTP request in the form of MOCK SERVER, so that a converted relation set S is formed;
(4) matching the HTTP requests in the MOCK SERVER form obtained in the step (2) with the relationships in the relationship set S obtained in the step (3) one by using a matching tool such as org.mockserver.mathers.HttpRequest, if the HTTP requests in the MOCK SERVER form corresponding to a certain relationship in the relationship set S are the same as the HTTP requests in the MOCK SERVER form obtained in the step (2), turning to the following step (5), otherwise, taking the next relationship in the S for matching, and returning an error code when the matched relationship is not found in the S;
(5) according to the hit relation, determining a response ResponsePO corresponding to the hit relation according to the hit relation, and converting (analyzing) the determined response ResponsePO into an HTTP response HttpResponse in the form of MOCK SERVER;
(6) the HTTP response HttpResponse in the form of MOCKSERVER determined in step (5) is converted into the required simulated response httpservletresponser using the mapping tool of MOCKSERVER (e.g., using the tool class "org.
The method has the advantages that request-response mapping can be preset, even if the requests are completely the same, the request can be fed back by determining which response is used through the mapping switch, and the response content can be in multiple formats such as JSON, HTML and XML; the method has the advantages that hard coding is not needed, only the expected request-response mapping is predefined on the MOCK platform, when the client side initiates the HTTP request, the MOCK platform can match the request with the stored mapping one by one, and the response is performed when the HTTP request is hit; the request-response mapping relation predefined by the user can be persisted into the database, and when the matching mapping is searched, the matching mapping is directly retrieved and converted from the database.
In addition, in the embodiment of the invention, the purpose of cross-domain access can be achieved by setting certain header attributes of the HTTP interface response. The specific header attribute and the corresponding attribute value that can be set are, for example:
setting an attribute value of a header attribute 'Access-Control-all-Origin' to 'a';
setting the attribute value of the header attribute "Access-Control-Allow-Methods" to "CONNECT, DELETE, GET, HEAD, OPTIONS, POST, PUT, TRACE";
setting the attribute value of the header attribute 'Access-Control-Allow-Headers' or 'Access-Control-Expose-Headers' to 'Allow, Content-Encoding, Content-Length, Content-Type, ETag, Expires, Last-Modified, Location, Server, Vary';
setting the attribute value of a header attribute 'Access-Control-Max-Age' to '1';
an attribute value of a header attribute "X-CORS (CORS, Cross-Origin Resource Sharing)" is set to "mock server CORS supported by default, to disabled configuration properties.
Fig. 3 is a schematic diagram of a main flow of a method of 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: receiving a test request sent by a client;
s302: 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;
s303: when the predefined request matched with the test request is found in the database, the corresponding predefined response is determined according to the matched predefined request and the request-response relation table, and the simulated response to the test request is generated according to the determined predefined response and returned to the client.
According to the preferred embodiment of the present invention, the database may further include an item table for indicating predefined requests in the database and item identifications of items to which the responses belong, wherein the item identifications are specified in the test request, and when a predefined request matching the test request is searched in the database, the predefined request is first screened according to the item identifications, so that only the predefined request associated with the item identification is matched.
According to a preferred embodiment of the invention, the predefined request and the predefined response and their correspondence are defined by means of a graphical interface.
According to the preferred embodiment of the present invention, the pre-defined request may further include a creator, a creation time, and a modification time for data maintenance and rights control.
According to a preferred embodiment of the present invention, generating a simulated response to the test request according to the determined predefined response comprises: the responses that match the determined predefined responses are looked up from the response table and the found responses are used as simulated responses to the test request.
Fig. 4 is a schematic diagram of main blocks of an apparatus for 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 responding to a test request from a client in an analog manner according to an embodiment of the present invention mainly includes:
a request receiving module 401, configured to receive a test request sent by a client;
a request searching module 402, configured to search a database for a predefined request matching the test request, wherein the database stores a predefined request table, a response table, and a request-response relationship table;
and a request response module 403, configured to, when a predefined request matching the test request is found in the database, determine a corresponding predefined response according to the matching predefined request and the request-response relationship table, and generate a simulated response to the test request according to the determined predefined response and return the simulated response to the client.
The modules described above are illustrative and may be divided into sub-modules, and different modules may be combined into one module.
According to the preferred embodiment of the present invention, the database may further include an item table for indicating predefined requests in the database and item identifications of items to which the responses belong, wherein the item identifications are specified in the test request, and when a predefined request matching the test request is searched in the database, the predefined request is first screened according to the item identifications, so that only the predefined request associated with the item identification is matched.
According to a preferred embodiment of the invention, the predefined request and the predefined response and their correspondence are defined by means of a graphical interface.
According to the preferred embodiment of the present invention, the pre-defined request may further include a creator, a creation time, and a modification time for data maintenance and rights control.
According to a preferred embodiment of the present invention, the request response module 403 may be further configured to:
the responses that match the determined predefined responses are looked up from the response table and the found responses are used as simulated responses to the test request.
According to the technical scheme of the embodiment of the invention, the predefined request matched with the test request sent by the client is searched in the database, when the predefined request matched with the test request is found in the database, the corresponding predefined response is determined according to the matched predefined request and the request-response relation table, the simulated response to the test request is generated according to the determined predefined response and returned to the client, the request-response mapping can be preset, even if the requests are completely the same, the response can be determined by a mapping switch to feed back the request, and the response content can be in multiple formats of JSON, HTML and XML; the method has the advantages that hard coding is not needed, only the expected request-response mapping is predefined on the MOCK platform, when the client side initiates the HTTP request, the MOCK platform can match the request with the stored mapping one by one, and the response is performed when the HTTP request is hit; the request-response mapping relation predefined by the user can be persisted into the database, and when the matching mapping is searched, the matching mapping is directly retrieved and converted from the database.
Fig. 5 illustrates an exemplary system architecture 500 of a method or corresponding apparatus for simulated response to a test request of a client to which an embodiment of the present invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links 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, to name a few.
The user may use the terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages or the like. The terminal devices 501, 502, 503 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
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 portable computers, desktop computers, and the like.
The server 505 may be a server providing various services, such as a background management server (for example only) providing support for shopping websites browsed by users using the terminal devices 501, 502, 503. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that, the method for responding to the test request of the client in a simulation manner provided by the embodiment of the present invention is generally executed by the server 505, and accordingly, the device for responding to the test request of the client in a simulation manner is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 6, a block diagram of a computer system 600 suitable for use with a terminal device implementing an embodiment of the invention is shown. The terminal device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 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, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic 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, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block 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 will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units (or "modules") described in the embodiments of the present invention may be implemented by software or hardware. The described units (or "modules") may also be provided in a processor, and may be described as, for example: a processor includes a request receiving module, a request lookup module, and a request response module. The names of these units do not in some cases form a limitation on the units themselves, and for example, the request receiving module may also be described as a "module for receiving a test request issued by the client".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: receiving a test request sent by the client; and searching a predefined request matched with the test request in a database, wherein the database stores a predefined request table, a 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.
According to the technical scheme of the embodiment of the invention, the predefined request matched with the test request sent by the client is searched in the database, when the predefined request matched with the test request is found in the database, the corresponding predefined response is determined according to the matched predefined request and the request-response relation table, the simulated response to the test request is generated according to the determined predefined response and returned to the client, the request-response mapping can be preset, even if the requests are completely the same, the response can be determined by a mapping switch to feed back the request, and the response content can be in multiple formats of JSON, HTML and XML; the method has the advantages that hard coding is not needed, only the expected request-response mapping is predefined on the MOCK platform, when the client side initiates the HTTP request, the MOCK platform can match the request with the stored mapping one by one, and the response is performed when the HTTP request is hit; the request-response mapping relation predefined by the user can be persisted into the database, and when the matching mapping is searched, the matching mapping is directly retrieved and converted from the database. The invention realizes the request-response data persistence, has flexible configuration, does not need hard coding, and particularly manages the data according to the project so as to improve the system processing efficiency.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in 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 (8)

* 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
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 (2)

* 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
CN107547312A (en) * 2017-09-21 2018-01-05 广州四三九九信息科技有限公司 Applied program testing method and system

Patent Citations (2)

* 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
CN107547312A (en) * 2017-09-21 2018-01-05 广州四三九九信息科技有限公司 Applied program testing method and system

Cited By (10)

* 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 深圳前海微众银行股份有限公司 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
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
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
WO2021023149A1 (en) Method and apparatus for dynamically returning message
CN110830374B (en) Method and device for gray level release based on SDK
CN111666293A (en) Database access method and device
CN109753424B (en) AB test method and device
CN113536748A (en) Method and device for generating chart data
CN113378346A (en) Method and device for model simulation
CN112948138A (en) Method and device for processing message
CN114896244A (en) Method, device and equipment for configuring database table and computer readable medium
CN113760928A (en) Cache data updating system and method
CN112929453A (en) Method and device for sharing session data
CN108696549B (en) Load balancing method, device and system
CN111984616A (en) Method, device and system for updating shared file
CN112306984A (en) Data source routing method and device
CN112099841A (en) Method and system for generating configuration file
CN112559001A (en) Method and device for updating application
CN113448830B (en) Method and device for managing software information
CN110728009A (en) Simulation method, device and system
CN114285743B (en) Method, device, electronic equipment and storage medium for updating configuration information
CN113495747B (en) Gray scale release method and device
CN108984189B (en) Module parsing method and device
CN112448931B (en) Network hijacking monitoring method and device
CN103036990B (en) A kind of browser client
CN113760886B (en) Method, apparatus, device and computer readable medium for providing data service
CN110262756B (en) Method and device for caching data

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