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.assertNotNull;
22  import static org.junit.jupiter.api.Assertions.assertNull;
23  import static org.junit.jupiter.api.Assertions.fail;
24  
25  import org.apache.syncope.common.lib.types.AnyTypeKind;
26  import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException;
27  import org.apache.syncope.core.persistence.api.dao.PlainAttrDAO;
28  import org.apache.syncope.core.persistence.api.dao.PlainAttrValueDAO;
29  import org.apache.syncope.core.persistence.api.entity.user.UPlainAttr;
30  import org.apache.syncope.core.persistence.api.entity.user.UPlainAttrValue;
31  import org.apache.syncope.core.persistence.jpa.AbstractTest;
32  import org.junit.jupiter.api.Tag;
33  import org.junit.jupiter.api.Test;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.transaction.annotation.Transactional;
36  
37  @Tag("plainAttrTable")
38  @Transactional("Master")
39  public class PlainAttrTest extends AbstractTest {
40  
41      @Autowired
42      private PlainAttrDAO plainAttrDAO;
43  
44      @Autowired
45      private PlainAttrValueDAO plainAttrValueDAO;
46  
47      @Test
48      public void deleteAttr() {
49          plainAttrDAO.delete(findPlainAttr("35f407a2-d254-4890-9e45-5a7dd8c8df7d", UPlainAttr.class));
50  
51          entityManager().flush();
52  
53          assertNull(findPlainAttr("35f407a2-d254-4890-9e45-5a7dd8c8df7d", UPlainAttr.class));
54          assertNull(findPlainAttrValue("0c67225a-030a-4c56-b337-17cf7a311f0f", UPlainAttrValue.class));
55      }
56  
57      @Test
58      public void deleteAllAttValues() {
59          UPlainAttrValue value = findPlainAttrValue("7034de3b-3687-4db5-8454-363468f1a9de", UPlainAttrValue.class);
60          assertNotNull(value);
61  
62          plainAttrValueDAO.deleteAll(value.getAttr(), anyUtilsFactory.getInstance(AnyTypeKind.USER));
63  
64          value = findPlainAttrValue("7034de3b-3687-4db5-8454-363468f1a9de", UPlainAttrValue.class);
65          assertNull(value);
66  
67          // by removing all values, the related attribute is not valid any more
68          try {
69              entityManager().flush();
70              fail();
71          } catch (InvalidEntityException e) {
72              assertNotNull(e);
73          }
74      }
75  }