Search in sources :

Example 61 with ExtensionModel

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

the class DefaultExtensionModelFactoryTestCase method sourceWithReducedBackPressureStrategies.

@Test
public void sourceWithReducedBackPressureStrategies() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    SourceModel source = extensionModel.getConfigurationModels().get(0).getSourceModel("ListenPayments").get();
    ParameterModel parameter = source.getAllParameterModels().stream().filter(p -> BACK_PRESSURE_STRATEGY_PARAMETER_NAME.equals(p.getName())).findAny().orElseThrow(() -> new IllegalStateException("No backPressureStrategy parameter"));
    assertThat(parameter.getType(), is(instanceOf(StringType.class)));
    assertThat(parameter.getDefaultValue(), is(FAIL));
    EnumAnnotation enumAnnotation = parameter.getType().getAnnotation(EnumAnnotation.class).orElseThrow(() -> new IllegalStateException("No enum annotation"));
    assertThat(asList(enumAnnotation.getValues()), containsInAnyOrder(FAIL.name(), DROP.name()));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 62 with ExtensionModel

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

the class DefaultExtensionModelFactoryTestCase method nonBlockingExecutionType.

@Test
public void nonBlockingExecutionType() {
    ExtensionModel extensionModel = createExtension(MarvelExtension.class);
    OperationModel operation = extensionModel.getConfigurationModel(CONFIG_NAME).get().getOperationModel("fireMissile").get();
    assertThat(operation.isBlocking(), is(false));
    assertThat(operation.getExecutionType(), is(CPU_LITE));
    assertThat(operation.getOutput().getType(), instanceOf(StringType.class));
    assertThat(operation.getOutputAttributes().getType(), equalTo(typeLoader.load(void.class)));
}
Also used : StringType(org.mule.metadata.api.model.StringType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 63 with ExtensionModel

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

the class DefaultExtensionModelFactoryTestCase method customStereotype.

@Test
public void customStereotype() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    OperationModel operation = extensionModel.getConfigurationModels().get(0).getOperationModel("callSaul").get();
    StereotypeModel stereotypeModel = operation.getStereotype();
    assertThat(stereotypeModel.isAssignableTo(PROCESSOR), is(true));
    assertThat(stereotypeModel.getType(), is(new EmpireStereotype().getName().toUpperCase()));
    assertThat(stereotypeModel.getNamespace(), is(HEISENBERG.toUpperCase()));
    assertThat(stereotypeModel.getParent().get(), is(PROCESSOR));
}
Also used : StereotypeModel(org.mule.runtime.api.meta.model.stereotype.StereotypeModel) EmpireStereotype(org.mule.test.heisenberg.extension.stereotypes.EmpireStereotype) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 64 with ExtensionModel

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

the class DefaultExtensionModelFactoryTestCase method blockingExecutionTypes.

@Test
public void blockingExecutionTypes() {
    final List<String> nonBlockingOperations = Arrays.asList("killMany", "executeAnything", "alwaysFailsWrapper", "getChain", "exceptionOnCallbacks", "neverFailsWrapper", "payloadModifier");
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    Reference<Boolean> cpuIntensive = new Reference<>(false);
    Reference<Boolean> blocking = new Reference<>(false);
    new IdempotentExtensionWalker() {

        @Override
        protected void onOperation(OperationModel operation) {
            String operationName = operation.getName();
            assertThat(operation.isBlocking(), is(!nonBlockingOperations.contains(operationName)));
            if (operationName.equals("approve")) {
                assertThat(operation.getExecutionType(), is(CPU_INTENSIVE));
                cpuIntensive.set(true);
            } else if (operation.requiresConnection()) {
                assertThat(operation.getExecutionType(), is(BLOCKING));
                blocking.set(true);
            } else {
                assertThat(operation.getExecutionType(), is(CPU_LITE));
            }
        }
    }.walk(extensionModel);
    assertThat(cpuIntensive.get(), is(true));
    assertThat(blocking.get(), is(true));
}
Also used : Reference(org.mule.runtime.api.util.Reference) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 65 with ExtensionModel

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

the class DefaultExtensionModelFactoryTestCase method exportedLibraries.

@Test
public void exportedLibraries() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    assertExternalLibraries(extensionModel);
    new IdempotentExtensionWalker() {

        @Override
        protected void onConfiguration(ConfigurationModel model) {
            assertExternalLibraries(model);
        }

        @Override
        protected void onConnectionProvider(ConnectionProviderModel model) {
            assertExternalLibraries(model);
        }
    }.walk(extensionModel);
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)94 Test (org.junit.Test)50 SmallTest (org.mule.tck.size.SmallTest)34 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)31 Optional (java.util.Optional)26 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)24 List (java.util.List)22 Set (java.util.Set)19 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)19 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)16 HashMap (java.util.HashMap)15 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)15 String.format (java.lang.String.format)13 Collectors.toList (java.util.stream.Collectors.toList)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 Reference (org.mule.runtime.api.util.Reference)12 Optional.empty (java.util.Optional.empty)11 ObjectType (org.mule.metadata.api.model.ObjectType)11