/** Test writing and reading of the fields in the properties file */ @Test public void writeAndReadProperties() { // ignore if in headless mode with no x11 if (GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadless()) return; try { final File tmpFile = File.createTempFile("artemis.props", ".tmp"); ProjectProperty.writeProperties(tmpFile, projects); final InputStream ins = new FileInputStream(tmpFile); final Properties projectProps = new Properties(); projectProps.load(ins); ins.close(); final HashMap<String, HashMap<String, String>> tmpProjects = ProjectProperty.getProjectMap(projectProps); for (String p : projects.keySet()) { assertTrue("Contains " + p, tmpProjects.containsKey(p)); HashMap<String, String> props = projects.get(p); HashMap<String, String> tmpProps = tmpProjects.get(p); for (final String key : props.keySet()) { // test property key (e.g. title, sequence, bam) assertTrue("Contains property " + key, tmpProps.containsKey(key)); // test values assertTrue( "Contains property " + key + " = " + props.get(key), props.get(key).equals(tmpProps.get(key))); } } } catch (IOException e) { org.junit.Assert.fail(e.getMessage()); } }
/** Load the test properties */ @Before public void loadProperties() { InputStream ins = this.getClass().getClassLoader().getResourceAsStream("data/project.properties"); try { final Properties projectProps = new Properties(); projectProps.load(ins); ins.close(); projects = ProjectProperty.getProjectMap(projectProps); } catch (IOException e) { org.junit.Assert.fail(e.getMessage()); } }