Merge pull request #55 from hhu-propra2/serialization-tests
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) {
|
||||
super(event_id, group_id, user_id);
|
||||
}
|
||||
|
||||
public DeleteUserEvent() {}
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@JsonTypeInfo(
|
||||
include = JsonTypeInfo.As.PROPERTY,
|
||||
use = JsonTypeInfo.Id.NAME,
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import mops.gruppen2.domain.event.AddUserEvent;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.event.*;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -12,44 +12,74 @@ import static org.mockito.Mockito.mock;
|
||||
|
||||
class SerializationServiceTest {
|
||||
|
||||
SerializationService serializationService;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
serializationService = new SerializationService(mock(EventRepository.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void serializeEventTest() {
|
||||
void serializeEventTest() throws JsonProcessingException {
|
||||
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\"}");
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@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\"}";
|
||||
void deserializeAddUserEventToRightClass() throws JsonProcessingException {
|
||||
String json = "{\"type\":\"AddUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
||||
|
||||
Event event = serializationService.deserializeEvent(json);
|
||||
|
||||
assertThat(event).isInstanceOf(Event.class);
|
||||
assertThat(event).isInstanceOf(AddUserEvent.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void serializeEventTestAddUserEvent(){
|
||||
AddUserEvent event = new AddUserEvent(1L,1L,"user_id","peter","mueller","a@a");
|
||||
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
||||
try {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
void deserializeDeleteUserEventToRightClass() throws JsonProcessingException {
|
||||
String json = "{\"type\":\"DeleteUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"1\"}";
|
||||
|
||||
Event event = serializationService.deserializeEvent(json);
|
||||
|
||||
assertThat(event).isInstanceOf(DeleteUserEvent.class);
|
||||
}
|
||||
|
||||
@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