Search in sources :

Example 26 with OperationModel

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

the class ExportedArtifactsCollectorTestCase method withMethod.

private void withMethod(OperationModel operationModel, Optional<Method> optionalMethod) {
    when(operationModel.getModelProperty(ImplementingMethodModelProperty.class)).thenReturn(optionalMethod.map(ImplementingMethodModelProperty::new));
    when(operationModel.getModelProperty(ExtensionOperationDescriptorModelProperty.class)).thenReturn(optionalMethod.map(method -> new ExtensionOperationDescriptorModelProperty(new MethodWrapper(method, loader))));
}
Also used : Optional.empty(java.util.Optional.empty) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Apple(org.mule.tck.testmodels.fruit.Apple) MethodWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.MethodWrapper) HeisenbergOperations(org.mule.test.heisenberg.extension.HeisenbergOperations) Mock(org.mockito.Mock) Optional.of(java.util.Optional.of) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) RunWith(org.junit.runner.RunWith) Shape(org.mule.test.metadata.extension.model.shapes.Shape) TypeToken(com.google.common.reflect.TypeToken) ExtensionsTestUtils.mockParameters(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.mockParameters) Arrays.asList(java.util.Arrays.asList) ExtensionModelTestUtils.visitableMock(org.mule.runtime.api.util.ExtensionModelTestUtils.visitableMock) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) IntrospectionUtils.getApiMethods(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getApiMethods) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) Method(java.lang.reflect.Method) VeganAttributes(org.mule.test.vegan.extension.VeganAttributes) Before(org.junit.Before) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClassLoaderModelProperty(org.mule.runtime.extension.api.property.ClassLoaderModelProperty) Result(org.mule.runtime.extension.api.runtime.operation.Result) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Type(java.lang.reflect.Type) OutputModel(org.mule.runtime.api.meta.model.OutputModel) Optional(java.util.Optional) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) Mockito.mock(org.mockito.Mockito.mock) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) MethodWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.MethodWrapper)

Example 27 with OperationModel

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

the class ErrorsDeclarationEnricherTestCase method extensionErrorsInheritFromMuleErrors.

@Test
public void extensionErrorsInheritFromMuleErrors() {
    extensionModel = loadExtension(HeisenbergExtension.class);
    OperationModel cureCancer = getNamedObject(extensionModel.getOperationModels(), "cureCancer");
    assertThat(cureCancer.getErrorModels(), hasItem(hasProperty(TYPE, is(HEALTH.getType()))));
    Optional<ErrorModel> healthError = extensionModel.getErrorModels().stream().filter(errorModel -> errorModel.getType().equals(HEALTH.getType())).findFirst();
    assertThat(healthError.isPresent(), is(true));
    Optional<ErrorModel> optConnectivityError = healthError.get().getParent();
    assertThat(optConnectivityError.isPresent(), is(true));
    ErrorModel connectivityError = optConnectivityError.get();
    assertThat(connectivityError.getType(), is(CONNECTIVITY_ERROR_IDENTIFIER));
    assertThat(connectivityError.getNamespace(), is(HEISENBERG));
    Optional<ErrorModel> optMuleConnectivityError = connectivityError.getParent();
    assertThat(optMuleConnectivityError.isPresent(), is(true));
    ErrorModel muleConnectivityError = optMuleConnectivityError.get();
    assertThat(muleConnectivityError.getType(), is(CONNECTIVITY_ERROR_IDENTIFIER));
    assertThat(muleConnectivityError.getNamespace(), is(MULE_NAMESPACE));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Optional.empty(java.util.Optional.empty) HEALTH(org.mule.test.heisenberg.extension.HeisenbergErrors.HEALTH) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Operations(org.mule.runtime.extension.api.annotation.Operations) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Extension(org.mule.runtime.extension.api.annotation.Extension) HeisenbergOperations(org.mule.test.heisenberg.extension.HeisenbergOperations) HeisenbergScopes(org.mule.test.heisenberg.extension.HeisenbergScopes) EXTENSION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.EXTENSION) KillingOperations(org.mule.test.heisenberg.extension.KillingOperations) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CONNECTIVITY_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.CONNECTIVITY_ERROR_IDENTIFIER) ExpectedException.none(org.junit.rules.ExpectedException.none) EnricherTestUtils.getNamedObject(org.mule.runtime.module.extension.internal.loader.enricher.EnricherTestUtils.getNamedObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) MuleExtensionUtils.loadExtension(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.loadExtension) Set(java.util.Set) Throws(org.mule.runtime.extension.api.annotation.error.Throws) Test(org.junit.Test) OPERATION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.OPERATION) ANY(org.mule.runtime.extension.api.error.MuleErrors.ANY) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) MoneyLaunderingOperation(org.mule.test.heisenberg.extension.MoneyLaunderingOperation) Rule(org.junit.Rule) HeisenbergErrors(org.mule.test.heisenberg.extension.HeisenbergErrors) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) HeisenbergRouters(org.mule.test.heisenberg.extension.HeisenbergRouters) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 28 with OperationModel

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

the class ErrorsDeclarationEnricherTestCase method operationThrowsOverridesExtensionThrows.

@Test
public void operationThrowsOverridesExtensionThrows() {
    extensionModel = loadExtension(HeisenbergWithOperationThrows.class);
    OperationModel someOperation = extensionModel.getOperationModel("someOperation").get();
    Optional<ErrorModel> operationError = someOperation.getErrorModels().stream().filter(errorModel -> errorModel.getType().equals(OPERATION.getType())).findFirst();
    assertThat(operationError.isPresent(), is(true));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Optional.empty(java.util.Optional.empty) HEALTH(org.mule.test.heisenberg.extension.HeisenbergErrors.HEALTH) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Operations(org.mule.runtime.extension.api.annotation.Operations) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Extension(org.mule.runtime.extension.api.annotation.Extension) HeisenbergOperations(org.mule.test.heisenberg.extension.HeisenbergOperations) HeisenbergScopes(org.mule.test.heisenberg.extension.HeisenbergScopes) EXTENSION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.EXTENSION) KillingOperations(org.mule.test.heisenberg.extension.KillingOperations) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) Collections.singleton(java.util.Collections.singleton) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) CONNECTIVITY_ERROR_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.CONNECTIVITY_ERROR_IDENTIFIER) ExpectedException.none(org.junit.rules.ExpectedException.none) EnricherTestUtils.getNamedObject(org.mule.runtime.module.extension.internal.loader.enricher.EnricherTestUtils.getNamedObject) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ExpectedException(org.junit.rules.ExpectedException) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) MuleExtensionUtils.loadExtension(org.mule.runtime.module.extension.api.util.MuleExtensionUtils.loadExtension) Set(java.util.Set) Throws(org.mule.runtime.extension.api.annotation.error.Throws) Test(org.junit.Test) OPERATION(org.mule.runtime.module.extension.internal.loader.enricher.LevelErrorTypes.OPERATION) ANY(org.mule.runtime.extension.api.error.MuleErrors.ANY) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) MoneyLaunderingOperation(org.mule.test.heisenberg.extension.MoneyLaunderingOperation) Rule(org.junit.Rule) HeisenbergErrors(org.mule.test.heisenberg.extension.HeisenbergErrors) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) HeisenbergRouters(org.mule.test.heisenberg.extension.HeisenbergRouters) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 29 with OperationModel

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

the class ErrorsDeclarationEnricherTestCase method operationsWithConnectionsThrowsConnectivityError.

@Test
public void operationsWithConnectionsThrowsConnectivityError() {
    extensionModel = loadExtension(HeisenbergExtension.class);
    OperationModel callSaul = getNamedObject(extensionModel.getConfigurationModel("config").get().getOperationModels(), "callSaul");
    Set<ErrorModel> errorTypesIdentifiers = callSaul.getErrorModels();
    assertThat(errorTypesIdentifiers, hasItem(hasProperty(TYPE, is(CONNECTIVITY_ERROR_IDENTIFIER))));
}
Also used : ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Example 30 with OperationModel

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

the class StereotypesDeclarationEnricherTestCase method operationParameterWithFlowReferenceParameter.

@Test
public void operationParameterWithFlowReferenceParameter() {
    OperationModel operation = configuration.getOperationModel("withFlowReference").get();
    assertThat(operation.getAllParameterModels(), hasSize(1));
    ParameterModel param = operation.getAllParameterModels().get(0);
    List<StereotypeModel> stereotypes = param.getAllowedStereotypes();
    assertThat(stereotypes, hasSize(1));
    assertThat(stereotypes.get(0), is(FLOW));
}
Also used : StereotypeModel(org.mule.runtime.api.meta.model.stereotype.StereotypeModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test)

Aggregations

OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)96 Test (org.junit.Test)68 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)29 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)27 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)15 SmallTest (org.mule.tck.size.SmallTest)14 Optional (java.util.Optional)13 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)12 MetadataType (org.mule.metadata.api.model.MetadataType)11 List (java.util.List)10 Set (java.util.Set)9 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)9 Optional.empty (java.util.Optional.empty)8 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)8 ObjectType (org.mule.metadata.api.model.ObjectType)7 OutputModel (org.mule.runtime.api.meta.model.OutputModel)7 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)7 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)7 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)6