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.assertNull;
25  import static org.junit.jupiter.api.Assertions.assertTrue;
26  
27  import java.util.List;
28  import org.apache.syncope.common.lib.types.ConnectorCapability;
29  import org.apache.syncope.core.persistence.api.dao.ConnInstanceDAO;
30  import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
31  import org.apache.syncope.core.persistence.api.entity.ConnInstance;
32  import org.apache.syncope.core.persistence.api.entity.ExternalResource;
33  import org.apache.syncope.core.persistence.jpa.AbstractTest;
34  import org.junit.jupiter.api.Test;
35  import org.springframework.beans.factory.annotation.Autowired;
36  import org.springframework.transaction.annotation.Transactional;
37  
38  @Transactional("Master")
39  public class ConnInstanceTest extends AbstractTest {
40  
41      @Autowired
42      private ExternalResourceDAO resourceDAO;
43  
44      @Autowired
45      private ConnInstanceDAO connInstanceDAO;
46  
47      @Test
48      public void deleteCascade() {
49          ConnInstance connInstance = connInstanceDAO.find("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
50          assertNotNull(connInstance);
51  
52          List<? extends ExternalResource> resources = connInstance.getResources();
53          assertNotNull(resources);
54          assertFalse(resources.isEmpty());
55  
56          connInstanceDAO.delete(connInstance.getKey());
57  
58          entityManager().flush();
59  
60          ConnInstance actual = connInstanceDAO.find("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
61          assertNull(actual);
62  
63          for (ExternalResource resource : resources) {
64              assertNull(resourceDAO.find(resource.getKey()));
65          }
66      }
67  
68      @Test
69      public void issue176() {
70          ConnInstance connInstance = connInstanceDAO.find("fcf9f2b0-f7d6-42c9-84a6-61b28255a42b");
71          assertNotNull(connInstance);
72          assertTrue(connInstance.getCapabilities().isEmpty());
73  
74          List<? extends ExternalResource> resources = connInstance.getResources();
75          assertNotNull(resources);
76          assertEquals(4, resources.size());
77          assertTrue(
78                  "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(0).getKey())
79                  || "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(1).getKey())
80                  || "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(2).getKey())
81                  || "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(3).getKey()));
82  
83          connInstance.getCapabilities().add(ConnectorCapability.SEARCH);
84  
85          connInstance = connInstanceDAO.save(connInstance);
86          assertNotNull(connInstance);
87          assertFalse(connInstance.getCapabilities().isEmpty());
88  
89          resources = connInstance.getResources();
90          assertNotNull(resources);
91          assertEquals(4, resources.size());
92          assertTrue(
93                  "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(0).getKey())
94                  || "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(1).getKey())
95                  || "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(2).getKey())
96                  || "ws-target-resource-nopropagation".equalsIgnoreCase(resources.get(3).getKey()));
97      }
98  }