View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.persistence.jpa.inner;
20  
21  import static org.junit.jupiter.api.Assertions.assertFalse;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertNull;
24  import static org.junit.jupiter.api.Assertions.assertTrue;
25  
26  import java.util.List;
27  import org.apache.syncope.common.lib.types.IdRepoEntitlement;
28  import org.apache.syncope.core.persistence.api.dao.RealmDAO;
29  import org.apache.syncope.core.persistence.api.dao.RoleDAO;
30  import org.apache.syncope.core.persistence.api.entity.Role;
31  import org.apache.syncope.core.persistence.jpa.AbstractTest;
32  import org.junit.jupiter.api.Assertions;
33  import org.junit.jupiter.api.Test;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.transaction.annotation.Transactional;
36  
37  @Transactional("Master")
38  public class RoleTest extends AbstractTest {
39  
40      @Autowired
41      private RoleDAO roleDAO;
42  
43      @Autowired
44      private RealmDAO realmDAO;
45  
46      @Test
47      public void find() {
48          Role role = roleDAO.find("User manager");
49          assertNotNull(role);
50          assertNotNull(role.getKey());
51          assertFalse(role.getRealms().isEmpty());
52          assertFalse(role.getEntitlements().isEmpty());
53          assertTrue(role.getEntitlements().contains(IdRepoEntitlement.USER_SEARCH));
54      }
55  
56      @Test
57      public void findAll() {
58          List<Role> list = roleDAO.findAll();
59          assertNotNull(list);
60          assertFalse(list.isEmpty());
61          list.forEach(Assertions::assertNotNull);
62      }
63  
64      @Test
65      public void save() {
66          Role role = entityFactory.newEntity(Role.class);
67          role.setKey("new");
68          role.add(realmDAO.getRoot());
69          role.add(realmDAO.findByFullPath("/even/two"));
70          role.getEntitlements().add(IdRepoEntitlement.AUDIT_LIST);
71          role.getEntitlements().add(IdRepoEntitlement.AUDIT_SET);
72  
73          Role actual = roleDAO.save(role);
74          assertNotNull(actual);
75      }
76  
77      @Test
78      public void delete() {
79          assertNotNull(roleDAO.find("Other"));
80  
81          roleDAO.delete("Other");
82          assertNull(roleDAO.find("Other"));
83      }
84  }