Search in sources :

Example 1 with OutputModel

use of org.mule.runtime.api.meta.model.OutputModel in project mule by mulesoft.

the class ExportedPackagesValidatorTestCase method setUpInvalidExtension.

private void setUpInvalidExtension() {
    OutputModel appleList = mockOutputModel(InternalTestClass.class);
    OperationModel firstOperation = mockOperationModel(appleList, mockOutputModel(InternalTestClass.class));
    withMethod(firstOperation, getApiMethods(InternalTestClass.class).stream().filter(m -> m.getName().equals("someOperation")).findFirst());
    ParameterModel parameter = mockParameterModel(Shape.class);
    OutputModel resultList = mockOutputModel(new TypeToken<List<Result<Apple, VeganAttributes>>>() {
    }.getType());
    OperationModel secondOperation = mockOperationModel(resultList, mockOutputModel(List.class), parameter);
    withMethod(secondOperation, empty());
    when(extensionModel.getOperationModels()).thenReturn(asList(firstOperation, secondOperation));
    visitableMock(firstOperation, secondOperation);
}
Also used : InternalTestClass(org.mule.test.module.extension.internal.InternalTestClass) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) TypeToken(com.google.common.reflect.TypeToken) Arrays.asList(java.util.Arrays.asList) List(java.util.List) OutputModel(org.mule.runtime.api.meta.model.OutputModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Result(org.mule.runtime.extension.api.runtime.operation.Result)

Example 2 with OutputModel

use of org.mule.runtime.api.meta.model.OutputModel in project mule by mulesoft.

the class MetadataOutputDelegate method getOutputMetadata.

/**
 * 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).onOutputAttributes());
    }
}
Also used : HasOutputModel(org.mule.runtime.api.meta.model.HasOutputModel) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) MetadataType(org.mule.metadata.api.model.MetadataType) MetadataFailure(org.mule.runtime.api.metadata.resolving.MetadataFailure) OutputModel(org.mule.runtime.api.meta.model.OutputModel) HasOutputModel(org.mule.runtime.api.meta.model.HasOutputModel) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException)

Example 3 with OutputModel

use of org.mule.runtime.api.meta.model.OutputModel in project mule by mulesoft.

the class ExportedArtifactsCollectorTestCase method setup.

@Before
public void setup() {
    ClassLoaderModelProperty classLoaderModelProperty = new ClassLoaderModelProperty(getClass().getClassLoader());
    when(extensionModel.getModelProperty(ClassLoaderModelProperty.class)).thenReturn(of(classLoaderModelProperty));
    OutputModel appleList = mockOutputModel(new TypeToken<List<Apple>>() {
    }.getType());
    OperationModel firstOperation = mockOperationModel(appleList, mockOutputModel(List.class));
    withMethod(firstOperation, getApiMethods(HeisenbergOperations.class).stream().filter(m -> m.getName().equals("callGusFring")).findFirst());
    ParameterModel parameter = mockParameterModel(Shape.class);
    OutputModel resultList = mockOutputModel(new TypeToken<List<Result<Apple, VeganAttributes>>>() {
    }.getType());
    OperationModel secondOperation = mockOperationModel(resultList, mockOutputModel(List.class), parameter);
    withMethod(secondOperation, empty());
    when(extensionModel.getOperationModels()).thenReturn(asList(firstOperation, secondOperation));
    visitableMock(firstOperation, secondOperation);
    collector = new ExportedArtifactsCollector(extensionModel);
}
Also used : ClassLoaderModelProperty(org.mule.runtime.extension.api.property.ClassLoaderModelProperty) Apple(org.mule.tck.testmodels.fruit.Apple) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) TypeToken(com.google.common.reflect.TypeToken) Arrays.asList(java.util.Arrays.asList) List(java.util.List) OutputModel(org.mule.runtime.api.meta.model.OutputModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Result(org.mule.runtime.extension.api.runtime.operation.Result) Before(org.junit.Before)

Example 4 with OutputModel

use of org.mule.runtime.api.meta.model.OutputModel in project mule by mulesoft.

the class ExportedArtifactsCollectorTestCase method mockOutputModel.

private OutputModel mockOutputModel(Type type) {
    OutputModel om = mock(OutputModel.class);
    when(om.getType()).thenReturn(loader.load(type));
    return om;
}
Also used : OutputModel(org.mule.runtime.api.meta.model.OutputModel)

Example 5 with OutputModel

use of org.mule.runtime.api.meta.model.OutputModel in project mule by mulesoft.

the class ExportedPackagesValidatorTestCase method mockOutputModel.

private OutputModel mockOutputModel(Type type) {
    OutputModel om = mock(OutputModel.class);
    when(om.getType()).thenReturn(loader.load(type));
    return om;
}
Also used : OutputModel(org.mule.runtime.api.meta.model.OutputModel)

Aggregations

OutputModel (org.mule.runtime.api.meta.model.OutputModel)8 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)5 TypeToken (com.google.common.reflect.TypeToken)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 Result (org.mule.runtime.extension.api.runtime.operation.Result)2 Before (org.junit.Before)1 Test (org.junit.Test)1 MessageMetadataType (org.mule.metadata.message.api.MessageMetadataType)1 ComponentModelVisitor (org.mule.runtime.api.meta.model.ComponentModelVisitor)1 HasOutputModel (org.mule.runtime.api.meta.model.HasOutputModel)1 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)1 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)1 MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)1 MetadataFailure (org.mule.runtime.api.metadata.resolving.MetadataFailure)1 Reference (org.mule.runtime.api.util.Reference)1 ImmutableOutputModel (org.mule.runtime.extension.api.model.ImmutableOutputModel)1 ImmutableConstructModel (org.mule.runtime.extension.api.model.construct.ImmutableConstructModel)1