@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 fireNotificationUsingLocation() { final LocationPart flowPart = mock(LocationPart.class); when(flowPart.getPartPath()).thenReturn("flowName"); final ComponentLocation location = mock(ComponentLocation.class); when(location.getParts()).thenReturn(Collections.singletonList(flowPart)); when(location.getComponentIdentifier()).thenReturn(TypedComponentIdentifier.builder() .type(SOURCE) .identifier(buildFromStringRepresentation("http:listener")) .build()); when(messageSource.getLocation()).thenReturn(location); final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getMuleContext()).thenReturn(muleContext); final int action = 100; helper.fireNotification(messageSource, event, location, action); assertConnectorMessageNotification(eventNotificationHandler, messageSource, location, action); }
@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")); }
private boolean isInsideMunitToolsSpy(ComponentLocation location) { return location.getParts().stream() .anyMatch(locationPart -> locationPart.getPartIdentifier().map(this::isMunitToolsSpy).orElse(false)); }
private static Boolean isLocationInsideMunitTest(ComponentLocation location) { Optional<TypedComponentIdentifier> partIdentifier = location.getParts().get(0).getPartIdentifier(); if (partIdentifier.isPresent()) { if ("munit".equals(partIdentifier.get().getIdentifier().getNamespace())) { return true; } } return false; }
public static CoverageComponentLocation fromComponentLocation(ComponentLocation location) { // TODO ask mule to expose the name in ComponentLocation Optional<String> name = ((DefaultComponentLocation) location).getName(); List<CoverageLocationPart> locationParts = location.getParts().stream().map(lp -> fromLocationPart(lp)).collect(Collectors.toList()); return new CoverageComponentLocation(name, locationParts); }
@Test public void fireNotificationUsingLocation() { final LocationPart flowPart = mock(LocationPart.class); when(flowPart.getPartPath()).thenReturn("flowName"); final ComponentLocation location = mock(ComponentLocation.class); when(location.getParts()).thenReturn(Collections.singletonList(flowPart)); when(location.getComponentIdentifier()).thenReturn(TypedComponentIdentifier.builder() .type(SOURCE) .identifier(buildFromStringRepresentation("http:listener")) .build()); when(messageSource.getLocation()).thenReturn(location); final FlowConstruct flowConstruct = mock(FlowConstruct.class, withSettings().extraInterfaces(Component.class)); when(flowConstruct.getMuleContext()).thenReturn(muleContext); final int action = 100; helper.fireNotification(messageSource, event, location, action); assertConnectorMessageNotification(eventNotificationHandler, messageSource, location, action); }
@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()))); BaseEventContext context = contextWithComponentLocation.apply(location); assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is("http")); assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("listener")); }