public static boolean isVoid(ComponentModel componentModel) { return componentModel instanceof HasOutputModel && ((HasOutputModel) componentModel).getOutput().getType() instanceof VoidType; }
@Before public void before() throws MuleException { streamingManager = new DefaultStreamingManager(); LifecycleUtils.initialiseIfNeeded(streamingManager, muleContext); event = eventBuilder(muleContext).message(Message.builder().value("").attributesValue(attributes).build()).build(); when(outputModel.getType()).thenReturn(BaseTypeBuilder.create(JAVA).voidType().build()); when(outputModel.getModelProperty(any())).thenReturn(empty()); when(outputModel.getModelProperties()).thenReturn(emptySet()); when(outputModel.getDescription()).thenReturn(""); when(componentModel.getModelProperty(MediaTypeModelProperty.class)).thenReturn(empty()); when(componentModel.getOutput()).thenReturn(outputModel); delegate = createReturnDelegate(); when(operationContext.getEvent()).thenReturn(event); when(operationContext.getMuleContext()).thenReturn(muleContext); when(operationContext.getComponentModel()).thenReturn(componentModel); when(operationContext.getVariable(contains(CONNECTION_PARAM))).thenReturn(connectionHandler); }
/** * Given a {@link MetadataKey} of a type and a {@link MetadataContext}, resolves the {@link MetadataType} of the Components's * output {@link Message#getAttributes()} using the {@link OutputTypeResolver} associated to the current component. * * @param context {@link MetadataContext} of the Metadata resolution * @param key {@link MetadataKey} of the type which's structure has to be resolved * @return a {@link MetadataResult} with the {@link MetadataType} of the components output {@link Message#getAttributes()} */ private MetadataResult<MetadataType> getOutputAttributesMetadata(final MetadataContext context, Object key) { OutputModel attributes = ((HasOutputModel) component).getOutputAttributes(); if (isVoid(attributes.getType()) || !attributes.hasDynamicType()) { return success(attributes.getType()); } return resolveOutputAttributesMetadata(context, key, (metadata) -> isMetadataResolvedCorrectly(metadata, true)); }
private OutputModel resolveOutputModelType(OutputModel untypedModel, TypeMetadataDescriptor typeMetadataDescriptor) { return new ImmutableOutputModel(untypedModel.getDescription(), typeMetadataDescriptor.getType(), typeMetadataDescriptor.isDynamic(), untypedModel.getModelProperties()); } }
private void assertOperation(String operationName, ExtensionModel extensionModel, DeclarationOperation declarer, String outputDocumentation, String outputAttributeDocumentation) { final Optional<OperationModel> operationModelOptional = extensionModel.getOperationModel(operationName); assertThat(operationModelOptional.isPresent(), is(true)); final OperationModel operationModel = operationModelOptional.get(); assertThat(operationModel.getOutput().getType(), is(declarer.getOutput())); assertThat(operationModel.getOutput().getDescription(), is(outputDocumentation)); assertThat(operationModel.getOutputAttributes().getType(), is(declarer.getOutputAttributes())); assertThat(operationModel.getOutputAttributes().getDescription(), is(outputAttributeDocumentation)); }
private MetadataType wrapInMessageType(MetadataType type, Object key, MetadataContext context, Optional<MetadataType> staticAttributes) throws MetadataResolvingException { MessageMetadataTypeBuilder message = new MessageMetadataTypeBuilder().payload(type); staticAttributes.ifPresent(message::attributes); if (((HasOutputModel) component).getOutputAttributes().hasDynamicType()) { MetadataResult<MetadataType> attributes = resolveOutputAttributesMetadata(context, key, Objects::nonNull); if (!attributes.isSuccess()) { throw new MetadataResolvingException("Could not resolve attributes of List<Message> output", attributes.getFailures().stream() .map(MetadataFailure::getFailureCode) .findFirst() .orElse(UNKNOWN)); } message.attributes(attributes.get()); } return message.build(); }
assertThat(allParameterModels.get(6).getDescription(), is(TARGET_VALUE_PARAMETER_DESCRIPTION)); assertThat(operationModel.getOutput().getDescription(), is("Documentation for the output")); assertThat(operationModel.getOutputAttributes().getDescription(), is("Documentation for the output attributes")); assertThat(operationModel.getErrorModels().size(), is(2)); assertThat(operationModel.getErrorModels(),
private OutputModel resolveOutputModelType(OutputModel untypedModel, TypeMetadataDescriptor typeMetadataDescriptor) { return new ImmutableOutputModel(untypedModel.getDescription(), typeMetadataDescriptor.getType(), typeMetadataDescriptor.isDynamic(), untypedModel.getModelProperties()); } }
private MetadataType wrapInMessageType(MetadataType type, Object key, MetadataContext context, Optional<MetadataType> staticAttributes) throws MetadataResolvingException { MessageMetadataTypeBuilder message = new MessageMetadataTypeBuilder().payload(type); staticAttributes.ifPresent(message::attributes); if (((HasOutputModel) component).getOutputAttributes().hasDynamicType()) { MetadataResult<MetadataType> attributes = resolveOutputAttributesMetadata(context, key, Objects::nonNull); if (!attributes.isSuccess()) { throw new MetadataResolvingException("Could not resolve attributes of List<Message> output", attributes.getFailures().stream() .map(MetadataFailure::getFailureCode) .findFirst() .orElse(UNKNOWN)); } message.attributes(attributes.get()); } return message.build(); }
private boolean hasCustomStaticMetadataDefined(OutputModel model) { return model.getType().getAnnotation(CustomDefinedStaticTypeAnnotation.class).isPresent(); }
@Test public void customTypeOutput() throws Exception { OperationModel o = getOperation("customTypeOutput"); OutputModel output = o.getOutput(); MetadataType type = output.getType(); assertThat(output.hasDynamicType(), is(false)); assertThat(type.getMetadataFormat(), is(CSV)); assertThat(type.toString(), is("csv-object")); }
/** * The operation returns its input as the output. * * @param model the model to assert on */ private void assertOutputSameAsInput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(VoidType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * @param componentModel a {@link ComponentModel} * @return Whether the {@code componentModel} returns a list of messages */ public static boolean returnsListOfMessages(HasOutputModel componentModel) { MetadataType outputType = componentModel.getOutput().getType(); return outputType instanceof ArrayType && Message.class.getName().equals(getId(((ArrayType) outputType).getType()).orElse(null)); }
/** * The operation buids its own output, leaving the resulting message without attrbiutes. * * @param model the model to assert on */ private void assertComponentDeterminesOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(VoidType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
private boolean hasJavaAsMetadataFormat(OutputModel model) { return model.getType().getMetadataFormat().getId().equals(MetadataFormat.JAVA.getId()); }
/** * The operation returns the result of one of its routes, keeping the attributes of the result message. * * @param model the model to assert on */ private void assertAssociatedProcessorsChangeOutput(final OperationModel model) { assertThat(model.getOutput().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutput().hasDynamicType(), is(false)); assertThat(model.getOutputAttributes().getType(), instanceOf(DefaultAnyType.class)); assertThat(model.getOutputAttributes().hasDynamicType(), is(false)); }
/** * Given a {@link MetadataKey} of a type and a {@link MetadataContext}, resolves the {@link MetadataType} of the Components's * output using the {@link OutputTypeResolver} associated to the current component. * * @param context {@link MetadataContext} of the Metadata resolution * @param key {@link MetadataKey} of the type which's structure has to be resolved * @return a {@link MetadataResult} with the {@link MetadataType} of the component's output */ private MetadataResult<MetadataType> getOutputMetadata(final MetadataContext context, final Object key) { OutputModel output = ((HasOutputModel) component).getOutput(); if (isVoid(output.getType()) || !output.hasDynamicType()) { return success(output.getType()); } try { MetadataType metadata = resolverFactory.getOutputResolver().getOutputType(context, key); if (isMetadataResolvedCorrectly(metadata, true)) { return success(adaptToListIfNecessary(metadata, key, context)); } MetadataFailure failure = newFailure() .withMessage("Error resolving Output Payload metadata") .withFailureCode(NO_DYNAMIC_TYPE_AVAILABLE) .withReason(NULL_TYPE_ERROR) .onOutputPayload(); return failure(output.getType(), failure); } catch (Exception e) { return failure(output.getType(), newFailure(e).onOutputPayload()); } }
private void validateMetadataOutputAttributes(ConnectableComponentModel component, MetadataResolverFactory resolverFactory, ProblemsReporter problemsReporter) { if (isVoid(component.getOutputAttributes().getType()) && !(resolverFactory.getOutputAttributesResolver() instanceof NullMetadataResolver) && (!isCollection(component.getOutput().getType()))) { problemsReporter .addError(new Problem(component, format("%s '%s' has an AttributesTypeResolver defined but it doesn't declare any attributes as part of its output.", capitalize(getComponentModelTypeName(component)), component.getName()))); } }