1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }