use of org.mule.runtime.api.meta.model.nested.NestedRouteModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method errorHandler.
@Test
public void errorHandler() {
final ConstructModel errorHandlerModel = coreExtensionModel.getConstructModel("errorHandler").get();
assertThat(errorHandlerModel.allowsTopLevelDeclaration(), is(true));
assertThat(errorHandlerModel.getStereotype().getType(), is(ERROR_HANDLER.getType()));
assertThat(errorHandlerModel.getAllParameterModels(), hasSize(1));
ParameterModel ref = errorHandlerModel.getAllParameterModels().get(0);
assertThat(ref.getName(), is("ref"));
assertThat(ref.getType(), is(instanceOf(StringType.class)));
assertThat(ref.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(ref.isRequired(), is(false));
assertThat(ref.getAllowedStereotypes(), hasSize(1));
assertThat(ref.getAllowedStereotypes().iterator().next().getType(), is(ERROR_HANDLER.getType()));
assertThat(errorHandlerModel.getNestedComponents(), hasSize(3));
NestedRouteModel onErrorContinue = (NestedRouteModel) errorHandlerModel.getNestedComponents().get(0);
verifyOnError(onErrorContinue);
NestedRouteModel onErrorPropagate = (NestedRouteModel) errorHandlerModel.getNestedComponents().get(1);
verifyOnError(onErrorPropagate);
NestedComponentModel onErrorDelegate = (NestedComponentModel) errorHandlerModel.getNestedComponents().get(2);
assertThat(onErrorDelegate.isRequired(), is(false));
assertThat(onErrorDelegate.getAllowedStereotypes(), hasSize(1));
assertThat(onErrorDelegate.getAllowedStereotypes().iterator().next().getType(), is(ON_ERROR.getType()));
final ConstructModel onError = coreExtensionModel.getConstructModel("onError").get();
List<ParameterModel> allParameterModels = onError.getAllParameterModels();
assertThat(allParameterModels, hasSize(1));
ParameterModel onErrorRef = allParameterModels.get(0);
assertThat(onErrorRef.getName(), is("ref"));
assertThat(onErrorRef.getType(), is(instanceOf(DefaultStringType.class)));
assertThat(onErrorRef.isRequired(), is(true));
assertThat(onErrorRef.getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(onErrorDelegate.getAllowedStereotypes(), hasSize(1));
assertThat(onErrorDelegate.getAllowedStereotypes().iterator().next().getType(), is(ON_ERROR.getType()));
}
use of org.mule.runtime.api.meta.model.nested.NestedRouteModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method choice.
@Test
public void choice() {
final ConstructModel choiceModel = coreExtensionModel.getConstructModel("choice").get();
assertThat(choiceModel.allowsTopLevelDeclaration(), is(false));
assertThat(choiceModel.getAllParameterModels(), empty());
assertThat(choiceModel.getNestedComponents(), hasSize(2));
final NestedRouteModel whenRouteModel = (NestedRouteModel) choiceModel.getNestedComponents().get(0);
assertThat(whenRouteModel.getName(), is("when"));
assertThat(whenRouteModel.getMinOccurs(), is(1));
assertThat(whenRouteModel.getMaxOccurs(), is(Optional.empty()));
assertThat(whenRouteModel.getAllParameterModels(), hasSize(1));
assertThat(whenRouteModel.getAllParameterModels().get(0).getName(), is("expression"));
assertThat(whenRouteModel.getAllParameterModels().get(0).getExpressionSupport(), is(SUPPORTED));
assertThat(whenRouteModel.getAllParameterModels().get(0).getType(), instanceOf(DefaultBooleanType.class));
assertThat(whenRouteModel.getAllParameterModels().get(0).isRequired(), is(true));
final NestedRouteModel otherwiseRouteModel = (NestedRouteModel) choiceModel.getNestedComponents().get(1);
assertThat(otherwiseRouteModel.getName(), is("otherwise"));
assertThat(otherwiseRouteModel.getMinOccurs(), is(0));
assertThat(otherwiseRouteModel.getMaxOccurs().get(), is(1));
assertThat(otherwiseRouteModel.getAllParameterModels(), empty());
}
use of org.mule.runtime.api.meta.model.nested.NestedRouteModel in project mule by mulesoft.
the class CoreExtensionModelTestCase method scatterGather.
@Test
public void scatterGather() {
final ConstructModel scatterGatherModel = coreExtensionModel.getConstructModel("scatterGather").get();
assertThat(scatterGatherModel.getAllParameterModels(), hasSize(4));
assertThat(scatterGatherModel.getAllParameterModels().get(0).getName(), is("timeout"));
assertThat(scatterGatherModel.getAllParameterModels().get(0).getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(scatterGatherModel.getAllParameterModels().get(0).getType(), instanceOf(DefaultNumberType.class));
assertThat(scatterGatherModel.getAllParameterModels().get(0).isRequired(), is(false));
assertThat(scatterGatherModel.getAllParameterModels().get(1).getName(), is("maxConcurrency"));
assertThat(scatterGatherModel.getAllParameterModels().get(1).getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(scatterGatherModel.getAllParameterModels().get(1).getType(), instanceOf(DefaultNumberType.class));
assertThat(scatterGatherModel.getAllParameterModels().get(1).isRequired(), is(false));
assertThat(scatterGatherModel.getAllParameterModels().get(2).getName(), is(TARGET_PARAMETER_NAME));
assertThat(scatterGatherModel.getAllParameterModels().get(2).getExpressionSupport(), is(NOT_SUPPORTED));
assertThat(scatterGatherModel.getAllParameterModels().get(2).getType(), instanceOf(DefaultStringType.class));
assertThat(scatterGatherModel.getAllParameterModels().get(2).isRequired(), is(false));
assertThat(scatterGatherModel.getAllParameterModels().get(3).getName(), is(TARGET_VALUE_PARAMETER_NAME));
assertThat(scatterGatherModel.getAllParameterModels().get(3).getExpressionSupport(), is(REQUIRED));
assertThat(scatterGatherModel.getAllParameterModels().get(3).getType(), instanceOf(StringType.class));
assertThat(scatterGatherModel.getAllParameterModels().get(3).isRequired(), is(false));
assertThat(scatterGatherModel.getNestedComponents(), hasSize(1));
final NestedRouteModel routeModel = (NestedRouteModel) scatterGatherModel.getNestedComponents().get(0);
assertThat(routeModel.getName(), is("route"));
assertThat(routeModel.getMinOccurs(), is(2));
assertThat(routeModel.getMaxOccurs(), is(Optional.empty()));
assertThat(routeModel.getAllParameterModels(), empty());
}
use of org.mule.runtime.api.meta.model.nested.NestedRouteModel in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createComponentElement.
private DslElementModel<? extends ComponentModel> createComponentElement(ComponentModel model, ComponentElementDeclaration<?> componentDeclaration) {
DslElementSyntax configDsl = dsl.resolve(model);
InternalComponentConfiguration.Builder configuration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(configDsl));
if (componentDeclaration instanceof ReferableElementDeclaration) {
configuration.withParameter(NAME_ATTRIBUTE_NAME, ((ReferableElementDeclaration) componentDeclaration).getRefName());
}
if (componentDeclaration.getConfigRef() != null) {
configuration.withParameter(CONFIG_ATTRIBUTE_NAME, componentDeclaration.getConfigRef());
}
DslElementModel.Builder<? extends ComponentModel> componentElement = createParameterizedElementModel(model, configDsl, componentDeclaration, configuration);
ExtensionModel componentsOwner = currentExtension;
DslSyntaxResolver componentsDslResolver = dsl;
componentDeclaration.getComponents().forEach(nestedComponentDeclaration -> {
if (nestedComponentDeclaration instanceof RouteElementDeclaration) {
if (model instanceof ComposableModel) {
((ComposableModel) model).getNestedComponents().stream().filter(nestedModel -> nestedModel instanceof NestedRouteModel && nestedModel.getName().equals(nestedComponentDeclaration.getName())).findFirst().ifPresent(nestedRouteModel -> componentElement.containing(crateRouteElement((NestedRouteModel) nestedRouteModel, (RouteElementDeclaration) nestedComponentDeclaration)));
}
} else {
create(nestedComponentDeclaration).ifPresent(nestedComponentElement -> {
nestedComponentElement.getConfiguration().ifPresent(configuration::withNestedComponent);
componentElement.containing(nestedComponentElement);
});
}
currentExtension = componentsOwner;
dsl = componentsDslResolver;
});
return componentElement.withConfig(configuration.build()).build();
}
use of org.mule.runtime.api.meta.model.nested.NestedRouteModel in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareRoute.
private Optional<RouteElementDeclaration> declareRoute(ComposableModel model, DslElementSyntax elementDsl, ConfigLine child, ElementDeclarer extensionElementsDeclarer) {
return model.getNestedComponents().stream().filter(nestedModel -> elementDsl.getContainedElement(nestedModel.getName()).map(nestedDsl -> child.getIdentifier().equals(nestedDsl.getElementName())).orElse(false)).filter(nestedModel -> nestedModel instanceof NestedRouteModel).findFirst().map(nestedModel -> {
RouteElementDeclarer routeDeclarer = extensionElementsDeclarer.newRoute(nestedModel.getName());
DslElementSyntax routeDsl = elementDsl.getContainedElement(nestedModel.getName()).get();
declareParameterizedComponent((ParameterizedModel) nestedModel, routeDsl, routeDeclarer, child.getConfigAttributes(), child.getChildren());
declareComposableModel((ComposableModel) nestedModel, elementDsl, child, routeDeclarer);
return routeDeclarer.getDeclaration();
});
}
Aggregations