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.assertFalse;
23  import static org.junit.jupiter.api.Assertions.assertNotNull;
24  import static org.junit.jupiter.api.Assertions.assertTrue;
25  
26  import org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO;
27  import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
28  import org.apache.syncope.core.persistence.api.entity.AnyType;
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 AnyTypeTest extends AbstractTest {
37  
38      @Autowired
39      private AnyTypeDAO anyTypeDAO;
40  
41      @Autowired
42      private AnyTypeClassDAO anyTypeClassDAO;
43  
44      @Test
45      public void manyToMany() {
46          AnyTypeClass other = anyTypeClassDAO.find("other");
47          assertNotNull(other);
48  
49          AnyType user = anyTypeDAO.findUser();
50          assertTrue(user.getClasses().contains(other));
51  
52          AnyType group = anyTypeDAO.findGroup();
53          assertFalse(group.getClasses().contains(other));
54  
55          group.add(other);
56          anyTypeDAO.save(group);
57  
58          entityManager().flush();
59  
60          user = anyTypeDAO.findUser();
61          assertTrue(user.getClasses().contains(other));
62          int userClassesBefore = user.getClasses().size();
63  
64          group = anyTypeDAO.findGroup();
65          assertTrue(group.getClasses().contains(other));
66          int groupClassesBefore = group.getClasses().size();
67  
68          anyTypeClassDAO.delete("other");
69  
70          entityManager().flush();
71  
72          user = anyTypeDAO.findUser();
73          assertEquals(userClassesBefore, user.getClasses().size() + 1);
74  
75          group = anyTypeDAO.findGroup();
76          assertEquals(groupClassesBefore, group.getClasses().size() + 1);
77      }
78  }