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.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertNull;
24  
25  import java.time.OffsetDateTime;
26  import java.util.UUID;
27  import org.apache.syncope.core.persistence.api.dao.AccessTokenDAO;
28  import org.apache.syncope.core.persistence.api.entity.AccessToken;
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 AccessTokenTest extends AbstractTest {
36  
37      @Autowired
38      private AccessTokenDAO accessTokenDAO;
39  
40      @Test
41      public void crud() {
42          AccessToken accessToken = entityFactory.newEntity(AccessToken.class);
43          accessToken.setKey(UUID.randomUUID().toString());
44          accessToken.setBody("pointless body");
45          accessToken.setExpirationTime(OffsetDateTime.now());
46          accessToken.setOwner("bellini");
47  
48          accessToken = accessTokenDAO.save(accessToken);
49          assertNotNull(accessToken);
50  
51          entityManager().flush();
52  
53          accessToken = accessTokenDAO.findByOwner("bellini");
54          assertNotNull(accessToken);
55          assertEquals("bellini", accessToken.getOwner());
56  
57          accessTokenDAO.deleteExpired();
58  
59          entityManager().flush();
60  
61          accessToken = accessTokenDAO.findByOwner("bellini");
62          assertNull(accessToken);
63      }
64  }