@Test public void implementsInitialisable() throws Exception { Component annotated = addAnnotationsToClass(ImplementsInitialisable.class).newInstance(); assertThat(annotated.getAnnotations().keySet(), empty()); annotated.setAnnotations(singletonMap(LOCATION_KEY, fromSingleComponent("value"))); assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY)); }
@Test public void extendsAbstractAnnotated() throws Exception { Component annotated = addAnnotationsToClass(ExtendsAnnotated.class).newInstance(); assertThat(annotated.getAnnotations().keySet(), empty()); annotated.setAnnotations(singletonMap(LOCATION_KEY, fromSingleComponent("value"))); assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY)); assertThat(annotated.getClass().getMethod("setSomething", Object.class).isAnnotationPresent(Inject.class), is(true)); }
@Test public void implementsAnnotated() throws Exception { Component annotated = addAnnotationsToClass(ImplementsAnnotated.class).newInstance(); assertThat(annotated.getAnnotations(), is(nullValue())); }
@Test public void notAnnotated() throws Exception { Component annotated = addAnnotationsToClass(NotAnnotated.class).newInstance(); assertThat(annotated.getAnnotations().keySet(), empty()); annotated.setAnnotations(singletonMap(LOCATION_KEY, fromSingleComponent("value"))); assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY)); assertThat(annotated.getClass().getMethod("setSomething", Object.class).isAnnotationPresent(Inject.class), is(true)); assertThat(removeDynamicAnnotations(annotated), instanceOf(NotAnnotated.class)); assertThat(removeDynamicAnnotations(annotated), not(instanceOf(Component.class))); }
@Test public void paramWithErrorExpression() throws Exception { Component annotatedProcessor = (Component) processor; Map<QName, Object> annotations = new HashMap<>(annotatedProcessor.getAnnotations()); Map<String, String> params = new HashMap<>((Map<String, String>) annotations.get(ANNOTATION_PARAMETERS)); params.put("errorExpr", "#[notAnExpression]"); annotations.put(ANNOTATION_PARAMETERS, params); ((Component) processor).setAnnotations(annotations); ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {}); startFlowWithInterceptors(interceptor); process(flow, eventBuilder(muleContext).message(Message.of("")).build()); if (useMockInterceptor) { InOrder inOrder = inOrder(processor, interceptor); inOrder.verify(interceptor) .before(any(), mapArgWithErrorEntry("errorExpr", instanceOf(ExpressionRuntimeException.class)/* "#[notAnExpression]" */), any()); inOrder.verify(interceptor) .around(any(), mapArgWithErrorEntry("errorExpr", instanceOf(ExpressionRuntimeException.class)/* "#[notAnExpression]" */), any(), any()); inOrder.verify(processor).process(any()); inOrder.verify(interceptor).after(any(), any(), any()); verifyParametersResolvedAndDisposed(times(1)); } }
Map<QName, Object> annotations = new HashMap<>(referencedFlow.getAnnotations()); annotations.put(ROOT_CONTAINER_NAME_KEY, getRootContainerLocation().toString()); referencedFlow.setAnnotations(annotations);
/** * Updates the {@link Component} root container name. * * @param rootContainerName the root container name of the object. * @param component the {@link Component} to update. */ static void updateRootContainerName(String rootContainerName, Component component) { Map<QName, Object> previousAnnotations = new HashMap<>(component.getAnnotations()); previousAnnotations.put(ROOT_CONTAINER_NAME_KEY, rootContainerName); component.setAnnotations(previousAnnotations); }
@Test public void extendsAbstractAnnotated() throws Exception { Component annotated = addAnnotationsToClass(ExtendsAnnotated.class).newInstance(); assertThat(annotated.getAnnotations().keySet(), empty()); annotated.setAnnotations(singletonMap(LOCATION_KEY, "value")); assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY)); assertThat(annotated.getClass().getMethod("setSomething", Object.class).isAnnotationPresent(Inject.class), is(true)); }
@Test public void implementsInitialisable() throws Exception { Component annotated = addAnnotationsToClass(ImplementsInitialisable.class).newInstance(); assertThat(annotated.getAnnotations().keySet(), empty()); annotated.setAnnotations(singletonMap(LOCATION_KEY, "value")); assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY)); }
@Test public void implementsAnnotated() throws Exception { Component annotated = addAnnotationsToClass(ImplementsAnnotated.class).newInstance(); assertThat(annotated.getAnnotations(), is(nullValue())); }
@Test public void notAnnotated() throws Exception { Component annotated = addAnnotationsToClass(NotAnnotated.class).newInstance(); assertThat(annotated.getAnnotations().keySet(), empty()); annotated.setAnnotations(singletonMap(LOCATION_KEY, "value")); assertThat(annotated.getAnnotations().keySet(), contains(LOCATION_KEY)); assertThat(annotated.getClass().getMethod("setSomething", Object.class).isAnnotationPresent(Inject.class), is(true)); assertThat(removeDynamicAnnotations(annotated), instanceOf(NotAnnotated.class)); assertThat(removeDynamicAnnotations(annotated), not(instanceOf(Component.class))); }
protected Processor getReferencedFlow(String name, FlowRefMessageProcessor flowRefMessageProcessor) throws MuleException { if (name == null) { throw new RoutePathNotFoundException(createStaticMessage("flow-ref name expression returned 'null'"), flowRefMessageProcessor); } Component referencedFlow = getReferencedProcessor(name); if (referencedFlow == null) { throw new RoutePathNotFoundException(createStaticMessage("No flow/sub-flow with name '%s' found", name), flowRefMessageProcessor); } // for subflows, we create a new one so it must be initialised manually if (!(referencedFlow instanceof Flow)) { if (referencedFlow instanceof SubflowMessageProcessorChainBuilder) { MessageProcessorChainBuilder chainBuilder = (MessageProcessorChainBuilder) referencedFlow; locator.find(flowRefMessageProcessor.getRootContainerLocation()).filter(c -> c instanceof Flow).map(c -> (Flow) c) .ifPresent(f -> chainBuilder.setProcessingStrategy(f.getProcessingStrategy())); referencedFlow = chainBuilder.build(); } initialiseIfNeeded(referencedFlow, muleContext); Map<QName, Object> annotations = new HashMap<>(referencedFlow.getAnnotations()); annotations.put(ROOT_CONTAINER_NAME_KEY, getRootContainerLocation().toString()); referencedFlow.setAnnotations(annotations); startIfNeeded(referencedFlow); } return (Processor) referencedFlow; }
@Test public void paramWithErrorExpression() throws Exception { Component annotatedProcessor = (Component) processor; Map<QName, Object> annotations = new HashMap<>(annotatedProcessor.getAnnotations()); Map<String, String> params = new HashMap<>((Map<String, String>) annotations.get(ANNOTATION_PARAMETERS)); params.put("errorExpr", "#[notAnExpression]"); annotations.put(ANNOTATION_PARAMETERS, params); ((Component) processor).setAnnotations(annotations); ProcessorInterceptor interceptor = prepareInterceptor(new ProcessorInterceptor() {}); startFlowWithInterceptors(interceptor); process(flow, eventBuilder(muleContext).message(Message.of("")).build()); if (useMockInterceptor) { InOrder inOrder = inOrder(processor, interceptor); inOrder.verify(interceptor) .before(any(), mapArgWithErrorEntry("errorExpr", instanceOf(ExpressionRuntimeException.class)/* "#[notAnExpression]" */), any()); inOrder.verify(interceptor) .around(any(), mapArgWithErrorEntry("errorExpr", instanceOf(ExpressionRuntimeException.class)/* "#[notAnExpression]" */), any(), any()); inOrder.verify(processor).process(any()); inOrder.verify(interceptor).after(any(), any(), any()); verifyParametersResolvedAndDisposed(times(1)); } }