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.api.serialization;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNull;
23  
24  import com.fasterxml.jackson.core.type.TypeReference;
25  import java.util.List;
26  import java.util.Set;
27  import org.apache.syncope.core.persistence.api.entity.task.PropagationData;
28  import org.apache.syncope.core.provisioning.api.AbstractTest;
29  import org.identityconnectors.framework.common.objects.AttributeBuilder;
30  import org.identityconnectors.framework.common.objects.AttributeDeltaBuilder;
31  import org.junit.jupiter.api.Test;
32  import org.mockito.Mock;
33  
34  public class POJOHelperTest extends AbstractTest {
35  
36      @Test
37      public void serialize() {
38          Object object = 9001;
39  
40          assertEquals(String.valueOf(object), POJOHelper.serialize(object));
41      }
42  
43      @Test
44      public void deserializeWithClassReference() {
45          String serialized = "false";
46  
47          assertEquals(Boolean.valueOf(serialized), POJOHelper.deserialize(serialized, Object.class));
48      }
49  
50      @Test
51      public void deserializeWithTypeReference(final @Mock TypeReference<? extends Object> reference) {
52          String serialized = "false";
53  
54          assertNull(POJOHelper.deserialize(serialized, reference));
55      }
56  
57      @Test
58      public void propagationData() {
59          PropagationData original = new PropagationData(Set.of(AttributeBuilder.build("title", "title1")));
60          original.setAttributeDeltas(Set.of(AttributeDeltaBuilder.build("title", List.of("title2"), List.of("title1"))));
61  
62          String serialized = POJOHelper.serialize(original);
63  
64          assertEquals(serialized, POJOHelper.serialize(POJOHelper.deserialize(serialized, PropagationData.class)));
65      }
66  }