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.logic;
20  
21  import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
22  import static org.mockito.Mockito.mock;
23  import static org.mockito.Mockito.when;
24  
25  import java.util.List;
26  import java.util.stream.Stream;
27  import org.apache.syncope.common.lib.scim.SCIMConf;
28  import org.apache.syncope.common.lib.to.UserTO;
29  import org.apache.syncope.core.logic.scim.SCIMConfManager;
30  import org.apache.syncope.core.spring.security.AuthDataAccessor;
31  import org.apache.syncope.ext.scimv2.api.data.SCIMPatchOperation;
32  import org.apache.syncope.ext.scimv2.api.data.SCIMPatchPath;
33  import org.junit.jupiter.api.BeforeAll;
34  import org.junit.jupiter.api.TestInstance;
35  import org.junit.jupiter.params.ParameterizedTest;
36  import org.junit.jupiter.params.provider.MethodSource;
37  
38  @TestInstance(TestInstance.Lifecycle.PER_CLASS)
39  public class SCIMDataBinderTest {
40  
41      private SCIMDataBinder dataBinder;
42  
43      private static Stream<String> getValue() {
44          return Stream.of("True", "False");
45      }
46  
47      @BeforeAll
48      void setup() {
49          SCIMConfManager scimConfManager = mock(SCIMConfManager.class);
50          when(scimConfManager.get()).thenReturn(new SCIMConf());
51          UserLogic userLogic = mock(UserLogic.class);
52          AuthDataAccessor authDataAccessor = mock(AuthDataAccessor.class);
53          dataBinder = new SCIMDataBinder(scimConfManager, userLogic, authDataAccessor);
54      }
55  
56      @ParameterizedTest
57      @MethodSource("getValue")
58      void toUserUpdate(final String value) {
59          SCIMPatchOperation operation = new SCIMPatchOperation();
60          SCIMPatchPath scimPatchPath = new SCIMPatchPath();
61          scimPatchPath.setAttribute("active");
62          operation.setPath(scimPatchPath);
63          operation.setValue(List.of(value));
64          assertDoesNotThrow(() -> dataBinder.toUserUpdate(new UserTO(), operation));
65      }
66  }