Started to removing changing UUID and many messages system
This commit is contained in:
@@ -51,106 +51,35 @@ public class MockController {
|
|||||||
* Returns the full list of messages. It's used by javascript on the client side to initialize homepage
|
* Returns the full list of messages. It's used by javascript on the client side to initialize homepage
|
||||||
* with data from the database.
|
* with data from the database.
|
||||||
* @param uuidValue the key-uuid of given set of messages
|
* @param uuidValue the key-uuid of given set of messages
|
||||||
* @return responds with 200 OK and list of {@link MockedMessageDto}
|
* @return responds with 200 OK and {@link MockedMessageDto}
|
||||||
*/
|
*/
|
||||||
@GetMapping({"/", "/{uuidValue}"})
|
@GetMapping({"/", "/{uuidValue}"})
|
||||||
public List<MockedMessageDto> getListOfMessages(@PathVariable(required = false) String uuidValue){
|
public MockedMessageDto getMessage(@PathVariable(required = false) String uuidValue){
|
||||||
UUID clientUUID;
|
UUID clientUUID;
|
||||||
|
MockedMessageDto message ;
|
||||||
if(uuidValue == null || uuidValue.equals("")) clientUUID = UUID.randomUUID();
|
if(uuidValue == null || uuidValue.equals("")) clientUUID = UUID.randomUUID();
|
||||||
else clientUUID = UUID.fromString(uuidValue);
|
else clientUUID = UUID.fromString(uuidValue);
|
||||||
List<MockedMessageDto> messages = klausService.getAllMockedResponses(clientUUID);
|
message = klausService
|
||||||
if(messages.size() == 0) {
|
.getMockedMessageByClientUUID(clientUUID)
|
||||||
klausService.setMockedResponse(buildDefaultMessage(clientUUID));
|
.orElse( buildDefaultMessage(clientUUID) );
|
||||||
messages = klausService.getAllMockedResponses(clientUUID);
|
|
||||||
}
|
|
||||||
Collections.sort(messages);
|
|
||||||
return messages;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If provided UUID does not exist in database returns ResponseEntity with new generated UUID(if previous UUID is not provided),
|
|
||||||
* or old UUID(if previous UUID is provided). If provided UUID exists function returns provided UUID.
|
|
||||||
* @param givenUUIDValue the UUID client wants to check exsitance in database
|
|
||||||
* @param previousUUIDValue the previous UUID used by client(optional variable)
|
|
||||||
* @return ResponseEntity with UUID
|
|
||||||
*/
|
|
||||||
@RequestMapping(
|
|
||||||
method = RequestMethod.GET ,
|
|
||||||
path = {"/check/{givenUUIDValue}/{previousUUIDValue}",
|
|
||||||
"/check/{givenUUIDValue}"})
|
|
||||||
public ResponseEntity<String> checkUUID(
|
|
||||||
@PathVariable String givenUUIDValue
|
|
||||||
,@PathVariable(required = false) String previousUUIDValue ){
|
|
||||||
try{
|
|
||||||
UUID.fromString(givenUUIDValue);
|
|
||||||
} catch (IllegalArgumentException ex){
|
|
||||||
log.error("Wrong UUID value!");
|
|
||||||
if (previousUUIDValue == null || previousUUIDValue.equals("")){
|
|
||||||
UUID newUUID = UUID.randomUUID();
|
|
||||||
log.info("New UUID generated.");
|
|
||||||
return ResponseEntity.ok(newUUID.toString());
|
|
||||||
}
|
|
||||||
log.info("Previous UUID value restored.");
|
|
||||||
return ResponseEntity.ok(previousUUIDValue);
|
|
||||||
}
|
|
||||||
return ResponseEntity.ok(givenUUIDValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Accepts empty post request and creates new message in given set. The new message has default set of data,
|
|
||||||
* which is constructed in {@link #buildDefaultMessage(UUID, int)} method.
|
|
||||||
* @param uuidValue the key-uuid of given set of messages
|
|
||||||
* @return confirmation response with 200 OK
|
|
||||||
*/
|
|
||||||
@PostMapping("/{uuidValue}")
|
|
||||||
public ResponseEntity<String> addNewMessage(@PathVariable String uuidValue){
|
|
||||||
UUID clientUUID = UUID.fromString(uuidValue);
|
|
||||||
List<MockedMessageDto> messages = klausService.getAllMockedResponses(clientUUID);
|
|
||||||
MockedMessageDto nextMessage = buildDefaultMessage(clientUUID, findNextId(messages));
|
|
||||||
return klausService.setMockedResponse(nextMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes message of given id via client request
|
|
||||||
* @param uuidValue the key-uuid of given set of messages
|
|
||||||
* @param idValue unique id of given message
|
|
||||||
* @return after deletion the confirmation is send with status 200 OK
|
|
||||||
*/
|
|
||||||
@DeleteMapping("/{uuidValue}/{idValue}")
|
|
||||||
public ResponseEntity<String> removeMessage(@PathVariable String uuidValue,
|
|
||||||
@PathVariable String idValue){
|
|
||||||
UUID clientUUID = UUID.fromString(uuidValue);
|
|
||||||
int id = Integer.parseInt(idValue);
|
|
||||||
return klausService.deleteMockedResponse(clientUUID, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recalls {@link #buildDefaultMessage(UUID)} for message construction and sets id of message
|
|
||||||
* @param uuid the key-uuid of given set of messages
|
|
||||||
* @param id unique id of given message
|
|
||||||
* @return message with default dataset and set id
|
|
||||||
*/
|
|
||||||
private static MockedMessageDto buildDefaultMessage(UUID uuid, int id){
|
|
||||||
MockedMessageDto message = buildDefaultMessage(uuid);
|
|
||||||
message.setMockedResponseId(id);
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs message with default set of data
|
* Constructs message with default set of data
|
||||||
* @param uuid the key-uuid of given set of messages
|
* @param uuid the key-uuid of given set of messages
|
||||||
* @return message with default dataset
|
* @return message with default dataset
|
||||||
*/
|
*/
|
||||||
private static MockedMessageDto buildDefaultMessage(UUID uuid){
|
private MockedMessageDto buildDefaultMessage(UUID uuid){
|
||||||
Map<String, String> headers = new HashMap<>();
|
Map<String, String> headers = new HashMap<>();
|
||||||
headers.put("Keep-Alive", "timeout=60");
|
headers.put("Keep-Alive", "timeout=60");
|
||||||
headers.put("Connection", "keep-alive");
|
headers.put("Connection", "keep-alive");
|
||||||
headers.put("Date", LocalDateTime.now().toString());
|
headers.put("Date", LocalDateTime.now().toString());
|
||||||
return MockedMessageDto.builder()
|
MockedMessageDto mockedMessageDto = MockedMessageDto.builder()
|
||||||
.clientUUID(uuid)
|
.clientUUID(uuid)
|
||||||
.mockedResponseId(1)
|
.contentType(MediaType.APPLICATION_XML_VALUE)
|
||||||
.mediaType(MediaType.APPLICATION_XML_VALUE)
|
|
||||||
.messageBody("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
.messageBody("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||||
"<note>\n" +
|
"<note>\n" +
|
||||||
" <to>Tove</to>\n" +
|
" <to>Tove</to>\n" +
|
||||||
@@ -161,38 +90,24 @@ public class MockController {
|
|||||||
.httpHeaders(headers)
|
.httpHeaders(headers)
|
||||||
.httpStatus(200)
|
.httpStatus(200)
|
||||||
.build();
|
.build();
|
||||||
|
klausService.setMockedResponse(mockedMessageDto);
|
||||||
|
return mockedMessageDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Finds the highest id in the list and returns it incremented by 1
|
|
||||||
* @param messages list of messages
|
|
||||||
* @return highest id incremented by 1
|
|
||||||
*/
|
|
||||||
public static int findNextId(List<MockedMessageDto> messages) {
|
|
||||||
int highestId = 0;
|
|
||||||
for (MockedMessageDto m : messages)
|
|
||||||
highestId = highestId > m.getMockedResponseId() ? highestId : m.getMockedResponseId();
|
|
||||||
return ++highestId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It's one of the most important features - the bread and butter of the Mocked Service. It's link that allows
|
* 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!
|
* to receive mocked response from the server and use it to mock!
|
||||||
* @param clientUUID the key-uuid of given set of messages
|
* @param clientUUID the key-uuid of given set of messages
|
||||||
* @param mockedResponseId unique id of given message
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping(value = "/r/{clientUUID}/{mockedResponseId}")
|
@RequestMapping(value = "/r/{clientUUID}")
|
||||||
public ResponseEntity getMockedResponse(
|
public ResponseEntity getMockedResponse(
|
||||||
@PathVariable UUID clientUUID,
|
@PathVariable UUID clientUUID) {
|
||||||
@PathVariable int mockedResponseId) {
|
MockedMessageDto mockedMessageDto = klausService.getMockedResponse(clientUUID);
|
||||||
MockedMessageDto mockedMessageDto = klausService.getMockedResponse(clientUUID, mockedResponseId);
|
|
||||||
HttpHeaders httpHeaders = new HttpHeaders();
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
if (mockedMessageDto.getHttpHeaders() != null) mockedMessageDto.getHttpHeaders().forEach(httpHeaders::set);
|
if (mockedMessageDto.getHttpHeaders() != null) mockedMessageDto.getHttpHeaders().forEach(httpHeaders::set);
|
||||||
httpHeaders.add("Content-Type", mockedMessageDto.getMediaType());
|
httpHeaders.add("Content-Type", mockedMessageDto.getContentType());
|
||||||
return new ResponseEntity<>(mockedMessageDto.getMessageBody(), httpHeaders,
|
return new ResponseEntity<>(mockedMessageDto.getMessageBody(), httpHeaders,
|
||||||
Objects.requireNonNull(HttpStatus.valueOf(mockedMessageDto.getHttpStatus())));
|
Objects.requireNonNull(HttpStatus.valueOf(mockedMessageDto.getHttpStatus())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,12 +47,10 @@ public class RequestHistoryController {
|
|||||||
/**
|
/**
|
||||||
* Returns the list of Events of last 24h from given date.
|
* Returns the list of Events of last 24h from given date.
|
||||||
* @param uuid unique id of message list
|
* @param uuid unique id of message list
|
||||||
* @param messageId unique id of message in message list
|
|
||||||
* @return list of {@link RequestHistory}
|
* @return list of {@link RequestHistory}
|
||||||
*/
|
*/
|
||||||
@GetMapping(path = "/{uuid}/{messageId}")
|
@GetMapping(path = "/{uuid}/{messageId}")
|
||||||
public ResponseEntity<List<RequestHistoryDTO>> getLastDay(@PathVariable UUID uuid,
|
public ResponseEntity<List<RequestHistoryDTO>> getLastDay(@PathVariable UUID uuid){
|
||||||
@PathVariable Integer messageId){
|
|
||||||
LocalDateTime requestTime = LocalDateTime.now();
|
LocalDateTime requestTime = LocalDateTime.now();
|
||||||
LocalDateTime dayBeforeRequest = requestTime.minusDays(1L);
|
LocalDateTime dayBeforeRequest = requestTime.minusDays(1L);
|
||||||
List<RequestHistoryDTO> requestHistory = service.getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(
|
List<RequestHistoryDTO> requestHistory = service.getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(
|
||||||
@@ -60,7 +58,6 @@ public class RequestHistoryController {
|
|||||||
.localDateTimeFrom(dayBeforeRequest)
|
.localDateTimeFrom(dayBeforeRequest)
|
||||||
.localDateTimeTo(requestTime)
|
.localDateTimeTo(requestTime)
|
||||||
.clientUUID(uuid)
|
.clientUUID(uuid)
|
||||||
.mockedResponseId(messageId)
|
|
||||||
.build()
|
.build()
|
||||||
).stream()
|
).stream()
|
||||||
.map(mapper::requestHistoryToRequestHistoryDTO)
|
.map(mapper::requestHistoryToRequestHistoryDTO)
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ public class IncomingMockRequestInterceptor implements HandlerInterceptor {
|
|||||||
RequestHistoryDTO historyDTO = RequestHistoryDTO.builder()
|
RequestHistoryDTO historyDTO = RequestHistoryDTO.builder()
|
||||||
.httpMethod(HttpMethod.valueOf(httpRequest.getMethod()))
|
.httpMethod(HttpMethod.valueOf(httpRequest.getMethod()))
|
||||||
.headers( headers )
|
.headers( headers )
|
||||||
.messageID(Integer.valueOf(pathVariable.get("mockedResponseId")))
|
|
||||||
.clientUUID(UUID.fromString(pathVariable.get("clientUUID")))
|
.clientUUID(UUID.fromString(pathVariable.get("clientUUID")))
|
||||||
.dateTimeStamp(LocalDateTime.now())
|
.dateTimeStamp(LocalDateTime.now())
|
||||||
.requestBody(requestBody)
|
.requestBody(requestBody)
|
||||||
|
|||||||
@@ -4,15 +4,23 @@ import com.r11.tools.model.MockedMessage;
|
|||||||
import com.r11.tools.model.MockedMessageDto;
|
import com.r11.tools.model.MockedMessageDto;
|
||||||
import org.mapstruct.*;
|
import org.mapstruct.*;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates key value for redis entry
|
* Creates key value for redis entry
|
||||||
* @author Rafał Źukowicz
|
* @author Rafał Źukowicz
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MockedMessageMapper {
|
public interface MockedMessageMapper {
|
||||||
@Mapping( target = "compositePrimaryKey", expression = "java(mockedMessageDto.getClientUUID() + \"_\"" +
|
|
||||||
" + mockedMessageDto.getMockedResponseId())")
|
|
||||||
@Mapping( target = "createdAt" , expression = "java(java.time.LocalDateTime.now())")
|
@Mapping( target = "createdAt" , expression = "java(java.time.LocalDateTime.now())")
|
||||||
MockedMessage mockedMessageDtoToMockedMessage(MockedMessageDto mockedMessageDto);
|
MockedMessage mockedMessageDtoToMockedMessage(MockedMessageDto mockedMessageDto);
|
||||||
MockedMessageDto mockedMessageToMockedMessageDto(MockedMessage mockedMessage);
|
MockedMessageDto mockedMessageToMockedMessageDto(MockedMessage mockedMessage);
|
||||||
|
|
||||||
|
default Optional<MockedMessageDto> optionalMockedMessageToOptionalMockedMessageDTO(Optional<MockedMessage> optionalMockedMessage){
|
||||||
|
return optionalMockedMessage.map(this::mockedMessageToMockedMessageDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
default Optional<MockedMessage> optionalMockedMessageDTOToOptionalMockedMessage(Optional<MockedMessageDto> optionalMockedMessageDto){
|
||||||
|
return optionalMockedMessageDto.map(this::mockedMessageDtoToMockedMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import org.mapstruct.Mapping;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface RequestHistoryMapper {
|
public interface RequestHistoryMapper {
|
||||||
|
|
||||||
@Mapping(target = "id", expression = "java(null)")
|
|
||||||
@Mapping(target = "clientUUID", expression = "java(requestHistoryDTO.getClientUUID().toString())")
|
@Mapping(target = "clientUUID", expression = "java(requestHistoryDTO.getClientUUID().toString())")
|
||||||
RequestHistory requestHistoryDTOToRequestHistory(RequestHistoryDTO requestHistoryDTO);
|
RequestHistory requestHistoryDTOToRequestHistory(RequestHistoryDTO requestHistoryDTO);
|
||||||
@Mapping(target = "clientUUID", expression = "java(java.util.UUID.fromString(requestHistory.getClientUUID()))")
|
@Mapping(target = "clientUUID", expression = "java(java.util.UUID.fromString(requestHistory.getClientUUID()))")
|
||||||
|
|||||||
@@ -25,6 +25,5 @@ public class HistoryRequestModel {
|
|||||||
private LocalDateTime localDateTimeFrom;
|
private LocalDateTime localDateTimeFrom;
|
||||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||||
private LocalDateTime localDateTimeTo;
|
private LocalDateTime localDateTimeTo;
|
||||||
private Integer mockedResponseId;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
package com.r11.tools.model;
|
package com.r11.tools.model;
|
||||||
|
|
||||||
import com.r11.tools.model.constraints.HttpCode;
|
import com.r11.tools.model.constraints.HttpCode;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
import javax.validation.constraints.Positive;
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -14,6 +9,11 @@ import org.springframework.data.annotation.Id;
|
|||||||
import org.springframework.data.redis.core.RedisHash;
|
import org.springframework.data.redis.core.RedisHash;
|
||||||
import org.springframework.data.redis.core.index.Indexed;
|
import org.springframework.data.redis.core.index.Indexed;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MockedMessage redis entity pojo
|
* MockedMessage redis entity pojo
|
||||||
* @author Rafał Żukowicz
|
* @author Rafał Żukowicz
|
||||||
@@ -24,13 +24,10 @@ import org.springframework.data.redis.core.index.Indexed;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MockedMessage implements Serializable {
|
public class MockedMessage implements Serializable {
|
||||||
@Id
|
|
||||||
private String compositePrimaryKey;
|
|
||||||
@Indexed
|
@Indexed
|
||||||
|
@Id
|
||||||
private UUID clientUUID;
|
private UUID clientUUID;
|
||||||
@Positive
|
private String contentType;
|
||||||
private Integer mockedResponseId;
|
|
||||||
private String mediaType;
|
|
||||||
private String messageBody;
|
private String messageBody;
|
||||||
private Map<String, String> httpHeaders;
|
private Map<String, String> httpHeaders;
|
||||||
@HttpCode
|
@HttpCode
|
||||||
@@ -38,5 +35,3 @@ public class MockedMessage implements Serializable {
|
|||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package com.r11.tools.model;
|
package com.r11.tools.model;
|
||||||
|
|
||||||
import com.r11.tools.model.constraints.HttpCode;
|
import com.r11.tools.model.constraints.HttpCode;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import javax.validation.constraints.Positive;
|
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alternative version of {@link MockedMessage} used in http body
|
* Alternative version of {@link MockedMessage} used in http body
|
||||||
@@ -18,19 +17,12 @@ import lombok.*;
|
|||||||
@ToString
|
@ToString
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class MockedMessageDto implements Serializable, Comparable<MockedMessageDto> {
|
public class MockedMessageDto implements Serializable{
|
||||||
private UUID clientUUID;
|
private UUID clientUUID;
|
||||||
@NotNull
|
private String contentType;
|
||||||
@Positive
|
|
||||||
private Integer mockedResponseId;
|
|
||||||
private String mediaType;
|
|
||||||
private String messageBody;
|
private String messageBody;
|
||||||
private Map<String, String> httpHeaders;
|
private Map<String, String> httpHeaders;
|
||||||
@HttpCode
|
@HttpCode
|
||||||
private Integer httpStatus;
|
private Integer httpStatus;
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(MockedMessageDto message) {
|
|
||||||
return this.mockedResponseId > message.getMockedResponseId() ? 1 : -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,14 +26,11 @@ import java.util.Map;
|
|||||||
@RedisHash("mockHistory")
|
@RedisHash("mockHistory")
|
||||||
public class RequestHistory implements Comparable<RequestHistory>, Serializable {
|
public class RequestHistory implements Comparable<RequestHistory>, Serializable {
|
||||||
|
|
||||||
@Id
|
|
||||||
private String id;
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-ddTHH:mm:ss")
|
@DateTimeFormat(pattern = "yyyy-MM-ddTHH:mm:ss")
|
||||||
private LocalDateTime dateTimeStamp;
|
private LocalDateTime dateTimeStamp;
|
||||||
@Indexed
|
@Indexed
|
||||||
|
@Id
|
||||||
private String clientUUID;
|
private String clientUUID;
|
||||||
@Indexed
|
|
||||||
private Integer messageID;
|
|
||||||
private Map<String,String> headers;
|
private Map<String,String> headers;
|
||||||
private HttpMethod httpMethod;
|
private HttpMethod httpMethod;
|
||||||
private String requestBody;
|
private String requestBody;
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public class RequestHistoryDTO {
|
|||||||
private UUID clientUUID;
|
private UUID clientUUID;
|
||||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
|
||||||
private LocalDateTime dateTimeStamp;
|
private LocalDateTime dateTimeStamp;
|
||||||
private Integer messageID;
|
|
||||||
private Map<String,String> headers;
|
private Map<String,String> headers;
|
||||||
private HttpMethod httpMethod;
|
private HttpMethod httpMethod;
|
||||||
private String requestBody;
|
private String requestBody;
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
*/
|
*/
|
||||||
@Repository
|
@Repository
|
||||||
@Transactional
|
@Transactional
|
||||||
public interface MockedResponseRepository extends CrudRepository<MockedMessage, String> {
|
public interface MockedResponseRepository extends CrudRepository<MockedMessage, UUID> {
|
||||||
/**
|
/**
|
||||||
* Finds all messages by their uuid
|
* Finds all messages by their uuid
|
||||||
* @param clientUUID the key-uuid of given set of messages
|
* @param clientUUID the key-uuid of given set of messages
|
||||||
* @return Optional of list of {@link com.r11.tools.model.MockedMessage}
|
* @return Optional of list of {@link com.r11.tools.model.MockedMessage}
|
||||||
*/
|
*/
|
||||||
Optional<List<MockedMessage>> findAllByClientUUID(UUID clientUUID);
|
Optional<MockedMessage> findAllByClientUUID(UUID clientUUID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,5 @@ import java.util.List;
|
|||||||
@Repository
|
@Repository
|
||||||
@Transactional
|
@Transactional
|
||||||
public interface RequestHistoryRepository extends CrudRepository<RequestHistory,String> {
|
public interface RequestHistoryRepository extends CrudRepository<RequestHistory,String> {
|
||||||
List<RequestHistory> findAllByClientUUIDAndMessageID(
|
List<RequestHistory> findAllByClientUUID(String clientUUID);
|
||||||
String clientUUID,
|
|
||||||
Integer messageID);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package com.r11.tools.service;
|
package com.r11.tools.service;
|
||||||
|
|
||||||
import com.r11.tools.model.MockedMessageDto;
|
import com.r11.tools.model.MockedMessageDto;
|
||||||
import java.util.List;
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -12,8 +13,7 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public interface KlausService {
|
public interface KlausService {
|
||||||
ResponseEntity<String> deleteMockedResponse(UUID clientUUID, int mockedResponseId);
|
Optional<MockedMessageDto> getMockedMessageByClientUUID(UUID clientUUID);
|
||||||
List<MockedMessageDto> getAllMockedResponses(UUID clientUUID);
|
MockedMessageDto getMockedResponse(UUID clientUUID);
|
||||||
MockedMessageDto getMockedResponse(UUID clientUUID, int mockedResponseId);
|
|
||||||
ResponseEntity<String> setMockedResponse(MockedMessageDto mockedMessageDto);
|
ResponseEntity<String> setMockedResponse(MockedMessageDto mockedMessageDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,16 +13,15 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service for {@link com.r11.tools.controller.MockController} and {@link com.r11.tools.controller.MockController}
|
* Service for {@link com.r11.tools.controller.MockController} and {@link com.r11.tools.controller.MockController}
|
||||||
* Allows for performing CRUD operations on {@link MockedMessageDto}
|
* Allows for performing CRUD operations on {@link MockedMessageDto}
|
||||||
* @author Rafał Żukowicz
|
* @author Rafał Żukowicz
|
||||||
* @author Gabriel Modzelewski
|
* @author Gabriel Modzelewski
|
||||||
|
* @author Mikołaj Widła
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -31,20 +30,6 @@ public class KlausServiceImpl implements KlausService {
|
|||||||
private final Logger log = LogManager.getRootLogger();
|
private final Logger log = LogManager.getRootLogger();
|
||||||
private final MockedResponseRepository mockedResponseRepository;
|
private final MockedResponseRepository mockedResponseRepository;
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes message of given id in given key-uuid set
|
|
||||||
* @param clientUUID the key-uuid of given set of messages
|
|
||||||
* @param mockedResponseId unique id of given message
|
|
||||||
* @return confirmation and status 200 OK
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ResponseEntity<String> deleteMockedResponse(UUID clientUUID, int mockedResponseId) {
|
|
||||||
String key = clientUUID.toString() + "_" + mockedResponseId;
|
|
||||||
mockedResponseRepository.deleteById(key);
|
|
||||||
log.info("Message: "+mockedResponseId+" has been removed.");
|
|
||||||
return new ResponseEntity<>("MockedResponse has been removed successfully",
|
|
||||||
new HttpHeaders(), HttpStatus.ACCEPTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all messages of given key-uuid
|
* Returns all messages of given key-uuid
|
||||||
@@ -52,28 +37,23 @@ public class KlausServiceImpl implements KlausService {
|
|||||||
* @return List of {@link MockedMessageDto}
|
* @return List of {@link MockedMessageDto}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<MockedMessageDto> getAllMockedResponses(UUID clientUUID){
|
public Optional<MockedMessageDto> getMockedMessageByClientUUID(UUID clientUUID){
|
||||||
Optional<List<MockedMessage>> listOptional = mockedResponseRepository.findAllByClientUUID(clientUUID);
|
Optional<MockedMessage> mockedMessageOptional = mockedResponseRepository.findAllByClientUUID(clientUUID);
|
||||||
log.info("Messages for UUID: "+clientUUID+" has been fetched from DB.");
|
log.info("Message for UUID: "+clientUUID+" has been fetched from DB.");
|
||||||
return listOptional.map(mockedMessages -> mockedMessages.stream()
|
return mockedMessageMapper.optionalMockedMessageToOptionalMockedMessageDTO(mockedMessageOptional);
|
||||||
.map(mockedMessageMapper::mockedMessageToMockedMessageDto)
|
|
||||||
.collect(Collectors.toList())).orElse(List.of());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns {@link MockedMessageDto} of given id and key-uuid. If message doesn't then empty message is returned
|
* Returns {@link MockedMessageDto} of given id and key-uuid. If message doesn't then empty message is returned
|
||||||
* @param clientUUID the key-uuid of given set of messages
|
* @param clientUUID the key-uuid of given set of messages
|
||||||
* @param mockedResponseId unique id of given message
|
|
||||||
* @return {@link MockedMessageDto} object
|
* @return {@link MockedMessageDto} object
|
||||||
*/
|
*/
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public MockedMessageDto getMockedResponse(UUID clientUUID, int mockedResponseId){
|
public MockedMessageDto getMockedResponse(UUID clientUUID){
|
||||||
String key = clientUUID.toString() + "_" + mockedResponseId;
|
Optional<MockedMessage> optionalMockedMessage = mockedResponseRepository.findById(clientUUID);
|
||||||
Optional<MockedMessage> optionalMockedMessage = mockedResponseRepository.findById(key);
|
|
||||||
MockedMessageDto mockedMessageDto = MockedMessageDto.builder()
|
MockedMessageDto mockedMessageDto = MockedMessageDto.builder()
|
||||||
.clientUUID(clientUUID)
|
.clientUUID(clientUUID)
|
||||||
.mockedResponseId(mockedResponseId)
|
|
||||||
.build();
|
.build();
|
||||||
if (optionalMockedMessage.isPresent()) {
|
if (optionalMockedMessage.isPresent()) {
|
||||||
mockedMessageDto = mockedMessageMapper.mockedMessageToMockedMessageDto(optionalMockedMessage.get());
|
mockedMessageDto = mockedMessageMapper.mockedMessageToMockedMessageDto(optionalMockedMessage.get());
|
||||||
|
|||||||
@@ -33,9 +33,8 @@ public class RequestHistoryServiceImpl implements RequestHistoryService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<RequestHistory> getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(HistoryRequestModel historyRequestModel) {
|
public List<RequestHistory> getHistoryRecordsBetweenDatesAndByUUIDAndMessageId(HistoryRequestModel historyRequestModel) {
|
||||||
List<RequestHistory> history = repository.findAllByClientUUIDAndMessageID(
|
List<RequestHistory> history = repository.findAllByClientUUID(
|
||||||
historyRequestModel.getClientUUID().toString(),
|
historyRequestModel.getClientUUID().toString()
|
||||||
historyRequestModel.getMockedResponseId()
|
|
||||||
);
|
);
|
||||||
Collections.sort(history);
|
Collections.sort(history);
|
||||||
|
|
||||||
|
|||||||
@@ -62,10 +62,6 @@ body {
|
|||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tool.extended .tool-context {
|
|
||||||
width: 75%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tool.extended .tool-extention {
|
.tool.extended .tool-extention {
|
||||||
width: 20%;
|
width: 20%;
|
||||||
padding-top: 2%;
|
padding-top: 2%;
|
||||||
|
|||||||
@@ -217,19 +217,19 @@ function initializeMock(index){
|
|||||||
clearMock();
|
clearMock();
|
||||||
fillStaticFields(json[index].clientUUID
|
fillStaticFields(json[index].clientUUID
|
||||||
, json[index].mockedResponseId
|
, json[index].mockedResponseId
|
||||||
, json[index].mediaType
|
, json[index].contentType
|
||||||
, json[index].messageBody
|
, json[index].messageBody
|
||||||
, json[index].httpStatus);
|
, json[index].httpStatus);
|
||||||
fillHeaderTable(json[index].httpHeaders);
|
fillHeaderTable(json[index].httpHeaders);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillStaticFields(uuid, id, mediaType, body, httpStatus){
|
function fillStaticFields(uuid, id, contentType, body, httpStatus){
|
||||||
let link = createLink(uuid,id);
|
let link = createLink(uuid,id);
|
||||||
let linkHtml = '<a class="hyperlink" target="_blank" href="'+link+'">'+link+'</a>';
|
let linkHtml = '<a class="hyperlink" target="_blank" href="'+link+'">'+link+'</a>';
|
||||||
$('#messageLink').html(linkHtml);
|
$('#messageLink').html(linkHtml);
|
||||||
$('#httpStatus').val(httpStatus);
|
$('#httpStatus').val(httpStatus);
|
||||||
$('#uuid-input').val(uuid);
|
$('#uuid-input').val(uuid);
|
||||||
$('#typeSelector').val(mediaType);
|
$('#typeSelector').val(contentType);
|
||||||
$('#bodyEditor').val(body);
|
$('#bodyEditor').val(body);
|
||||||
$('#mockedMessageId').html(id);
|
$('#mockedMessageId').html(id);
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ function fillMessageList(){
|
|||||||
$("#listItems").html('');
|
$("#listItems").html('');
|
||||||
var innerHTML = '';
|
var innerHTML = '';
|
||||||
for(let i=0; i<json.length; i++){
|
for(let i=0; i<json.length; i++){
|
||||||
innerHTML += generateMessageTileHtml(json[i].mockedResponseId, json[i].httpStatus, json[i].mediaType);
|
innerHTML += generateMessageTileHtml(json[i].mockedResponseId, json[i].httpStatus, json[i].contentType);
|
||||||
}
|
}
|
||||||
$("#listItems").append(innerHTML);
|
$("#listItems").append(innerHTML);
|
||||||
$('.tile').click(function(e) {
|
$('.tile').click(function(e) {
|
||||||
@@ -475,7 +475,7 @@ function selectMessage(id){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function generateMessageTileHtml(id, httpStatus, mediaType){
|
function generateMessageTileHtml(id, httpStatus, contentType){
|
||||||
var innerHTML = '' +
|
var innerHTML = '' +
|
||||||
'<div tileid="' + id + '" class="tile">' +
|
'<div tileid="' + id + '" class="tile">' +
|
||||||
'<div class="content">' +
|
'<div class="content">' +
|
||||||
@@ -515,8 +515,7 @@ function generateJson(){
|
|||||||
var newJson =
|
var newJson =
|
||||||
{
|
{
|
||||||
clientUUID: json[jsonIndex].clientUUID,
|
clientUUID: json[jsonIndex].clientUUID,
|
||||||
mockedResponseId: json[jsonIndex].mockedResponseId,
|
contentType: $('#typeSelector').val(),
|
||||||
mediaType: $('#typeSelector').val(),
|
|
||||||
messageBody: $('#bodyEditor').val(),
|
messageBody: $('#bodyEditor').val(),
|
||||||
httpStatus: $('#httpStatus').val(),
|
httpStatus: $('#httpStatus').val(),
|
||||||
httpHeaders: {},
|
httpHeaders: {},
|
||||||
|
|||||||
@@ -43,36 +43,9 @@
|
|||||||
<div>
|
<div>
|
||||||
<h1>MockedServices</h1>
|
<h1>MockedServices</h1>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
|
||||||
<label for="uuid-input" class="block-display">UUID</label>
|
|
||||||
<div id="uuid-edit">
|
|
||||||
<div id="uuid-edit-field" class="bordered-field disabled">
|
|
||||||
<input id="uuid-input" disabled onfocusout="changeUUID(this);" value="UUID" />
|
|
||||||
<button onclick="copyUUIDToClipboard();" class="uuid-inputField-icon modification-button flex-item btn-copy action-button">
|
|
||||||
<span class="material-icons uuid-inputField-icon-span ">content_copy</span>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div id="editableBlock">
|
|
||||||
<input type="checkbox" onchange="changeEditionOfUUID(this)" name="editable" id="editable" value="false"/>
|
|
||||||
<label for="editable">Editable</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="hiddable" id="uuid-validation-strategy">
|
|
||||||
<label><b>UUID generation strategy:</b></label>
|
|
||||||
|
|
||||||
<input type="radio" checked name="uuid-validation-type" value="new" id="generateNew"/>
|
|
||||||
<label for="generateNew">Generate new UUID</label>
|
|
||||||
|
|
||||||
<input type="radio" name="uuid-validation-type" value="restore" id="restore"/>
|
|
||||||
<label for="restore">Restore previous UUID</label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<!-- h2 -->
|
<!-- h2 -->
|
||||||
<div id="basicItemData" class="hiddable active"><h2>Your Message</h2></div>
|
<div><h2>Your Message</h2></div>
|
||||||
<div id="advancedItemData" class="hiddable"><h2>Messaged id: <span id="mockedMessageId">1</span></h2></div>
|
|
||||||
|
|
||||||
<!-- link -->
|
<!-- link -->
|
||||||
<div>
|
<div>
|
||||||
@@ -195,18 +168,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="selectMenuContent" class="tool-extention">
|
|
||||||
<!-- header -->
|
|
||||||
<div>
|
|
||||||
<h2>Message List</h2>
|
|
||||||
</div>
|
|
||||||
<!-- tile list -->
|
|
||||||
<div id="listItems">
|
|
||||||
</div>
|
|
||||||
<div id="new-tile" class="max-width centered-content small-vertical-margin">
|
|
||||||
<button id="btn-newtile" class="modification-button btn-addtile"><i class="icon-plus"></i></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="tooltip-window lite">
|
<div class="tooltip-window lite">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user