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.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertNull;
24  
25  import java.util.List;
26  import org.apache.syncope.common.lib.SyncopeConstants;
27  import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
28  import org.apache.syncope.core.persistence.api.dao.GroupDAO;
29  import org.apache.syncope.core.persistence.api.dao.RealmDAO;
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 GroupTest extends AbstractTest {
38  
39      @Autowired
40      private GroupDAO groupDAO;
41  
42      @Autowired
43      private RealmDAO realmDAO;
44  
45      @Autowired
46      private AnyTypeDAO anyTypeDAO;
47  
48      @Test
49      public void findAll() {
50          List<Group> groups = groupDAO.findAll(1, 100);
51          assertEquals(16, groups.size());
52  
53          List<String> groupKeys = groupDAO.findAllKeys(1, 100);
54          assertNotNull(groupKeys);
55  
56          assertEquals(groups.size(), groupKeys.size());
57      }
58  
59      @Test
60      public void find() {
61          Group group = groupDAO.findByName("root");
62          assertNotNull(group);
63  
64          group = groupDAO.findByName("additional");
65          assertNotNull(group);
66          assertEquals(1, group.getTypeExtensions().size());
67          assertEquals(2, group.getTypeExtension(anyTypeDAO.findUser()).get().getAuxClasses().size());
68      }
69  
70      @Test
71      public void save() {
72          Group group = entityFactory.newEntity(Group.class);
73          group.setName("secondChild");
74          group.setRealm(realmDAO.findByFullPath(SyncopeConstants.ROOT_REALM));
75  
76          group = groupDAO.save(group);
77  
78          Group actual = groupDAO.find(group.getKey());
79          assertNotNull(actual);
80      }
81  
82      @Test
83      public void delete() {
84          Group group = groupDAO.find("8fb2d51e-c605-4e80-a72b-13ffecf1aa9a");
85          groupDAO.delete(group.getKey());
86  
87          Group actual = groupDAO.find("8fb2d51e-c605-4e80-a72b-13ffecf1aa9a");
88          assertNull(actual);
89      }
90  }