add more testcases
This commit is contained in:
@ -6,13 +6,16 @@ import mops.gruppen2.domain.Group;
|
|||||||
import mops.gruppen2.domain.GroupType;
|
import mops.gruppen2.domain.GroupType;
|
||||||
import mops.gruppen2.domain.User;
|
import mops.gruppen2.domain.User;
|
||||||
import mops.gruppen2.domain.Visibility;
|
import mops.gruppen2.domain.Visibility;
|
||||||
|
import mops.gruppen2.domain.exception.UserNotFoundException;
|
||||||
import mops.gruppen2.repository.EventRepository;
|
import mops.gruppen2.repository.EventRepository;
|
||||||
import mops.gruppen2.security.Account;
|
import mops.gruppen2.security.Account;
|
||||||
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.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
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;
|
||||||
@ -22,8 +25,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ -213,7 +215,7 @@ class ControllerServiceTest {
|
|||||||
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
|
void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException {
|
||||||
eventRepository.deleteAll();
|
eventRepository.deleteAll();
|
||||||
controllerService.createOrga(account, "test", "hi", null, true, true, null, null);
|
controllerService.createOrga(account, "test", "hi", null, true, true, null, null);
|
||||||
List<Group> groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
List<Group> groups=userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||||
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
assertEquals(GroupType.LECTURE, groups.get(0).getType());
|
||||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||||
@ -221,8 +223,26 @@ class ControllerServiceTest {
|
|||||||
assertNull(groups.get(0).getParent());
|
assertNull(groups.get(0).getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteUserTest() {
|
||||||
|
eventRepository.deleteAll();
|
||||||
|
controllerService.createGroup(account,"test", "hi", true, true, null, null);
|
||||||
|
List<Group> groups=userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||||
|
controllerService.addUser(account2,groups.get(0).getId());
|
||||||
|
controllerService.deleteUser(account.getName(), groups.get(0).getId());
|
||||||
|
assertTrue(userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail())).isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Disabled
|
||||||
|
@Test
|
||||||
|
public void deleteNonUserTest() {
|
||||||
|
eventRepository.deleteAll();
|
||||||
|
controllerService.createGroup(account,"test", "hi", true, true, null, null);
|
||||||
|
List<Group> groups=userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||||
|
|
||||||
|
Throwable exception = assertThrows(UserNotFoundException.class, () -> controllerService.deleteUser(account2.getName(), groups.get(0).getId()));
|
||||||
|
assertEquals(HttpStatus.NOT_FOUND, "Der User wurde nicht gefunden. (class mops.gruppen2.service.ControllerService)", exception.getMessage()); //noch fixen
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void testTitleAndDescription(String title, String description) {
|
void testTitleAndDescription(String title, String description) {
|
||||||
|
|||||||
Reference in New Issue
Block a user