/** * True if an <operation/> A calls an <operation/> B defined in the same <module/> by using <tns:B .../> * * @param operationComponentModel operation that might or might not be referencing operations of the same module. * @return true if it's an <operation/> reference in the same <module/>, false otherwise */ private boolean referencesOperationsWithinModule(ComponentModel operationComponentModel) { return TNS_PREFIX.equals(operationComponentModel.getIdentifier().getNamespace()); }
private boolean isCoreComponent(ComponentIdentifier componentIdentifier, String name) { return componentIdentifier.getNamespace().equals(CORE_PREFIX) && componentIdentifier.getName().equals(name); }
private boolean isAggregatorComponent(ComponentModel componentModel, String referenceNameParameter) { return componentModel.getIdentifier().getNamespace().equals("aggregators") && componentModel.getParameters().containsKey(referenceNameParameter); }
public static ErrorTypeMatcher errorType(ComponentIdentifier errorIdentifier) { return new ErrorTypeMatcher(is(errorIdentifier.getNamespace()), is(errorIdentifier.getName())); }
@Override public Action getAction() { if (action == null) { action = new ExtensionAction(component.getLocation().getComponentIdentifier().getIdentifier().getNamespace().toUpperCase(), ((Enum) actionDefinition).name()); } return action; }
private void validateSingleElementExistence(ComponentIdentifier componentIdentifier) { Map<String, Map<ComponentIdentifier, ComponentModel>> existingComponentsPerFile = new HashMap<>(); executeOnEveryMuleComponentTree(componentModel -> componentModel .getConfigFileName().ifPresent(configFileName -> { ComponentIdentifier identifier = componentModel.getIdentifier(); if (componentIdentifier.getNamespace().equals(identifier.getNamespace()) && componentIdentifier.getName().equals(identifier.getName())) { if (existingComponentsPerFile.containsKey(configFileName) && existingComponentsPerFile.get(configFileName).containsKey(identifier)) { throw new MuleRuntimeException(createStaticMessage( "Two configuration elements %s have been defined. Element [%s] must be unique. Clashing components are %s and %s", identifier.getNamespace() + ":" + identifier.getName(), identifier.getNamespace() + ":" + identifier.getName(), componentModel.getNameAttribute(), existingComponentsPerFile.get(configFileName).get(identifier) .getNameAttribute())); } Map<ComponentIdentifier, ComponentModel> existingComponentWithName = new HashMap<>(); existingComponentWithName.put(identifier, componentModel); existingComponentsPerFile.put(configFileName, existingComponentWithName); } })); }
private Optional<ConfigurationModel> looForConfiguration(ComponentModel componentModel) { final ComponentIdentifier identifier = componentModel.getIdentifier(); return identifier.getNamespace().equals(extensionModel.getXmlDslModel().getPrefix()) ? extensionModel.getConfigurationModel(identifier.getName()) : empty(); }
private Exception handleMissingRequiredParameter(RequiredParameterNotSetException e) { String description = getAnnotations().values().stream() .filter(v -> v instanceof ComponentLocation) .map(v -> (ComponentLocation) v) .findFirst() .map(v -> format("Element <%s:%s> in line %s of file %s is missing required parameter '%s'", v.getComponentIdentifier().getIdentifier().getNamespace(), v.getComponentIdentifier().getIdentifier().getName(), v.getLineInFile().map(n -> "" + n).orElse("<UNKNOWN>"), v.getFileName().orElse("<UNKNOWN>"), hyphenize(e.getParameterName()))) .orElse(e.getMessage()); return new ConfigurationException(createStaticMessage(description), e); }
private void validateNamedTopLevelElementsHaveName(ComponentBuildingDefinitionRegistry componentBuildingDefinitionRegistry) throws ConfigurationException { try { List<ComponentModel> topLevelComponents = muleComponentModels.get(0).getInnerComponents(); topLevelComponents.stream().forEach(topLevelComponent -> { final ComponentIdentifier identifier = topLevelComponent.getIdentifier(); componentBuildingDefinitionRegistry.getBuildingDefinition(identifier).filter(ComponentBuildingDefinition::isNamed) .ifPresent(buildingDefinition -> { if (isBlank(topLevelComponent.getNameAttribute())) { throw new MuleRuntimeException(createStaticMessage(format("Global element %s:%s does not provide a name attribute.", identifier.getNamespace(), identifier.getName()))); } }); }); } catch (Exception e) { throw new ConfigurationException(e); } }
private ErrorType createErrorType(ErrorModel errorModel, ComponentIdentifier identifier, ExtensionModel extensionModel) { final ErrorType errorType; if (identifier.getNamespace().equals(MULE)) { throw new MuleRuntimeException(createStaticMessage(format("The extension [%s] tried to register the [%s] error with [%s] namespace, which is not allowed.", extensionModel.getName(), identifier, MULE))); } if (errorModel.getParent().isPresent()) { errorType = errorTypeRepository.addErrorType(identifier, getErrorType(errorModel.getParent().get(), extensionModel)); } else { errorType = errorTypeRepository.addErrorType(identifier, null); } return errorType; }
private Optional<NestableElementModel> findNestableElementModel(ComponentIdentifier componentIdentifier) { try { return extensionNestableElementModelByComponentIdentifier.get(componentIdentifier, () -> { String componentName = toCamelCase(componentIdentifier.getName(), COMPONENT_NAME_SEPARATOR); for (ExtensionModel extensionModel : extensionsModels) { if (extensionModel.getXmlDslModel().getPrefix().equals(componentIdentifier.getNamespace())) { Optional<NestableElementModel> elementModelOptional = searchNestableElementModel(extensionModel, componentName); if (elementModelOptional.isPresent()) { return elementModelOptional; } return searchNestableElementModel(extensionModel, componentIdentifier.getName()); } } return empty(); }); } catch (ExecutionException e) { throw new MuleRuntimeException(e); } }
private EventMatcher isErrorTypeSourceResponseGenerate() { return hasErrorType(SOURCE_RESPONSE_GENERATE.getNamespace(), SOURCE_RESPONSE_GENERATE.getName()); }
private EventMatcher isErrorTypeSourceResponseSend() { return hasErrorType(SOURCE_RESPONSE_SEND.getNamespace(), SOURCE_RESPONSE_SEND.getName()); }
private Optional<TypedComponentIdentifier> getModuleOperationTypeComponentIdentifier(ComponentModel componentModel) { final ComponentIdentifier originalIdentifier = (ComponentIdentifier) componentModel.getCustomAttributes().get(ORIGINAL_IDENTIFIER); final String namespace = originalIdentifier.getNamespace(); final String operationName = originalIdentifier.getName(); final ComponentIdentifier operationIdentifier = ComponentIdentifier.builder().namespace(namespace).name(operationName).build(); return of(builder().identifier(operationIdentifier).type(OPERATION).build()); }
private EventMatcher isErrorTypeSourceErrorResponseGenerate() { return hasErrorType(SOURCE_ERROR_RESPONSE_GENERATE.getNamespace(), SOURCE_ERROR_RESPONSE_GENERATE.getName()); }
private EventMatcher isErrorTypeSourceErrorResponseSend() { return hasErrorType(SOURCE_ERROR_RESPONSE_SEND.getNamespace(), SOURCE_ERROR_RESPONSE_SEND.getName()); }
@Override protected boolean matchesSafely(TypedException item) { ErrorType errorType = item.getErrorType(); return errorIdentifier.getNamespace().equals(errorType.getNamespace()) && errorIdentifier.getName().equals( errorType .getIdentifier()); }
@Test public void errorIsPropagatedCorrectly() throws Exception { expectedError .expectErrorType(FATAL.getNamespace().toUpperCase(), FATAL.getName()) .expectCause(instanceOf(MuleFatalException.class)); try { flowRunner("throwError").run(); fail("Should've thrown an exception"); } catch (Throwable t) { Throwable problem = t.getCause(); assertThat(problem, instanceOf(MuleFatalException.class)); assertThat(problem.getCause(), instanceOf(LinkageError.class)); throw t; } } }
@Test @Description("Verify that a location produces connector and source data.") public void componentData() throws Exception { TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder() .type(SOURCE) .identifier(buildFromStringRepresentation("http:listener")) .build(); ComponentLocation location = mock(ComponentLocation.class); when(location.getComponentIdentifier()).thenReturn(typedComponentIdentifier); when(location.getParts()).thenReturn(asList(new DefaultLocationPart("flow", empty(), empty(), empty(), empty()))); BaseEventContext context = contextWithComponentLocation.apply(location); assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is("http")); assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("listener")); }
@Test @Description("Verify that a single component location produces connector and source data.") public void componentDataFromSingleComponent() throws Exception { BaseEventContext context = this.context.get(); assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is(CORE_PREFIX)); assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("test")); }