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.core.persistence.api.dao.AnyTypeClassDAO;
28  import org.apache.syncope.core.persistence.api.dao.PlainSchemaDAO;
29  import org.apache.syncope.core.persistence.api.entity.AnyTypeClass;
30  import org.apache.syncope.core.persistence.jpa.AbstractTest;
31  import org.junit.jupiter.api.Test;
32  import org.springframework.beans.factory.annotation.Autowired;
33  import org.springframework.transaction.annotation.Transactional;
34  
35  @Transactional("Master")
36  public class AnyTypeClassTest extends AbstractTest {
37  
38      @Autowired
39      private PlainSchemaDAO plainSchemaDAO;
40  
41      @Autowired
42      private AnyTypeClassDAO anyTypeClassDAO;
43  
44      @Test
45      public void find() {
46          AnyTypeClass minimalGroup = anyTypeClassDAO.find("minimal group");
47          assertNotNull(minimalGroup);
48  
49          assertFalse(minimalGroup.getPlainSchemas().isEmpty());
50          assertFalse(minimalGroup.getDerSchemas().isEmpty());
51          assertFalse(minimalGroup.getVirSchemas().isEmpty());
52      }
53  
54      @Test
55      public void findAll() {
56          List<AnyTypeClass> list = anyTypeClassDAO.findAll();
57          assertFalse(list.isEmpty());
58      }
59  
60      @Test
61      public void save() {
62          AnyTypeClass newClass = entityFactory.newEntity(AnyTypeClass.class);
63          newClass.setKey("new class");
64          newClass.add(plainSchemaDAO.find("firstname"));
65  
66          newClass = anyTypeClassDAO.save(newClass);
67          assertNotNull(newClass);
68          assertFalse(newClass.getPlainSchemas().isEmpty());
69          assertTrue(newClass.getDerSchemas().isEmpty());
70          assertTrue(newClass.getVirSchemas().isEmpty());
71      }
72  
73      @Test
74      public void delete() {
75          AnyTypeClass minimalUser = anyTypeClassDAO.find("minimal user");
76          assertNotNull(minimalUser);
77  
78          anyTypeClassDAO.delete(minimalUser.getKey());
79          assertNull(anyTypeClassDAO.find("minimal user"));
80      }
81  }