package io.bootique.linkmove;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
import io.bootique.config.ConfigurationFactory;
import io.bootique.config.jackson.JsonNodeConfigurationFactory;
import io.bootique.jackson.DefaultJacksonService;
import io.bootique.jackson.JacksonService;
import io.bootique.linkmove.connector.JdbcConnectorFactoryFactory;
import io.bootique.linkmove.connector.IConnectorFactoryFactory;
import io.bootique.linkmove.connector.URIConnectorFactoryFactory;
import io.bootique.log.DefaultBootLogger;
import org.junit.Test;

import java.io.IOException;
import java.net.URL;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class LinkMoveModule_ConfigurationIT {

    private static final String CONFIG_PREFIX = "linkmove";

    private ConfigurationFactory factory(URL configUrl) {

        // not using a mock; making sure all Jackson extensions are loaded
        JacksonService jacksonService = new DefaultJacksonService(new DefaultBootLogger(true));

        YAMLParser parser;
        try {
            parser = new YAMLFactory().createParser(configUrl);
            JsonNode rootNode = jacksonService.newObjectMapper().readTree(parser);
            return new JsonNodeConfigurationFactory(rootNode, jacksonService.newObjectMapper());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void testConfiguration_ConnectorFactories() {

        LinkMoveFactory f = factory(this.getClass().getResource("/io/bootique/linkmove/config.yml"))
                .config(LinkMoveFactory.class, CONFIG_PREFIX);

        assertEquals("Unexpected number of connector factory providers", 2, f.getConnectorFactories().size());

        IConnectorFactoryFactory<?> factory;

        factory = f.getConnectorFactories().get(0);
        assertTrue(factory instanceof JdbcConnectorFactoryFactory);

        factory = f.getConnectorFactories().get(1);
        assertTrue(factory instanceof URIConnectorFactoryFactory);
        Map<String, String> connectors = ((URIConnectorFactoryFactory) factory).getConnectors();
        assertContainsEntry(connectors, "c1", "file:///path/to/file");
        assertContainsEntry(connectors, "c2", "http://host/path/to/resource");
    }

    private static void assertContainsEntry(Map<?, ?> m, Object k, Object v) {
        assertTrue("Missing key: " + k, m.containsKey(k));
        assertEquals("Unexpected value for key: " + k, m.get(k), v);
    }
}

@@ -227,32 +227,124 @@
 urationFactory;%0A
+import io.bootique.config.PolymorphicConfiguration;%0Aimport io.bootique.config.TypesFactory;%0A
 import io.bootiq
@@ -522,20 +522,17 @@
 nnector.
-Jdbc
+I
 Connecto
@@ -578,33 +578,36 @@
 kmove.connector.
-I
+Jdbc
 ConnectorFactory
@@ -719,24 +719,49 @@
 BootLogger;%0A
+import org.junit.Before;%0A
 import org.j
@@ -1041,16 +1041,310 @@
 move%22;%0A%0A
+    private TypesFactory%3CPolymorphicConfiguration%3E typesFactory;%0A%0A    @Before%0A    public void before() %7B%0A        typesFactory = new TypesFactory%3C%3E(%0A                getClass().getClassLoader(),%0A                PolymorphicConfiguration.class,%0A                new DefaultBootLogger(true));%0A    %7D%0A%0A
     priv
@@ -1539,34 +1539,30 @@
 ice(
-new DefaultBootLogger(true
+typesFactory.getTypes(
 ));%0A

Upgrade to bootique 0.21, bootique-cayenne 0.18 and Cayenne 4.0.M4 #18