@Test
@ExtendWith(TemporaryFolderExtension.class)
void testEnvironmentFromConfigFolder(TemporaryFolder temporaryFolder) throws URISyntaxException, IOException {

    File testTemplatizedBundlesFolder = new File(temporaryFolder.getRoot(), "templatized-bundles");
    File testDetemplatizedBundlesFolder = new File(temporaryFolder.getRoot(), "detemplatized-bundles");
    File keyStoreFolder = new File(temporaryFolder.getRoot(), "keystore");
    File envFolder = new File(temporaryFolder.getRoot(), "config");
    File privateKeyFolder = new File(envFolder, "privateKeys");
    assertTrue(testDetemplatizedBundlesFolder.mkdirs());
    copyDirectory(new File(Objects.requireNonNull(getClass().getClassLoader().getResource("templatized-bundles")).toURI()), testTemplatizedBundlesFolder);
    writeStringToFile(
            new File(envFolder, "identity-providers.json"),
            "{\n" +
                    "  \"simple ldap\": {\n" +
                    "    \"type\" : \"BIND_ONLY_LDAP\",\n" +
                    "    \"environmentVariables\": {\n" +
                    "      \"key1\":\"value1\",\n" +
                    "      \"key2\":\"value2\"\n" +
                    "    },\n" +
                    "    \"identityProviderDetail\" : {\n" +
                    "      \"serverUrls\": [\n" +
                    "        \"ldap://host:port\",\n" +
                    "        \"ldap://host:port2\"\n" +
                    "      ],\n" +
                    "      \"useSslClientAuthentication\":false,\n" +
                    "      \"bindPatternPrefix\": \"somePrefix\",\n" +
                    "      \"bindPatternSuffix\": \"someSuffix\"\n" +
                    "    }\n" +
                    "  }\n" +
                    "}",
            defaultCharset()
    );
    writeStringToFile(
            new File(envFolder, "listen-ports.json"),
            "{\n" +
                    "  \"Custom HTTPS Port\": {\n" +
                    "      \"protocol\" : \"HTTPS\",\n" +
                    "      \"port\" : 12345,\n" +
                    "      \"enabledFeatures\" : [ \"Published service message input\" ],\n" +
                    "      \"tlsSettings\" : {\n" +
                    "        \"clientAuthentication\" : \"REQUIRED\",\n" +
                    "        \"enabledVersions\" : [ \"TLSv1.2\" ],\n" +
                    "        \"enabledCipherSuites\" : [ \"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384\", \"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384\", \"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384\" ],\n" +
                    "        \"environmentVariables\" : {\n" +
                    "          \"usesTLS\" : true\n" +
                    "        }\n" +
                    "      },\n" +
                    "      \"environmentVariables\" : { \n" +
                    "         \"threadPoolSize\" : \"20\"\n" +
                    "      }\n" +
                    "    } \n" +
                    "}",
            defaultCharset()
    );
    writeStringToFile(
            new File(envFolder, "jdbc-connections.json"),
            "{\n" +
                    "  \"my-jdbc\": {\n" +
                    "    \"driverClass\" : \"com.mysql.jdbc.Driver\",\n" +
                    "    \"jdbcUrl\" : \"jdbc:mysql://localhost:3306/ssg\",\n" +
                    "    \"user\" : \"gateway\",\n" +
                    "    \"passwordRef\" : \"gateway\",\n" +
                    "    \"minimumPoolSize\" : 3,\n" +
                    "    \"maximumPoolSize\" : 15,\n" +
                    "    \"properties\" : {\n" +
                    "      \"EnableCancelTimeout\" : \"true\"\n" +
                    "    }\n" +
                    "  }\n" +
                    "}",
            defaultCharset()
    );
    writeStringToFile(
            new File(envFolder, "trusted-certs.json"),
            "{\n" +
                    "  \"my-cert\": {\n" +
                    "      \"verifyHostname\" : false,\n" +
                    "      \"trustedForSsl\" : true,\n" +
                    "      \"trustedAsSamlAttestingEntity\" : false,\n" +
                    "      \"trustAnchor\" : true,\n" +
                    "      \"revocationCheckingEnabled\" : true,\n" +
                    "      \"trustedForSigningClientCerts\" : true,\n" +
                    "      \"trustedForSigningServerCerts\" : true,\n" +
                    "      \"trustedAsSamlIssuer\" : false,\n" +
                    "      \"certificateData\" : {\n" +
                    "           \"issuerName\" : \"my-cert\",\n" +
                    "           \"serialNumber\" : \"123\",\n" +
                    "           \"subjectName\" : \"my-cert\",\n" +
                    "           \"encodedData\" : \"my-cert-data\"\n" +
                    "      }\n" +
                    "  }\n" +
                    "}",
            defaultCharset()
    );
    writeStringToFile(
            new File(envFolder, "stored-passwords.properties"),
            "my_password=my_secret_password",
            defaultCharset()
    );
    writeStringToFile(
            new File(envFolder, "service-env.properties"),
            "my-gateway-api.myEnvironmentVariable=my-service-property-value",
            defaultCharset()
    );
    writeStringToFile(new File( envFolder, "context-env.properties"), "anotherEnvVar=context-variable-value", defaultCharset());
    new EnvironmentCreatorApplication(
            System.getenv(),
            testTemplatizedBundlesFolder.getPath(),
            testDetemplatizedBundlesFolder.getPath(),
            keyStoreFolder.getPath(),
            privateKeyFolder.getPath(),
            temporaryFolder.getRoot().getPath()
    ).run();
    assertEnvironment(testDetemplatizedBundlesFolder);
}