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