From e9d1d70a203d06c3f0e4695c3710b527b0a6eab3 Mon Sep 17 00:00:00 2001 From: jhh Date: Mon, 14 Feb 2022 11:06:52 -0600 Subject: Handle metadata policy-id as object Issue-ID: POLICY-3832 Signed-off-by: jhh Change-Id: I60b4c3b9f8d6f74161d2e9532b3c3adba10cdc6b --- .../policy/drools/lifecycle/LifecycleFsmTest.java | 31 +++++++++++++--------- .../server/restful/RestLifecycleManagerTest.java | 2 +- .../domain/models/DomainPolicyTypesTest.java | 4 +-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java index df9e5eed..0ad776cc 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2021-2022 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,7 @@ import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.concurrent.ScheduledExecutorService; import org.junit.AfterClass; import org.junit.Before; @@ -259,17 +260,23 @@ public class LifecycleFsmTest { fsm.deployedPolicyAction(opPolicy); fsm.deployedPolicyAction(controllerPolicy); - assertEquals(List.of(opPolicy, controllerPolicy), fsm.getActivePolicies()); - assertEquals(List.of(opPolicy, controllerPolicy), fsm.mergePolicies(List.of(), List.of())); - assertEquals(List.of(opPolicy), fsm.mergePolicies(List.of(), List.of(controllerPolicy.getIdentifier()))); - - assertEquals(List.of(controllerPolicy, op2Policy, valPolicy, opPolicy, unvalPolicy), - fsm.mergePolicies(List.of(op2Policy, valPolicy, unvalPolicy), List.of())); - assertEquals(List.of(controllerPolicy, op2Policy, valPolicy, opPolicy, unvalPolicy), - fsm.mergePolicies(List.of(controllerPolicy, opPolicy, op2Policy, valPolicy, unvalPolicy), List.of())); - assertEquals(List.of(op2Policy, valPolicy, unvalPolicy), - fsm.mergePolicies(List.of(op2Policy, valPolicy, unvalPolicy), - List.of(controllerPolicy.getIdentifier(), opPolicy.getIdentifier()))); + assertEquals(Set.of(opPolicy, controllerPolicy), toSet(fsm.getActivePolicies())); + assertEquals(Set.of(opPolicy, controllerPolicy), toSet(fsm.mergePolicies(List.of(), List.of()))); + assertEquals(Set.of(opPolicy), toSet(fsm.mergePolicies(List.of(), List.of(controllerPolicy.getIdentifier())))); + + assertEquals(Set.of(controllerPolicy, op2Policy, valPolicy, opPolicy, unvalPolicy), + toSet(fsm.mergePolicies(List.of(op2Policy, valPolicy, unvalPolicy), List.of()))); + assertEquals(Set.of(controllerPolicy, op2Policy, valPolicy, opPolicy, unvalPolicy), + toSet(fsm.mergePolicies(List.of(controllerPolicy, opPolicy, op2Policy, valPolicy, unvalPolicy), + List.of()))); + assertEquals(Set.of(op2Policy, valPolicy, unvalPolicy), + toSet(fsm.mergePolicies(List.of(op2Policy, valPolicy, unvalPolicy), + List.of(controllerPolicy.getIdentifier(), opPolicy.getIdentifier())))); + } + + private Set toSet(List policies) { + return Set.copyOf(policies); + } @Test diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java index cb2d5add..b8139e6e 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java @@ -254,7 +254,7 @@ public class RestLifecycleManagerTest { ToscaPolicy opPolicy = getExamplesPolicy(VCPE_OPERATIONAL_DROOLS_POLICY_JSON, OP_POLICY_NAME_VCPE); opPolicy.getProperties().put("controllerName", "lifecycle"); if (StringUtils.isBlank(opPolicy.getName())) { - opPolicy.setName(opPolicy.getMetadata().get("policy-id")); + opPolicy.setName("" + opPolicy.getMetadata().get("policy-id")); } testNotNativePolicy(opPolicy); diff --git a/policy-domains/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java b/policy-domains/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java index e9071a2b..bb28a45f 100644 --- a/policy-domains/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java +++ b/policy-domains/src/test/java/org/onap/policy/drools/domain/models/DomainPolicyTypesTest.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020,2022 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -86,7 +86,7 @@ public class DomainPolicyTypesTest { assertEquals("lifecycle", domainDroolsPolicy.getProperties().getRulesArtifact().getArtifactId()); assertEquals("1.0.0", domainDroolsPolicy.getProperties().getRulesArtifact().getVersion()); - String policyId = toscaPolicy.getMetadata().remove("policy-id"); + String policyId = "" + toscaPolicy.getMetadata().remove("policy-id"); assertThatThrownBy(() -> domainMaker.convertTo(toscaPolicy, NativeArtifactPolicy.class)) .isInstanceOf(CoderException.class).hasCauseInstanceOf(ValidationFailedException.class); -- cgit 1.2.3-korg