in core/src/main/java/org/apache/sling/testing/mock/osgi/MapMergeUtil.java [76:116]
static Map<String, Object> propertiesMergeWithOsgiMetadata(Class<?> targetClass,
ConfigurationAdmin configAdmin,
Map<String, Object> properties) {
Map<String, Object> mergedProperties = new HashMap<>();
OsgiMetadata metadata = OsgiMetadataUtil.getMetadata(targetClass);
if (metadata != null) {
Map<String,Object> metadataProperties = metadata.getProperties();
if (metadataProperties != null) {
mergedProperties.putAll(metadataProperties);
// merge with configuration from config admin
if (configAdmin != null) {
for (String pid : metadata.getConfigurationPID()) {
if (pid != null) {
try {
Configuration config = configAdmin.getConfiguration(pid);
Dictionary<String, Object> caProperties = config.getProperties();
if (caProperties != null) {
mergedProperties.putAll(toMap(caProperties));
}
}
catch (IOException ex) {
throw new RuntimeException("Unable to read config for pid " + pid, ex);
}
}
}
}
}
}
// merge with properties from calling unit test code
if (properties != null) {
mergedProperties.putAll(properties);
}
// add non overwritable auto-generated properties
mergedProperties.put(ComponentConstants.COMPONENT_NAME, targetClass.getName());
mergedProperties.put(ComponentConstants.COMPONENT_ID, COMPONENT_ID_COUNTER.getAndIncrement());
return mergedProperties;
}