restore things lost in merge ffs
This commit is contained in:
@ -1,12 +1,10 @@
|
|||||||
package mops.gruppen2.controller;
|
package mops.gruppen2.controller;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import com.github.javafaker.Faker;
|
import com.github.javafaker.Faker;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import mops.gruppen2.domain.ProductSwaggerExample;
|
import mops.gruppen2.domain.ProductSwaggerExample;
|
||||||
import mops.gruppen2.domain.event.AddUserEvent;
|
|
||||||
import mops.gruppen2.service.SerializationService;
|
import mops.gruppen2.service.SerializationService;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -24,7 +22,7 @@ public class SwaggerAPIController {
|
|||||||
private final List<ProductSwaggerExample> products = new ArrayList<>();
|
private final List<ProductSwaggerExample> products = new ArrayList<>();
|
||||||
private final SerializationService serializationService;
|
private final SerializationService serializationService;
|
||||||
|
|
||||||
public SwaggerAPIControllerExample(SerializationService serializationService) {
|
public SwaggerAPIController(SerializationService serializationService) {
|
||||||
this.serializationService = serializationService;
|
this.serializationService = serializationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package mops.gruppen2.service;
|
|||||||
|
|
||||||
import mops.gruppen2.domain.Exceptions.EventException;
|
import mops.gruppen2.domain.Exceptions.EventException;
|
||||||
import mops.gruppen2.domain.Group;
|
import mops.gruppen2.domain.Group;
|
||||||
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -29,4 +30,16 @@ public class GroupService {
|
|||||||
|
|
||||||
return newGroup;
|
return newGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Group buildGroupFromEvent(CreateGroupEvent createGroupEvent) {
|
||||||
|
Group newGroup = new Group();
|
||||||
|
|
||||||
|
try {
|
||||||
|
newGroup.applyEvent(createGroupEvent);
|
||||||
|
} catch (EventException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return newGroup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import mops.gruppen2.domain.Exceptions.UserNotFoundException;
|
|||||||
import mops.gruppen2.domain.event.*;
|
import mops.gruppen2.domain.event.*;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
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;
|
||||||
@ -23,7 +22,7 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createSingleGroup() throws Exception{
|
void createSingleGroup() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,2, "asd", "hello", "foo");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,2L, "asd", "hello", "foo");
|
||||||
|
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
|
|
||||||
@ -38,12 +37,12 @@ class GroupTest {
|
|||||||
// Verwendet CreateGroupEvent
|
// Verwendet CreateGroupEvent
|
||||||
@Test
|
@Test
|
||||||
void addSingleUser() throws Exception{
|
void addSingleUser() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1,"prof1", "hi", "foo");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1L,"prof1", "hi", "foo");
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
User user = new User("prof", "jens", "bendi", "hi@gmail.com");
|
User user = new User("prof", "jens", "bendi", "hi@gmail.com");
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(1,1, user);
|
AddUserEvent addUserEvent = new AddUserEvent(1L,1L, user);
|
||||||
group.applyEvent(addUserEvent);
|
group.applyEvent(addUserEvent);
|
||||||
|
|
||||||
assertThat(group.getMembers().get(0)).isEqualTo(user);
|
assertThat(group.getMembers().get(0)).isEqualTo(user);
|
||||||
@ -51,16 +50,16 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void addExistingUser() throws Exception{
|
void addExistingUser() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1,"prof1", "hi", "foo");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L,1L,"prof1", "hi", "foo");
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
User user1 = new User("prof", "jens", "bendi", "hi@gmail.com");
|
User user1 = new User("prof", "jens", "bendi", "hi@gmail.com");
|
||||||
AddUserEvent addUserEvent1 = new AddUserEvent(2,1, user1);
|
AddUserEvent addUserEvent1 = new AddUserEvent(2L,1L, user1);
|
||||||
group.applyEvent(addUserEvent1);
|
group.applyEvent(addUserEvent1);
|
||||||
|
|
||||||
User user2 = new User("prof", "olga", "bendi", "hi@gmail.com");
|
User user2 = new User("prof", "olga", "bendi", "hi@gmail.com");
|
||||||
AddUserEvent addUserEvent2 = new AddUserEvent(3,1, user2);
|
AddUserEvent addUserEvent2 = new AddUserEvent(3L,1L, user2);
|
||||||
Assertions.assertThrows(UserAlreadyExistsException.class, () ->{
|
Assertions.assertThrows(UserAlreadyExistsException.class, () ->{
|
||||||
group.applyEvent(addUserEvent2);
|
group.applyEvent(addUserEvent2);
|
||||||
});
|
});
|
||||||
@ -71,14 +70,14 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteSingleUser() throws Exception{
|
void deleteSingleUser() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
|
||||||
User user = new User("Prof", "Pro", "fessor", "pro@fessor.de");
|
User user = new User("Prof", "Pro", "fessor", "pro@fessor.de");
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(2, 2, user);
|
AddUserEvent addUserEvent = new AddUserEvent(2L, 2L, user);
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
group.applyEvent(addUserEvent);
|
group.applyEvent(addUserEvent);
|
||||||
|
|
||||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(3, 2, "Prof");
|
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(3L, 2L, "Prof");
|
||||||
group.applyEvent(deleteUserEvent);
|
group.applyEvent(deleteUserEvent);
|
||||||
|
|
||||||
assertThat(group.getMembers().size()).isEqualTo(0);
|
assertThat(group.getMembers().size()).isEqualTo(0);
|
||||||
@ -86,11 +85,11 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteUserThatDoesNotExists() throws Exception{
|
void deleteUserThatDoesNotExists() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1, 2L, "Prof", "Tolle Gruppe", "Tolle Beshreibung");
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(3, 2, "Prof");
|
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(3L, 2L, "Prof");
|
||||||
|
|
||||||
Assertions.assertThrows(UserNotFoundException.class, () ->{
|
Assertions.assertThrows(UserNotFoundException.class, () ->{
|
||||||
group.applyEvent(deleteUserEvent);
|
group.applyEvent(deleteUserEvent);
|
||||||
@ -122,7 +121,7 @@ class GroupTest {
|
|||||||
@Test
|
@Test
|
||||||
void updateRoleForNonExistingUser() throws Exception{
|
void updateRoleForNonExistingUser() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "1L", "gruppe1", "Eine Testgruppe");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, 1L, "1L", "gruppe1", "Eine Testgruppe");
|
||||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(345L, 33 , "coolerUser", Role.ADMIN);
|
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(345L, 33L , "coolerUser", Role.ADMIN);
|
||||||
|
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
@ -133,11 +132,11 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateTitle() throws Exception{
|
void updateTitle() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1,"prof1", "hi", "foo");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1L,"prof1", "hi", "foo");
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(2, 1, "Klaus", "Toller Titel");
|
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(2L, 1L, "Klaus", "Toller Titel");
|
||||||
group.applyEvent(updateGroupTitleEvent);
|
group.applyEvent(updateGroupTitleEvent);
|
||||||
|
|
||||||
assertThat(group.getTitle()).isEqualTo("Toller Titel");
|
assertThat(group.getTitle()).isEqualTo("Toller Titel");
|
||||||
@ -145,11 +144,11 @@ class GroupTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void updateBeschreibung() throws Exception{
|
void updateBeschreibung() throws Exception{
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1,"prof1", "hi", "foo");
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1,1L,"prof1", "hi", "foo");
|
||||||
Group group = new Group();
|
Group group = new Group();
|
||||||
group.applyEvent(createGroupEvent);
|
group.applyEvent(createGroupEvent);
|
||||||
|
|
||||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(2, 1, "Peter", "Tolle Beschreibung");
|
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(2L, 1L, "Peter", "Tolle Beschreibung");
|
||||||
group.applyEvent(updateGroupDescriptionEvent);
|
group.applyEvent(updateGroupDescriptionEvent);
|
||||||
|
|
||||||
assertThat(group.getDescription()).isEqualTo("Tolle Beschreibung");
|
assertThat(group.getDescription()).isEqualTo("Tolle Beschreibung");
|
||||||
|
|||||||
@ -1,12 +1,10 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import mops.gruppen2.builder.EventBuilder;
|
|
||||||
import mops.gruppen2.domain.event.AddUserEvent;
|
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;
|
||||||
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;
|
||||||
@ -22,9 +20,9 @@ class SerializationServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void serializeEventTest() {
|
void serializeEventTest() {
|
||||||
event = new Event(1L,1L,"1");
|
Event event = new Event(1L,1L,"1");
|
||||||
|
|
||||||
SerializationService serializationService = new SerializationService(eventRepository);
|
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
||||||
|
|
||||||
try {
|
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\"}");
|
||||||
@ -46,7 +44,7 @@ class SerializationServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void serializeEventTestAddUserEvent(){
|
void serializeEventTestAddUserEvent(){
|
||||||
AddUserEvent event = new AddUserEvent(1,1,"user_id","peter","mueller","a@a");
|
AddUserEvent event = new AddUserEvent(1L,1L,"user_id","peter","mueller","a@a");
|
||||||
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
SerializationService serializationService = new SerializationService(mock(EventRepository.class));
|
||||||
try {
|
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\"}");
|
assertThat(serializationService.serializeEvent(event)).isEqualTo("{\"type\":\"AddUserEvent\",\"event_id\":1,\"group_id\":1,\"user_id\":\"user_id\",\"givenname\":\"peter\",\"familyname\":\"mueller\",\"email\":\"a@a\"}");
|
||||||
|
|||||||
Reference in New Issue
Block a user