@Test void testParseEnvironmentValues() throws IOException { mockEntityLoader(); final File configFolder = rootProjectDir.createDirectory("config"); final File identityProvidersFile = new File(configFolder, "identity-providers.yml"); Files.touch(identityProvidersFile); Mockito.when(fileUtils.getInputStream(Mockito.any(File.class))).thenReturn(new ByteArrayInputStream(yml.getBytes(Charset.forName("UTF-8")))); EntityTypeRegistry entityTypeRegistry = new EntityTypeRegistry(new Reflections()); EnvironmentConfigurationUtils environmentConfigurationUtils = new EnvironmentConfigurationUtils(JsonTools.INSTANCE, entityLoaderRegistry, JsonFileUtils.INSTANCE, entityTypeRegistry); Map environmentConfig = new HashMap(); environmentConfig.put("IDENTITY_PROVIDER", identityProvidersFile); Map<String, String> map = environmentConfigurationUtils.parseEnvironmentValues(environmentConfig); Assert.assertNotNull(map.get("ENV.IDENTITY_PROVIDER.simple ldap")); }
@SuppressWarnings("unchecked") public Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues) { final Map<String, String> environmentValues = new HashMap<>(); providedEnvironmentValues.entrySet().forEach((Consumer<Entry>) e -> { int index = e.getKey().toString().indexOf('.'); if (index != -1) { environmentValues.put(PREFIX_ENV + e.getKey().toString(), getEnvValue(e.getKey().toString(), e.getValue())); } else { final String entityType = (String) e.getKey(); final Object object = e.getValue(); if (!(object instanceof File)) { throw new MissingEnvironmentException("Unable to load environment from specified property '" + e.getKey().toString() + "' due to unsupported value, it has to be a file"); } Map<String, String> entities = loadConfigFromFile((File) object, entityType); entities.entrySet().forEach(entry -> environmentValues.put(PREFIX_ENV + entityType + "." + entry.getKey(), entry.getValue())); } }); return unmodifiableMap(environmentValues); }
EnvironmentConfigurationUtils { @SuppressWarnings("unchecked") public Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues) { final Map<String, String> environmentValues = new HashMap<>(); providedEnvironmentValues.entrySet().forEach((Consumer<Entry>) e -> { int index = e.getKey().toString().indexOf('.'); if (index != -1) { environmentValues.put(PREFIX_ENV + e.getKey().toString(), getEnvValue(e.getKey().toString(), e.getValue())); } else { final String entityType = (String) e.getKey(); final Object object = e.getValue(); if (!(object instanceof File)) { throw new MissingEnvironmentException("Unable to load environment from specified property '" + e.getKey().toString() + "' due to unsupported value, it has to be a file"); } Map<String, String> entities = loadConfigFromFile((File) object, entityType); entities.entrySet().forEach(entry -> environmentValues.put(PREFIX_ENV + entityType + "." + entry.getKey(), entry.getValue())); } }); return unmodifiableMap(environmentValues); } }
EnvironmentConfigurationUtils { @SuppressWarnings("unchecked") public Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues) { final Map<String, String> environmentValues = new HashMap<>(); providedEnvironmentValues.entrySet().forEach((Consumer<Entry>) e -> { int index = e.getKey().toString().indexOf('.'); if (index != -1) { environmentValues.put(PREFIX_ENV + e.getKey().toString(), getEnvValue(e.getKey().toString(), e.getValue())); } else { final String entityType = (String) e.getKey(); final Object object = e.getValue(); if (!(object instanceof File)) { throw new MissingEnvironmentException("Unable to load environment from specified property '" + e.getKey().toString() + "' due to unsupported value, it has to be a file"); } Map<String, String> entities = loadConfigFromFile((File) object, entityType); entities.entrySet().forEach(entry -> environmentValues.put(PREFIX_ENV + entityType + "." + entry.getKey(), entry.getValue())); } }); return unmodifiableMap(environmentValues); } @Inject  EnvironmentConfigurationUtils(JsonTools jsonTools, EntityLoaderRegistry entityLoaderRegistry,
                                  JsonFileUtils jsonFileUtils, final EntityTypeRegistry entityTypeRegistry); }
EnvironmentConfigurationUtils { @SuppressWarnings("unchecked") public Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues) { final Map<String, String> environmentValues = new HashMap<>(); providedEnvironmentValues.entrySet().forEach((Consumer<Entry>) e -> { int index = e.getKey().toString().indexOf('.'); if (index != -1) { environmentValues.put(PREFIX_ENV + e.getKey().toString(), getEnvValue(e.getKey().toString(), e.getValue())); } else { final String entityType = (String) e.getKey(); final Object object = e.getValue(); if (!(object instanceof File)) { throw new MissingEnvironmentException("Unable to load environment from specified property '" + e.getKey().toString() + "' due to unsupported value, it has to be a file"); } Map<String, String> entities = loadConfigFromFile((File) object, entityType); entities.entrySet().forEach(entry -> environmentValues.put(PREFIX_ENV + entityType + "." + entry.getKey(), entry.getValue())); } }); return unmodifiableMap(environmentValues); } @Inject  EnvironmentConfigurationUtils(JsonTools jsonTools, EntityLoaderRegistry entityLoaderRegistry,
                                  JsonFileUtils jsonFileUtils, final EntityTypeRegistry entityTypeRegistry); @SuppressWarnings("unchecked") Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues); Pair<String, Map<String, String>> parseBundleMetadata(File metaDataFile, File configFolder); Map<String, String> loadConfigFolder(final File configFolder); @NotNull String loadConfigFromFile(File configFile, String entityType, String entityName); @NotNull Map<String, String> loadConfigFromFile(File configFile, String entityType); static String tryInferContentTypeFromValue(final String value); static DependentBundle generateDependentEnvBundleFromProject(final ProjectInfo projectInfo); static String extractEntityName(final String entityName); }
EnvironmentConfigurationUtils { @SuppressWarnings("unchecked") public Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues) { final Map<String, String> environmentValues = new HashMap<>(); providedEnvironmentValues.entrySet().forEach((Consumer<Entry>) e -> { int index = e.getKey().toString().indexOf('.'); if (index != -1) { environmentValues.put(PREFIX_ENV + e.getKey().toString(), getEnvValue(e.getKey().toString(), e.getValue())); } else { final String entityType = (String) e.getKey(); final Object object = e.getValue(); if (!(object instanceof File)) { throw new MissingEnvironmentException("Unable to load environment from specified property '" + e.getKey().toString() + "' due to unsupported value, it has to be a file"); } Map<String, String> entities = loadConfigFromFile((File) object, entityType); entities.entrySet().forEach(entry -> environmentValues.put(PREFIX_ENV + entityType + "." + entry.getKey(), entry.getValue())); } }); return unmodifiableMap(environmentValues); } @Inject  EnvironmentConfigurationUtils(JsonTools jsonTools, EntityLoaderRegistry entityLoaderRegistry,
                                  JsonFileUtils jsonFileUtils, final EntityTypeRegistry entityTypeRegistry); @SuppressWarnings("unchecked") Map<String, String> parseEnvironmentValues(Map providedEnvironmentValues); Pair<String, Map<String, String>> parseBundleMetadata(File metaDataFile, File configFolder); Map<String, String> loadConfigFolder(final File configFolder); @NotNull String loadConfigFromFile(File configFile, String entityType, String entityName); @NotNull Map<String, String> loadConfigFromFile(File configFile, String entityType); static String tryInferContentTypeFromValue(final String value); static DependentBundle generateDependentEnvBundleFromProject(final ProjectInfo projectInfo); static String extractEntityName(final String entityName);  }