Merge branch 'event-db' into html-gruppe
This commit is contained in:
@ -53,7 +53,7 @@ public class SwaggerAPIControllerExample {
|
|||||||
return "Product saved successfully";
|
return "Product saved successfully";
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@GetMapping("/json") //just for testing
|
/*@GetMapping("/json")
|
||||||
public void json() {
|
public void json() {
|
||||||
AddUserEvent aEvent = new AddUserEvent(
|
AddUserEvent aEvent = new AddUserEvent(
|
||||||
1,
|
1,
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package mops.gruppen2.repository;
|
package mops.gruppen2.repository;
|
||||||
|
|
||||||
import mops.gruppen2.domain.EventDTO;
|
import mops.gruppen2.domain.EventDTO;
|
||||||
import mops.gruppen2.domain.event.Event;
|
|
||||||
import org.springframework.data.repository.CrudRepository;
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
|
||||||
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
public interface EventRepository extends CrudRepository<EventDTO, Long> {
|
||||||
|
|||||||
@ -24,10 +24,11 @@ public class SerializationService {
|
|||||||
|
|
||||||
public String serializeEvent(Event event) throws JsonProcessingException {
|
public String serializeEvent(Event event) throws JsonProcessingException {
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String json = mapper.writeValueAsString(event);
|
return mapper.writeValueAsString(event);
|
||||||
log.info(json);
|
|
||||||
return json;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Event deserializeEvent(String json) throws JsonProcessingException {
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
return mapper.readValue(json, Event.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import mops.gruppen2.domain.event.AddUserEvent;
|
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@ -9,15 +8,14 @@ import org.junit.jupiter.api.Disabled;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
class SerializationServiceTest {
|
class SerializationServiceTest {
|
||||||
|
|
||||||
EventRepository eventRepository;
|
EventRepository eventRepository;
|
||||||
Event event;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp(){
|
public void setUp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -28,7 +26,9 @@ class SerializationServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void serializeEventTest() {
|
void serializeEventTest() {
|
||||||
|
|
||||||
event = new Event(1L,1L,"1");
|
event = new Event(1L,1L,"1");
|
||||||
|
|
||||||
SerializationService serializationService = new SerializationService(eventRepository);
|
SerializationService serializationService = new SerializationService(eventRepository);
|
||||||
try {
|
try {
|
||||||
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"Event\":{\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}}");
|
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"Event\":{\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}}");
|
||||||
@ -37,5 +37,15 @@ class SerializationServiceTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deserializeAddUserEvent() throws JsonProcessingException {
|
||||||
|
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
||||||
|
|
||||||
}
|
String json = "{\"type\":\"Event\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
||||||
|
|
||||||
|
Event event = serializationService.deserializeEvent(json);
|
||||||
|
|
||||||
|
assertThat(event).isInstanceOf(Event.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user