diff options
author | xuegao <xue.gao@intl.att.com> | 2021-03-26 16:05:41 +0100 |
---|---|---|
committer | Vasyl Razinkov <vasyl.razinkov@est.tech> | 2021-03-26 23:16:09 +0000 |
commit | f0f0dc563562a93cb92341058c84ed0233558089 (patch) | |
tree | 90b713e1be622ebb7dd251d47e243356f333cb80 /catalog-be | |
parent | e83d137179fa3c532c191f89f9e6cdd53b0778c7 (diff) |
Improve test coverage
Add unit tests to improve test coverage.
Issue-ID: SDC-3428
Change-Id: I6eb08c6094e0c06bd781b88b00f9301b43f1e965
Signed-off-by: xuegao <xue.gao@intl.att.com>
Diffstat (limited to 'catalog-be')
2 files changed, 86 insertions, 48 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPolicyTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPolicyTemplate.java index 18f2b7f488..6d427e2b92 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPolicyTemplate.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPolicyTemplate.java @@ -19,52 +19,20 @@ */ package org.openecomp.sdc.be.tosca.model; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + import java.util.List; import java.util.Map; +@Getter +@Setter +@AllArgsConstructor public class ToscaPolicyTemplate { private String type; private IToscaMetadata metadata; private Map<String, Object> properties; private List<String> targets; - - public ToscaPolicyTemplate(String type, IToscaMetadata metadata, Map<String, Object> properties, List<String> targets) { - this.type = type; - this.metadata = metadata; - this.properties = properties; - this.targets = targets; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public IToscaMetadata getMetadata() { - return metadata; - } - - public void setMetadata(IToscaMetadata metadata) { - this.metadata = metadata; - } - - public Map<String, Object> getProperties() { - return properties; - } - - public void setProperties(Map<String, Object> properties) { - this.properties = properties; - } - - public List<String> getTargets() { - return targets; - } - - public void setTargets(List<String> targets) { - this.targets = targets; - } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java index 82dde5e396..bcf815f09f 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidationTest.java @@ -22,12 +22,14 @@ package org.openecomp.sdc.be.components.validation; import fj.data.Either; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction; +import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; @@ -37,13 +39,15 @@ import org.openecomp.sdc.be.model.ComponentInstance; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.common.impl.ExternalConfiguration; +import org.openecomp.sdc.common.impl.FSConfigurationSource; import org.openecomp.sdc.exception.ResponseFormat; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; public class NodeFilterValidationTest { @@ -63,10 +67,34 @@ public class NodeFilterValidationTest { @InjectMocks private NodeFilterValidator nodeFilterValidator; - @Before + @BeforeEach public void setup() { componentsUtils = Mockito.mock(ComponentsUtils.class); MockitoAnnotations.initMocks(this); + new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be")); + } + + @Test + public void testValidateComponentInstanceExist() { + Either<Boolean, ResponseFormat> either = + nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE); + assertTrue(either.isRight()); + assertEquals("Error: Internal Server Error. Please try again later.", either.right().value().getText()); + assertEquals(500, either.right().value().getStatus()); + + Service service = createService("booleanIncorrect"); + either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE); + assertTrue(either.isRight()); + assertEquals("Error: Internal Server Error. Please try again later.", either.right().value().getText()); + assertEquals(500, either.right().value().getStatus()); + + List<ComponentInstance> list = new LinkedList<>(); + ComponentInstance instance = new ComponentInstance(); + instance.setUniqueId("uniqueId"); + list.add(instance); + service.setComponentInstances(list); + either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId"); + assertTrue(either.isLeft()); } @Test @@ -76,8 +104,50 @@ public class NodeFilterValidationTest { nodeFilterValidator.validateFilter(service, INNER_SERVICE, Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")), NodeFilterConstraintAction.ADD, NodeFilterConstraintType.PROPERTIES); + assertTrue(either.isRight()); - Assert.assertFalse(either.isLeft()); + either = + nodeFilterValidator.validateFilter(service, INNER_SERVICE, + Collections.singletonList(UI_CONSTRAINT_STATIC.replace(VALUE, "true")), + NodeFilterConstraintAction.ADD, NodeFilterConstraintType.CAPABILITIES); + assertTrue(either.isRight()); + } + + @Test + public void testValidateComponentFilter() { + Service service = createService("booleanIncorrect"); + String property = "Prop1: {equal: {get_property: ['test','test2']}}"; + Either<Boolean, ResponseFormat> either = + nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(property), + NodeFilterConstraintAction.ADD); + assertTrue(either.isRight()); + + property = "Prop1: {equal: {get_property: ['parentservice','Prop1']}}"; + either = + nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(property), + NodeFilterConstraintAction.ADD); + assertTrue(either.isLeft()); + + String staticStr = "Prop1: {equal: 1}"; + either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr), + NodeFilterConstraintAction.ADD); + assertTrue(either.isLeft()); + assertTrue(either.left().value()); + + staticStr = "Prop1: {equal: 'true'}"; + either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr), + NodeFilterConstraintAction.ADD); + assertTrue(either.isRight()); + + staticStr = "Prop1: {greater_than: '3'}"; + either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr), + NodeFilterConstraintAction.ADD); + assertTrue(either.isRight()); + + staticStr = "test: {greater_than: '3'}"; + either = nodeFilterValidator.validateComponentFilter(service, Collections.singletonList(staticStr), + NodeFilterConstraintAction.ADD); + assertTrue(either.isRight()); } @Test |