KindFilenameMapperUtil { public static Map<String, List<String>> loadMappings() { final String location = "/META-INF/fabric8/kind-filename-type-mapping-default.adoc"; final String locationMappingProperties = EnvUtil.getEnvVarOrSystemProperty("fabric8.mapping", "/META-INF/fabric8/kind-filename-type-mapping-default.properties"); try (final InputStream mappingFile = loadContent(location); final InputStream mappingPropertiesFile = loadContent(locationMappingProperties)) { final AsciiDocParser asciiDocParser = new AsciiDocParser(); final Map<String, List<String>> defaultMapping = asciiDocParser.serializeKindFilenameTable(mappingFile); if (mappingPropertiesFile != null) { PropertiesMappingParser propertiesMappingParser = new PropertiesMappingParser(); defaultMapping.putAll(propertiesMappingParser.parse(mappingPropertiesFile)); } return defaultMapping; } catch (IOException e) { throw new IllegalStateException(e); } }  static Map<String, List<String>> loadMappings();  }
@Test public void should_load_default_mapping_file() { final Map<String, List<String>> mappings = KindFilenameMapperUtil.loadMappings(); final Map<String, List<String>> expectedSerlializedContent = new HashMap<>(); expectedSerlializedContent.put("ConfigMap", Arrays.asList("cm", "configmap")); expectedSerlializedContent.put("CronJob", Arrays.asList("cj", "cronjob")); expectedSerlializedContent.put("Pod", Arrays.asList("pd", "pod")); assertThat(mappings).containsAllEntriesOf(expectedSerlializedContent); }
@Test public void should_load_mappings_from_custom_properties_file() throws IOException { final File customMappings = temporaryFolder.newFile("custom.properties"); Files.write(customMappings.toPath(), MAPPING_PROPERTIES.getBytes()); System.setProperty("fabric8.mapping", customMappings.getAbsolutePath()); final Map<String, List<String>> mappings = KindFilenameMapperUtil.loadMappings(); final Map<String, List<String>> expectedSerlializedContent = new HashMap<>(); expectedSerlializedContent.put("ConfigMap", Arrays.asList("cm", "configmap")); expectedSerlializedContent.put("CronJob", Arrays.asList("cj", "cronjob")); expectedSerlializedContent.put("Var", Arrays.asList("foo", "bar")); assertThat(mappings).containsAllEntriesOf(expectedSerlializedContent); }
@Test public void should_load_mappings_and_override_from_custom_properties_file() throws IOException { final File customMappings = temporaryFolder.newFile("custom.properties"); Files.write(customMappings.toPath(), OVERRIDE_MAPPING_PROPERTIES.getBytes()); System.setProperty("fabric8.mapping", customMappings.getAbsolutePath()); final Map<String, List<String>> mappings = KindFilenameMapperUtil.loadMappings(); final Map<String, List<String>> expectedSerlializedContent = new HashMap<>(); expectedSerlializedContent.put("ConfigMap", Arrays.asList("foo", "bar")); expectedSerlializedContent.put("CronJob", Arrays.asList("cj", "cronjob")); assertThat(mappings).containsAllEntriesOf(expectedSerlializedContent); }