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.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertNull;
24  
25  import java.util.UUID;
26  import org.apache.syncope.core.persistence.api.dao.CASSPClientAppDAO;
27  import org.apache.syncope.core.persistence.api.entity.am.CASSPClientApp;
28  import org.apache.syncope.core.persistence.api.entity.policy.AccessPolicy;
29  import org.apache.syncope.core.persistence.api.entity.policy.AuthPolicy;
30  import org.junit.jupiter.api.Test;
31  import org.springframework.beans.factory.annotation.Autowired;
32  import org.springframework.transaction.annotation.Transactional;
33  
34  @Transactional("Master")
35  public class CASSPTest extends AbstractClientAppTest {
36  
37      @Autowired
38      private CASSPClientAppDAO casspDAO;
39  
40      @Test
41      public void find() {
42          int beforeCount = casspDAO.findAll().size();
43  
44          CASSPClientApp rp = entityFactory.newEntity(CASSPClientApp.class);
45          rp.setName("CAS");
46          rp.setClientAppId(UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE);
47          rp.setDescription("This is a sample CAS RP");
48          rp.setServiceId("https://syncope.apache.org/.*");
49  
50          AccessPolicy accessPolicy = buildAndSaveAccessPolicy();
51          rp.setAccessPolicy(accessPolicy);
52  
53          AuthPolicy authPolicy = buildAndSaveAuthPolicy();
54          rp.setAuthPolicy(authPolicy);
55  
56          casspDAO.save(rp);
57  
58          assertNotNull(rp);
59          assertNotNull(rp.getKey());
60  
61          int afterCount = casspDAO.findAll().size();
62          assertEquals(afterCount, beforeCount + 1);
63  
64          rp = casspDAO.findByName("CAS");
65          assertNotNull(rp);
66  
67          rp = casspDAO.findByClientAppId(rp.getClientAppId());
68          assertNotNull(rp);
69  
70          casspDAO.delete(rp);
71          assertNull(casspDAO.findByName("CAS"));
72      }
73  }