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.outer;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertTrue;
24  
25  import org.apache.syncope.core.persistence.api.dao.GroupDAO;
26  import org.apache.syncope.core.persistence.api.dao.RealmDAO;
27  import org.apache.syncope.core.persistence.api.dao.RoleDAO;
28  import org.apache.syncope.core.persistence.api.entity.Realm;
29  import org.apache.syncope.core.persistence.api.entity.Role;
30  import org.apache.syncope.core.persistence.api.entity.group.Group;
31  import org.apache.syncope.core.persistence.jpa.AbstractTest;
32  import org.junit.jupiter.api.Test;
33  import org.springframework.beans.factory.annotation.Autowired;
34  import org.springframework.transaction.annotation.Transactional;
35  
36  @Transactional("Master")
37  public class RealmTest extends AbstractTest {
38  
39      @Autowired
40      private RealmDAO realmDAO;
41  
42      @Autowired
43      private RoleDAO roleDAO;
44  
45      @Autowired
46      private GroupDAO groupDAO;
47  
48      @Test
49      public void test() {
50          Realm realm = realmDAO.findByFullPath("/odd");
51          assertNotNull(realm);
52  
53          // need to remove this group in order to remove the realm, which is otherwise empty
54          Group group = groupDAO.findByName("fake");
55          assertNotNull(group);
56          assertEquals(realm, group.getRealm());
57          groupDAO.delete(group);
58  
59          Role role = roleDAO.find("User reviewer");
60          assertTrue(role.getRealms().contains(realm));
61  
62          int beforeSize = role.getRealms().size();
63  
64          realmDAO.delete(realm);
65  
66          entityManager().flush();
67  
68          role = roleDAO.find("User reviewer");
69          assertEquals(beforeSize - 1, role.getRealms().size());
70      }
71  }