From a79ab6473bcfaf783e185f309937029095f23c60 Mon Sep 17 00:00:00 2001 From: killerber4t Date: Thu, 26 Mar 2020 16:26:07 +0100 Subject: [PATCH] add more testcases --- .../service/ControllerServiceTest.java | 98 ++++++++++++++++++- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/src/test/java/mops/gruppen2/service/ControllerServiceTest.java b/src/test/java/mops/gruppen2/service/ControllerServiceTest.java index 47b85d9..c2b3107 100644 --- a/src/test/java/mops/gruppen2/service/ControllerServiceTest.java +++ b/src/test/java/mops/gruppen2/service/ControllerServiceTest.java @@ -31,8 +31,7 @@ import static org.mockito.Mockito.mock; @Transactional @Rollback class ControllerServiceTest { - Faker faker; - Account account; + Account account, account2; ControllerService controllerService; EventService eventService; UserService userService; @@ -42,8 +41,6 @@ class ControllerServiceTest { @Autowired JsonService jsonService; - - @BeforeEach void setUp() { eventService = new EventService(jsonService, eventRepository); @@ -53,6 +50,7 @@ class ControllerServiceTest { Set roles = new HashSet<>(); roles.add("l"); account = new Account("ich", "ich@hhu.de", "l", "ichdude", "jap", roles); + account2 = new Account("ich2", "ich2@hhu.de", "l", "ichdude2", "jap2", roles); } @Test @@ -99,6 +97,58 @@ class ControllerServiceTest { assertNull(groups.get(0).getParent()); } + @Test + void createPrivateGroupWithParentAndLimitedNumberTest() throws IOException { + eventRepository.deleteAll(); + controllerService.createOrga(account2, "test", "hi", null, null, true, null, null); + List groups1= userService.getUserGroups(new User(account2.getName(),account2.getGivenname(),account2.getFamilyname(),account2.getEmail())); + controllerService.createGroup(account,"test", "hi", true, null, 20L, groups1.get(0).getId()); + List 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" + assertEquals(groups1.get(0).getId(),groups.get(0).getParent()); + } + + @Test + void createPublicGroupWithParentAndLimitedNumberTest() throws IOException { + eventRepository.deleteAll(); + controllerService.createOrga(account2, "test", "hi", null, null, true, null, null); + List groups1= userService.getUserGroups(new User(account2.getName(),account2.getGivenname(),account2.getFamilyname(),account2.getEmail())); + controllerService.createGroup(account,"test", "hi", null, null, 20L, groups1.get(0).getId()); + List 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()); //100k ist "maximum" + assertEquals(groups1.get(0).getId(),groups.get(0).getParent()); + } + + @Test + void createPublicGroupWithParentAndUnlimitedNumberTest() throws IOException { + eventRepository.deleteAll(); + controllerService.createOrga(account2, "test", "hi", null, null, true, null, null); + List groups1= userService.getUserGroups(new User(account2.getName(),account2.getGivenname(),account2.getFamilyname(),account2.getEmail())); + controllerService.createGroup(account,"test", "hi", null, true, null, groups1.get(0).getId()); + List 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" + assertEquals(groups1.get(0).getId(),groups.get(0).getParent()); + } + + @Test + void createPrivateGroupWithParentAndUnlimitedNumberTest() throws IOException { + eventRepository.deleteAll(); + controllerService.createOrga(account2, "test", "hi", null, null, true, null, null); + List groups1= userService.getUserGroups(new User(account2.getName(),account2.getGivenname(),account2.getFamilyname(),account2.getEmail())); + controllerService.createGroup(account,"test", "hi", true, true, null, groups1.get(0).getId()); + List 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" + assertEquals(groups1.get(0).getId(),groups.get(0).getParent()); + } + @Test void createPublicOrgaGroupWithNoParentAndLimitedNumberTest() throws IOException { eventRepository.deleteAll(); @@ -135,6 +185,46 @@ class ControllerServiceTest { assertNull(groups.get(0).getParent()); } + @Test + void createPrivateOrgaGroupWithNoParentAndUnlimitedNumberTest() throws IOException { + eventRepository.deleteAll(); + controllerService.createOrga(account, "test", "hi", true, null, true, null, null); + List 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(100000L, groups.get(0).getUserMaximum()); + assertNull(groups.get(0).getParent()); + } + + @Test + void createOrgaLectureGroupAndLimitedNumberTest() throws IOException { + eventRepository.deleteAll(); + controllerService.createOrga(account, "test", "hi", null, true, null, 20L, null); + List groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail())); + testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); + assertEquals(GroupType.LECTURE, groups.get(0).getType()); + assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility()); + assertEquals(20L, groups.get(0).getUserMaximum()); + assertNull(groups.get(0).getParent()); + } + + @Test + void createOrgaLectureGroupAndUnlimitedNumberTest() throws IOException { + eventRepository.deleteAll(); + controllerService.createOrga(account, "test", "hi", null, true, true, null, null); + List groups= userService.getUserGroups(new User(account.getName(),account.getGivenname(),account.getFamilyname(),account.getEmail())); + testTitleAndDescription(groups.get(0).getTitle(), groups.get(0).getDescription()); + assertEquals(GroupType.LECTURE, groups.get(0).getType()); + assertEquals(Visibility.PUBLIC, groups.get(0).getVisibility()); + assertEquals(100000L, groups.get(0).getUserMaximum()); + assertNull(groups.get(0).getParent()); + } + + + + + void testTitleAndDescription(String title, String description) { assertEquals("test", title); assertEquals("hi", description);