Search in sources :

Example 21 with ExtensionModel

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

the class ExtensionActivatorTestCase method enumsReleasedWhenStopped.

@Test
public void enumsReleasedWhenStopped() throws Exception {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(TYPE_PROPERTY_NAME, HeisenbergExtension.class.getName());
    attributes.put(VERSION, "1.0.0");
    ExtensionModel extensionModel = new DefaultJavaExtensionModelLoader().loadExtensionModel(HeisenbergExtension.class.getClassLoader(), new DefaultDslResolvingContext(Collections.emptySet()), attributes);
    ExtensionActivator extensionActivator = new ExtensionActivator(mock(ExtensionErrorsRegistrant.class, RETURNS_DEEP_STUBS), mockMuleContext());
    extensionActivator.activateExtension(extensionModel);
    assertThat(extensionActivator.getEnumTypes().size(), is(greaterThan(0)));
    extensionActivator.stop();
    assertThat(extensionActivator.getEnumTypes(), hasSize(0));
}
Also used : HashMap(java.util.HashMap) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DefaultJavaExtensionModelLoader(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) DefaultDslResolvingContext(org.mule.runtime.internal.dsl.DefaultDslResolvingContext) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 22 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel 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 23 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel 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 24 with ExtensionModel

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

the class CraftedExtensionModelLoaderTestCase method load.

@Test
public void load() throws Exception {
    ExtensionModel extensionModel = loader.loadExtensionModel(classLoader, dslResolvingContext, attributes);
    assertThat(extensionModel, is(notNullValue()));
    assertThat(extensionModel.getName(), is(EXTENSION_NAME));
}
Also used : ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 25 with ExtensionModel

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

the class XmlExtensionLoaderDelegate method createTnsExtensionModel.

/**
 * Transforms the current <module/> by stripping out the <body/>'s content, so that there are not parsing errors, to generate
 * a simpler {@link ExtensionModel} if there are references to the TNS prefix defined by the {@link #XMLNS_TNS}.
 *
 * @param resource <module/>'s resource
 * @param extensions complete list of extensions the current module depends on
 * @return an {@link ExtensionModel} if there's a {@link #XMLNS_TNS} defined, {@link Optional#empty()} otherwise
 * @throws IOException if it fails reading the resource
 */
private Optional<ExtensionModel> createTnsExtensionModel(URL resource, Set<ExtensionModel> extensions) throws IOException {
    ExtensionModel result = null;
    final ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
    try {
        final Source xslt = new StreamSource(getClass().getClassLoader().getResourceAsStream(TRANSFORMATION_FOR_TNS_RESOURCE));
        final Source moduleToTransform = new StreamSource(resource.openStream());
        TransformerFactory.newInstance().newTransformer(xslt).transform(moduleToTransform, new StreamResult(resultStream));
    } catch (TransformerException e) {
        throw new MuleRuntimeException(createStaticMessage(format("There was an issue transforming the stream for the resource %s while trying to remove the content of the <body> element to generate an XSD", resource.getFile())), e);
    }
    final Document transformedModuleDocument = schemaValidatingDocumentLoader(NoOpXmlErrorHandler::new).loadDocument(extensions, resource.getFile(), new ByteArrayInputStream(resultStream.toByteArray()));
    if (StringUtils.isNotBlank(transformedModuleDocument.getDocumentElement().getAttribute(XMLNS_TNS))) {
        final ExtensionDeclarer extensionDeclarer = new ExtensionDeclarer();
        loadModuleExtension(extensionDeclarer, resource, transformedModuleDocument, extensions, true);
        result = createExtensionModel(extensionDeclarer);
    }
    return Optional.ofNullable(result);
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) StreamSource(javax.xml.transform.stream.StreamSource) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Document(org.w3c.dom.Document) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException)

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