Java Code Examples for org.apache.camel.util.CollectionHelper#mapOf()

The following examples show how to use org.apache.camel.util.CollectionHelper#mapOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractDebeziumTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());
    try {
        storeFile = Files.createTempFile(getClass().getSimpleName() + "-store-", "");

        container = createContainer();

        container.start();

        Map<String, String> map = CollectionHelper.mapOf(
                type.getPropertyHostname(), container.getContainerIpAddress(),
                type.getPropertyPort(), container.getMappedPort(getPort()) + "",
                type.getPropertyUsername(), getUsername(),
                type.getPropertyPassword(), getPassword(),
                type.getPropertyOffsetFileName(), storeFile.toString(),
                type.getPropertyJdbc(), getJdbcUrl());

        return map;

    } catch (Exception e) {
        LOGGER.error("Container does not start", e);
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: InfluxdbTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer<>(INFLUXDB_IMAGE)
                .withExposedPorts(INFLUXDB_PORT)
                .waitingFor(Wait.forListeningPort());

        container.start();

        return CollectionHelper.mapOf(
                InfluxdbResource.INFLUXDB_CONNECTION_PROPERTY,
                "http://" + ContainerSupport.getHostAndPort(container, INFLUXDB_PORT));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: FhirTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer(CONTAINER_IMAGE)
                .withExposedPorts(CONTAINER_PORT)
                .withEnv("HAPI_FHIR_VERSION", "DSTU3")
                .waitingFor(Wait.forListeningPort());

        container.start();

        return CollectionHelper.mapOf(
                "camel.fhir.test-url",
                String.format(
                        "http://%s:%d/hapi-fhir-jpaserver/fhir",
                        container.getContainerIpAddress(),
                        container.getMappedPort(CONTAINER_PORT)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: InfinispanServerTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer<>(CONTAINER_IMAGE)
                .withExposedPorts(HOTROD_PORT)
                .withEnv("USER", USER)
                .withEnv("PASS", PASS)
                .waitingFor(Wait.forListeningPort());

        container.start();

        return CollectionHelper.mapOf(
                "quarkus.infinispan-client.server-list", getHostAndPort(container, HOTROD_PORT),
                "quarkus.infinispan-client.near-cache-max-entries", "3",
                "quarkus.infinispan-client.auth-username", USER,
                "quarkus.infinispan-client.auth-password", PASS,
                "quarkus.infinispan-client.auth-realm", "default",
                "quarkus.infinispan-client.sasl-mechanism", "DIGEST-MD5",
                "quarkus.infinispan-client.auth-server-name", "infinispan");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: ActiveMQTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer(ACTIVEMQ_IMAGE)
                .withExposedPorts(AMQP_PORT)
                .withLogConsumer(new Slf4jLogConsumer(LOGGER))
                .withEnv("BROKER_CONFIG_MAX_DISK_USAGE", "100")
                .waitingFor(Wait.forListeningPort());

        container.start();

        String brokerUrl = String.format("amqp://127.0.0.1:%d", container.getMappedPort(AMQP_PORT));

        return CollectionHelper.mapOf(
                "quarkus.qpid-jms.url", brokerUrl,
                "quarkus.qpid-jms.username", ACTIVEMQ_USERNAME,
                "quarkus.qpid-jms.password", ACTIVEMQ_PASSWORD);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: ConsulTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer(CONTAINER_IMAGE)
                .withExposedPorts(CONTAINER_PORT)
                .withCommand("agent", "-dev", "-server", "-bootstrap", "-client", "0.0.0.0", "-log-level", "trace")
                .waitingFor(Wait.forLogMessage(".*Synced node info.*", 1));

        container.start();

        return CollectionHelper.mapOf(
                "camel.consul.test-url",
                String.format("http://%s:%d",
                        container.getContainerIpAddress(),
                        container.getMappedPort(CONTAINER_PORT)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 7
Source File: MongoDbTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer(MONGO_IMAGE)
                .withExposedPorts(MONGODB_PORT)
                .waitingFor(Wait.forListeningPort());

        container.start();

        return CollectionHelper.mapOf(
                "quarkus.mongodb.hosts",
                container.getContainerIpAddress() + ":" + container.getMappedPort(MONGODB_PORT).toString());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 8
Source File: ElasticSearchTestResource.java    From camel-quarkus with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer(ELASTICSEARCH_IMAGE)
                .withExposedPorts(ELASTICSEARCH_PORT)
                .withLogConsumer(new Slf4jLogConsumer(LOGGER))
                .withEnv("discovery.type", "single-node")
                .waitingFor(Wait.forListeningPort());

        container.start();

        return CollectionHelper.mapOf(
                "camel.component.elasticsearch-rest.host-addresses",
                String.format("localhost:%s", container.getMappedPort(ELASTICSEARCH_PORT)));

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 9
Source File: CouchdbTestResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer(COUCHDB_IMAGE).withExposedPorts(COUCHDB_PORT).waitingFor(Wait.forListeningPort());
        container.start();

        final String authority = container.getContainerIpAddress() + ":" + container.getMappedPort(COUCHDB_PORT).toString();
        return CollectionHelper.mapOf("camel.couchdb.test.server.authority", authority);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 10
Source File: SftpTestResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    try {
        final int port = AvailablePortFinder.getNextAvailable();

        sftpHome = Files.createTempDirectory("sftp-");
        sshHome = sftpHome.resolve("admin/.ssh");

        Files.createDirectories(sshHome);

        byte[] knownHostsBytes = String.format(KNOWN_HOSTS, port).getBytes(StandardCharsets.UTF_8);
        Files.write(sshHome.resolve(".known_hosts"), knownHostsBytes);

        VirtualFileSystemFactory factory = new VirtualFileSystemFactory();
        factory.setUserHomeDir("admin", sftpHome.resolve("admin").toAbsolutePath());

        sshServer = SshServer.setUpDefaultServer();
        sshServer.setPort(port);
        sshServer.setKeyPairProvider(new ClassLoadableResourceKeyPairProvider("hostkey.pem"));
        sshServer.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
        sshServer.setCommandFactory(new ScpCommandFactory());
        sshServer.setPasswordAuthenticator((username, password, session) -> true);
        sshServer.setPublickeyAuthenticator((username, key, session) -> true);
        sshServer.setFileSystemFactory(factory);
        sshServer.start();

        return CollectionHelper.mapOf("camel.sftp.test-port", Integer.toString(port));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 11
Source File: ActiveMQTestResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    LOGGER.info(TestcontainersConfiguration.getInstance().toString());

    try {
        container = new GenericContainer<>(ACTIVEMQ_IMAGE)
                .withExposedPorts(ACTIVEMQ_PORT)
                .withLogConsumer(new Slf4jLogConsumer(LOGGER))
                .withEnv("BROKER_CONFIG_MAX_DISK_USAGE", "100")
                .waitingFor(Wait.forListeningPort());

        container.start();

        String brokerUrlTcp = String.format("tcp://127.0.0.1:%d", container.getMappedPort(ACTIVEMQ_PORT));
        String brokerUrlWs = String.format("ws://127.0.0.1:%d", container.getMappedPort(ACTIVEMQ_PORT));

        return CollectionHelper.mapOf(
                "quarkus.artemis.url", brokerUrlTcp,
                "quarkus.artemis.username", ACTIVEMQ_USERNAME,
                "quarkus.artemis.password", ACTIVEMQ_PASSWORD,
                "camel.component.paho.brokerUrl", brokerUrlTcp,
                "camel.component.paho.username", ACTIVEMQ_USERNAME,
                "camel.component.paho.password", ACTIVEMQ_PASSWORD,
                "broker-url.ws", brokerUrlWs);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 12
Source File: GrpcServerTestResource.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> start() {
    try {
        final int port = AvailablePortFinder.getNextAvailable();
        grpcServer = ServerBuilder.forPort(port).addService(new PingPongImpl()).build().start();
        return CollectionHelper.mapOf(
                "camel.grpc.test.server.port", String.valueOf(port),
                "camel.grpc.consumer.port", String.valueOf(AvailablePortFinder.getNextAvailable()));
    } catch (Exception e) {
        throw new RuntimeException("Could not start gRPC server", e);
    }
}
 
Example 13
Source File: FtpTestResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> start() {
    try {
        final int port = AvailablePortFinder.getNextAvailable();

        ftpRoot = Files.createTempDirectory("ftp-");
        usrFile = Files.createTempFile("ftp-", ".properties");

        NativeFileSystemFactory fsf = new NativeFileSystemFactory();
        fsf.setCreateHome(true);

        PropertiesUserManagerFactory pumf = new PropertiesUserManagerFactory();
        pumf.setAdminName("admin");
        pumf.setPasswordEncryptor(new ClearTextPasswordEncryptor());
        pumf.setFile(usrFile.toFile());

        UserManager userMgr = pumf.createUserManager();

        BaseUser user = new BaseUser();
        user.setName("admin");
        user.setPassword("admin");
        user.setHomeDirectory(ftpRoot.toString());

        List<Authority> authorities = new ArrayList<>();
        WritePermission writePermission = new WritePermission();
        writePermission.authorize(new WriteRequest());
        authorities.add(writePermission);
        user.setAuthorities(authorities);
        userMgr.save(user);

        ListenerFactory factory = new ListenerFactory();
        factory.setPort(port);

        FtpServerFactory serverFactory = new FtpServerFactory();
        serverFactory.setUserManager(userMgr);
        serverFactory.setFileSystem(fsf);
        serverFactory.setConnectionConfig(new ConnectionConfigFactory().createConnectionConfig());
        serverFactory.addListener("default", factory.createListener());

        FtpServerFactory ftpServerFactory = serverFactory;
        ftpServer = ftpServerFactory.createServer();
        ftpServer.start();

        return CollectionHelper.mapOf(
                "camel.ftp.test-port", Integer.toString(port),
                "camel.ftp.test-root-dir", ftpRoot.toString(),
                "camel.ftp.test-user-file", usrFile.toString());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 14
Source File: KuduTestResource.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> start() {
    LOG.info(TestcontainersConfiguration.getInstance().toString());

    try {
        Network kuduNetwork = Network.newNetwork();

        // Setup the Kudu master server container
        masterContainer = new GenericContainer(KUDU_IMAGE).withCommand("master")
                .withExposedPorts(KUDU_MASTER_RPC_PORT, KUDU_MASTER_HTTP_PORT).withNetwork(kuduNetwork)
                .withNetworkAliases(KUDU_MASTER_NETWORK_ALIAS);
        masterContainer = masterContainer.withLogConsumer(new Slf4jLogConsumer(LOG)).waitingFor(Wait.forListeningPort());
        masterContainer.start();

        // Force host name and port, so that the tablet container is accessible from KuduResource, KuduTest and KuduIT.
        Consumer<CreateContainerCmd> consumer = cmd -> {
            Ports portBindings = new Ports();
            portBindings.bind(ExposedPort.tcp(KUDU_TABLET_RPC_PORT), Ports.Binding.bindPort(KUDU_TABLET_RPC_PORT));
            portBindings.bind(ExposedPort.tcp(KUDU_TABLET_HTTP_PORT), Ports.Binding.bindPort(KUDU_TABLET_HTTP_PORT));
            HostConfig hostConfig = HostConfig.newHostConfig().withPortBindings(portBindings)
                    .withNetworkMode(kuduNetwork.getId());
            cmd.withHostName(KUDU_TABLET_NETWORK_ALIAS).withHostConfig(hostConfig);
        };

        // Setup the Kudu tablet server container
        tabletContainer = new GenericContainer(KUDU_IMAGE).withCommand("tserver")
                .withEnv("KUDU_MASTERS", KUDU_MASTER_NETWORK_ALIAS)
                .withExposedPorts(KUDU_TABLET_RPC_PORT, KUDU_TABLET_HTTP_PORT).withNetwork(kuduNetwork)
                .withNetworkAliases(KUDU_TABLET_NETWORK_ALIAS).withCreateContainerCmdModifier(consumer);
        tabletContainer = tabletContainer.withLogConsumer(new Slf4jLogConsumer(LOG)).waitingFor(Wait.forListeningPort());
        tabletContainer.start();

        // Print interesting Kudu servers connectivity information
        final String masterRpcAuthority = masterContainer.getContainerIpAddress() + ":"
                + masterContainer.getMappedPort(KUDU_MASTER_RPC_PORT);
        LOG.info("Kudu master RPC accessible at " + masterRpcAuthority);
        final String masterHttpAuthority = masterContainer.getContainerIpAddress() + ":"
                + masterContainer.getMappedPort(KUDU_MASTER_HTTP_PORT);
        LOG.info("Kudu master HTTP accessible at " + masterHttpAuthority);
        final String tServerRpcAuthority = tabletContainer.getContainerIpAddress() + ":"
                + tabletContainer.getMappedPort(KUDU_TABLET_RPC_PORT);
        LOG.info("Kudu tablet server RPC accessible at " + tServerRpcAuthority);
        final String tServerHttpAuthority = tabletContainer.getContainerIpAddress() + ":"
                + tabletContainer.getMappedPort(KUDU_TABLET_HTTP_PORT);
        LOG.info("Kudu tablet server HTTP accessible at " + tServerHttpAuthority);

        return CollectionHelper.mapOf(KUDU_AUTHORITY_CONFIG_KEY, masterRpcAuthority);
    } catch (Exception ex) {
        LOG.error("Issue starting KuduTestResource, please have a look at KuduInfrastructureTestHelper", ex);
        return CollectionHelper.mapOf(KUDU_AUTHORITY_CONFIG_KEY,
                "Please_have_a_look_at_KuduInfrastructureTestHelper");
    }
}