/** * Update the map-elements in the datasource that are below <i>parent</i>. * * @param parent Parent element to add / update * @param configuration configuration that holds the properties * @param mapName the name of the map-property in the configuration that holds the elements * @param propertyElementName the name of the element to write below <i>parent</i> */ private static void updateMap( Element parent, Configuration configuration, String mapName, String propertyElementName) { PropertyMap map = configuration.getMap(mapName); // Wrap in ArrayList to avoid ConcurrentModificationException when adding or removing children // while iterating. List<Element> mapElements = new ArrayList<Element>(parent.getChildren(propertyElementName)); if ((map == null) || map.getMap().isEmpty()) { if (!mapElements.isEmpty()) { parent.removeChildren(propertyElementName); } return; } Map<String, Element> elements = new HashMap<String, Element>(); for (Element el : mapElements) { elements.put(el.getAttributeValue("name"), el); if (map.get(el.getAttributeValue("name")) == null) { parent.removeContent(el); } } for (Property prop : map.getMap().values()) { Element element = elements.get(prop.getName()); if (element == null) { element = new Element(propertyElementName); element.setAttribute("name", prop.getName()); parent.addContent(element); } element.setText(((PropertySimple) prop).getStringValue()); } }
public void loadResourceConfiguration() throws Exception { // Just bail because this test wont work yet if (true) { return; } Configuration configuration; try { configuration = component.loadResourceConfiguration(pluginConfiguration); } catch (UnsatisfiedLinkError ule) { // Skip tests if augeas not available return; } assert configuration != null : "Null configuration returned from load call"; Collection<Property> allProperties = configuration.getProperties(); assert allProperties.size() == 1 : "Incorrect number of properties found. Expected: 1, Found: " + allProperties.size(); PropertyList entryList = (PropertyList) allProperties.iterator().next(); for (Property property : entryList.getList()) { PropertyMap entry = (PropertyMap) property; Property typeProperty = entry.get("type"); Property uriProperty = entry.get("uri"); Property distributionProperty = entry.get("distribution"); assert typeProperty != null : "Type was null in entry"; assert uriProperty != null : "URI was null in entry"; assert distributionProperty != null : "Distribution was null in entry"; log.info("Type: " + ((PropertySimple) typeProperty).getStringValue()); log.info("URI: " + ((PropertySimple) uriProperty).getStringValue()); log.info("Distribution: " + ((PropertySimple) distributionProperty).getStringValue()); } }
public void configurationMembersSwappedAndKeptPositions() { Configuration testConfig = getFreshConfig(); // keep track of the order of the properies in the original map PropertyMap originalMap = (PropertyMap) testConfig.getList("topLevelListOfMaps").getList().get(0); List<Property> originalMapPropertiesInOrder = new ArrayList<Property>(originalMap.getMap().values()); PasswordObfuscationUtility.obfuscatePasswords(DEFINITION, testConfig); PropertyList list = testConfig.getList("topLevelListOfMaps"); PropertyMap map = (PropertyMap) list.getList().get(0); Assert.assertTrue( map.get("password") instanceof ObfuscatedPropertySimple, "The password in the map failed to be swapped to obfuscated form"); // now check that the positions in the map actually didn't change List<Property> mapPropertiesInOrder = new ArrayList<Property>(map.getMap().values()); Assert.assertEquals( mapPropertiesInOrder.size(), originalMapPropertiesInOrder.size(), "Different number of properties in the map after obfuscation"); for (int i = 0; i < mapPropertiesInOrder.size(); ++i) { Property originalProp = originalMapPropertiesInOrder.get(i); Property prop = mapPropertiesInOrder.get(i); Assert.assertEquals( prop.getName(), originalProp.getName(), "Properties seem to be mixed up after obfuscation"); } }