add Multiple tests And rename 1 Method
This commit is contained in:
@ -77,7 +77,7 @@ public class GroupService {
|
|||||||
* @throws EventException Projektionsfehler
|
* @throws EventException Projektionsfehler
|
||||||
*/
|
*/
|
||||||
//TODO Rename
|
//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"));
|
List<Event> groupEvents = eventService.translateEventDTOs(eventRepository.findAllEventsByType("CreateGroupEvent"));
|
||||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupDescriptionEvent")));
|
||||||
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
groupEvents.addAll(eventService.translateEventDTOs(eventRepository.findAllEventsByType("UpdateGroupTitleEvent")));
|
||||||
@ -126,10 +126,10 @@ public class GroupService {
|
|||||||
//Todo Rename
|
//Todo Rename
|
||||||
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
public List<Group> findGroupWith(String search, Account account) throws EventException {
|
||||||
if (search.isEmpty()) {
|
if (search.isEmpty()) {
|
||||||
return getAllGroupWithVisibilityPublic(account.getName());
|
return getAllGroupsWithVisibilityPublic(account.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAllGroupWithVisibilityPublic(account.getName())
|
return getAllGroupsWithVisibilityPublic(account.getName())
|
||||||
.parallelStream()
|
.parallelStream()
|
||||||
.filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase())
|
.filter(group -> group.getTitle().toLowerCase().contains(search.toLowerCase())
|
||||||
|| group.getDescription().toLowerCase().contains(search.toLowerCase()))
|
|| group.getDescription().toLowerCase().contains(search.toLowerCase()))
|
||||||
|
|||||||
@ -1,32 +1,51 @@
|
|||||||
package mops.gruppen2.service;
|
package mops.gruppen2.service;
|
||||||
|
|
||||||
import com.github.javafaker.Faker;
|
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.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.Test;
|
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.HashSet;
|
||||||
|
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.assertNull;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@SpringBootTest(classes = Gruppen2Application.class)
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
class ControllerServiceTest {
|
class ControllerServiceTest {
|
||||||
Faker faker;
|
Faker faker;
|
||||||
Account account;
|
Account account;
|
||||||
ControllerService controllerService;
|
ControllerService controllerService;
|
||||||
EventService eventService;
|
EventService eventService;
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
@Autowired
|
||||||
EventRepository eventRepository;
|
EventRepository eventRepository;
|
||||||
GroupService groupService;
|
GroupService groupService;
|
||||||
|
@Autowired
|
||||||
JsonService jsonService;
|
JsonService jsonService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() {
|
void setUp() {
|
||||||
jsonService = new JsonService();
|
|
||||||
eventRepository = mock(EventRepository.class);
|
|
||||||
eventService = new EventService(jsonService, eventRepository);
|
eventService = new EventService(jsonService, eventRepository);
|
||||||
groupService = new GroupService(eventService, eventRepository);
|
groupService = new GroupService(eventService, eventRepository);
|
||||||
userService = new UserService(groupService, eventService);
|
userService = new UserService(groupService, eventService);
|
||||||
@ -37,41 +56,88 @@ class ControllerServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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
|
@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
|
@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
|
@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
|
@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
|
@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
|
@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 testTitleAndDescription(String title, String description) {
|
||||||
void deleteUser() {
|
assertEquals("test", title);
|
||||||
}
|
assertEquals("hi", description);
|
||||||
|
|
||||||
@Test
|
|
||||||
void deleteGroupEvent() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@ -117,7 +117,7 @@ class GroupServiceTest {
|
|||||||
Group group = TestBuilder.apply(test1, test2);
|
Group group = TestBuilder.apply(test1, test2);
|
||||||
|
|
||||||
assertThat(group.getType()).isEqualTo(null);
|
assertThat(group.getType()).isEqualTo(null);
|
||||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1")).isEmpty();
|
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1")).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -131,7 +131,7 @@ class GroupServiceTest {
|
|||||||
deleteGroupEvent(uuidFromInt(0)),
|
deleteGroupEvent(uuidFromInt(0)),
|
||||||
createPublicGroupEvent());
|
createPublicGroupEvent());
|
||||||
|
|
||||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(1);
|
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1").size()).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -151,7 +151,7 @@ class GroupServiceTest {
|
|||||||
createPublicGroupEvent(),
|
createPublicGroupEvent(),
|
||||||
createPrivateGroupEvent());
|
createPrivateGroupEvent());
|
||||||
|
|
||||||
assertThat(groupService.getAllGroupWithVisibilityPublic("test1").size()).isEqualTo(3);
|
assertThat(groupService.getAllGroupsWithVisibilityPublic("test1").size()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -167,8 +167,8 @@ class GroupServiceTest {
|
|||||||
//Das kommt glaube ich eher in einen Test für die Projektion
|
//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("test2").get(0).getMembers().size()).isEqualTo(1);
|
||||||
|
|
||||||
assertThat(groupService.getAllGroupWithVisibilityPublic("kobold")).hasSize(1);
|
assertThat(groupService.getAllGroupsWithVisibilityPublic("kobold")).hasSize(1);
|
||||||
assertThat(groupService.getAllGroupWithVisibilityPublic("peter")).hasSize(2);
|
assertThat(groupService.getAllGroupsWithVisibilityPublic("peter")).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user