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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations