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.provisioning.java;
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.core.persistence.api.dao.DerSchemaDAO;
27  import org.apache.syncope.core.persistence.api.dao.UserDAO;
28  import org.apache.syncope.core.persistence.api.entity.DerSchema;
29  import org.apache.syncope.core.persistence.api.entity.user.User;
30  import org.apache.syncope.core.provisioning.api.DerAttrHandler;
31  import org.junit.jupiter.api.Test;
32  import org.springframework.beans.factory.annotation.Autowired;
33  import org.springframework.transaction.annotation.Transactional;
34  
35  @Transactional("Master")
36  public class DerAttrTest extends AbstractTest {
37  
38      @Autowired
39      private DerSchemaDAO derSchemaDAO;
40  
41      @Autowired
42      private UserDAO userDAO;
43  
44      @Autowired
45      private DerAttrHandler derAttrHandler;
46  
47      @Test
48      public void derAttrFromSpecialAttrs() {
49          DerSchema info = derSchemaDAO.find("info");
50          assertEquals("username + ' - ' + creationDate + '[' + failedLogins + ']'", info.getExpression());
51  
52          User user = userDAO.findByUsername("vivaldi");
53          assertNotNull(user);
54  
55          String value = derAttrHandler.getValue(user, info);
56          assertNotNull(value);
57          assertFalse(value.isEmpty());
58          assertTrue(value.startsWith("vivaldi - 2010-10-20"));
59          assertTrue(value.endsWith("[0]"));
60      }
61  }