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.common.lib.to.Item;
27  import org.apache.syncope.common.lib.types.AnyTypeKind;
28  import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO;
29  import org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO;
30  import org.apache.syncope.core.persistence.api.dao.VirSchemaDAO;
31  import org.apache.syncope.core.persistence.api.entity.ExternalResource;
32  import org.apache.syncope.core.persistence.api.entity.VirSchema;
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 VirSchemaTest extends AbstractTest {
40  
41      @Autowired
42      private VirSchemaDAO virSchemaDAO;
43  
44      @Autowired
45      private ExternalResourceDAO resourceDAO;
46  
47      @Autowired
48      private AnyTypeDAO anyTypeDAO;
49  
50      @Test
51      public void deal() {
52          ExternalResource resource = resourceDAO.find("ws-target-resource-1");
53          assertNotNull(resource);
54          assertTrue(virSchemaDAO.find(resource).isEmpty());
55          assertTrue(virSchemaDAO.find(resource.getKey(), AnyTypeKind.USER.name()).isEmpty());
56  
57          VirSchema virSchema = entityFactory.newEntity(VirSchema.class);
58          virSchema.setKey("vSchema");
59          virSchema.setReadonly(true);
60          virSchema.setExtAttrName("EXT_ATTR");
61          virSchema.setResource(resource);
62          virSchema.setAnyType(anyTypeDAO.findUser());
63  
64          virSchemaDAO.save(virSchema);
65          entityManager().flush();
66  
67          virSchema = virSchemaDAO.find("vSchema");
68          assertNotNull(virSchema);
69          assertTrue(virSchema.isReadonly());
70          assertEquals("EXT_ATTR", virSchema.getExtAttrName());
71  
72          assertFalse(virSchemaDAO.find(resource).isEmpty());
73          assertTrue(virSchemaDAO.find(resource).contains(virSchema.getKey()));
74  
75          assertFalse(virSchemaDAO.find(resource.getKey(), AnyTypeKind.USER.name()).isEmpty());
76          assertTrue(virSchemaDAO.find(resource.getKey(), AnyTypeKind.USER.name()).contains(virSchema));
77  
78          Item item = virSchema.asLinkingMappingItem();
79          assertNotNull(item);
80          assertEquals(virSchema.getKey(), item.getIntAttrName());
81      }
82  }