From 7f5501ed9e9807a4e5a17c06dd9b5989cced11aa Mon Sep 17 00:00:00 2001 From: aribeiro Date: Fri, 4 Sep 2020 13:31:21 +0100 Subject: Make directives options configurable backend Issue-ID: SDC-3277 Signed-off-by: aribeiro Change-Id: I51ece01c0b0deb93cc7ab79ce8dcb9e1c5503074 --- .../impl/ComponentNodeFilterBusinessLogicTest.java | 5 +- ...mponentSubstitutionFilterBusinessLogicTest.java | 7 +-- .../components/impl/utils/DirectivesEnumTest.java | 61 --------------------- .../components/impl/utils/DirectivesUtilTest.java | 62 ++++++++++++++++++++++ .../be/nodeFilter/BaseServiceFilterUtilsTest.java | 12 +++-- 5 files changed, 77 insertions(+), 70 deletions(-) delete mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java (limited to 'catalog-be/src/test/java/org') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java index 5867c4d199..be9dd1689a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentNodeFilterBusinessLogicTest.java @@ -49,10 +49,10 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; -import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; import org.openecomp.sdc.be.components.validation.NodeFilterValidator; import org.openecomp.sdc.be.components.validation.UserValidations; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -552,7 +552,8 @@ public class ComponentNodeFilterBusinessLogicTest extends BaseBusinessLogicMock componentInstance = new ComponentInstance(); componentInstance.setUniqueId(componentInstanceId); componentInstance.setName("myComponentInstance"); - componentInstance.setDirectives(new LinkedList<>(Arrays.asList(DirectivesEnum.SELECT.getValue()))); + componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives()); final UIConstraint uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java index 6031416dbb..eaeb5ea11a 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ComponentSubstitutionFilterBusinessLogicTest.java @@ -48,10 +48,10 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; -import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; import org.openecomp.sdc.be.components.validation.NodeFilterValidator; import org.openecomp.sdc.be.components.validation.UserValidations; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; @@ -439,7 +439,8 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo componentInstance = new ComponentInstance(); componentInstance.setUniqueId(componentInstanceId); componentInstance.setName("myComponentInstance"); - componentInstance.setDirectives(new LinkedList<>(Arrays.asList(DirectivesEnum.SUBSTITUTE.getValue()))); + componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives()); final UIConstraint uiConstraint = new UIConstraint(servicePropertyName, constraintOperator, sourceType, sourceName, propertyValue); @@ -479,4 +480,4 @@ public class ComponentSubstitutionFilterBusinessLogicTest extends BaseBusinessLo fail(e.getMessage()); } } -} \ No newline at end of file +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java deleted file mode 100644 index 529625b451..0000000000 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesEnumTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * - - * * ============LICENSE_START======================================================= - * * Copyright (C) 2019 Nordix Foundation. - * * ================================================================================ - * * Licensed under the Apache License, Version 2.0 (the "License"); - * * you may not use this file except in compliance with the License. - * * You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. - * * - * * SPDX-License-Identifier: Apache-2.0 - * * ============LICENSE_END========================================================= - * - */ - -package org.openecomp.sdc.be.components.impl.utils; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; - -public class DirectivesEnumTest { - - private List directives; - - @Before - public void setup() { - directives = new ArrayList<>(); - } - - @Test - public void testGivenValidDirectives_returnsTrue() { - directives.add(DirectivesEnum.SELECT.getValue()); - directives.add(DirectivesEnum.SELECTABLE.getValue()); - directives.add(DirectivesEnum.SUBSTITUTE.getValue()); - directives.add(DirectivesEnum.SUBSTITUTABLE.getValue()); - assertTrue(DirectivesEnum.isValid(directives)); - } - - @Test - public void testGivenEmptyDirectives_returnsTrue() { - assertTrue(DirectivesEnum.isValid(directives)); - } - - @Test - public void testGivenInvalidDirectives_returnsFalse() { - directives.add("Invalid"); - assertFalse(DirectivesEnum.isValid(directives)); - } -} \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java new file mode 100644 index 0000000000..412b62cb0a --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/DirectivesUtilTest.java @@ -0,0 +1,62 @@ +/* + * - + * * ============LICENSE_START======================================================= + * * Copyright (C) 2019 Nordix Foundation. + * * ================================================================================ + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * + * * SPDX-License-Identifier: Apache-2.0 + * * ============LICENSE_END========================================================= + * + */ + +package org.openecomp.sdc.be.components.impl.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.sdc.be.config.ConfigurationManager; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; + +public class DirectivesUtilTest { + + @Before + public void setup() { + new ConfigurationManager(new FSConfigurationSource( + ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be")); + } + + @Test + public void testGivenValidDirectives_returnsTrue() { + assertTrue(DirectivesUtil.isValid(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives())); + } + + @Test + public void testGivenEmptyDirectives_returnsTrue() { + assertTrue(DirectivesUtil.isValid(Collections.emptyList())); + } + + @Test + public void testGivenInvalidDirectives_returnsFalse() { + final List directives = new ArrayList<>(); + directives.add("invalidValue"); + assertFalse(DirectivesUtil.isValid(directives)); + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java index adf6e4439d..68ceaca0a6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java @@ -16,17 +16,18 @@ package org.openecomp.sdc.be.nodeFilter; +import java.util.Arrays; import org.junit.Assert; import org.junit.Before; -import org.openecomp.sdc.be.components.impl.utils.DirectivesEnum; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition; import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Service; - -import java.util.Arrays; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; public class BaseServiceFilterUtilsTest { @@ -41,12 +42,15 @@ public class BaseServiceFilterUtilsTest { @Before public void initService() { try { + new ConfigurationManager(new FSConfigurationSource( + ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be")); service = new Service(); ComponentInstance componentInstance = new ComponentInstance(); componentInstance.setUniqueId(CI_NAME); componentInstance.setName(CI_NAME); service.setComponentInstances(Arrays.asList(componentInstance)); - componentInstance.setDirectives(Arrays.asList(DirectivesEnum.SELECTABLE.getValue())); + componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration() + .getDirectives()); CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition(); componentInstance.setNodeFilter(serviceFilter); requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition(); -- cgit 1.2.3-korg