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.nio.charset.StandardCharsets;
26  import java.util.UUID;
27  import org.apache.syncope.core.persistence.api.dao.SAML2IdPEntityDAO;
28  import org.apache.syncope.core.persistence.api.entity.am.SAML2IdPEntity;
29  import org.apache.syncope.core.persistence.jpa.AbstractTest;
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 SAML2IdPEntityTest extends AbstractTest {
36  
37      @Autowired
38      private SAML2IdPEntityDAO saml2IdPEntityDAO;
39  
40      @Test
41      public void find() {
42          create("Syncope");
43          SAML2IdPEntity entity = saml2IdPEntityDAO.find("Syncope");
44          assertNotNull(entity);
45  
46          entity = saml2IdPEntityDAO.find(UUID.randomUUID().toString());
47          assertNull(entity);
48      }
49  
50      @Test
51      public void save() {
52          create("SyncopeCreate");
53      }
54  
55      @Test
56      public void update() {
57          SAML2IdPEntity entity = create("SyncopeUpdate");
58          assertNotNull(entity);
59          entity.setKey("OtherSyncope");
60  
61          entity = saml2IdPEntityDAO.save(entity);
62          assertNotNull(entity);
63          assertNotNull(entity.getKey());
64          SAML2IdPEntity found = saml2IdPEntityDAO.find(entity.getKey());
65          assertNotNull(found);
66          assertEquals("OtherSyncope", found.getKey());
67      }
68  
69      private SAML2IdPEntity create(final String owner) {
70          SAML2IdPEntity entity = entityFactory.newEntity(SAML2IdPEntity.class);
71          entity.setKey(owner);
72          entity.setMetadata("metadata".getBytes(StandardCharsets.UTF_8));
73          entity.setEncryptionCertificate("encryptionCert".getBytes(StandardCharsets.UTF_8));
74          entity.setEncryptionKey("encryptionKey".getBytes(StandardCharsets.UTF_8));
75          entity.setSigningCertificate("signatureCert".getBytes(StandardCharsets.UTF_8));
76          entity.setSigningKey("signatureKey".getBytes(StandardCharsets.UTF_8));
77          saml2IdPEntityDAO.save(entity);
78          assertNotNull(entity);
79          assertNotNull(entity.getKey());
80          assertNotNull(saml2IdPEntityDAO.find(entity.getKey()));
81  
82          return entity;
83      }
84  }