add EventServiceTest tests
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import mops.gruppen2.Gruppen2Application;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.domain.dto.EventDTO;
|
||||
@ -8,8 +9,14 @@ import mops.gruppen2.domain.event.CreateGroupEvent;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -20,51 +27,49 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = Gruppen2Application.class)
|
||||
@Rollback
|
||||
@Transactional
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
class EventServiceTest {
|
||||
|
||||
@Autowired
|
||||
private EventRepository eventRepository;
|
||||
@Autowired
|
||||
private EventService eventService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
eventRepository = mock(EventRepository.class);
|
||||
eventService = new EventService(mock(JsonService.class), eventRepository);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void getMaxID() {
|
||||
when(eventRepository.getHighesEvent_ID()).thenReturn(42L);
|
||||
|
||||
assertEquals(eventService.getMaxEvent_id(), 42L);
|
||||
assertEquals(5L, eventService.getMaxEvent_id()); // weil in DataSQL eine Gruppe erstellt wird
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkGroupReturnNextValue() {
|
||||
when(eventRepository.getMaxGroupID()).thenReturn(2L);
|
||||
|
||||
assertEquals(eventService.checkGroup(), 3L);
|
||||
assertEquals(2L, eventService.checkGroup()); // weil in DataSQL eine Gruppe erstellt wird
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkGroupReturnOneIfDBIsEmpty() {
|
||||
List<EventDTO> eventDTOS = new ArrayList<>();
|
||||
when(eventRepository.findAll()).thenReturn(eventDTOS);
|
||||
|
||||
assertEquals(eventService.checkGroup(), 1);
|
||||
//dafür muss data.sql weg
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDTOOffentlichTest() {
|
||||
void getDTOPublicTest() {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(eventService.checkGroup(), "test", null, GroupType.LECTURE, Visibility.PUBLIC, null);
|
||||
EventDTO eventDTO = eventService.getDTO(createGroupEvent);
|
||||
assertTrue(eventDTO.isVisibility());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDTOPrivatTest() {
|
||||
AddUserEvent addUserEvent = new AddUserEvent(eventService.checkGroup(), "test", "franz", "mueller", "a@a");
|
||||
EventDTO eventDTO = eventService.getDTO(addUserEvent);
|
||||
void getDTOPrivateTest() {
|
||||
CreateGroupEvent createGroupEvent = new CreateGroupEvent(10L, "hi",null, GroupType.SIMPLE, Visibility.PRIVATE, 20L);
|
||||
EventDTO eventDTO = eventService.getDTO(createGroupEvent);
|
||||
assertFalse(eventDTO.isVisibility());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user