diff options
author | shrek2000 <orenkle@amdocs.com> | 2019-02-07 12:57:08 +0200 |
---|---|---|
committer | shrek2000 <orenkle@amdocs.com> | 2019-02-07 16:21:31 +0200 |
commit | 1dd5db924b88f390f3301a0e3f229c0a81a91080 (patch) | |
tree | ac56d507ba986934477d0cabd4c98ed9d74c231d /catalog-be/src/test | |
parent | b551a05893bcf6ac1ff3679d3354ba106fef24bb (diff) |
Add dependent child service to service
Add dependent child service to service
Issue-ID: SDC-1987
Change-Id: I5a650f57a27587c4ce6f33059719060ffa1f13de
Signed-off-by: shrek2000 <orenkle@amdocs.com>
Diffstat (limited to 'catalog-be/src/test')
5 files changed, 304 insertions, 0 deletions
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 new file mode 100644 index 0000000000..7cd7f3f45f --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/BaseServiceFilterUtilsTest.java @@ -0,0 +1,73 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +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.DirectivesUtils; +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; + +public class BaseServiceFilterUtilsTest { + + protected Service service; + protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition; + protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition2; + protected static final String CI_NAME = "AAAAAA"; + protected static final String A_PROP_NAME = "A_PROP"; + protected static final String SIZE_PROP = "size"; + protected static final String ORIG_COMP_INSTANCE_ID = "54355645457457"; + + @Before + public void initService() { + try { + service = new Service(); + ComponentInstance componentInstance = new ComponentInstance(); + componentInstance.setUniqueId(CI_NAME); + componentInstance.setName(CI_NAME); + service.setComponentInstances(Arrays.asList(componentInstance)); + componentInstance.setDirectives(Arrays.asList(DirectivesUtils.SELECTABLE)); + CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition(); + componentInstance.setNodeFilter(serviceFilter); + requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition(); + requirementNodeFilterPropertyDataDefinition.setName("Name1"); + requirementNodeFilterPropertyDataDefinition + .setConstraints(Arrays.asList("mem_size:\n" + " equal: { get_property : [" + CI_NAME + ", size]}\n")); + requirementNodeFilterPropertyDataDefinition2 = new RequirementNodeFilterPropertyDataDefinition(); + requirementNodeFilterPropertyDataDefinition2.setName("Name2"); + requirementNodeFilterPropertyDataDefinition2 + .setConstraints(Arrays.asList("mem_size:\n {equal: { get_property : [SELF, "+A_PROP_NAME+"]}}\n")); + + ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition = + new ListDataDefinition<>(Arrays.asList( + requirementNodeFilterPropertyDataDefinition, + requirementNodeFilterPropertyDataDefinition2)); + serviceFilter.setProperties(listDataDefinition); + PropertyDefinition property = new PropertyDefinition(); + property.setName(A_PROP_NAME); + service.setProperties(Arrays.asList(property)); + } catch (Exception e) { + Assert.fail(e.getMessage()); + } + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java new file mode 100644 index 0000000000..a6a41c53e9 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterRenameCiTest.java @@ -0,0 +1,48 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.nodeFilter; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Map; +import org.junit.Test; +import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition; +import org.openecomp.sdc.be.impl.ServiceFilterUtils; + +public class ServiceFilterRenameCiTest extends BaseServiceFilterUtilsTest { + + protected static final String CI_NEW_NAME = "BBBBB"; + + @Test + public void renameCI() { + Map<String, CINodeFilterDataDefinition> renamedNodeFilters = getRenamedNodeFilters(CI_NAME, CI_NEW_NAME); + assertNotNull(renamedNodeFilters); + final List<String> constraints = + renamedNodeFilters.get(CI_NAME).getProperties().getListToscaDataDefinition().iterator().next() + .getConstraints(); + assertEquals(1,constraints.size()); + final String constraint = constraints.iterator().next(); + assertTrue(constraint.contains(CI_NEW_NAME)); + } + + private Map<String, CINodeFilterDataDefinition> getRenamedNodeFilters(String oldName, String newName) { + return ServiceFilterUtils.getRenamedNodesFilter(service, oldName, newName); + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java new file mode 100644 index 0000000000..b6bf0ad3b4 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsCIChangeTest.java @@ -0,0 +1,89 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.nodeFilter; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import fj.data.Either; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.Set; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.sdc.be.auditing.impl.AuditingManager; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.impl.ComponentsUtils; +import org.openecomp.sdc.be.impl.ServiceFilterUtils; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; +import org.openecomp.sdc.be.ui.model.UIConstraint; +import org.openecomp.sdc.exception.ResponseFormat; + +public class ServiceFilterUtilsCIChangeTest extends BaseServiceFilterUtilsTest { + + + @Test + public void checkComponentInstanceIsFound() { + Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME); + assertNotNull(nodesFiltersToBeDeleted); + assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME)); + } + + private Set<String> getNodeFiltersToBeDeleted(String inCiName) { + requirementNodeFilterPropertyDataDefinition + .setConstraints(Arrays.asList("mem_size:\n" + " equal:\n" + " get_property: ["+CI_NAME+", some static]\n")); + ComponentInstance ci = new ComponentInstance(); + ci.setName(inCiName); + return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, ci); + } + + @Test + public void checkComponentInstanceIsNotFound() { + Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CI_NAME + " aaa bbb"); + assertNotNull(nodesFiltersToBeDeleted); + assertTrue(nodesFiltersToBeDeleted.isEmpty()); + assertFalse(nodesFiltersToBeDeleted.contains(CI_NAME)); + } + + @Test + public void testServiceConstraintPairSerialization() throws IOException { + UIConstraint uiConstraint =new UIConstraint(); + ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + assertTrue(mapper.canSerialize(uiConstraint.getClass())); + String data; + try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream() ) { + mapper.writeValue(outputStream, uiConstraint); + data = outputStream.toString(); + + } + assertNotNull(data); + final AuditingManager mock = Mockito.mock(AuditingManager.class); + final Either<UIConstraint, ResponseFormat> serviceConstraintPairResponseFormatEither = + new ComponentsUtils(mock) + .convertJsonToObjectUsingObjectMapper(data, new User(), UIConstraint.class, + AuditingActionEnum.ADD_GROUPING, ComponentTypeEnum.SERVICE); + assertTrue(serviceConstraintPairResponseFormatEither.isLeft()); + + } +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java new file mode 100644 index 0000000000..739ba3a9f9 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsPropertyRemovedTest.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.nodeFilter; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openecomp.sdc.be.impl.ServiceFilterUtils; + +public class ServiceFilterUtilsPropertyRemovedTest extends BaseServiceFilterUtilsTest { + + + @Test + public void checkPropertyIsFound() { + assertTrue(ServiceFilterUtils.isNodeFilterAffectedByPropertyRemoval(service, CI_NAME, SIZE_PROP)); + } + + @Test + public void checkPropertyIsNotFound() { + assertFalse(ServiceFilterUtils.isNodeFilterAffectedByPropertyRemoval(service, CI_NAME, A_PROP_NAME + "XXXX")); + } + +} diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java new file mode 100644 index 0000000000..8f12fd1284 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/nodeFilter/ServiceFilterUtilsServiceInputTest.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.be.nodeFilter; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.Set; +import org.junit.Test; +import org.openecomp.sdc.be.impl.ServiceFilterUtils; +import org.openecomp.sdc.be.model.InputDefinition; + +public class ServiceFilterUtilsServiceInputTest extends BaseServiceFilterUtilsTest { + + private static final String CONSTRAINT_NAME = "InputName"; + + + @Test + public void checkInputStreamIsFound() { + Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME); + assertNotNull(nodesFiltersToBeDeleted); + assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME)); + } + + private Set<String> getNodeFiltersToBeDeleted(String constraintName) { + requirementNodeFilterPropertyDataDefinition + .setConstraints(Arrays.asList("mem_size:\n equal: {get_input: " + CONSTRAINT_NAME + "}\n")); + InputDefinition inputDefinition = new InputDefinition(); + inputDefinition.setName(constraintName); + return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, inputDefinition); + } + + @Test + public void checkInputStreamIsNOtFound() { + Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME + " aaa bbb"); + assertNotNull(nodesFiltersToBeDeleted); + assertTrue(nodesFiltersToBeDeleted.isEmpty()); + assertFalse(nodesFiltersToBeDeleted.contains(CI_NAME)); + } +} |