refactor Tests and delete unnecessary Test
Co-Authored-By: tomvahl <tomvahl@users.noreply.github.com>
This commit is contained in:
@ -1,141 +0,0 @@
|
|||||||
package mops.gruppen2.domain;
|
|
||||||
|
|
||||||
class GroupTest {
|
|
||||||
/*
|
|
||||||
@BeforeEach
|
|
||||||
public void setUp() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void applyEvent() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void createSingleGroup() throws Exception {
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
|
||||||
|
|
||||||
Group group = new Group();
|
|
||||||
|
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
assertThat(group.getId()).isEqualTo(1L);
|
|
||||||
assertNull(group.getParent());
|
|
||||||
assertEquals(GroupType.LECTURE, group.getType());
|
|
||||||
assertEquals(Visibility.PRIVATE, group.getVisibility());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verwendet CreateGroupEvent
|
|
||||||
@Test
|
|
||||||
void addSingleUser() throws Exception {
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "pepee",null, GroupType.LECTURE , Visibility.PRIVATE);
|
|
||||||
Group group = new Group();
|
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
|
|
||||||
User user = new User("prof", "jens", "bendi", "hi@gmail.com");
|
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(1L, 1L, user);
|
|
||||||
group.applyEvent(addUserEvent);
|
|
||||||
|
|
||||||
assertThat(group.getMembers().get(0)).isEqualTo(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void addExistingUser() throws Exception {
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "prof1", null, GroupType.LECTURE, Visibility.PRIVATE);
|
|
||||||
Group group = new Group();
|
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
|
|
||||||
User user1 = new User("prof", "jens", "bendi", "hi@gmail.com");
|
|
||||||
AddUserEvent addUserEvent1 = new AddUserEvent(2L, 1L, user1);
|
|
||||||
group.applyEvent(addUserEvent1);
|
|
||||||
|
|
||||||
User user2 = new User("prof", "olga", "bendi", "hi@gmail.com");
|
|
||||||
AddUserEvent addUserEvent2 = new AddUserEvent(3L, 1L, user2);
|
|
||||||
Assertions.assertThrows(UserAlreadyExistsException.class, () -> {
|
|
||||||
group.applyEvent(addUserEvent2);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
assertThat(group.getMembers().size()).isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deleteSingleUser() throws Exception {
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
|
||||||
User user = new User("Prof", "Pro", "fessor", "pro@fessor.de");
|
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(2L, 2L, user);
|
|
||||||
Group group = new Group();
|
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
group.applyEvent(addUserEvent);
|
|
||||||
|
|
||||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(3L, 2L, "Prof");
|
|
||||||
group.applyEvent(deleteUserEvent);
|
|
||||||
|
|
||||||
assertThat(group.getMembers().size()).isEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void deleteUserThatDoesNotExists() throws Exception {
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
|
||||||
Group group = new Group();
|
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
|
|
||||||
DeleteUserEvent deleteUserEvent = new DeleteUserEvent(3L, 2L, "Prof");
|
|
||||||
|
|
||||||
Assertions.assertThrows(UserNotFoundException.class, () -> {
|
|
||||||
group.applyEvent(deleteUserEvent);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verwendet CreateGroupEvent und AddUserEvent
|
|
||||||
@Test
|
|
||||||
void updateRoleForExistingUser() throws Exception {
|
|
||||||
// Arrange
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
|
||||||
AddUserEvent addUserEvent = new AddUserEvent(1L, 1L, "5L", "Peter", "Pan", "123@mail.de");
|
|
||||||
|
|
||||||
Group group = new Group();
|
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
group.applyEvent(addUserEvent);
|
|
||||||
|
|
||||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(1L, 1L, "5L", Role.ADMIN);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
group.applyEvent(updateRoleEvent);
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
assertThat(group.getRoles())
|
|
||||||
.containsOnlyKeys(group.getMembers().get(0).getUser_id())
|
|
||||||
.containsValue(Role.ADMIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void updateRoleForNonExistingUser() throws Exception {
|
|
||||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE);
|
|
||||||
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(345L, 33L, "coolerUser", Role.ADMIN);
|
|
||||||
|
|
||||||
Group group = new Group();
|
|
||||||
group.applyEvent(createGroupEvent);
|
|
||||||
Assertions.assertThrows(UserNotFoundException.class, () -> {
|
|
||||||
group.applyEvent(updateRoleEvent);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void updateTitle() throws Exception { //bitte umschreiben
|
|
||||||
Group group = new Group();
|
|
||||||
UpdateGroupTitleEvent updateGroupTitleEvent = new UpdateGroupTitleEvent(2L, 1L, "Klaus", "Toller Titel");
|
|
||||||
group.applyEvent(updateGroupTitleEvent);
|
|
||||||
|
|
||||||
assertThat("Toller Titel").isEqualTo("Toller Titel");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void updateBeschreibung() throws Exception { //bitte umschreiben
|
|
||||||
Group group = new Group();
|
|
||||||
|
|
||||||
UpdateGroupDescriptionEvent updateGroupDescriptionEvent = new UpdateGroupDescriptionEvent(2L, 1L, "Peter", "Tolle Beschreibung");
|
|
||||||
group.applyEvent(updateGroupDescriptionEvent);
|
|
||||||
|
|
||||||
assertThat("Tolle Beschreibung").isEqualTo("Tolle Beschreibung");
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
@ -1,11 +1,16 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import mops.gruppen2.Gruppen2Application;
|
import mops.gruppen2.Gruppen2Application;
|
||||||
|
import mops.gruppen2.domain.GroupType;
|
||||||
|
import mops.gruppen2.domain.Role;
|
||||||
|
import mops.gruppen2.domain.Visibility;
|
||||||
import mops.gruppen2.domain.dto.EventDTO;
|
import mops.gruppen2.domain.dto.EventDTO;
|
||||||
import mops.gruppen2.domain.event.CreateGroupEvent;
|
import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||||
import mops.gruppen2.domain.event.Event;
|
import mops.gruppen2.domain.event.Event;
|
||||||
|
import mops.gruppen2.domain.event.UpdateRoleEvent;
|
||||||
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 org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -15,19 +20,10 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|||||||
import org.springframework.test.annotation.Rollback;
|
import org.springframework.test.annotation.Rollback;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.InstanceOfAssertFactories.ARRAY;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@SpringBootTest(classes = Gruppen2Application.class)
|
@SpringBootTest(classes = Gruppen2Application.class)
|
||||||
@ -47,13 +43,20 @@ class EventServiceTest {
|
|||||||
eventService = new EventService(jsonService, eventRepository);
|
eventService = new EventService(jsonService, eventRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
void getMaxID() {
|
void getMaxID() {
|
||||||
assertEquals(5L, eventService.getMaxEvent_id()); // weil in DataSQL eine Gruppe erstellt wird
|
eventRepository.deleteAll();
|
||||||
|
UpdateRoleEvent updateRoleEvent = new UpdateRoleEvent(2L, "hi",Role.ADMIN);
|
||||||
|
eventService.saveEvent(updateRoleEvent);
|
||||||
|
assertEquals(1L, eventService.getMaxEvent_id()); // funzt noch net richtig weil Autoincrement hochaddiert auch wenn DB leer
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void checkGroupReturnNextValue() {
|
void checkGroupReturnNextValue() {
|
||||||
|
eventRepository.deleteAll();
|
||||||
|
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), "lol", null, GroupType.SIMPLE, Visibility.PUBLIC, 20L);
|
||||||
|
eventService.saveEvent(createGroupEvent);
|
||||||
assertEquals(2L, eventService.checkGroup()); // weil in DataSQL eine Gruppe erstellt wird
|
assertEquals(2L, eventService.checkGroup()); // weil in DataSQL eine Gruppe erstellt wird
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +70,8 @@ class EventServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void translateEventDTOsTest() {
|
void translateEventDTOsTest() {
|
||||||
EventDTO eventDTO1 = new EventDTO(1L,1L, "killerbert", "CreateGroupEvent", "{\"type\":\"CreateGroupEvent\",\"groupId\":1,\"userId\":\"orga\",\"groupVisibility\":\"PUBLIC\",\"groupParent\":null,\"groupType\":\"SIMPLE\",\"groupUserMaximum\":2}");
|
EventDTO eventDTO1 = new EventDTO(1L,1L, "killerbert", "CreateGroupEvent", "{\"type\":\"CreateGroupEvent\",\"groupId\":1,\"userId\":\"orga\",\"groupVisibility\":\"PUBLIC\",\"groupParent\":null,\"groupType\":\"SIMPLE\",\"groupUserMaximum\":2}");
|
||||||
EventDTO eventDTO2 = new EventDTO(2L,2L,"jens","AddUserEvent","{\"type\":\"AddUserEvent\",\"groupId\":1,\"userId\":\"orga\",\"givenname\":\"orga\",\"familyname\":\"orga\",\"email\":\"blorga@orga.org\"}");
|
|
||||||
List<EventDTO> eventDTOS1 = new ArrayList<>();
|
List<EventDTO> eventDTOS1 = new ArrayList<>();
|
||||||
eventDTOS1.add(eventDTO1);
|
eventDTOS1.add(eventDTO1);
|
||||||
eventDTOS1.add(eventDTO2);
|
|
||||||
List<Event> events = eventService.translateEventDTOs(eventDTOS1);
|
List<Event> events = eventService.translateEventDTOs(eventDTOS1);
|
||||||
assertThat(events.get(0)).isInstanceOf(CreateGroupEvent.class);
|
assertThat(events.get(0)).isInstanceOf(CreateGroupEvent.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,16 +24,14 @@ class GroupServiceTest {
|
|||||||
void setUp() {
|
void setUp() {
|
||||||
groupService = new GroupService(mock(EventService.class), mock(EventRepository.class));
|
groupService = new GroupService(mock(EventService.class), mock(EventRepository.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void rightClassForSuccessfulGroup() {
|
void rightClassForSuccessfulGroup() {
|
||||||
List<Event> eventList = new ArrayList<>();
|
List<Event> eventList = new ArrayList<>();
|
||||||
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE,1000L));
|
eventList.add(new CreateGroupEvent(1L, "Prof", null, GroupType.LECTURE, Visibility.PRIVATE,1000L));
|
||||||
eventList.add(new AddUserEvent(1L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
eventList.add(new AddUserEvent(1L, "Ulli", "Ulli", "Honnis", "FC@B.de"));
|
||||||
|
|
||||||
List<Group> groups = groupService.projectEventList(eventList);
|
List<Group> groups = groupService.projectEventList(eventList);
|
||||||
|
|
||||||
assertThat(groups.get(0)).isInstanceOf(Group.class);
|
assertThat(groups.get(0)).isInstanceOf(Group.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user