DefaultMessageMapperFactory implements MessageMapperFactory { @Override public Optional<MessageMapper> mapperOf(final String mapperId, final MappingContext mappingContext) { final Optional<MessageMapper> mapper = createMessageMapperInstance(mappingContext.getMappingEngine()); final Map<String, String> configuredIncomingConditions = mappingContext.getIncomingConditions(); final Map<String, String> configuredOutgoingConditions = mappingContext.getOutgoingConditions(); final JsonObject defaultOptions = mapper.map(MessageMapper::getDefaultOptions).orElse(JsonObject.empty()); final MergedJsonObjectMap configuredAndDefaultOptions = mergeMappingOptions(defaultOptions, mappingContext.getOptionsAsJson()); final MessageMapperConfiguration options = DefaultMessageMapperConfiguration.of(mapperId, configuredAndDefaultOptions, configuredIncomingConditions, configuredOutgoingConditions); return mapper.flatMap(m -> configureInstance(m, options)); } private  DefaultMessageMapperFactory(final ConnectionId connectionId,
            final MappingConfig mappingConfig,
            final ExtendedActorSystem actorSystem,
            final List<MessageMapperExtension> messageMapperExtensions,
            final LoggingAdapter log); static DefaultMessageMapperFactory of(final ConnectionId connectionId,
            final ActorSystem actorSystem,
            final MappingConfig mappingConfig,
            final LoggingAdapter log); @Override Optional<MessageMapper> mapperOf(final String mapperId, final MappingContext mappingContext); @Override MessageMapperRegistry registryOf(final MappingContext defaultContext,
            final PayloadMappingDefinition payloadMappingDefinition); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void loadMapperFromFactoryMethod() { final Map<String, String> options = new HashMap<>(); options.put(MockMapper.OPT_IS_VALID, String.valueOf(true)); final MappingContext ctx = MappingContexts.mock("test", options); assertThat(underTest.mapperOf("test", ctx)).isPresent(); }
@Test public void loadMapperFromClass() { final MappingContext ctx = MappingContexts.mock(true); assertThat(underTest.mapperOf("test", ctx)).isPresent(); }
@Test public void loadMapperWitInvalidOptions() { final MappingContext ctx = MappingContexts.mock(false); assertThat(underTest.mapperOf("test", ctx)).isEmpty(); }
@Test public void loadMissingMapper() { final MappingContext ctx = MappingContexts.mock("missing-mapper", Collections.emptyMap()); assertThat(underTest.mapperOf("missing-mapper-id", ctx)).isEmpty(); }
@Test public void loadNonMessageMapperClass() { final MappingContext ctx = MappingContexts.mock(String.class.getCanonicalName(), Collections.emptyMap()); assertThat(underTest.mapperOf("some-id", ctx)).isEmpty(); }
@Test public void loadMapperWithInvalidConfig() { final MappingContext ctx = MappingContexts.mock(false); assertThat(underTest.mapperOf("test", ctx)).isEmpty(); }
@Test public void loadMapperWithoutContentType() { final Map<String, String> opts = new HashMap<>(); final MappingContext ctx = ConnectivityModelFactory.newMappingContext(MockMapper.class.getCanonicalName(), opts); assertThat(underTest.mapperOf("test", ctx)).isEmpty(); }