Merge remote-tracking branch 'origin/event-db'
# Conflicts: # src/main/java/mops/gruppen2/domain/Aggregate.java # src/main/java/mops/gruppen2/service/GroupService.java # src/test/java/mops/gruppen2/domain/GroupTest.java
This commit is contained in:
92
src/test/java/mops/gruppen2/builder/EventBuilder.java
Normal file
92
src/test/java/mops/gruppen2/builder/EventBuilder.java
Normal file
@ -0,0 +1,92 @@
|
||||
package mops.gruppen2.builder;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import mops.gruppen2.domain.Role;
|
||||
import mops.gruppen2.domain.event.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EventBuilder {
|
||||
|
||||
public static CreateGroupEvent randomCreateGroupEvent() {
|
||||
Faker faker = new Faker();
|
||||
|
||||
return new CreateGroupEvent(
|
||||
faker.random().nextLong(),
|
||||
faker.random().nextLong(),
|
||||
faker.random().hex(),
|
||||
faker.leagueOfLegends().champion(),
|
||||
faker.leagueOfLegends().quote()
|
||||
);
|
||||
}
|
||||
|
||||
public static AddUserEvent randomAddUserEvent() {
|
||||
Faker faker = new Faker();
|
||||
|
||||
String firstname = faker.name().firstName();
|
||||
String lastname = faker.name().lastName();
|
||||
|
||||
return new AddUserEvent(
|
||||
faker.random().nextLong(),
|
||||
faker.random().nextLong(),
|
||||
faker.random().hex(),
|
||||
firstname,
|
||||
lastname,
|
||||
firstname + "." + lastname + "@mail.de"
|
||||
);
|
||||
}
|
||||
|
||||
public static List<Event> randomAddUserEvents(int count) {
|
||||
List<Event> eventList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
eventList.add(EventBuilder.randomAddUserEvent());
|
||||
}
|
||||
|
||||
return eventList;
|
||||
}
|
||||
|
||||
public static DeleteUserEvent randomDeleteUserEvent(long group_id, String user_id) {
|
||||
Faker faker = new Faker();
|
||||
|
||||
return new DeleteUserEvent(
|
||||
faker.random().nextLong(),
|
||||
group_id,
|
||||
user_id
|
||||
);
|
||||
}
|
||||
|
||||
public static UpdateGroupDescriptionEvent randomUpdateGroupDescriptionEvent(long group_id) {
|
||||
Faker faker = new Faker();
|
||||
|
||||
return new UpdateGroupDescriptionEvent(
|
||||
faker.random().nextLong(),
|
||||
group_id,
|
||||
faker.random().hex(),
|
||||
faker.leagueOfLegends().quote()
|
||||
);
|
||||
}
|
||||
|
||||
public static UpdateGroupTitleEvent randomUpdateGroupTitleEvent(long group_id) {
|
||||
Faker faker = new Faker();
|
||||
|
||||
return new UpdateGroupTitleEvent(
|
||||
faker.random().nextLong(),
|
||||
group_id,
|
||||
faker.random().hex(),
|
||||
faker.leagueOfLegends().champion()
|
||||
);
|
||||
}
|
||||
|
||||
public static UpdateRoleEvent randomUpdateRoleEvent(long group_id, String user_id, Role role) {
|
||||
Faker faker = new Faker();
|
||||
|
||||
return new UpdateRoleEvent(
|
||||
faker.random().nextLong(),
|
||||
group_id,
|
||||
user_id,
|
||||
role
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class EventServiceTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import mops.gruppen2.builder.EventBuilder;
|
||||
import mops.gruppen2.domain.event.AddUserEvent;
|
||||
import mops.gruppen2.domain.event.Event;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class SerializationServiceTest {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void serializeEventTest() {
|
||||
event = new Event(1L,1L,"1");
|
||||
|
||||
SerializationService serializationService = new SerializationService(eventRepository);
|
||||
|
||||
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\"}";
|
||||
|
||||
Event event = serializationService.deserializeEvent(json);
|
||||
|
||||
assertThat(event).isInstanceOf(Event.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void serializeEventTestAddUserEvent(){
|
||||
AddUserEvent event = new AddUserEvent(1,1,"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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user