aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/sdc/tosca
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/sdc/tosca')
-rw-r--r--src/test/java/org/onap/sdc/tosca/parser/elements/EntityDetailsFactoryTest.java106
-rw-r--r--src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java163
-rw-r--r--src/test/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQueryTest.java122
3 files changed, 391 insertions, 0 deletions
diff --git a/src/test/java/org/onap/sdc/tosca/parser/elements/EntityDetailsFactoryTest.java b/src/test/java/org/onap/sdc/tosca/parser/elements/EntityDetailsFactoryTest.java
new file mode 100644
index 0000000..4ecce9d
--- /dev/null
+++ b/src/test/java/org/onap/sdc/tosca/parser/elements/EntityDetailsFactoryTest.java
@@ -0,0 +1,106 @@
+package org.onap.sdc.tosca.parser.elements;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.sdc.tosca.parser.enums.EntityTemplateType;
+import org.onap.sdc.toscaparser.api.Group;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.Policy;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class EntityDetailsFactoryTest {
+
+ @Mock
+ private NodeTemplate nodeTemplate;
+
+ @Mock
+ private Group group;
+
+ @Mock
+ private Policy policy;
+
+
+ @Test
+ public void createNodeTemplateEntityDetailsWhenParentNodeIsNotNull() {
+ when(nodeTemplate.getParentNodeTemplate())
+ .thenReturn(nodeTemplate)
+ .thenReturn(null);
+ EntityDetails entityDetails = EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, nodeTemplate);
+ assertTrue(entityDetails instanceof NodeTemplateEntityDetails);
+ assertTrue(entityDetails.getParent() instanceof NodeTemplateEntityDetails);
+ }
+
+ @Test
+ public void createNodeTemplateEntityDetailsWhenParentNodeIsNull() {
+ EntityDetails entityDetails = EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, nodeTemplate);
+ assertTrue(entityDetails instanceof NodeTemplateEntityDetails);
+ assertEquals(null, entityDetails.getParent());
+ }
+
+ @Test
+ public void createNodeTemplateEntityDetailsWhenNnIsNull() {
+ assertEquals(null, EntityDetailsFactory.createEntityDetails(EntityTemplateType.NODE_TEMPLATE, null));
+ }
+
+ @Test
+ public void createGroupEntityDetailsWhenParentNodeIsNotNull() {
+ when(group.getParentNodeTemplate())
+ .thenReturn(nodeTemplate)
+ .thenReturn(null);
+ EntityDetails entityDetails = EntityDetailsFactory.createEntityDetails(EntityTemplateType.GROUP, group);
+ assertTrue(entityDetails instanceof GroupEntityDetails);
+ assertTrue(entityDetails.getParent() instanceof NodeTemplateEntityDetails);
+ }
+
+ @Test
+ public void createGroupEntityDetailsWhenParentNodeIsNull() {
+ EntityDetails entityDetails = EntityDetailsFactory.createEntityDetails(EntityTemplateType.GROUP, group);
+ assertTrue(entityDetails instanceof GroupEntityDetails);
+ assertEquals(null, entityDetails.getParent());
+ }
+
+ @Test
+ public void createGroupEntityDetailsWhenNnIsNull() {
+ assertEquals(null, EntityDetailsFactory.createEntityDetails(EntityTemplateType.GROUP, null));
+ }
+
+ @Test
+ public void createPolicyEntityDetailsWhenParentNodeIsNotNull() {
+ when(policy.getParentNodeTemplate())
+ .thenReturn(nodeTemplate)
+ .thenReturn(null);
+ EntityDetails entityDetails = EntityDetailsFactory.createEntityDetails(EntityTemplateType.POLICY, policy);
+ assertTrue(entityDetails instanceof PolicyEntityDetails);
+ assertTrue(entityDetails.getParent() instanceof NodeTemplateEntityDetails);
+ }
+
+ @Test
+ public void createPolicyEntityDetailsWhenParentNodeIsNull() {
+ EntityDetails entityDetails = EntityDetailsFactory.createEntityDetails(EntityTemplateType.POLICY, policy);
+ assertTrue(entityDetails instanceof PolicyEntityDetails);
+ assertEquals(null, entityDetails.getParent());
+ }
+
+ @Test
+ public void createPolicyEntityDetailsWhenNnIsNull() {
+ assertEquals(null, EntityDetailsFactory.createEntityDetails(EntityTemplateType.POLICY, null));
+ }
+
+ @Test(expected = ClassCastException.class)
+ public void createWrongEntityDetails() {
+ EntityDetailsFactory.createEntityDetails(EntityTemplateType.POLICY, group);
+ }
+
+
+ @Test
+ public void createEntityDetailsWhenTypeIsNull() {
+ assertEquals(null, EntityDetailsFactory.createEntityDetails(null, group));
+ }
+
+}
diff --git a/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java b/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java
new file mode 100644
index 0000000..ecf764c
--- /dev/null
+++ b/src/test/java/org/onap/sdc/tosca/parser/elements/queries/EntityQueryTest.java
@@ -0,0 +1,163 @@
+package org.onap.sdc.tosca.parser.elements.queries;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.sdc.tosca.parser.enums.EntityTemplateType;
+import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class EntityQueryTest {
+ @Mock
+ private Metadata metadata;
+
+ @Test
+ public void findEntityWhenUuidAndCuudNotSetAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("12345");
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenMetadataIsNull() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .build();
+ assertFalse(entityQuery.isSearchCriteriaMatched(null,"abc"));
+ }
+
+ @Test
+ public void findEntityWhenMetadataIsNullAndUuidsAreProvided() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE)
+ .customizationUUID("2345")
+ .uUID("9700")
+ .build();
+ assertFalse(entityQuery.isSearchCriteriaMatched(null, ""));
+ }
+
+ @Test
+ public void findEntityWhenUuidIsSetAndMatchedAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("123")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("12345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, "abc"));
+ }
+
+ @Test
+ public void findEntityWhenUuidIsSetAndMatchedAndCuuidIsNullAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("123")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn(null);
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenUuidAndCuuidAreSetAndMatchedAndCuuidIsNullAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("123")
+ .customizationUUID("567")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn(null);
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.POLICY)
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, "qwe"));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedPartiallyAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.POLICY)
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("444");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenUuidIsSetAndDoesNotMatchAndToscaTypeNotSet() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.GROUP)
+ .uUID("7890")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("12345");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, ""));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeIsNull() {
+ EntityQuery entityQuery = EntityQuery.newBuilder(EntityTemplateType.POLICY)
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, null));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeIsNotMatched() {
+ EntityQuery entityQuery = EntityQuery.newBuilder("a.policies.b")
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, "abc"));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreSetAndMatchedAndToscaTypeIsMatched() {
+ EntityQuery entityQuery = EntityQuery.newBuilder("a.groups.b")
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("123");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("345");
+
+ assertTrue(entityQuery.isSearchCriteriaMatched(metadata, "a.groups.b"));
+ }
+
+ @Test
+ public void findEntityWhenUIDsAreNotMatchedAndToscaTypeIsMatched() {
+ EntityQuery entityQuery = EntityQuery.newBuilder("a.groups.b")
+ .uUID("123")
+ .customizationUUID("345")
+ .build();
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_UUID))).thenReturn("12345");
+ when(metadata.getValue(eq(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))).thenReturn("3456");
+
+ assertFalse(entityQuery.isSearchCriteriaMatched(metadata, "a.groups.b"));
+ }
+}
diff --git a/src/test/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQueryTest.java b/src/test/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQueryTest.java
new file mode 100644
index 0000000..08d3708
--- /dev/null
+++ b/src/test/java/org/onap/sdc/tosca/parser/elements/queries/TopologyTemplateQueryTest.java
@@ -0,0 +1,122 @@
+package org.onap.sdc.tosca.parser.elements.queries;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.sdc.tosca.parser.enums.SdcTypes;
+import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
+import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.elements.Metadata;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertFalse;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TopologyTemplateQueryTest {
+
+ @Mock
+ private Metadata metadata;
+
+ @Mock
+ private NodeTemplate nodeTemplate;
+
+ @Test(expected=IllegalArgumentException.class)
+ public void objectIsNotTopologyTemplate() {
+ TopologyTemplateQuery.newBuilder(SdcTypes.CP)
+ .build();
+ }
+
+ @Test
+ public void templateIsFoundByTypeOnly() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
+ assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsNotFoundWhenMetadataIsNull() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(null);
+ assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsFoundIfItIsService() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE)
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.SERVICE.getValue());
+ assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsFoundByTypeAndCUUID() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
+ .customizationUUID("345")
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
+ assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsNotSet() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
+ assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsFoundWhenTypeIsMatchedCuuidIsProvidedAndCuuidIsNullInMetadata() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
+ .customizationUUID("2345")
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
+ assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsFoundWhenTypeIsMatchedAndCuuidIsNullInMetadata() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF)
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn(null);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.VF.getValue());
+ assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsNotFoundWhenTypeIsMatchedAndCuuidIsSet() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CVFC)
+ .customizationUUID("345")
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
+ assertTrue(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+ @Test
+ public void templateIsNotFoundWhenTypeIsNotMatchedAndCuuidIsSet() {
+ TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.CR)
+ .customizationUUID("345")
+ .build();
+ when(nodeTemplate.getMetaData()).thenReturn(metadata);
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_TYPE)).thenReturn(SdcTypes.CVFC.getValue());
+ when(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)).thenReturn("345");
+ assertFalse(topologyTemplateQuery.isMatchingSearchCriteria(nodeTemplate));
+ }
+
+
+}