private void withXmlElement(Component component, String value) { when(component.getAnnotation(SOURCE_ELEMENT_ANNOTATION_KEY)).thenReturn(value); } }
private void setCacheIdGenerator() { DslResolvingContext context = DslResolvingContext.getDefault(extensionManager.getExtensions()); MetadataCacheIdGeneratorFactory.ComponentLocator<ComponentConfiguration> configLocator = location -> componentLocator .find(location) .map(component -> (ComponentConfiguration) component.getAnnotation(ANNOTATION_COMPONENT_CONFIG)); this.cacheIdGenerator = cacheIdGeneratorFactory.create(context, configLocator); }
@Override public void onStart(SourceCallback<InputStream, Void> sourceCallback) throws MuleException { if (nextOperationReference != null) { Component proc = locator.find(builderFromStringRepresentation(location.getParts().get(0).getPartPath()).addProcessorsPart() .addIndexPart(0).build()) .orElseThrow(() -> new IllegalArgumentException("Missing processor after this source")); Map<String, Object> parameters = (Map<String, Object>) proc.getAnnotation(ANNOTATION_PARAMETERS); if (!parameters.get("name").equals(nextOperationReference)) { throw new IllegalArgumentException(String.format("Next processor %s does not match the expected operation %s", parameters.get("name"), nextOperationReference)); } } scheduler = schedulerService.cpuLightScheduler(); sourceCallbackHandleTask = scheduler.scheduleAtFixedRate(() -> sourceCallback.handle(Result.<InputStream, Void>builder() .output(new ByteArrayInputStream(getSpellBytes(spell))) .build()), 0, castFrequencyInMillis, MILLISECONDS); }
@Test public void annotatedComponent() { Component annotated = mock(Component.class); when(annotated.getAnnotation(eq(docNameAttrName))).thenReturn("Mock Component"); when(annotated.toString()).thenReturn("Mock@1"); configureProcessorLocation(annotated); LocatedMuleException lme = new LocatedMuleException(annotated); assertThat(lme.getInfo().get(INFO_LOCATION_KEY).toString(), is("Mock@1 @ app:muleApp.xml:10 (Mock Component)")); }
public Processor createMockProcessor(String processorPath, boolean useLocationSettings) { ComponentLocation componentLocation = mock(ComponentLocation.class); when(componentLocation.getLocation()).thenReturn(processorPath); when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty()); when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty()); Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS)); when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null); when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation); return (Processor) annotatedMessageProcessor; }
@Test public void namedAnnotatedComponent() { Component namedAnnotated = mock(Component.class, withSettings().extraInterfaces(NamedObject.class)); when(((NamedObject) namedAnnotated).getName()).thenReturn("mockComponent"); when(namedAnnotated.getAnnotation(eq(docNameAttrName))).thenReturn("Mock Component"); when(namedAnnotated.toString()).thenReturn("Mock@1"); configureProcessorLocation(namedAnnotated); LocatedMuleException lme = new LocatedMuleException(namedAnnotated); assertThat(lme.getInfo().get(INFO_LOCATION_KEY).toString(), is("/mockComponent @ app:muleApp.xml:10 (Mock Component)")); }
@Before public void setupMVEL() throws InitialisationException { mvel = new MVELExpressionLanguage(muleContext); mvel.initialise(); flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getName()).thenReturn("myFlow"); final DefaultComponentLocation location = fromSingleComponent("myFlow"); when(((Component) flowConstruct).getAnnotation(LOCATION_KEY)).thenReturn(location); when(((Component) flowConstruct).getLocation()).thenReturn(location); }
public static List<ErrorMapping> getErrorMappings(Component object) { List<ErrorMapping> list = (List<ErrorMapping>) object.getAnnotation(ANNOTATION_ERROR_MAPPINGS); return list != null ? list : emptyList(); }
public static Optional<ComponentIdentifier> getComponentIdentifier(Component obj) { return Optional.ofNullable((ComponentIdentifier) obj.getAnnotation(ANNOTATION_NAME)); }
@Test public void newAnnotatedComponentCall() { CoreEvent event = buildEvent("newAnnotatedComponentCall"); PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName()); assertThat(getContextInfo(event, rootFlowConstruct), is("")); manager.onPipelineNotificationStart(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), startsWith("at " + rootFlowConstruct.getName())); Component annotatedMessageProcessor = (Component) createMockProcessor("/comp", true); when(annotatedMessageProcessor.getAnnotation(docNameAttrName)).thenReturn("annotatedName"); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, (Processor) annotatedMessageProcessor)); assertThat(getContextInfo(event, rootFlowConstruct), startsWith("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":muleApp.xml:10 (annotatedName))")); manager.onPipelineNotificationComplete(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), is("")); }
protected static String getSourceXML(Component element) { Object sourceXml = element.getAnnotation(SOURCE_ELEMENT_ANNOTATION_KEY); return sourceXml != null ? maskPasswords(sourceXml.toString()) : null; }
private void withXmlElement(Component component, String value) { when(component.getAnnotation(SOURCE_ELEMENT_ANNOTATION_KEY)).thenReturn(value); } }
public Processor createMockProcessor(String processorPath, boolean useLocationSettings) { ComponentLocation componentLocation = mock(ComponentLocation.class); when(componentLocation.getLocation()).thenReturn(processorPath); when(componentLocation.getFileName()).thenReturn(useLocationSettings ? of(CONFIG_FILE_NAME) : empty()); when(componentLocation.getLineInFile()).thenReturn(useLocationSettings ? of(LINE_NUMBER) : empty()); Component annotatedMessageProcessor = (Component) mock(Processor.class, withSettings().extraInterfaces(Component.class).defaultAnswer(RETURNS_DEEP_STUBS)); when(annotatedMessageProcessor.getAnnotation(any())).thenReturn(null); when(annotatedMessageProcessor.getLocation()).thenReturn(componentLocation); return (Processor) annotatedMessageProcessor; }
@Test public void annotatedComponent() { Component annotated = mock(Component.class); when(annotated.getAnnotation(eq(docNameAttrName))).thenReturn("Mock Component"); when(annotated.toString()).thenReturn("Mock@1"); configureProcessorLocation(annotated); LocatedMuleException lme = new LocatedMuleException(annotated); assertThat(lme.getInfo().get(INFO_LOCATION_KEY).toString(), is("Mock@1 @ app:muleApp.xml:10 (Mock Component)")); }
@Test public void namedAnnotatedComponent() { Component namedAnnotated = mock(Component.class, withSettings().extraInterfaces(NamedObject.class)); when(((NamedObject) namedAnnotated).getName()).thenReturn("mockComponent"); when(namedAnnotated.getAnnotation(eq(docNameAttrName))).thenReturn("Mock Component"); when(namedAnnotated.toString()).thenReturn("Mock@1"); configureProcessorLocation(namedAnnotated); LocatedMuleException lme = new LocatedMuleException(namedAnnotated); assertThat(lme.getInfo().get(INFO_LOCATION_KEY).toString(), is("/mockComponent @ app:muleApp.xml:10 (Mock Component)")); }
@Override public ReactiveProcessor apply(Processor component, ReactiveProcessor next) { if (!isInterceptable(component)) { return next; } final ComponentLocation componentLocation = ((Component) component).getLocation(); if (!interceptorFactory.intercept(componentLocation)) { return next; } final ProcessorInterceptor interceptor = interceptorFactory.get(); Map<String, String> dslParameters = (Map<String, String>) ((Component) component).getAnnotation(ANNOTATION_PARAMETERS); ReactiveProcessor interceptedProcessor = doApply(component, next, componentLocation, interceptor, dslParameters); LOGGER.debug("Interceptor '{}' for processor '{}' configured.", interceptor, componentLocation.getLocation()); return interceptedProcessor; }
@Before public void setupMVEL() throws InitialisationException { mvel = new MVELExpressionLanguage(muleContext); mvel.initialise(); flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getName()).thenReturn("myFlow"); final DefaultComponentLocation location = fromSingleComponent("myFlow"); when(((Component) flowConstruct).getAnnotation(LOCATION_KEY)).thenReturn(location); when(((Component) flowConstruct).getLocation()).thenReturn(location); }
@Test public void newAnnotatedComponentCall() { CoreEvent event = buildEvent("newAnnotatedComponentCall"); PipelineMessageNotification pipelineNotification = buildPipelineNotification(event, rootFlowConstruct.getName()); assertThat(getContextInfo(event, rootFlowConstruct), is("")); manager.onPipelineNotificationStart(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName())); Component annotatedMessageProcessor = (Component) createMockProcessor("/comp", true); when(annotatedMessageProcessor.getAnnotation(docNameAttrName)).thenReturn("annotatedName"); manager .onMessageProcessorNotificationPreInvoke(buildProcessorNotification(event, (Processor) annotatedMessageProcessor)); assertThat(getContextInfo(event, rootFlowConstruct), is("at " + rootFlowConstruct.getName() + "(/comp @ " + APP_ID + ":muleApp.xml:10 (annotatedName))")); manager.onPipelineNotificationComplete(pipelineNotification); assertThat(getContextInfo(event, rootFlowConstruct), is("")); }