Merge branch 'modzeleg' into developer
This commit is contained in:
		
							
								
								
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							| @@ -1,7 +1,7 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project version="4"> | ||||
|   <component name="JavadocGenerationManager"> | ||||
|     <option name="OUTPUT_DIRECTORY" value="$USER_HOME$/Documents" /> | ||||
|     <option name="OUTPUT_DIRECTORY" value="$USER_HOME$/Desktop/javadocKlaus" /> | ||||
|     <option name="OPTION_SCOPE" value="private" /> | ||||
|     <option name="OPTION_DOCUMENT_TAG_USE" value="true" /> | ||||
|     <option name="OPTION_DOCUMENT_TAG_AUTHOR" value="true" /> | ||||
|   | ||||
							
								
								
									
										166
									
								
								api-doc.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										166
									
								
								api-doc.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,166 @@ | ||||
| openapi: 3.0.0 | ||||
|  | ||||
| info: | ||||
|   version: 0.0.1 | ||||
|   title: Mocked Service | ||||
|   description: Service for creating your own mocked endpoints | ||||
|  | ||||
| tags: | ||||
|   - name: "MockedMessage" | ||||
|   - name: "MessageHistory" | ||||
|  | ||||
| paths: | ||||
|   /mock/json/{uuid}: | ||||
|     get: | ||||
|       tags: | ||||
|         - "MockedMessage" | ||||
|       description: Generates new uuid and default message | ||||
|       parameters: | ||||
|         - in: path | ||||
|           name: uuid | ||||
|           required: true | ||||
|           description: If not given, server will create and return new one | ||||
|           schema: | ||||
|             type: string | ||||
|             example: '9bfddcc1-ef89-4c53-84e8-c88f13ecc7ec' | ||||
|       responses: | ||||
|         '200': | ||||
|           description: Message list sent | ||||
|           content: | ||||
|             application/json: | ||||
|               schema: | ||||
|                 $ref: '#/components/schemas/MockedMessage' | ||||
|  | ||||
|   /mock/json: | ||||
|     get: | ||||
|       tags: | ||||
|         - "MockedMessage" | ||||
|       description: Generates new uuid and default message | ||||
|       responses: | ||||
|         '200': | ||||
|           description: Message list sent | ||||
|           content: | ||||
|             application/json: | ||||
|               schema: | ||||
|                 $ref: '#/components/schemas/MockedMessage' | ||||
|  | ||||
|     post: | ||||
|       tags: | ||||
|         - "MockedMessage" | ||||
|       description: creates new message in the list | ||||
|       responses: | ||||
|         '200': | ||||
|           description: message has been created | ||||
|  | ||||
|  | ||||
|     put: | ||||
|       tags: | ||||
|         - "MockedMessage" | ||||
|       description: Adds new item or modifies existing | ||||
|       requestBody: | ||||
|         required: true | ||||
|         description: json format describing MockedMessage object | ||||
|         content: | ||||
|           application/json: | ||||
|             schema: | ||||
|               $ref: '#/components/schemas/MockedMessage' | ||||
|       responses: | ||||
|         '200': | ||||
|           description: message has been updated | ||||
|  | ||||
|   /mock/json/{uuid}/{id}: | ||||
|     delete: | ||||
|       tags: | ||||
|         - "MockedMessage" | ||||
|       description: Deletes message of given id assigned to given uuid | ||||
|       parameters: | ||||
|         - in: path | ||||
|           name: uuid | ||||
|           required: true | ||||
|           schema: | ||||
|             type: string | ||||
|             example: '9bfddcc1-ef89-4c53-84e8-c88f13ecc7ec' | ||||
|         - in: path | ||||
|           name: id | ||||
|           required: true | ||||
|           schema: | ||||
|             type: integer | ||||
|             example: 1 | ||||
|       responses: | ||||
|         '200': | ||||
|           description: message has been deleted | ||||
|  | ||||
|   /api/event: | ||||
|     post: | ||||
|       tags: | ||||
|         - "MessageHistory" | ||||
|       description: returns history of responses for given uuid | ||||
|       requestBody: | ||||
|         required: true | ||||
|         description: json format describing Event query | ||||
|         content: | ||||
|           application/json: | ||||
|             schema: | ||||
|               $ref: '#/components/schemas/EventRequest' | ||||
|       responses: | ||||
|         '200': | ||||
|           description: history of given uuid | ||||
|           content: | ||||
|             application/json: | ||||
|               schema: | ||||
|                 $ref: '#/components/schemas/EventEntry' | ||||
|  | ||||
|  | ||||
|  | ||||
| components: | ||||
|   schemas: | ||||
|  | ||||
|     MockedMessage: | ||||
|       description: Model containing data about created response | ||||
|       properties: | ||||
|         mockedResponseId: | ||||
|           type: integer | ||||
|           example: 1 | ||||
|         clientUUID: | ||||
|           type: string | ||||
|           example: '9bfddcc1-ef89-4c53-84e8-c88f13ecc7ec' | ||||
|         mediaType: | ||||
|           type: string | ||||
|           example: 'application/xml' | ||||
|         messageBody: | ||||
|           type: string | ||||
|           example: '<root><element>Hello World</element></root>' | ||||
|         httpStatus: | ||||
|           type: integer | ||||
|           example: 200 | ||||
|         httpHeaders: | ||||
|           type: object | ||||
|           additionalProperties: | ||||
|             type: string | ||||
|  | ||||
|     EventRequest: | ||||
|       description: Model containing data about Event query | ||||
|       properties: | ||||
|         clientUUID: | ||||
|           type: string | ||||
|           example: '9bfddcc1-ef89-4c53-84e8-c88f13ecc7ec' | ||||
|         localDateTimeFrom: | ||||
|           type: string | ||||
|           example: '2021-01-01T01:01:01' | ||||
|         localDateTimeTo: | ||||
|           type: string | ||||
|           example: '2021-01-01T23:59:59' | ||||
|         mockedResponseId: | ||||
|           type: integer | ||||
|           example: 1 | ||||
|  | ||||
|     EventEntry: | ||||
|       description: Model containing data about Event entry | ||||
|       properties: | ||||
|         dateTimeStamp: | ||||
|           type: string | ||||
|           example: '2021-01-01T01:01:01' | ||||
|         interfaceName: | ||||
|           type: string | ||||
|           example: 'MockedMessage - request' | ||||
|  | ||||
| @@ -1,65 +0,0 @@ | ||||
| package com.release11.klaus.controller; | ||||
|  | ||||
|  | ||||
| import com.release11.klaus.model.MockedMessageDto; | ||||
| import com.release11.klaus.service.KlausService; | ||||
| import com.release11.klaus.utilis.BusinessKey; | ||||
| import com.release11.klaus.utilis.TrackingClient; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.http.HttpHeaders; | ||||
| import org.springframework.http.HttpStatus; | ||||
| import org.springframework.http.RequestEntity; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
| import java.util.UUID; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * This controller is responsible for returning the data of given mocked message. The content is made of usual | ||||
|  * http parameters like: body, status, headers etc. | ||||
|  * Basicly the api is responsible for what a client is looking for - a mocked server response. | ||||
|  * Important note: {@link TrackingClient} use is to create logs - the history. | ||||
|  * @author Gabriel Modzelewski | ||||
|  * @author Rafał Żukowicz | ||||
|  */ | ||||
| @RestController | ||||
| @Slf4j | ||||
| @RequestMapping(path = ("/klaus/v1")) | ||||
| @AllArgsConstructor | ||||
| public class KlausController { | ||||
|  | ||||
|     private final KlausService klausService; | ||||
|  | ||||
| //    TODO: Move to MockController | ||||
|     /** | ||||
|      * It's one of the most important features - the bread and butter of the Mocked Service. It's link that allows | ||||
|      * to receive mocked response from the server and use it to mock! | ||||
|      * @param requestEntity Logs the data of request | ||||
|      * @param clientUUID the key-uuid of given set of messages | ||||
|      * @param mockedResponseId unique id of given message | ||||
|      * @return | ||||
|      */ | ||||
|     @RequestMapping(value = "/get/{clientUUID}/{mockedResponseId}") | ||||
|     public ResponseEntity getMockedResponse(RequestEntity<String> requestEntity, | ||||
|                                             @PathVariable UUID clientUUID, | ||||
|                                             @PathVariable int mockedResponseId) { | ||||
|         TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getMockedResponse - request", | ||||
|                 BusinessKey.CLIENT_UUID, String.valueOf(clientUUID), | ||||
|                 BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId))); | ||||
|         log.info(requestEntity.toString().replaceAll("\"", "\\\\\"").substring(1)); | ||||
|         TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getMockedResponse - response", | ||||
|                 BusinessKey.CLIENT_UUID, String.valueOf(clientUUID), | ||||
|                 BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId))); | ||||
|         MockedMessageDto mockedMessageDto = klausService.getMockedResponse(clientUUID, mockedResponseId); | ||||
|         HttpHeaders httpHeaders = new HttpHeaders(); | ||||
|         if (mockedMessageDto.getHttpHeaders() != null) mockedMessageDto.getHttpHeaders().forEach(httpHeaders::set); | ||||
|         return new ResponseEntity<>(mockedMessageDto.getMessageBody(), httpHeaders, | ||||
|                 Objects.requireNonNull(HttpStatus.valueOf(mockedMessageDto.getHttpStatus()))); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -3,11 +3,12 @@ package com.release11.klaus.controller; | ||||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||||
| import com.release11.klaus.model.MockedMessageDto; | ||||
| import com.release11.klaus.service.KlausService; | ||||
| import com.release11.klaus.utilis.BusinessKey; | ||||
| import com.release11.klaus.utilis.TrackingClient; | ||||
| import lombok.AllArgsConstructor; | ||||
| import lombok.SneakyThrows; | ||||
| import lombok.extern.slf4j.Slf4j; | ||||
| import org.springframework.http.MediaType; | ||||
| import org.springframework.http.ResponseEntity; | ||||
| import org.springframework.http.*; | ||||
| import org.springframework.stereotype.Controller; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import org.springframework.web.servlet.ModelAndView; | ||||
| @@ -154,5 +155,31 @@ public class MockController { | ||||
|         return ++highestId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * It's one of the most important features - the bread and butter of the Mocked Service. It's link that allows | ||||
|      * to receive mocked response from the server and use it to mock! | ||||
|      * @param requestEntity Logs the data of request | ||||
|      * @param clientUUID the key-uuid of given set of messages | ||||
|      * @param mockedResponseId unique id of given message | ||||
|      * @return | ||||
|      */ | ||||
|     @GetMapping(value = "/klaus/v1/get/{clientUUID}/{mockedResponseId}") | ||||
|     public ResponseEntity getMockedResponse(RequestEntity<String> requestEntity, | ||||
|                                             @PathVariable UUID clientUUID, | ||||
|                                             @PathVariable int mockedResponseId) { | ||||
|         TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getMockedResponse - request", | ||||
|                 BusinessKey.CLIENT_UUID, String.valueOf(clientUUID), | ||||
|                 BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId))); | ||||
|         log.info(requestEntity.toString().replaceAll("\"", "\\\\\"").substring(1)); | ||||
|         TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getMockedResponse - response", | ||||
|                 BusinessKey.CLIENT_UUID, String.valueOf(clientUUID), | ||||
|                 BusinessKey.MESSAGE_ID, String.valueOf(mockedResponseId))); | ||||
|         MockedMessageDto mockedMessageDto = klausService.getMockedResponse(clientUUID, mockedResponseId); | ||||
|         HttpHeaders httpHeaders = new HttpHeaders(); | ||||
|         if (mockedMessageDto.getHttpHeaders() != null) mockedMessageDto.getHttpHeaders().forEach(httpHeaders::set); | ||||
|         return new ResponseEntity<>(mockedMessageDto.getMessageBody(), httpHeaders, | ||||
|                 Objects.requireNonNull(HttpStatus.valueOf(mockedMessageDto.getHttpStatus()))); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user