content: /*
   * Copyright 2017-2025 Hyland Software, Inc. and its affiliates.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.activiti.cloud.services.audit.jpa.converters;
  
  import static net.javacrumbs.jsonunit.assertj.JsonAssertions.assertThatJson;
  import static org.activiti.test.Assertions.assertThat;
  
  import java.util.Date;
  import org.activiti.api.task.model.Task;
  import org.activiti.api.task.model.impl.TaskImpl;
  import org.activiti.cloud.services.audit.jpa.converters.json.TaskJpaJsonConverter;
  import org.junit.jupiter.api.Test;
  
  public class TaskJpaJsonConverterTest {
  
      private TaskJpaJsonConverter converter = new TaskJpaJsonConverter();
  
      @Test
      public void convertToDatabaseColumnShouldReturnTheEntityJsonRepresentation() throws Exception {
          //given
          Date now = new Date();
          TaskImpl task = new TaskImpl("3", "task1", Task.TaskStatus.CREATED);
          task.setAssignee("user1");
          task.setDescription("First task");
          task.setOwner("user2");
          task.setPriority(50);
          task.setProcessDefinitionId("proc-def-id");
          task.setProcessInstanceId("10");
          task.setParentTaskId("parent-task-id");
  
          //when
          String jsonRepresentation = converter.convertToDatabaseColumn(task);
  
          //then
          assertThatJson(jsonRepresentation).inPath("id").isEqualTo("\"3\"");
          assertThatJson(jsonRepresentation).inPath("name").isEqualTo("task1");
          assertThatJson(jsonRepresentation).inPath("processDefinitionId").isEqualTo("proc-def-id");
          assertThatJson(jsonRepresentation).inPath("assignee").isEqualTo("user1");
          assertThatJson(jsonRepresentation).inPath("description").isEqualTo("First task");
          assertThatJson(jsonRepresentation).inPath("owner").isEqualTo("user2");
          assertThatJson(jsonRepresentation).inPath("priority").isEqualTo("50");
          assertThatJson(jsonRepresentation).inPath("processInstanceId").isEqualTo("\"10\"");
          assertThatJson(jsonRepresentation).inPath("parentTaskId").isEqualTo("parent-task-id");
      }
  
      @Test
      public void convertToEntityAttributeShouldCreatedATaskInstanceWithFieldsSet() throws Exception {
          //given
          String jsonRepresentation =
              "{\"id\":\"3\"," +
              "\"owner\":\"user2\"," +
              "\"assignee\":\"user1\"," +
              "\"name\":\"task1\"," +
              "\"description\":\"First task\"," +
              "\"priority\":50," +
              "\"parentTaskId\":\"parent-task-id\"," +
              "\"processDefinitionId\":\"proc-def-id\"," +
              "\"processInstanceId\":\"10\"}";
  
          //when
          Task task = converter.convertToEntityAttribute(jsonRepresentation);
  
          //then
          assertThat(task)
              .isNotNull()
              .hasId("3")
              .hasOwner("user2")
              .hasAssignee("user1")
              .hasName("task1")
              .hasDescription("First task")
              .hasPriority(50)
              .hasParentTaskId("parent-task-id")
              .hasProcessDefinitionId("proc-def-id")
              .hasProcessInstanceId("10");
      }
  }
  