### Question:
AutoApproveConfig { public Properties getPropertiesForResource(String resourceName) { Properties result = new Properties(); if (!isAutoApproved(resourceName)) { return result; } int prefixLength = resourceName.length() + 1; for (Object keyRef : this.autoApproveProps.keySet()) { String key = (String) keyRef; if (!key.equals(resourceName) && key.startsWith(resourceName)) { result.put(key.substring(prefixLength), this.autoApproveProps.getProperty(key)); } } return result; } AutoApproveConfig(String agentConfigDirName, String encryptionKeyFileName); boolean exists(); boolean isAutoApproved(String resourceName); Properties getPropertiesForResource(String resourceName); static final String PLATFORM_PROPERTY_NAME; }### Answer:
@Test public void getPropertiesForResource() { AutoApproveConfig autoApproveConfig = new AutoApproveConfig(PROPS_FOLDER_NAME , ENCRYPTION_KEY_FILE_NAME); TestCase.assertTrue(autoApproveConfig.exists()); TestCase.assertTrue(autoApproveConfig.isAutoApproved("MySQL 5.1.x")); Properties props4res = autoApproveConfig.getPropertiesForResource("MySQL 5.1.x"); TestCase.assertEquals(2, props4res.size()); }
@Test public void addProperties() throws Exception { String propsFileName = PROPS_FOLDER_NAME + "auto-approve.properties"; Properties properties = PropertyUtil.loadProperties(propsFileName); properties.setProperty("New Prop", "true"); properties.setProperty("New Prop.p1", "New Value1"); properties.setProperty("New Prop.p2", "New Value2"); properties.store(new FileOutputStream(propsFileName), null); AutoApproveConfig autoApproveConfig = new AutoApproveConfig(PROPS_FOLDER_NAME, ENCRYPTION_KEY_FILE_NAME); Properties props4res = autoApproveConfig.getPropertiesForResource("New Prop"); TestCase.assertEquals(2, props4res.size()); properties = PropertyUtil.loadProperties(propsFileName); for (Object key : properties.keySet()) { if (!SecurityUtil.isMarkedEncrypted(properties.getProperty((String) key))) { TestCase.fail("properties not encrypted"); } } }