/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
-import java.util.function.UnaryOperator;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.ToString;
+import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
this.definition = new ToscaConceptIdentifier(otherElement.definition);
this.participantId = otherElement.participantId;
this.description = otherElement.description;
- this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
- this.outProperties = PfUtils.mapMap(otherElement.outProperties, UnaryOperator.identity());
+ this.properties = AcmUtils.cloneMap(otherElement.properties);
+ this.outProperties = AcmUtils.cloneMap(otherElement.outProperties);
this.restarting = otherElement.restarting;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDeploy;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.clamp.models.acm.persistence.concepts.StringToMapConverter;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ObjectValidationResult;
import org.onap.policy.common.parameters.ValidationResult;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class AcmUtils {
public static final String ENTRY = "entry ";
+ private static StringToMapConverter MAP_CONVERTER = new StringToMapConverter();
/**
* Get the Policy information in the service template for the deploy message to participants.
}
}
}
+
+ public static Map<String, Object> cloneMap(Map<String, Object> map) {
+ var str = MAP_CONVERTER.convertToDatabaseColumn(map);
+ return MAP_CONVERTER.convertToEntityAttribute(str);
+ }
}
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
assertNull(subMap.get("myParameterToRemove"));
assertEquals("I am new", subMap.get("myParameter"));
}
+
+ @Test
+ void testCopyMap() {
+ Map<String, Object> map = new HashMap<>();
+ Map<String, Object> subMap = new HashMap<>();
+ subMap.put("test", "value");
+ map.put("sub", subMap);
+ var result = AcmUtils.cloneMap(map);
+ var subMap2 = (Map<String, Object>) result.get("sub");
+ subMap2.put("test", "value2");
+ assertNotEquals(subMap.get("test"), subMap2.get("test"));
+ }
}