added deserialization tests
This commit is contained in:
@ -11,4 +11,6 @@ public class DeleteUserEvent extends Event {
|
|||||||
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
|
public DeleteUserEvent(Long event_id, Long group_id, String user_id) {
|
||||||
super(event_id, group_id, user_id);
|
super(event_id, group_id, user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DeleteUserEvent() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,8 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
@JsonTypeInfo(
|
@JsonTypeInfo(
|
||||||
include = JsonTypeInfo.As.PROPERTY,
|
include = JsonTypeInfo.As.PROPERTY,
|
||||||
use = JsonTypeInfo.Id.NAME,
|
use = JsonTypeInfo.Id.NAME,
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
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.Role;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.*;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -12,44 +12,74 @@ import static org.mockito.Mockito.mock;
|
|||||||
|
|
||||||
class SerializationServiceTest {
|
class SerializationServiceTest {
|
||||||
|
|
||||||
|
SerializationService serializationService;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
serializationService = new SerializationService(mock(EventRepository.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void serializeEventTest() {
|
void serializeEventTest() throws JsonProcessingException {
|
||||||
Event event = new Event(1L,1L,"1");
|
Event event = new Event(1L,1L,"1");
|
||||||
|
|
||||||
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
|
||||||
|
|
||||||
try {
|
|
||||||
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"Event\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}");
|
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"Event\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}");
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deserializeAddUserEvent() throws JsonProcessingException {
|
void deserializeAddUserEventToRightClass() throws JsonProcessingException {
|
||||||
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
String json = "{\"type\":\"AddUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
||||||
|
|
||||||
String json = "{\"type\":\"Event\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
|
||||||
|
|
||||||
Event event = serializationService.deserializeEvent(json);
|
Event event = serializationService.deserializeEvent(json);
|
||||||
|
|
||||||
assertThat(event).isInstanceOf(Event.class);
|
assertThat(event).isInstanceOf(AddUserEvent.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void serializeEventTestAddUserEvent(){
|
void deserializeDeleteUserEventToRightClass() throws JsonProcessingException {
|
||||||
AddUserEvent event = new AddUserEvent(1L,1L,"user_id","peter","mueller","a@a");
|
String json = "{\"type\":\"DeleteUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
||||||
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
|
||||||
try {
|
Event event = serializationService.deserializeEvent(json);
|
||||||
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"AddUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"user_id\",\"givenname\":\"peter\",\"familyname\":\"mueller\",\"email\":\"a@a\"}");
|
|
||||||
} catch (JsonProcessingException e) {
|
assertThat(event).isInstanceOf(DeleteUserEvent.class);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deserializeUpdateGroupDescriptionEventToRightClass() throws JsonProcessingException {
|
||||||
|
String json = "{\"type\":\"UpdateGroupDescriptionEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\",\"newGroupDescription\":\"test\"}";
|
||||||
|
|
||||||
|
Event event = serializationService.deserializeEvent(json);
|
||||||
|
|
||||||
|
assertThat(event).isInstanceOf(UpdateGroupDescriptionEvent.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deserializeUpdateGroupTitleEventToRightClass() throws JsonProcessingException {
|
||||||
|
String json = "{\"type\":\"UpdateGroupTitleEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\",\"newGroupTitle\":\"test\"}";
|
||||||
|
|
||||||
|
Event event = serializationService.deserializeEvent(json);
|
||||||
|
|
||||||
|
assertThat(event).isInstanceOf(UpdateGroupTitleEvent.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deserializeUpdateRoleEventToRightClass() throws JsonProcessingException {
|
||||||
|
System.out.println(serializationService.serializeEvent(new UpdateRoleEvent(1L, 1L, "1", Role.ADMIN)));
|
||||||
|
|
||||||
|
String json = "{\"type\":\"UpdateRoleEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":1,\"newRole\":\"ADMIN\"}";
|
||||||
|
|
||||||
|
Event event = serializationService.deserializeEvent(json);
|
||||||
|
|
||||||
|
assertThat(event).isInstanceOf(UpdateRoleEvent.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void deserializeCreateGroupEventToRightClass() throws JsonProcessingException {
|
||||||
|
String json = "{\"type\":\"CreateGroupEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\",\"groupTitle\":\"test\",\"groupDescription\":\"test\"}";
|
||||||
|
|
||||||
|
Event event = serializationService.deserializeEvent(json);
|
||||||
|
|
||||||
|
assertThat(event).isInstanceOf(CreateGroupEvent.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user