@Test
public void testSetResourcePropertyWithMaps() {

  Set<String> propertyIds = new HashSet<String>();
  propertyIds.add("cat1/emptyMapProperty");
  propertyIds.add("cat1/mapProperty");
  propertyIds.add("cat2/mapMapProperty");
  propertyIds.add("cat3/mapProperty3/key2");
  propertyIds.add("cat4/mapMapProperty4/subMap1/key3");
  propertyIds.add("cat4/mapMapProperty4/subMap2");
  Resource resource = new ResourceImpl(Resource.Type.Service);
  // Adding an empty Map as a property should add the actual Map as a property
  Map<String, String> emptyMapProperty = new HashMap<String, String>();
  BaseProvider.setResourceProperty(resource, "cat1/emptyMapProperty", emptyMapProperty, propertyIds);
  assertTrue(resource.getPropertiesMap().containsKey("cat1/emptyMapProperty"));
  Map<String, String> mapProperty = new HashMap<String, String>();
  mapProperty.put("key1", "value1");
  mapProperty.put("key2", "value2");
  mapProperty.put("key3", "value3");
  // Adding a property of type Map should add all of its keys as sub properties
  // if the map property was requested
  BaseProvider.setResourceProperty(resource, "cat1/mapProperty", mapProperty, propertyIds);
  assertNull(resource.getPropertyValue("cat1/mapProperty"));
  assertEquals("value1", resource.getPropertyValue("cat1/mapProperty/key1"));
  assertEquals("value2", resource.getPropertyValue("cat1/mapProperty/key2"));
  assertEquals("value3", resource.getPropertyValue("cat1/mapProperty/key3"));
  Map<String, Map<String, String>> mapMapProperty = new HashMap<String, Map<String, String>>();
  Map<String, String> mapSubProperty1 = new HashMap<String, String>();
  mapSubProperty1.put("key1", "value11");
  mapSubProperty1.put("key2", "value12");
  mapSubProperty1.put("key3", "value13");
  mapMapProperty.put("subMap1", mapSubProperty1);
  Map<String, String> mapSubProperty2 = new HashMap<String, String>();
  mapSubProperty2.put("key1", "value21");
  mapSubProperty2.put("key2", "value22");
  mapSubProperty2.put("key3", "value23");
  mapMapProperty.put("subMap2", mapSubProperty2);
  Map<String, String> mapSubProperty3 = new HashMap<String, String>();
  mapMapProperty.put("subMap3", mapSubProperty3);
  // Map of maps ... adding a property of type Map should add all of its keys as sub properties
  // if the map property was requested
  BaseProvider.setResourceProperty(resource, "cat2/mapMapProperty", mapMapProperty, propertyIds);
  assertNull(resource.getPropertyValue("cat2/mapMapProperty"));
  assertNull(resource.getPropertyValue("cat2/mapMapProperty/subMap1"));
  assertNull(resource.getPropertyValue("cat2/mapMapProperty/subMap2"));
  assertTrue(resource.getPropertiesMap().containsKey(
      "cat2/mapMapProperty/subMap3"));
  assertEquals("value11",
      resource.getPropertyValue("cat2/mapMapProperty/subMap1/key1"));
  assertEquals("value12",
      resource.getPropertyValue("cat2/mapMapProperty/subMap1/key2"));
  assertEquals("value13",
      resource.getPropertyValue("cat2/mapMapProperty/subMap1/key3"));
  assertEquals("value21",
      resource.getPropertyValue("cat2/mapMapProperty/subMap2/key1"));
  assertEquals("value22",
      resource.getPropertyValue("cat2/mapMapProperty/subMap2/key2"));
  assertEquals("value23",
      resource.getPropertyValue("cat2/mapMapProperty/subMap2/key3"));
  Map<String, String> mapProperty3 = new HashMap<String, String>();
  mapProperty3.put("key1", "value1");
  mapProperty3.put("key2", "value2");
  mapProperty3.put("key3", "value3");
  // Adding a property of type Map shouldn't add the map if it wasn't requested and
  // should only add requested keys as sub properties ...
  // only "cat3/mapProperty3/key2" was requested
  BaseProvider.setResourceProperty(resource, "cat3/mapProperty3", mapProperty3, propertyIds);
  assertNull(resource.getPropertyValue("cat3/mapProperty3"));
  assertNull(resource.getPropertyValue("cat3/mapProperty3/key1"));
  assertEquals("value2", resource.getPropertyValue("cat3/mapProperty3/key2"));
  assertNull(resource.getPropertyValue("cat3/mapProperty3/key3"));
  Map<String, Map<String, String>> mapMapProperty4 = new HashMap<String, Map<String, String>>();
  mapMapProperty4.put("subMap1", mapSubProperty1);
  mapMapProperty4.put("subMap2", mapSubProperty2);
  // Map of maps ... adding a property of type Map shouldn't add the map if it wasn't requested and
  // should only add requested keys as sub properties ...
  // only "cat4/mapMapProperty4/subMap1/key3" and "cat4/mapMapProperty4/subMap2" are requested
  BaseProvider.setResourceProperty(resource, "cat4/mapMapProperty4", mapMapProperty4, propertyIds);
  assertNull(resource.getPropertyValue("cat4/mapMapProperty4"));
  assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap1"));
  assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap2"));
  assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap1/key1"));
  assertNull(resource.getPropertyValue("cat4/mapMapProperty4/subMap1/key2"));
  assertEquals("value13",
      resource.getPropertyValue("cat4/mapMapProperty4/subMap1/key3"));
  assertEquals("value21",
      resource.getPropertyValue("cat4/mapMapProperty4/subMap2/key1"));
  assertEquals("value22",
      resource.getPropertyValue("cat4/mapMapProperty4/subMap2/key2"));
  assertEquals("value23",
      resource.getPropertyValue("cat4/mapMapProperty4/subMap2/key3"));
}