@Test void shouldSerializeWorkflowTemplate() { Node nodeA = createNode("a").toBuilder().upstreamNodeIds(singletonList("b")).build(); Node nodeB = createNode("b"); WorkflowMetadata metadata = WorkflowMetadata.builder().build(); TypedInterface interface_ = TypedInterface.builder().inputs(emptyMap()).outputs(emptyMap()).build(); WorkflowTemplate template = WorkflowTemplate.builder() .nodes(Arrays.asList(nodeA, nodeB)) .metadata(metadata) .interface_(interface_) .outputs(emptyList()) .build(); Workflow.Node expectedNode1 = Workflow.Node.newBuilder() .setId("a") .addUpstreamNodeIds("b") .setTaskNode( Workflow.TaskNode.newBuilder() .setReferenceId( IdentifierOuterClass.Identifier.newBuilder() .setResourceType(TASK) .setDomain(DOMAIN) .setProject(PROJECT) .setName("task-a") .setVersion("version-a") .build()) .build()) .addInputs( Literals.Binding.newBuilder() .setVar("input-name-a") .setBinding( Literals.BindingData.newBuilder() .setScalar( Literals.Scalar.newBuilder() .setPrimitive( Literals.Primitive.newBuilder() .setStringValue("input-scalar-a") .build()) .build()) .build()) .build()) .build(); Workflow.Node expectedNode2 = Workflow.Node.newBuilder() .setId("b") .setTaskNode( Workflow.TaskNode.newBuilder() .setReferenceId( IdentifierOuterClass.Identifier.newBuilder() .setResourceType(TASK) .setDomain(DOMAIN) .setProject(PROJECT) .setName("task-b") .setVersion("version-b") .build()) .build()) .addInputs( Literals.Binding.newBuilder() .setVar("input-name-b") .setBinding( Literals.BindingData.newBuilder() .setScalar( Literals.Scalar.newBuilder() .setPrimitive( Literals.Primitive.newBuilder() .setStringValue("input-scalar-b") .build()) .build()) .build()) .build()) .build(); Workflow.WorkflowTemplate serializedTemplate = ProtoUtil.serialize(template); assertThat( serializedTemplate, equalTo( Workflow.WorkflowTemplate.newBuilder() .setMetadata(Workflow.WorkflowMetadata.newBuilder().build()) .setInterface( Interface.TypedInterface.newBuilder() .setOutputs(Interface.VariableMap.newBuilder().build()) .setInputs(Interface.VariableMap.newBuilder().build()) .build()) .addNodes(expectedNode1) .addNodes(expectedNode2) .build())); }
static IdentifierOuterClass.Identifier serialize(Identifier id) { IdentifierOuterClass.ResourceType type = getResourceType(id); return IdentifierOuterClass.Identifier.newBuilder() .setResourceType(type) .setDomain(id.domain()) .setProject(id.project()) .setName(id.name()) .setVersion(id.version()) .build(); }
ProtoUtil { static IdentifierOuterClass.Identifier serialize(Identifier id) { IdentifierOuterClass.ResourceType type = getResourceType(id); return IdentifierOuterClass.Identifier.newBuilder() .setResourceType(type) .setDomain(id.domain()) .setProject(id.project()) .setName(id.name()) .setVersion(id.version()) .build(); } }
ProtoUtil { static IdentifierOuterClass.Identifier serialize(Identifier id) { IdentifierOuterClass.ResourceType type = getResourceType(id); return IdentifierOuterClass.Identifier.newBuilder() .setResourceType(type) .setDomain(id.domain()) .setProject(id.project()) .setName(id.name()) .setVersion(id.version()) .build(); } private  ProtoUtil(); }
ProtoUtil { static IdentifierOuterClass.Identifier serialize(Identifier id) { IdentifierOuterClass.ResourceType type = getResourceType(id); return IdentifierOuterClass.Identifier.newBuilder() .setResourceType(type) .setDomain(id.domain()) .setProject(id.project()) .setName(id.name()) .setVersion(id.version()) .build(); } private  ProtoUtil(); static Workflow.WorkflowTemplate serialize(WorkflowTemplate template); }
ProtoUtil { static IdentifierOuterClass.Identifier serialize(Identifier id) { IdentifierOuterClass.ResourceType type = getResourceType(id); return IdentifierOuterClass.Identifier.newBuilder() .setResourceType(type) .setDomain(id.domain()) .setProject(id.project()) .setName(id.name()) .setVersion(id.version()) .build(); } private  ProtoUtil(); static Workflow.WorkflowTemplate serialize(WorkflowTemplate template);  }