ConfigUtils { public static ConfigDefinitionKey createConfigDefinitionKeyFromDefFile(File file) throws IOException { String[] fileName = file.getName().split("\\."); assert (fileName.length >= 2); String name = fileName[fileName.length - 2]; byte[] content = IOUtils.readFileBytes(file); return createConfigDefinitionKeyFromDefContent(name, content); }  static String getMd5(ConfigPayload payload); static String getMd5(String input); static String getMd5(Utf8Array input); static String getMd5(byte[] input); static String stripSpaces(String str); static String getDefMd5(List<String> lines); static String getDefNamespace(Reader in); static Tuple2<String, String> getNameAndNamespaceFromString(String nameDotNamespace); static ConfigDefinitionKey createConfigDefinitionKeyFromZKString(String nodeName); static ConfigDefinitionKey createConfigDefinitionKeyFromDefFile(File file); static String escapeConfigFormatValue(String input); static String getDefMd5FromRequest(String defMd5, List<String> defContent); static String getCanonicalHostName(); static String getEnvValue(String defaultValue, String... envVars); static boolean isGenerationNewer(long newGen, long oldGen);  }
@Test public void testCreateConfigDefinitionKeyFromDefFile() { ConfigDefinitionKey def = null; try { def = ConfigUtils.createConfigDefinitionKeyFromDefFile(new File("src/test/resources/configs/def-files/app.def")); } catch (IOException e) { e.printStackTrace(); fail(); } assertThat(def.getName(), is("app")); assertThat(def.getNamespace(), is("foo")); try { def = ConfigUtils.createConfigDefinitionKeyFromDefFile(new File("src/test/resources/configs/def-files/testnamespace.def")); } catch (IOException e) { e.printStackTrace(); fail(); } assertThat(def.getName(), is("testnamespace")); assertThat(def.getNamespace(), is("foo")); try { byte[] content = IOUtils.readFileBytes(new File("src/test/resources/configs/def-files/app.def")); def = ConfigUtils.createConfigDefinitionKeyFromDefContent("app", content); } catch (IOException e) { fail(); } assertThat(def.getName(), is("app")); assertThat(def.getNamespace(), is("foo")); try { byte[] content = IOUtils.readFileBytes(new File("src/test/resources/configs/def-files-nogen/app.def")); def = ConfigUtils.createConfigDefinitionKeyFromDefContent("app", content); } catch (IOException e) { fail(); } assertThat(def.getName(), is("app")); assertThat(def.getNamespace(), is("mynamespace")); }