@Test public void shouldCreateMetaDataFromSurroundingSteps() throws IOException { Step previousStep = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .inputDataShape(StepMetadataHelper.NO_SHAPE) .outputDataShape(new DataShape.Builder() .kind(DataShapeKinds.JAVA) .specification(getSpecification("person-spec.json")) .description("person") .type(Person.class.getName()) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_ELEMENT) .addVariant(new DataShape.Builder() .kind(DataShapeKinds.JAVA) .specification(getSpecification("person-list-spec.json")) .description("person-list") .collectionType("List") .type(Person.class.getName()) .collectionClassName(List.class.getName()) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_COLLECTION) .build()) .addVariant(dummyShape(DataShapeKinds.JSON_INSTANCE)) .build()) .build()) .build()) .build(); Step subsequentStep = new Step.Builder() .stepKind(StepKind.endpoint) .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder() .inputDataShape(new DataShape.Builder() .kind(DataShapeKinds.JAVA) .specification(getSpecification("person-list-spec.json")) .description("person-list") .collectionType("List") .type(Person.class.getName()) .collectionClassName(List.class.getName()) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_COLLECTION) .addVariant(new DataShape.Builder() .kind(DataShapeKinds.JAVA) .specification(getSpecification("person-spec.json")) .description("person") .type(Person.class.getName()) .putMetadata(DataShapeMetaData.VARIANT, DataShapeMetaData.VARIANT_ELEMENT) .build()) .addVariant(dummyShape(DataShapeKinds.JSON_INSTANCE)) .build()) .outputDataShape(StepMetadataHelper.NO_SHAPE) .build()) .build()) .build(); DynamicActionMetadata metadata = metadataHandler.createMetadata(aggregateStep, Collections.singletonList(previousStep), Collections.singletonList(subsequentStep)); Assert.assertNotNull(metadata.inputShape()); Assert.assertEquals(DataShapeKinds.JAVA, metadata.inputShape().getKind()); Assert.assertEquals(DataShapeMetaData.VARIANT_COLLECTION, metadata.inputShape().getMetadata(DataShapeMetaData.VARIANT).orElse("")); Assert.assertEquals(getSpecification("person-list-spec.json"), metadata.inputShape().getSpecification()); Assert.assertEquals(2, metadata.inputShape().getVariants().size()); Assert.assertEquals(DataShapeMetaData.VARIANT_ELEMENT, metadata.inputShape().getVariants().get(0).getMetadata().get(DataShapeMetaData.VARIANT)); Assert.assertEquals("person", metadata.inputShape().getVariants().get(0).getDescription()); Assert.assertEquals("dummy", metadata.inputShape().getVariants().get(1).getMetadata().get(DataShapeMetaData.VARIANT)); Assert.assertNotNull(metadata.outputShape()); Assert.assertEquals(DataShapeKinds.JAVA, metadata.outputShape().getKind()); Assert.assertEquals(DataShapeMetaData.VARIANT_ELEMENT, metadata.outputShape().getMetadata(DataShapeMetaData.VARIANT).orElse("")); Assert.assertEquals(getSpecification("person-spec.json"), metadata.outputShape().getSpecification()); Assert.assertEquals(2, metadata.outputShape().getVariants().size()); Assert.assertEquals(DataShapeMetaData.VARIANT_COLLECTION, metadata.outputShape().getVariants().get(0).getMetadata().get(DataShapeMetaData.VARIANT)); Assert.assertEquals("person-list", metadata.outputShape().getVariants().get(0).getDescription()); Assert.assertEquals("dummy", metadata.outputShape().getVariants().get(1).getMetadata().get(DataShapeMetaData.VARIANT)); }
@Override public DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps) { DataShape inputShape = StepMetadataHelper.getFirstWithInputShape(subsequentSteps) .flatMap(Step::inputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); DataShape outputShape = StepMetadataHelper.getLastWithOutputShape(previousSteps) .flatMap(Step::outputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); return new DynamicActionMetadata.Builder() .inputShape(inputShape) .outputShape(outputShape) .build(); }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps) { DataShape inputShape = StepMetadataHelper.getFirstWithInputShape(subsequentSteps) .flatMap(Step::inputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); DataShape outputShape = StepMetadataHelper.getLastWithOutputShape(previousSteps) .flatMap(Step::outputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); return new DynamicActionMetadata.Builder() .inputShape(inputShape) .outputShape(outputShape) .build(); } }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps) { DataShape inputShape = StepMetadataHelper.getFirstWithInputShape(subsequentSteps) .flatMap(Step::inputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); DataShape outputShape = StepMetadataHelper.getLastWithOutputShape(previousSteps) .flatMap(Step::outputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); return new DynamicActionMetadata.Builder() .inputShape(inputShape) .outputShape(outputShape) .build(); }  }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps) { DataShape inputShape = StepMetadataHelper.getFirstWithInputShape(subsequentSteps) .flatMap(Step::inputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); DataShape outputShape = StepMetadataHelper.getLastWithOutputShape(previousSteps) .flatMap(Step::outputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); return new DynamicActionMetadata.Builder() .inputShape(inputShape) .outputShape(outputShape) .build(); }  @Override boolean canHandle(StepKind kind); @Override DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps); @Override DynamicActionMetadata handle(DynamicActionMetadata metadata); }
AggregateMetadataHandler implements StepMetadataHandler { @Override public DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps) { DataShape inputShape = StepMetadataHelper.getFirstWithInputShape(subsequentSteps) .flatMap(Step::inputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); DataShape outputShape = StepMetadataHelper.getLastWithOutputShape(previousSteps) .flatMap(Step::outputDataShape) .orElse(StepMetadataHelper.NO_SHAPE); return new DynamicActionMetadata.Builder() .inputShape(inputShape) .outputShape(outputShape) .build(); }  @Override boolean canHandle(StepKind kind); @Override DynamicActionMetadata createMetadata(Step step, List<Step> previousSteps, List<Step> subsequentSteps); @Override DynamicActionMetadata handle(DynamicActionMetadata metadata); static final String BODY; }