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.common.lib;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  
23  import org.apache.syncope.common.lib.request.AnyObjectUR;
24  import org.apache.syncope.common.lib.request.AttrPatch;
25  import org.apache.syncope.common.lib.to.AnyObjectTO;
26  import org.apache.syncope.common.lib.types.PatchOperation;
27  import org.junit.jupiter.api.Test;
28  
29  public class AnyOperationsTest {
30  
31      @Test
32      public void mindiff() {
33          AnyObjectTO oldOne = new AnyObjectTO();
34          oldOne.setName("name");
35          oldOne.getPlainAttrs().add(new Attr.Builder("plain").value("oldValue").build());
36          oldOne.getPlainAttrs().add(new Attr.Builder("encrypted").value("oldValue").build());
37  
38          AnyObjectTO newOne = new AnyObjectTO();
39          newOne.setName("name");
40          newOne.getPlainAttrs().add(new Attr.Builder("plain").value("newValue").build());
41          newOne.getPlainAttrs().add(new Attr.Builder("encrypted").value("oldValue").build());
42  
43          AnyObjectUR diff = AnyOperations.diff(newOne, oldOne, true);
44          assertEquals(1, diff.getPlainAttrs().size());
45  
46          AttrPatch patch = diff.getPlainAttrs().iterator().next();
47          assertEquals(PatchOperation.ADD_REPLACE, patch.getOperation());
48          assertEquals("plain", patch.getAttr().getSchema());
49      }
50  }