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.to;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  
23  import com.fasterxml.jackson.core.type.TypeReference;
24  import com.fasterxml.jackson.databind.ObjectMapper;
25  import java.io.IOException;
26  import java.io.StringWriter;
27  import java.util.Date;
28  import java.util.UUID;
29  import org.apache.syncope.common.lib.Attr;
30  import org.apache.syncope.common.lib.form.FormProperty;
31  import org.apache.syncope.common.lib.form.FormPropertyType;
32  import org.apache.syncope.common.lib.form.FormPropertyValue;
33  import org.apache.syncope.common.lib.request.AttrPatch;
34  import org.apache.syncope.common.lib.request.UserUR;
35  import org.junit.jupiter.api.Test;
36  
37  public abstract class SerializationTest {
38  
39      protected abstract ObjectMapper objectMapper();
40  
41      @Test
42      public void userRequestForm() throws IOException {
43          UserRequestForm form = new UserRequestForm();
44          form.setBpmnProcess("process");
45          form.setCreateTime(new Date());
46          form.setUsername("username");
47          form.setExecutionId("434343");
48          form.setFormKey("123456");
49  
50          UserTO userTO = new UserTO();
51          userTO.setKey(UUID.randomUUID().toString());
52          form.setUserTO(userTO);
53  
54          UserUR userUR = new UserUR();
55          userUR.setKey(userTO.getKey());
56          userUR.getPlainAttrs().add(new AttrPatch.Builder(new Attr.Builder("schema1").value("value1").build()).build());
57          form.setUserUR(userUR);
58  
59          FormProperty property = new FormProperty();
60          property.setId("printMode");
61          property.setName("Preferred print mode");
62          property.setType(FormPropertyType.Dropdown);
63          property.getDropdownValues().add(
64                  new FormPropertyValue("8559d14d-58c2-46eb-a2d4-a7d35161e8f8", "value1"));
65          property.getDropdownValues().add(
66                  new FormPropertyValue(UUID.randomUUID().toString(), "value2 / value3"));
67          form.getProperties().add(property);
68  
69          PagedResult<UserRequestForm> original = new PagedResult<>();
70          original.getResult().add(form);
71          original.setSize(1);
72          original.setTotalCount(1);
73  
74          StringWriter writer = new StringWriter();
75          objectMapper().writeValue(writer, original);
76  
77          PagedResult<UserRequestForm> actual = objectMapper().readValue(writer.toString(), new TypeReference<>() {
78          });
79          assertEquals(original, actual);
80      }
81  }