Search in sources :

Example 1 with MessageMetadataType

use of org.mule.metadata.message.api.MessageMetadataType in project mule by mulesoft.

the class MetadataOutputDelegate method adaptToListIfNecessary.

private MetadataType adaptToListIfNecessary(MetadataType resolvedType, Object key, MetadataContext metadataContext) throws MetadataResolvingException {
    MetadataType componentOutputType = ((HasOutputModel) component).getOutput().getType();
    if (!isCollection(componentOutputType) || isVoid(resolvedType) || isNullType(resolvedType)) {
        return resolvedType;
    }
    MetadataType collectionValueType = ((ArrayType) componentOutputType).getType();
    Class<?> collectionType = getCollectionType(collectionValueType);
    if (Message.class.equals(collectionType)) {
        MessageMetadataType message = (MessageMetadataType) collectionValueType;
        resolvedType = wrapInMessageType(resolvedType, key, metadataContext, message.getAttributesType());
    }
    return metadataContext.getTypeBuilder().arrayType().with(new ClassInformationAnnotation(getCollectionType(componentOutputType))).of(resolvedType).build();
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) MetadataType(org.mule.metadata.api.model.MetadataType) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation)

Example 2 with MessageMetadataType

use of org.mule.metadata.message.api.MessageMetadataType in project mule by mulesoft.

the class ExtensionsTestUtils method assertMessageType.

public static void assertMessageType(MetadataType type, MetadataType payloadType, MetadataType attributesType) {
    assertThat(type, is(instanceOf(MessageMetadataType.class)));
    assertThat(getId(type).get(), is(Message.class.getName()));
    MessageMetadataType messageType = (MessageMetadataType) type;
    assertThat(messageType.getPayloadType().get(), equalTo(payloadType));
    assertThat(messageType.getAttributesType().get(), equalTo(attributesType));
}
Also used : MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType)

Example 3 with MessageMetadataType

use of org.mule.metadata.message.api.MessageMetadataType in project mule by mulesoft.

the class ExtensionsTestUtils method assertMessageType.

public static void assertMessageType(MetadataType type, Matcher payloadMatch, Matcher attributesMatcher) {
    assertThat(type, is(instanceOf(MessageMetadataType.class)));
    assertThat(getId(type).get(), is(Message.class.getName()));
    MessageMetadataType messageType = (MessageMetadataType) type;
    assertThat(messageType.getPayloadType().get(), payloadMatch);
    assertThat(messageType.getAttributesType().get(), attributesMatcher);
}
Also used : MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType)

Example 4 with MessageMetadataType

use of org.mule.metadata.message.api.MessageMetadataType in project mule by mulesoft.

the class IntrospectionUtilsTestCase method getPagingProviderImplementationTypesReturnType.

@Test
public void getPagingProviderImplementationTypesReturnType() throws Exception {
    OperationElement getPagingProvider = getMethod("getPagingProvider");
    MetadataType methodReturnType = IntrospectionUtils.getMethodReturnType(getPagingProvider);
    assertThat(methodReturnType, instanceOf(ArrayType.class));
    MetadataType valueType = ((ArrayType) methodReturnType).getType();
    assertThat(valueType, instanceOf(MessageMetadataType.class));
    MessageMetadataType messageType = (MessageMetadataType) valueType;
    MetadataType payloadType = messageType.getPayloadType().get();
    MetadataType attributesTypes = messageType.getAttributesType().get();
    // These assertions are too simple, but AST Loader doesn't enrich with the same annotations as the Java does
    // making impossible to do an equals assertion.
    assertThat(payloadType.getAnnotation(TypeIdAnnotation.class).get().getValue(), is(Banana.class.getName()));
    assertThat(attributesTypes.getAnnotation(TypeIdAnnotation.class).get().getValue(), is(Apple.class.getName()));
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) OperationElement(org.mule.runtime.module.extension.api.loader.java.type.OperationElement) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) IntrospectionUtils.getFieldMetadataType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldMetadataType) MetadataType(org.mule.metadata.api.model.MetadataType) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) TypeIdAnnotation(org.mule.metadata.api.annotation.TypeIdAnnotation) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

MessageMetadataType (org.mule.metadata.message.api.MessageMetadataType)4 ArrayType (org.mule.metadata.api.model.ArrayType)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 Test (org.junit.Test)1 TypeIdAnnotation (org.mule.metadata.api.annotation.TypeIdAnnotation)1 ClassInformationAnnotation (org.mule.metadata.java.api.annotation.ClassInformationAnnotation)1 OperationElement (org.mule.runtime.module.extension.api.loader.java.type.OperationElement)1 IntrospectionUtils.getFieldMetadataType (org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldMetadataType)1 SmallTest (org.mule.tck.size.SmallTest)1