@Test public void testWithPermissionsFromGroupFromGroup() { // Given a new user without permissions nor Groups Permission p1 = new Permission("permission1"); Permission p2 = new Permission("permission2"); Permission p3 = new Permission("permission3"); User u = new User(); Group g1 = new Group(); u.getGroups().add(g1); Group g2 = new Group(); g1.getGroups().add(g2); List<Permission> lp = u.getPermissions(); lp.add(p1); lp = g1.getPermissions(); lp.add(p2); lp = g2.getPermissions(); lp.add(p3); // When we retrieve InheritedPermission lp = PermissionsOwnerTools.getInheritedPermission(u); // There is no permissions Assertions.assertThat(lp.size() == 3).isTrue(); Assertions.assertThat(lp.contains(p1)).isTrue(); Assertions.assertThat(lp.contains(p2)).isTrue(); Assertions.assertThat(lp.contains(p3)).isTrue(); }
@Override public void testUpdate() throws Exception { User u1 = dao.readByPrimaryKey(this.id); u1.setEmail("*****@*****.**"); dao.save(u1); User u2 = dao.readByPrimaryKey(this.id); assertEquals("User not updated!", u2.getEmail(), "*****@*****.**"); }
@Override protected User createTestEntity() { String userLogin = "******" + Math.round(Math.random() * 1000); String userPassword = "******"; User u = new User(); u.setLogin(userLogin); u.setPassword(userPassword); return u; }
@Test public void testWithoutPermissions() { // Given a new user without permissions nor Groups User u = new User(); List<Permission> lp = u.getPermissions(); if (lp == null) { lp = new ArrayList<Permission>(); } // When we retrieve InheritedPermission lp = PermissionsOwnerTools.getInheritedPermission(u); // There is no permissions Assertions.assertThat(lp.size() == 0).isTrue(); }
@Test public void testGetANDPermissions() { // given a new user User u1 = new User(); String login = "******"; String password = "******"; u1.setLogin(login); u1.setPassword(password); ArrayList<String> permissions = new ArrayList<String>(); permissions.add("ADMIN"); permissions.add("USER"); u1.getPermissions().addAll(permissions); dao.save(u1); // when we search him by his login and password List<User> l = dao.findEquals("Login", login); assertNotNull(l); u1 = l.get(0); // we get the user as response assertNotNull(u1); assertEquals(login, u1.getLogin()); assertEquals(u1.getPermissions().get(0), "ADMIN"); // TODO : remove this when we will use DBunit u1.getPermissions().clear(); }
@Test public void testWithPermissions() { // Given a new user without permissions nor Groups Permission p1 = new Permission("permission1"); Permission p2 = new Permission("permission2"); User u = new User(); List<Permission> lp = u.getPermissions(); if (lp == null) { lp = new ArrayList<Permission>(); } lp.add(p1); lp.add(p2); // When we retrieve InheritedPermission lp = PermissionsOwnerTools.getInheritedPermission(u); // There is the 2 permissions Assertions.assertThat(lp.size() == 2).isTrue(); Assertions.assertThat(lp.contains(p1)).isTrue(); Assertions.assertThat(lp.contains(p2)).isTrue(); }