content: package com.aliyun.dataworks.migrationx.domain.dataworks.service.spec;
  
  import com.alibaba.fastjson.JSON;
  
  import com.aliyun.dataworks.common.spec.SpecUtil;
  import com.aliyun.dataworks.common.spec.domain.DataWorksWorkflowSpec;
  import com.aliyun.dataworks.common.spec.domain.Specification;
  import com.aliyun.dataworks.common.spec.domain.enums.FunctionType;
  import com.aliyun.dataworks.migrationx.domain.dataworks.objects.entity.client.File;
  import com.aliyun.dataworks.migrationx.domain.dataworks.objects.entity.client.FileNodeCfg;
  import com.aliyun.dataworks.migrationx.domain.dataworks.objects.types.NodeUseType;
  import com.aliyun.dataworks.migrationx.domain.dataworks.service.spec.FunctionSpecUpdateAdapter.UdfDefinition;
  import com.aliyun.dataworks.migrationx.domain.dataworks.service.spec.entity.FileDetailEntityAdapter;
  import org.junit.Assert;
  import org.junit.Before;
  import org.junit.Test;
  import org.mockito.InjectMocks;
  import org.mockito.Mock;
  import org.mockito.MockitoAnnotations;
  import org.slf4j.Logger;
  
  public class FunctionSpecUpdateAdapterTest {
      @Mock
      Logger log;
      @InjectMocks
      FunctionSpecUpdateAdapter functionSpecUpdateAdapter;
  
      @Before
      public void setUp() {
          MockitoAnnotations.openMocks(this);
      }
  
      @Test
      public void testUpdateSpecificationCreateFunction() throws Exception {
          File file = new File();
          FileNodeCfg fileNodeCfg = new FileNodeCfg();
          fillFile(file);
          fillNodeCfg(fileNodeCfg);
  
          FileDetailEntityAdapter adapter = new FileDetailEntityAdapter();
          adapter.setFile(file);
          adapter.setFileNodeCfg(fileNodeCfg);
          Specification<DataWorksWorkflowSpec> specification = new Specification<>();
          new FunctionSpecUpdateAdapter().updateSpecification(adapter, specification);
          Assert.assertEquals("{\n"
              + "\t\"version\":\"1.1.0\",\n"
              + "\t\"kind\":\"Function\",\n"
              + "\t\"spec\":{\n"
              + "\t\t\"description\":\"Concatenate several strings to generate a new string\",\n"
              + "\t\t\"functions\":[\n"
              + "\t\t\t{\n"
              + "\t\t\t\t\"name\":\"test_file_name.jar\",\n"
              + "\t\t\t\t\"id\":\"123456789\",\n"
              + "\t\t\t\t\"script\":{\n"
              + "\t\t\t\t\t\"path\":\"test/path/test_file_name.jar\",\n"
              + "\t\t\t\t\t\"runtime\":{\n"
              + "\t\t\t\t\t\t\"command\":\"ODPS_FUNCTION\",\n"
              + "\t\t\t\t\t\t\"commandTypeId\":17,\n"
              + "\t\t\t\t\t\t\"engine\":\"MaxCompute\"\n"
              + "\t\t\t\t\t}\n"
              + "\t\t\t\t},\n"
              + "\t\t\t\t\"type\":\"other\",\n"
              + "\t\t\t\t\"className\":\"com.alibaba.DataWorks.api.udf.StringConcat\",\n"
              + "\t\t\t\t\"datasource\":{\n"
              + "\t\t\t\t\t\"name\":\"odps_test\"\n"
              + "\t\t\t\t},\n"
              + "\t\t\t\t\"runtimeResource\":{\n"
              + "\t\t\t\t\t\"resourceGroup\":\"resgroup\"\n"
              + "\t\t\t\t},\n"
              + "\t\t\t\t\"usageDescription\":\"StringConcat(String... substrs)\",\n"
              + "\t\t\t\t\"argumentsDescription\":\"List of strings to be connected\",\n"
              + "\t\t\t\t\"returnValueDescription\":\"New strings generated by concatenating all strings before and after the input order\",\n"
              + "\t\t\t\t\"usageExample\":\"StringConcat('a', 'b', 'c')\",\n"
              + "\t\t\t\t\"resourceType\":\"file\",\n"
              + "\t\t\t\t\"fileResources\":[\n"
              + "\t\t\t\t\t{\n"
              + "\t\t\t\t\t\t\"name\":\"string-concat-1.0.0.jar\"\n"
              + "\t\t\t\t\t},\n"
              + "\t\t\t\t\t{\n"
              + "\t\t\t\t\t\t\"name\":\"commons-lang-2.6.jar\"\n"
              + "\t\t\t\t\t}\n"
              + "\t\t\t\t]\n"
              + "\t\t\t}\n"
              + "\t\t]\n"
              + "\t},\n"
              + "\t\"metadata\":{\n"
              + "\t\t\"owner\":\"111222\",\n"
              + "\t\t\"uuid\":\"123456789\"\n"
              + "\t}\n"
              + "}", SpecUtil.writeToSpec(specification));
      }
  
      private void fillFile(File file) {
          file.setFileId(123456789L);
          file.setFileFolderPath("test/path");
          file.setFileName("test_file_name.jar");
          file.setFileType(17);
          file.setOwner("111222");
          file.setContent("select 1;");
          file.setUseType(NodeUseType.SCHEDULED.getValue());
          file.setFileDesc("test_description");
          file.setConnName("odps_test");
          UdfDefinition udfDefinition = new UdfDefinition();
          udfDefinition.setFunctionType(FunctionType.OTHER);
          udfDefinition.setClassName("com.alibaba.DataWorks.api.udf.StringConcat");
          udfDefinition.setCmdDesc("StringConcat(String... substrs)");
          udfDefinition.setParamDesc("List of strings to be connected");
          udfDefinition.setReturnValue("New strings generated by concatenating all strings before and after the input order");
          udfDefinition.setResources("string-concat-1.0.0.jar,commons-lang-2.6.jar");
          udfDefinition.setDescription("Concatenate several strings to generate a new string");
          udfDefinition.setExample("StringConcat('a', 'b', 'c')");
          file.setContent(JSON.toJSONString(udfDefinition));
      }
  
      private void fillNodeCfg(FileNodeCfg fileNodeCfg) {
          fileNodeCfg.setResourceGroupIdentifier("resgroup");
      }
  }
  
  // Generated with love by TestMe :) Please report issues and submit feature requests at: http://weirddev.com/forum#!/testme