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.fit.core.wa;
20  
21  import static org.junit.jupiter.api.Assertions.assertFalse;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertThrows;
24  
25  import java.io.Serializable;
26  import java.util.Collection;
27  import java.util.List;
28  import java.util.UUID;
29  import org.apache.syncope.common.lib.Attr;
30  import org.apache.syncope.common.lib.SyncopeClientException;
31  import org.apache.syncope.fit.AbstractITCase;
32  import org.junit.jupiter.api.Test;
33  
34  public class WAConfigITCase extends AbstractITCase {
35  
36      private static Attr runTest(final List<String> initialValue, final List<String> updatedValue) {
37          Attr config = new Attr.Builder(UUID.randomUUID().toString()).values(initialValue).build();
38          WA_CONFIG_SERVICE.set(config);
39  
40          assertFalse(WA_CONFIG_SERVICE.list().isEmpty());
41  
42          config = WA_CONFIG_SERVICE.get(config.getSchema());
43          assertNotNull(config);
44  
45          config = new Attr.Builder(config.getSchema()).values(updatedValue).build();
46          WA_CONFIG_SERVICE.set(config);
47  
48          Attr updatedTO = WA_CONFIG_SERVICE.get(config.getSchema());
49          updatedTO.getValues().stream().allMatch(((Collection) updatedValue)::contains);
50          return updatedTO;
51      }
52  
53      private static <T extends Serializable> void deleteEntry(final Attr configTO) {
54          WA_CONFIG_SERVICE.delete(configTO.getSchema());
55          assertThrows(SyncopeClientException.class, () -> WA_CONFIG_SERVICE.get(configTO.getSchema()));
56      }
57  
58      @Test
59      public void verify() {
60          deleteEntry(runTest(List.of("v1", "v2"), List.of("newValue")));
61          deleteEntry(runTest(List.of("12345"), List.of("98765")));
62          deleteEntry(runTest(List.of("123.45"), List.of("987.65")));
63          deleteEntry(runTest(List.of("1", "2", "3"), List.of("4", "5", "6")));
64      }
65  }