CN115774990A - RESTful API comparison method, system, equipment and storage medium based on configuration file - Google Patents
RESTful API comparison method, system, equipment and storage medium based on configuration file Download PDFInfo
- Publication number
- CN115774990A CN115774990A CN202310098697.XA CN202310098697A CN115774990A CN 115774990 A CN115774990 A CN 115774990A CN 202310098697 A CN202310098697 A CN 202310098697A CN 115774990 A CN115774990 A CN 115774990A
- Authority
- CN
- China
- Prior art keywords
- result
- item
- old
- dictionary container
- comparison
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 36
- 230000004044 response Effects 0.000 claims abstract description 120
- 238000004422 calculation algorithm Methods 0.000 claims abstract description 17
- 238000004458 analytical method Methods 0.000 claims abstract description 5
- 239000008186 active pharmaceutical agent Substances 0.000 claims description 49
- 238000009877 rendering Methods 0.000 claims description 37
- 238000012545 processing Methods 0.000 claims description 7
- 238000004364 calculation method Methods 0.000 claims description 6
- 238000012163 sequencing technique Methods 0.000 claims 2
- 238000012360 testing method Methods 0.000 abstract description 15
- 238000013461 design Methods 0.000 description 6
- 238000010586 diagram Methods 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 238000004590 computer program Methods 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 210000001503 joint Anatomy 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 230000000007 visual effect Effects 0.000 description 1
Images
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a RESTful API comparison method, a system, equipment and a storage medium based on a configuration file, wherein a new item HTTP request and an old item HTTP request of the RESTful API are obtained through analysis by obtaining the configuration file, then the new item HTTP request and the old item HTTP request of the RESTful API are sent to a target server, a response result of a new item and a response result of an old item are obtained, then a set signaldiff algorithm is used for comparing the response result of the new item with the response result of the old item, a comparison result containing a first color character string, a second color character string and a third color character string is obtained, and finally a corresponding comparison file is generated according to the comparison result, so that automatic testing of the request and the response of the old item and the reconstructed new item RESTful API can be realized. The invention can replace the traditional manual test mode, realize the automatic test comparison of the RESTful API of the old project and the new project, improve the efficiency and the accuracy of the test comparison and save the labor and the time.
Description
Technical Field
The invention belongs to the technical field of automatic testing, and particularly relates to a RESTful API comparison method, a system, equipment and a storage medium based on a configuration file.
Background
In the development process of the software platform, due to iteration reasons, the software platform often has a plurality of projects needing to be reconstructed, and after the projects are reconstructed, a comparison test of corresponding new and old projects is needed. Such project testing is usually done manually, which consumes a lot of labor and time, and the manual testing has a high error rate compared with the error rate. At present, no effective technical means capable of automatically testing the items is available in the market.
Disclosure of Invention
The invention aims to provide a RESTful API comparison method, a RESTful API comparison system, RESTful API comparison equipment and a RESTful API comparison storage medium based on configuration files, which are used for solving the problems in the prior art.
In order to achieve the purpose, the invention adopts the following technical scheme:
in a first aspect, a method for profile-based restful api comparison is provided, including:
acquiring a configuration file, wherein the configuration file comprises a plurality of groups of RESTful APIs, and each group of RESTful APIs comprises a new item HTTP request and an old item HTTP request;
reading and analyzing the configuration file to obtain a new item HTTP request and an old item HTTP request of each RESTful API group;
sending a new item HTTP request and an old item HTTP request of the same RESTful API group to a target server, and receiving a response result of the target server, wherein the response result comprises a response result of the new item and a response result of the old item;
comparing the response result of the new project with the response result of the old project by adopting a set signaliff algorithm to obtain a comparison result, wherein the comparison result comprises a first color character string, a second color character string and a third color character string, the first color character string is a part of the new project response result which corresponds to the same part of the old project response result, and the second color character string and the third color character string are respectively corresponding parts of the new project response result which correspond to different parts of the old project response result;
and generating a comparison file according to the comparison result, and storing, outputting and displaying the comparison file.
In one possible design, the response result for the new item includes a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap, and a response body respBodyMap for the RESTful API new item HTTP request, and the response result for the old item includes a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap, and a response body pBResedoMap for the RESTful API old item HTTP request.
In a possible design, the comparing the response result of the new item with the response result of the old item by using the set signaliff algorithm to obtain a comparison result, including:
creating a reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container of the new item to respectively store a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap and a response body respBodyMap corresponding to the new item HTTP request, creating a reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container of the old item to respectively store a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeader and a response body respBodyMap corresponding to the old item HTTP request;
sorting the storage contents of a new project reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container according to a lexicographical order, then respectively carrying out coding calculation by adopting an MD5 coding algorithm to obtain a first coding result, a second coding result, a third coding result and a third coding result, sorting the storage contents of an old project reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container according to the lexicographic order, then respectively carrying out coding calculation by adopting the MD5 coding algorithm to obtain a fifth coding result, a sixth coding result, a seventh coding result and an eighth coding result;
comparing the first coding result with the fifth coding result, and if the first coding result is the same as the fifth coding result, serializing the storage contents of the new item reqHeaderMap dictionary container and the old item reqHeaderMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; comparing the second coding result with the sixth coding result, if the second coding result is the same as the sixth coding result, serializing the storage contents of the new item reqParamsMap dictionary container and the old item reqParamsMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; comparing the third encoding result with the seventh encoding result, and if the third encoding result is the same as the seventh encoding result, serializing the storage contents of the new item respheidmap dictionary container and the old item respheidmap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; and comparing the fourth encoding result with the eighth encoding result, and if the fourth encoding result is the same as the eighth encoding result, serializing the storage contents of the new item respcodemap dictionary container and the old item respcodemap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color to the comparison result.
In one possible design, the method further includes:
when the first coding result is different from the fifth coding result, traversing and searching corresponding key value pairs from the storage contents of a new item reqHeaderMap dictionary container and an old item reqHeaderMap dictionary container for comparison, rendering the key value pair corresponding to the new item reqHeaderMap dictionary container into a second color when the key value pair of the new item reqHeaderMap dictionary container is identical with the key value pair of the old item reqHeaderMap dictionary container but different in value, rendering the key value pair corresponding to the old item reqHeaderMap dictionary container into a third color, combining the two rendered key value pairs, separating the two key value pairs by using a separator and extracting the two key value pairs into a comparison result;
when the second coding result is different from the sixth coding result, traversing and searching corresponding key value pairs from the storage contents of a new item reqParamsMap dictionary container and an old item reqParamsMap dictionary container to compare, rendering the key value pair corresponding to the new item reqParamsMap dictionary container into a second color when the key value pair of the new item reqParamsMap dictionary container is the same as the key value pair of the old item reqParamsMap dictionary container but the key value pairs have different values, rendering the key value pair corresponding to the old item reqParamsMap dictionary container into a third color, combining the two rendered key value pairs together and separating the two key value pairs by using separators to extract the comparison result;
when the third encoding result is different from the seventh encoding result, traversing and searching corresponding key-value pairs from the storage contents of the new item respheidmap dictionary container and the old item respheidmap dictionary container for comparison, rendering the key-value pair corresponding to the new item respheidmap dictionary container to be a second color when the key-value pair of the new item respheidmap dictionary container is the same as the key-value pair of the old item respheidmap dictionary container but different in value, rendering the key-value pair corresponding to the old item respheidmap dictionary container to be a third color, combining the two rendered pairs of key-value pairs together and separating by using a separator, and extracting the two rendered pairs of key-value pairs into the comparison result;
and when the fourth encoding result is different from the eighth encoding result, traversing and searching corresponding key value pairs from the storage contents of the new item respbedymap dictionary container and the old item respbedymap dictionary container, comparing, rendering the key value pair corresponding to the new item respbedymap dictionary container to be a second color when the key value pair of the new item respbedymap dictionary container is identical to the key value pair of the old item respbedymap dictionary container but different in value, rendering the key value pair corresponding to the old item respbedymap dictionary container to be a third color, combining the two rendered key value pairs together, separating by using a separator, and extracting into the comparison result.
In one possible design, the method further includes:
after the key value pairs of the dictionary containers of the new item and the old item are compared, if the key value pairs still exist in the corresponding dictionary container of the new item, the key value pairs of the corresponding dictionary container of the new item are extracted to add the first identifier, then the key value pairs are rendered into a second color and summarized into a comparison result, if the key value pairs still exist in the corresponding dictionary container of the old item, the key value pairs of the corresponding dictionary container of the old item are extracted to add the second identifier, and then the key value pairs are rendered into a third color and summarized into the comparison result.
In one possible design, the method further includes: after the comparison result is obtained, storing the comparison result into a buffer; when generating the comparison file according to the comparison result, extracting the comparison result in the buffer to generate the comparison file in the HTML format.
In one possible design, the reading and parsing the configuration file includes: the configuration file is read and parsed using the yaml library and the correctness of the configuration file is verified.
In a second aspect, a restful api comparison system based on a configuration file is provided, which includes an obtaining unit, an analyzing unit, a transceiving unit, a comparing unit, and a generating unit, wherein:
the configuration file comprises a plurality of groups of RESTful APIs, and each group of RESTful APIs comprises a new item HTTP request and an old item HTTP request;
the analysis unit is used for reading and analyzing the configuration file to obtain a new item HTTP request and an old item HTTP request of each RESTful API group;
the receiving and sending unit is used for sending a new item HTTP request and an old item HTTP request of the same RESTful API group to the target server and receiving a response result of the target server, wherein the response result comprises a response result of the new item and a response result of the old item;
the comparison unit is used for comparing a response result of a new item with a response result of an old item by adopting a set signaliff algorithm to obtain a comparison result, wherein the comparison result comprises a first color character string, a second color character string and a third color character string, the first color character string is a part of the new item response result, which corresponds to the same part of the old item response result, and the second color character string and the third color character string are respectively corresponding parts of the new item response result and the old item response result, which are different from each other;
and the generating unit is used for generating a comparison file according to the comparison result to store and output for display.
In a third aspect, a profile-based restful api comparison device is provided, comprising:
a memory to store instructions;
a processor configured to read the instructions stored in the memory and execute the method of any of the first aspects according to the instructions.
In a fourth aspect, there is provided a computer-readable storage medium having stored thereon instructions which, when run on a computer, cause the computer to perform the method of any of the first aspects. Also, a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of any of the first aspects is provided.
Has the advantages that: the method comprises the steps of obtaining a configuration file to analyze and obtain a new item HTTP request and an old item HTTP request of the RESTful API, then sending the new item HTTP request and the old item HTTP request of the RESTful API to a target server to obtain a response result of the new item and a response result of the old item, then comparing the response result of the new item with the response result of the old item by using a set signaliff algorithm to obtain a comparison result containing a first color character string, a second color character string and a third color character string, and finally generating a corresponding comparison file according to the comparison result, so that the automatic test of the RESTful API request and the response of the old item and the reconstructed new item can be realized. The invention can replace the traditional manual test mode, realize the automatic test comparison of the RESTful API of the old project and the new project, improve the efficiency and the accuracy of the test comparison and save the labor cost and the time.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the embodiments or the prior art descriptions will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
FIG. 1 is a schematic illustration of the steps of a method in an embodiment of the invention;
FIG. 2 is a schematic diagram showing the configuration of a system according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of the apparatus according to the embodiment of the present invention.
Detailed Description
It should be noted that the description of the embodiments is provided to help understanding of the present invention, and the present invention is not limited thereto. Specific structural and functional details disclosed herein are merely illustrative of example embodiments of the invention. The present invention may, however, be embodied in many alternate forms and should not be construed as limited to the embodiments set forth herein.
It is to be understood that, unless expressly stated or limited otherwise, the term "connected" is to be interpreted broadly, as meaning fixed or detachable connections or integral connections; can be mechanically or electrically connected; they may be connected directly or indirectly through intervening media, or they may be interconnected between two elements. Specific meanings of the above terms in the examples can be understood by those of ordinary skill in the art according to specific situations.
In the following description, specific details are provided to facilitate a thorough understanding of example embodiments. However, it will be understood by those of ordinary skill in the art that the example embodiments may be practiced without these specific details. For example, systems may be shown in block diagrams in order not to obscure the examples in unnecessary detail. In other instances, well-known processes, structures and techniques may be shown without unnecessary detail in order to avoid obscuring the embodiments.
Example 1:
the embodiment provides a restful api comparison method based on a configuration file, as shown in fig. 1, the method includes the following steps:
s1, obtaining a configuration file, wherein the configuration file comprises a plurality of groups of RESTful APIs, and each group of RESTful APIs comprises a new item HTTP request and an old item HTTP request.
In specific implementation, a configuration file written by a user is obtained, wherein the configuration file is a yml format configuration file, the configuration file comprises a plurality of groups of RESTful APIs, and each group of RESTful APIs comprises a new item and an old item HTTP request (request 1 and request 2), a request parameter params and a response result response.
And S2, reading and analyzing the configuration file to obtain a new item HTTP request and an old item HTTP request of each RESTful API group.
In specific implementation, after the configuration file is obtained, the configuration file is read and analyzed by using a yaml library, the correctness of the configuration file is verified, if the correctness is verified, the new item HTTP request and the old item HTTP request of each RESTful API group are obtained, and if the correctness is verified, corresponding error prompt information is returned to a user. The yml file format is a file format written in YAML (YAML air Markup Language), which is an intuitive computer-recognizable data serialization format, and is easily readable by humans, easily interactive with scripting languages, and can be imported by different programming Language programs that support the YAML library.
And S3, sending a new item HTTP request and an old item HTTP request of the same RESTful API group to the target server, and receiving a response result of the target server, wherein the response result comprises a response result of the new item and a response result of the old item.
In specific implementation, in order to test and compare an old item with a reconstructed new item, a new item HTTP request and old item HTTP requests (request 1 and request 2) of the same restful api group need to be sent to a target server, and then a response result of the target server is received, where the response result includes a response result of the new item and a response result of the old item. The response result of the new item comprises a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap and a response body respBodyMap corresponding to the RESTful API new item HTTP request, and the response result of the old item comprises a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap and a response body respBodyMap corresponding to the RESTful API old item HTTP request. The restful api generally uses an HTTP protocol, which is generally divided into a request header, a request parameter, a response header and a response body, so the embodiment mainly develops a comparison based on the above 4 aspects.
And S4, comparing the response result of the new project with the response result of the old project by adopting a set signaliff algorithm to obtain a comparison result, wherein the comparison result comprises a first color character string, a second color character string and a third color character string, the first color character string is a part of the new project response result which is the same as the part of the old project response result, and the second color character string and the third color character string are respectively corresponding parts of the new project response result which is different from the part of the old project response result which is different from the part of the new project response result which is different from the part of the old project response result.
In specific implementation, after the response result of the new project and the response result of the old project are obtained, the set signaliff algorithm is adopted to perform overall comparison, detailed content comparison and residual error processing on the response result of the new project and the response result of the old project, and the specific process comprises the following steps:
1. the reqHeaderMap dictionary container, the reqParamsMap dictionary container, the respHeaderMap dictionary container and the respBodyMap dictionary container of the new item are created to store a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap and a response body respBodyMap corresponding to the new item HTTP request, and the reqHeaderMap dictionary container, the reqParamsMap dictionary container, the respHeaderMap dictionary container and the respBodyMap dictionary container of the old item are created to store a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeader and a response body respBodyMap corresponding to the old item HTTP request. The method mainly compares a request header, request parameters, a response header and a response body of RESTful API, and because the four comparison items are all based on key value pairs, 4 dictionary containers are created for each request, and the reqHeaderMap for comparing the request header, the reqParamsMap for requesting parameters, the respHeaderMap for responding headers and the respBodyMap for responding bodies are respectively stored.
2. And (6) overall comparison. Sorting the storage contents of a new project reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container according to a lexicographical order, then respectively carrying out coding calculation by adopting an MD5 coding algorithm to obtain a first coding result, a second coding result, a third coding result and a third coding result, sorting the storage contents of an old project reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container according to the lexicographic order, then respectively carrying out coding calculation by adopting the MD5 coding algorithm to obtain a fifth coding result, a sixth coding result, a seventh coding result and an eighth coding result;
comparing the first coding result with the fifth coding result, and if the first coding result is the same as the fifth coding result, serializing the storage contents of the new item reqHeaderMap dictionary container and the old item reqHeaderMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; comparing the second coding result with the sixth coding result, if the second coding result is the same as the sixth coding result, serializing the storage contents of the new item reqParamsMap dictionary container and the old item reqParamsMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; comparing the third coding result with the seventh coding result, if the third coding result is the same as the seventh coding result, serializing the storage contents of the new project respHeaderMap dictionary container and the old project respHeaderMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; and comparing the fourth encoding result with the eighth encoding result, if the fourth encoding result is the same as the eighth encoding result, serializing the storage contents of the new project respBodyMap dictionary container and the old project respBodyMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result. The first color may be selected to be gray.
3. And (6) comparing the details. When the first coding result is different from the fifth coding result, traversing and searching corresponding key value pairs from the storage contents of a new item reqHeaderMap dictionary container and an old item reqHeaderMap dictionary container for comparison, rendering the key value pair corresponding to the new item reqHeaderMap dictionary container into a second color when the key value pair of the new item reqHeaderMap dictionary container is identical with the key value pair of the old item reqHeaderMap dictionary container but different in value, rendering the key value pair corresponding to the old item reqHeaderMap dictionary container into a third color, combining the two rendered key value pairs, separating the two key value pairs by using a separator and extracting the two key value pairs into a comparison result;
when the second coding result is different from the sixth coding result, traversing and searching corresponding key value pairs from the storage contents of the new item reqParamsMap dictionary container and the old item reqParamsMap dictionary container for comparison, rendering the key value pair corresponding to the new item reqParamsMap dictionary container into a second color when the key value pair of the new item reqParamsMap dictionary container is the same as the key value pair of the old item reqParamsMap dictionary container but the values are different, rendering the key value pair corresponding to the old item reqParamsMap dictionary container into a third color, combining the two rendered key value pairs together and extracting the two key value pairs into a comparison result after being separated by a separator;
when the third encoding result is different from the seventh encoding result, traversing and searching corresponding key value pairs from the storage contents of a new item respHeaderMap dictionary container and an old item respHeaderMap dictionary container, and comparing, when the key value pair of the new item respHeaderMap dictionary container and the key value pair of the old item respHeaderMap dictionary container have the condition that the keys are the same but the values are different, rendering the key value pair corresponding to the new item respHeaderMap dictionary container to be a second color, rendering the key value pair corresponding to the old item respHeaderMap dictionary container to be a third color, combining the two rendered key value pairs together and separating by using a separator, and extracting the two rendered key value pairs into the comparison result;
and when the fourth encoding result is different from the eighth encoding result, traversing and searching corresponding key value pairs from the storage contents of the new project respBodyMap dictionary container and the old project respBodyMap dictionary container, comparing, rendering the key value pair corresponding to the new project respBodyMap dictionary container to be a second color when the key value pair of the new project respBodyMap dictionary container and the key value pair of the old project respBodyMap dictionary container have the same key but different values, rendering the key value pair corresponding to the old project respBodyMap dictionary container to be a third color, combining the two rendered key value pairs together, separating by using separators, and extracting into the comparison result.
When the key values of the dictionary container corresponding to the new item are the same as the key values of the dictionary container corresponding to the old item, rendering the key values of the dictionary container corresponding to the new item and the key values of the dictionary container corresponding to the old item into a first color, combining the two rendered key value pairs, separating the two key value pairs by using separators, and extracting the two key value pairs into a comparison result. The first color may be gray, the second color may be blue, and the third color may be red. Illustratively, if the old item corresponds to a key-value pair of age:12 and the new item corresponds to a key-value pair of age:13, then the combination will use age:12/13 as the delimiter, "/".
4. And (6) residual error processing. After the key value pairs of the dictionary containers of the new item and the old item are compared, if the key value pairs still exist in the corresponding dictionary container of the new item, the condition that the new item newly-added key value pairs still exist in the corresponding dictionary container of the new item is indicated, at the moment, the key value pairs of the corresponding dictionary container of the new item are extracted to add the first identifier, and then the new item is rendered into a second color to be summarized into a comparison result. If the key value pairs still exist in the corresponding dictionary container of the old item, the condition that the key value pairs of the old item are deleted still exist in the corresponding dictionary container of the old item is indicated, at this time, the key value pairs of the corresponding dictionary container of the old item are extracted to add the second identifier, and then the key value pairs are rendered into a third color to be summarized into the comparison result. The first identifier may take the form of a "+ +", and the second identifier may take the form of a "-", with the corresponding key-value pair illustratively being added with the first identifier as "+ + key2: val2", and the corresponding key-value pair being added with the second identifier as "- -key1: val1".
After the comparison of the four dictionary containers of the new item and the old item is completed, the comparison result needs to be stored in a buffer (buffer) immediately in order to prevent data loss.
And S5, generating a comparison file according to the comparison result, and storing, outputting and displaying the comparison file.
In specific implementation, after the comparison is finished to obtain a final comparison result, the comparison result in the buffer is extracted to generate a comparison file in an HTML format for storage and output display. Because colored texts are supported, the embodiment adopts the comparison file in the HTML format for storage, output and display, so that the result generated by automatic test comparison is visual and clear, and the user is clear at a glance.
Example 2:
the present embodiment provides a restful api comparison system based on a configuration file, as shown in fig. 2, including an obtaining unit, an analyzing unit, a transceiving unit, a comparing unit, and a generating unit, where:
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a configuration file, the configuration file comprises a plurality of groups of RESTful APIs, and each group of RESTful APIs comprises a new item HTTP request and an old item HTTP request;
the analysis unit is used for reading and analyzing the configuration file to obtain a new item HTTP request and an old item HTTP request of each RESTful API group;
the receiving and sending unit is used for sending a new item HTTP request and an old item HTTP request of the same RESTful API group to the target server and receiving a response result of the target server, wherein the response result comprises a response result of the new item and a response result of the old item;
the comparison unit is used for comparing a response result of a new item with a response result of an old item by adopting a set signaliff algorithm to obtain a comparison result, wherein the comparison result comprises a first color character string, a second color character string and a third color character string, the first color character string is a part of the new item response result, which corresponds to the same part of the old item response result, and the second color character string and the third color character string are respectively corresponding parts of the new item response result and the old item response result, which are different from each other;
and the generating unit is used for generating a comparison file according to the comparison result to store and output for display.
Example 3:
the embodiment provides a restful api comparison device based on a configuration file, as shown in fig. 3, at a hardware level, including:
the data interface is used for establishing data butt joint between the processor and the data acquisition assembly so as to acquire a configuration file;
a memory to store instructions;
and the processor is used for reading the instruction stored in the memory and executing the RESTful API comparison method based on the configuration file in the embodiment 1 according to the instruction.
Optionally, the device further comprises an internal bus. The processor, the memory, and the data interface may be interconnected via an internal bus, which may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc.
The Memory may include, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Flash Memory (Flash Memory), a First In First Out (FIFO), a First In Last Out (FILO), and/or the like. The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), application Specific Integrated Circuits (ASICs), field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
Example 4:
the present embodiment provides a computer-readable storage medium having stored thereon instructions that, when executed on a computer, cause the computer to perform the profile-based restful api comparison method of embodiment 1. The computer-readable storage medium refers to a carrier for storing data, and may include, but is not limited to, a floppy disk, an optical disk, a hard disk, a flash Memory, a flash disk and/or a Memory Stick (Memory Stick), etc., and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable system.
The present embodiment also provides a computer program product containing instructions, which when run on a computer, cause the computer to execute the configuration file-based restful api comparison method of embodiment 1. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable system.
Finally, it should be noted that: the above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims (10)
1. The RESTful API comparison method based on the configuration file is characterized by comprising the following steps:
acquiring a configuration file, wherein the configuration file comprises a plurality of groups of RESTful APIs, and each group of RESTful APIs comprises a new item HTTP request and an old item HTTP request;
reading and analyzing the configuration file to obtain a new item HTTP request and an old item HTTP request of each RESTful API group;
sending a new item HTTP request and an old item HTTP request of the same group of RESTful APIs to a target server, and receiving a response result of the target server, wherein the response result comprises a response result of the new item and a response result of the old item;
comparing the response result of the new project with the response result of the old project by adopting a set signaliff algorithm to obtain a comparison result, wherein the comparison result comprises a first color character string, a second color character string and a third color character string, the first color character string is a part of the new project response result which corresponds to the same part of the old project response result, and the second color character string and the third color character string are respectively corresponding parts of the new project response result which correspond to different parts of the old project response result;
and generating a comparison file according to the comparison result, and storing, outputting and displaying the comparison file.
2. The RESTful API comparison method of claim 1, wherein the response result of the new item comprises a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap, and a response body respBodyMap corresponding to the RESTful API new item HTTP request, and the response result of the old item comprises a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap, and a response body respBodyMap corresponding to the RESTful API old item HTTP request.
3. The method of claim 2, wherein comparing the response result of the new item with the response result of the old item using a set signaliff algorithm to obtain a comparison result comprises:
creating a reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container of a new project to respectively store a request header reqHeaderMap, a request parameter reqParamsMap, a response header respHeaderMap and a response body respBodyMap corresponding to a new project HTTP request, and creating a reqHeaderMap dictionary container, a reParamMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container of an old project to respectively store a request header reqHeaderMap, a request parameter reqParamsMap, a response header resEAdermap and a response body respBodyMap corresponding to an old project HTTP request;
sequencing the stored contents of a new project reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container according to a lexicographical order, then respectively carrying out coding calculation by adopting an MD5 coding algorithm to obtain a first coding result, a second coding result, a third coding result and a third coding result, sequencing the stored contents of an old project reqHeaderMap dictionary container, a reqParamsMap dictionary container, a respHeaderMap dictionary container and a respBodyMap dictionary container according to the lexicographic order, then respectively carrying out coding calculation by adopting the MD5 coding algorithm to obtain a fifth coding result, a sixth coding result, a seventh coding result and an eighth coding result;
comparing the first coding result with the fifth coding result, if the first coding result is the same as the fifth coding result, serializing the stored contents of a new project reqHeaderMap dictionary container and an old project reqHeaderMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; comparing the second coding result with the sixth coding result, if the second coding result is the same as the sixth coding result, serializing the storage contents of the new item reqParamsMap dictionary container and the old item reqParamsMap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; comparing the third encoding result with the seventh encoding result, and if the third encoding result is the same as the seventh encoding result, serializing the storage contents of the new item respheidmap dictionary container and the old item respheidmap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color into the comparison result; and comparing the fourth encoding result with the eighth encoding result, and if the fourth encoding result is the same as the eighth encoding result, serializing the storage contents of the new item respcodemap dictionary container and the old item respcodemap dictionary container into character strings, rendering the character strings into a first color, and extracting the first color to the comparison result.
4. The profile-based restful api comparison method of claim 3, wherein the method further comprises:
when the first encoding result is different from the fifth encoding result, traversing and searching corresponding key value pairs from the storage contents of a new item reqHeaderMap dictionary container and an old item reqHeaderMap dictionary container to compare, rendering the key value pair corresponding to the new item reqHeaderMap dictionary container into a second color when the key value pair of the new item reqHeaderMap dictionary container is the same as the key value pair of the old item reqHeaderMap dictionary container but the key value pairs are different from the key value pair of the old item reqHeaderMap dictionary container, rendering the key value pair corresponding to the old item reqHeaderMap dictionary container into a third color, combining the two rendered key value pairs and extracting the two key value pairs into a comparison result after being separated by a separator;
when the second coding result is different from the sixth coding result, traversing and searching corresponding key value pairs from the storage contents of the new item reqParamsMap dictionary container and the old item reqParamsMap dictionary container for comparison, rendering the key value pair corresponding to the new item reqParamsMap dictionary container into a second color when the key value pair of the new item reqParamsMap dictionary container is the same as the key value pair of the old item reqParamsMap dictionary container but the values are different, rendering the key value pair corresponding to the old item reqParamsMap dictionary container into a third color, combining the two rendered key value pairs together and extracting the two key value pairs into a comparison result after being separated by a separator;
when the third encoding result is different from the seventh encoding result, traversing and searching corresponding key-value pairs from the storage contents of the new item respheidmap dictionary container and the old item respheidmap dictionary container for comparison, rendering the key-value pair corresponding to the new item respheidmap dictionary container to be a second color when the key-value pair of the new item respheidmap dictionary container is the same as the key-value pair of the old item respheidmap dictionary container but different in value, rendering the key-value pair corresponding to the old item respheidmap dictionary container to be a third color, combining the two rendered pairs of key-value pairs together and separating by using a separator, and extracting the two rendered pairs of key-value pairs into the comparison result;
and when the fourth encoding result is different from the eighth encoding result, traversing and searching corresponding key value pairs from the storage contents of the new project respBodyMap dictionary container and the old project respBodyMap dictionary container, comparing, rendering the key value pair corresponding to the new project respBodyMap dictionary container to be a second color when the key value pair of the new project respBodyMap dictionary container and the key value pair of the old project respBodyMap dictionary container have the same key but different values, rendering the key value pair corresponding to the old project respBodyMap dictionary container to be a third color, combining the two rendered key value pairs together, separating by using separators, and extracting into the comparison result.
5. The profile-based restful api comparison method of claim 4, wherein the method further comprises:
after the key value pairs of the dictionary containers of the new item and the old item are compared, if the key value pairs still exist in the corresponding dictionary container of the new item, the key value pairs of the corresponding dictionary container of the new item are extracted to add the first identifier, then the key value pairs are rendered into a second color and summarized into a comparison result, if the key value pairs still exist in the corresponding dictionary container of the old item, the key value pairs of the corresponding dictionary container of the old item are extracted to add the second identifier, and then the key value pairs are rendered into a third color and summarized into the comparison result.
6. The profile-based restful api comparison method of claim 1, wherein the method further comprises: after the comparison result is obtained, the comparison result is stored in a buffer; when generating a comparison file according to the comparison result, extracting the comparison result in the buffer to generate the comparison file in the HTML format.
7. The method of claim 1, wherein reading and parsing the configuration file comprises: the configuration file is read and parsed using the yaml library and the correctness of the configuration file is verified.
8. The RESTful API comparison system based on the configuration file is characterized by comprising an acquisition unit, an analysis unit, a transceiving unit, a comparison unit and a generation unit, wherein:
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a configuration file, the configuration file comprises a plurality of groups of RESTful APIs, and each group of RESTful APIs comprises a new item HTTP request and an old item HTTP request;
the analysis unit is used for reading and analyzing the configuration file to obtain a new item HTTP request and an old item HTTP request of each RESTful API group;
the receiving and sending unit is used for sending a new item HTTP request and an old item HTTP request of the same RESTful API group to the target server and receiving a response result of the target server, wherein the response result comprises a response result of the new item and a response result of the old item;
the comparison unit is used for comparing the response result of the new item with the response result of the old item by adopting a set signaliff algorithm to obtain a comparison result, wherein the comparison result comprises a first color character string, a second color character string and a third color character string, the first color character string is a part of the new item response result, which corresponds to the same part of the old item response result, and the second color character string and the third color character string are respectively corresponding parts of the new item response result and the old item response result, which correspond to different parts;
and the generating unit is used for generating a comparison file according to the comparison result to store and output for display.
9. RESTful API contrast equipment based on configuration files is characterized by comprising the following components:
a memory to store instructions;
a processor configured to read the instructions stored in the memory and execute the method of any one of claims 1-7 according to the instructions.
10. A computer-readable storage medium having stored thereon instructions which, when executed on a computer, cause the computer to perform the method of any one of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310098697.XA CN115774990A (en) | 2023-02-10 | 2023-02-10 | RESTful API comparison method, system, equipment and storage medium based on configuration file |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310098697.XA CN115774990A (en) | 2023-02-10 | 2023-02-10 | RESTful API comparison method, system, equipment and storage medium based on configuration file |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115774990A true CN115774990A (en) | 2023-03-10 |
Family
ID=85393454
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310098697.XA Pending CN115774990A (en) | 2023-02-10 | 2023-02-10 | RESTful API comparison method, system, equipment and storage medium based on configuration file |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115774990A (en) |
Citations (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105099811A (en) * | 2015-06-03 | 2015-11-25 | 北京金山安全软件有限公司 | Interface testing method and device |
CN106326108A (en) * | 2016-08-09 | 2017-01-11 | 北京金山安全软件有限公司 | New application testing method and device |
CN110083543A (en) * | 2019-05-07 | 2019-08-02 | 江苏满运软件科技有限公司 | Regression testing method, device, electronic equipment and storage medium |
CN110457628A (en) * | 2019-07-05 | 2019-11-15 | 平安国际智慧城市科技股份有限公司 | Webpage edition correcting method, device, equipment and storage medium |
CN111552632A (en) * | 2020-03-27 | 2020-08-18 | 北京奇艺世纪科技有限公司 | Interface testing method and device |
CN112416749A (en) * | 2020-08-27 | 2021-02-26 | 苏州浪潮智能科技有限公司 | Development code testing method, system, terminal and storage medium of BMC (baseboard management controller) functional items |
CN112491659A (en) * | 2020-12-02 | 2021-03-12 | 广州品唯软件有限公司 | Flow playback test method and device, computer equipment and storage medium |
CN112948271A (en) * | 2021-04-09 | 2021-06-11 | 腾讯科技(深圳)有限公司 | Code testing method, device, equipment and storage medium |
CN112965901A (en) * | 2021-03-05 | 2021-06-15 | 北京百度网讯科技有限公司 | API testing method, server, system and electronic equipment |
CN113238940A (en) * | 2021-05-12 | 2021-08-10 | 建信金融科技有限责任公司 | Interface test result comparison method, device, equipment and storage medium |
CN113282854A (en) * | 2021-06-01 | 2021-08-20 | 平安国际智慧城市科技股份有限公司 | Data request response method and device, electronic equipment and storage medium |
CN114489839A (en) * | 2022-01-12 | 2022-05-13 | 海南车智易通信息技术有限公司 | Method and device for loading configuration data aiming at page and server |
CN114661590A (en) * | 2022-03-14 | 2022-06-24 | 北京百度网讯科技有限公司 | Interface consistency checking method, device, equipment and storage medium |
CN115293279A (en) * | 2022-08-17 | 2022-11-04 | 广州市百果园网络科技有限公司 | Key-value pair difference comparison method and device, equipment and medium thereof |
-
2023
- 2023-02-10 CN CN202310098697.XA patent/CN115774990A/en active Pending
Patent Citations (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105099811A (en) * | 2015-06-03 | 2015-11-25 | 北京金山安全软件有限公司 | Interface testing method and device |
CN106326108A (en) * | 2016-08-09 | 2017-01-11 | 北京金山安全软件有限公司 | New application testing method and device |
CN110083543A (en) * | 2019-05-07 | 2019-08-02 | 江苏满运软件科技有限公司 | Regression testing method, device, electronic equipment and storage medium |
CN110457628A (en) * | 2019-07-05 | 2019-11-15 | 平安国际智慧城市科技股份有限公司 | Webpage edition correcting method, device, equipment and storage medium |
CN111552632A (en) * | 2020-03-27 | 2020-08-18 | 北京奇艺世纪科技有限公司 | Interface testing method and device |
CN112416749A (en) * | 2020-08-27 | 2021-02-26 | 苏州浪潮智能科技有限公司 | Development code testing method, system, terminal and storage medium of BMC (baseboard management controller) functional items |
CN112491659A (en) * | 2020-12-02 | 2021-03-12 | 广州品唯软件有限公司 | Flow playback test method and device, computer equipment and storage medium |
CN112965901A (en) * | 2021-03-05 | 2021-06-15 | 北京百度网讯科技有限公司 | API testing method, server, system and electronic equipment |
CN112948271A (en) * | 2021-04-09 | 2021-06-11 | 腾讯科技(深圳)有限公司 | Code testing method, device, equipment and storage medium |
CN113238940A (en) * | 2021-05-12 | 2021-08-10 | 建信金融科技有限责任公司 | Interface test result comparison method, device, equipment and storage medium |
CN113282854A (en) * | 2021-06-01 | 2021-08-20 | 平安国际智慧城市科技股份有限公司 | Data request response method and device, electronic equipment and storage medium |
CN114489839A (en) * | 2022-01-12 | 2022-05-13 | 海南车智易通信息技术有限公司 | Method and device for loading configuration data aiming at page and server |
CN114661590A (en) * | 2022-03-14 | 2022-06-24 | 北京百度网讯科技有限公司 | Interface consistency checking method, device, equipment and storage medium |
CN115293279A (en) * | 2022-08-17 | 2022-11-04 | 广州市百果园网络科技有限公司 | Key-value pair difference comparison method and device, equipment and medium thereof |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8745641B1 (en) | Automatic verification and anomaly detection in a representational state transfer (REST) application programming interface | |
CN102662966B (en) | Method and system for obtaining subject-oriented dynamic page content | |
US9830316B2 (en) | Content availability for natural language processing tasks | |
WO2022127259A1 (en) | Data cleaning method, apparatus and device, and storage medium | |
CN111273891A (en) | Business decision method and device based on rule engine and terminal equipment | |
CN115757483A (en) | Automatic testing method and device, electronic equipment and storage medium | |
CN113688256A (en) | Construction method and device of clinical knowledge base | |
CN108664546B (en) | XML data structure conversion method and device | |
US20210182183A1 (en) | Enhanced Performance Testing Script Conversion | |
CN111464515A (en) | Data conversion method, device, equipment and storage medium | |
CN115221191A (en) | Virtual column construction method based on data lake and data query method | |
CN113900944A (en) | Logic verification method and device applied to Flink SQL | |
EP1710718B1 (en) | Systems and methods for performing streaming checks on data format for UDTs | |
CN112883088B (en) | Data processing method, device, equipment and storage medium | |
CN115774990A (en) | RESTful API comparison method, system, equipment and storage medium based on configuration file | |
CN117349188B (en) | Test case generation method and device based on large model | |
CN113391972A (en) | Interface testing method and device | |
CN110489740B (en) | Semantic analysis method and related product | |
CN112307751A (en) | Data desensitization method and system based on natural language processing | |
CN117235744B (en) | Source file online method, device, electronic equipment and computer readable medium | |
CN117194437B (en) | File storage method, device, electronic equipment and computer readable medium | |
CN118838798A (en) | Component file detection method, device, apparatus, medium and program product | |
CN116320060A (en) | Message conversion method and device, electronic equipment and storage medium | |
CN117453854A (en) | Ancient book searching and inputting method and device, electronic equipment and storage medium | |
CN118069898A (en) | Log generalization method and device for multiple log sources |
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 | ||
RJ01 | Rejection of invention patent application after publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20230310 |