add Multiple tests And rename 1 Method
This commit is contained in:
@ -77,7 +77,7 @@ public class GroupService {
|
||||
* @throws EventException Projektionsfehler
|
||||
*/
|
||||
//TODO Rename
|
||||
public List<Group> getAllGroupWithVisibilityPublic(String userId) throws EventException {
|
||||
public List<Group> getAllGroupsWithVisibilityPublic(String userId) throws EventException {
|
||||
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||
@ -126,10 +126,10 @@ public class GroupService {
|
||||
//Todo Rename
|
||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||
if (search.isEmpty()) {
|
||||
return getAllGroupWithVisibilityPublic(account.getName());
|
||||
return getAllGroupsWithVisibilityPublic(account.getName());
|
||||
}
|
||||
|
||||
return getAllGroupWithVisibilityPublic(account.getName())
|
||||
return getAllGroupsWithVisibilityPublic(account.getName())
|
||||
.parallelStream()
|
||||
.filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase())
|
||||
|| group.getDescription().toLowerCase().contains(search.toLowerCase()))
|
||||
|
@ -1,32 +1,51 @@
|
||||
package mops.gruppen2.service;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import mops.gruppen2.Gruppen2Application;
|
||||
import mops.gruppen2.domain.Group;
|
||||
import mops.gruppen2.domain.GroupType;
|
||||
import mops.gruppen2.domain.User;
|
||||
import mops.gruppen2.domain.Visibility;
|
||||
import mops.gruppen2.repository.EventRepository;
|
||||
import mops.gruppen2.security.Account;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest(classes = Gruppen2Application.class)
|
||||
@Transactional
|
||||
@Rollback
|
||||
class ControllerServiceTest {
|
||||
Faker faker;
|
||||
Account account;
|
||||
ControllerService controllerService;
|
||||
EventService eventService;
|
||||
UserService userService;
|
||||
@Autowired
|
||||
EventRepository eventRepository;
|
||||
GroupService groupService;
|
||||
@Autowired
|
||||
JsonService jsonService;
|
||||
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
jsonService = new JsonService();
|
||||
eventRepository = mock(EventRepository.class);
|
||||
eventService = new EventService(jsonService, eventRepository);
|
||||
groupService = new GroupService(eventService, eventRepository);
|
||||
userService = new UserService(groupService, eventService);
|
||||
@ -37,41 +56,88 @@ class ControllerServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGroupTest() {
|
||||
|
||||
void createPublicGroupWithNoParentAndLimitedNumberTest() {
|
||||
eventRepository.deleteAll();
|
||||
controllerService.createGroup(account,"test", "hi", null, null, 20L, null);
|
||||
List<Group> groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createOrga() {
|
||||
void createPublicGroupWithNoParentAndUnlimitedNumberTest() {
|
||||
eventRepository.deleteAll();
|
||||
controllerService.createGroup(account,"test", "hi", null, true, null, null);
|
||||
List<Group> groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum()); //100k ist "maximum"
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addUser() {
|
||||
void createPrivateGroupWithNoParentAndUnlimitedNumberTest() {
|
||||
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()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum()); //100k ist "maximum"
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addUserList() {
|
||||
void createPrivateGroupWithNoParentAndLimitedNumberTest() {
|
||||
eventRepository.deleteAll();
|
||||
controllerService.createGroup(account,"test", "hi", true, null, 20L, null);
|
||||
List<Group> groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum()); //100k ist "maximum"
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTitle() {
|
||||
void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||
eventRepository.deleteAll();
|
||||
controllerService.createOrga(account, "test", "hi", null, null, null, 20L, null);
|
||||
List<Group> groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateDescription() {
|
||||
void createPublicOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException {
|
||||
eventRepository.deleteAll();
|
||||
controllerService.createOrga(account, "test", "hi", null, null, true, null, null);
|
||||
List<Group> groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility());
|
||||
assertEquals(100000L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRoleTest() {
|
||||
|
||||
void createPrivateOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException {
|
||||
eventRepository.deleteAll();
|
||||
controllerService.createOrga(account, "test", "hi", true, null, null, 20L, null);
|
||||
List<Group> groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail()));
|
||||
testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription());
|
||||
assertEquals(GroupType.SIMPLE, groups.get(0).getType());
|
||||
assertEquals(Visibility.PRIVATE, groups.get(0).getVisibility());
|
||||
assertEquals(20L, groups.get(0).getUserMaximum());
|
||||
assertNull(groups.get(0).getParent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteUser() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteGroupEvent() {
|
||||
void testTitleAndDescription(String title, String description) {
|
||||
assertEquals("test", title);
|
||||
assertEquals("hi", description);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -117,7 +117,7 @@ class GroupServiceTest {
|
||||
Group group = TestBuilder.apply(test1, test2);
|
||||
|
||||
assertThat(group.getType()).isEqualTo(null);
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1")).isEmpty();
|
||||
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -131,7 +131,7 @@ class GroupServiceTest {
|
||||
deleteGroupEvent(uuidFromInt(0)),
|
||||
createPublicGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
|
||||
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1").size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -151,7 +151,7 @@ class GroupServiceTest {
|
||||
createPublicGroupEvent(),
|
||||
createPrivateGroupEvent());
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
|
||||
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1").size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -167,8 +167,8 @@ class GroupServiceTest {
|
||||
//Das kommt glaube ich eher in einen Test für die Projektion
|
||||
//assertThat(groupService.getAllGroupWithVisibilityPublic("test2").get(0).getMembers().size()).isEqualTo(1);
|
||||
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
|
||||
assertThat(groupService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
|
||||
assertThat(groupService.getAllGroupsWithVisibilityPublic("kobold")).hasSize(1);
|
||||
assertThat(groupService.getAllGroupsWithVisibilityPublic("peter")).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user