summaryrefslogtreecommitdiffstats
path: root/catalog-model/src/test
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-08-13 16:51:44 +0300
committerMichael Lando <ml636r@att.com>2017-08-13 17:08:41 +0300
commit335d13c0e57ae61148b7a0871c5c9e46f768cd93 (patch)
tree0aec18acdd36c8092ea112e0a7d96dc78e35eb89 /catalog-model/src/test
parentce07d7cd59425944f85d0fef5126ebeef731bc7b (diff)
[SDC-235] rebase code
Change-Id: Iea503188e521fa3846f580ced7c1c4fce303abe5 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'catalog-model/src/test')
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java111
1 files changed, 111 insertions, 0 deletions
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
new file mode 100644
index 0000000000..d2d26e79d5
--- /dev/null
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsontitan/operations/ToscaOperationFacadeTest.java
@@ -0,0 +1,111 @@
+package org.openecomp.sdc.be.model.jsontitan.operations;
+
+import fj.data.Either;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum;
+import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
+import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
+import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
+import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
+import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentParametersView;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.TopologyTemplate;
+import org.openecomp.sdc.be.model.jsontitan.datamodel.ToscaElement;
+import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ToscaOperationFacadeTest {
+
+ @InjectMocks
+ private ToscaOperationFacade testInstance;
+
+ @Mock
+ private TitanDao titanDaoMock;
+
+ @Mock
+ private TopologyTemplateOperation topologyTemplateOperationMock;
+
+ @Before
+ public void setUp() throws Exception {
+ testInstance = new ToscaOperationFacade();
+ MockitoAnnotations.initMocks(this);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void fetchMetaDataByResourceType() throws Exception {
+ ArgumentCaptor<Map> criteriaCapture = ArgumentCaptor.forClass(Map.class);
+ ComponentParametersView dataFilter = new ComponentParametersView();
+ List<GraphVertex> mockVertices = getMockVertices(2);
+ Either<List<GraphVertex>, TitanOperationStatus> returnedVertices = Either.left(mockVertices);
+
+ when(titanDaoMock.getByCriteria(Mockito.eq(null), criteriaCapture.capture(), Mockito.eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(returnedVertices);
+ when(topologyTemplateOperationMock.getToscaElement(mockVertices.get(0), dataFilter)).thenReturn(Either.left(getResourceToscaElement("0")));
+ when(topologyTemplateOperationMock.getToscaElement(mockVertices.get(1), dataFilter)).thenReturn(Either.left(getResourceToscaElement("1")));
+ Either<List<Component>, StorageOperationStatus> fetchedComponents = testInstance.fetchMetaDataByResourceType(ResourceTypeEnum.VF.getValue(), dataFilter);
+
+ verifyCriteriaForHighestVersionAndVfResourceType(criteriaCapture);
+
+ assertTrue(fetchedComponents.isLeft());
+ List<Component> cmpts = fetchedComponents.left().value();
+ assertEquals(2, cmpts.size());
+ assertEquals("0", cmpts.get(0).getUniqueId());
+ assertEquals("1", cmpts.get(1).getUniqueId());
+ }
+
+ private void verifyCriteriaForHighestVersionAndVfResourceType(ArgumentCaptor<Map> criteriaCapture) {
+ Map<GraphPropertyEnum, Object> criteria = (Map<GraphPropertyEnum, Object>)criteriaCapture.getValue();
+ assertEquals(2, criteria.size());
+ assertEquals(criteria.get(GraphPropertyEnum.RESOURCE_TYPE), "VF");
+ assertEquals(criteria.get(GraphPropertyEnum.IS_HIGHEST_VERSION), true);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void fetchMetaDataByResourceType_failedToGetData() throws Exception {
+ when(titanDaoMock.getByCriteria(Mockito.eq(null), Mockito.anyMap(), Mockito.eq(JsonParseFlagEnum.ParseMetadata))).thenReturn(Either.right(TitanOperationStatus.GENERAL_ERROR));
+ Either<List<Component>, StorageOperationStatus> fetchedComponents = testInstance.fetchMetaDataByResourceType(ResourceTypeEnum.VF.getValue(), new ComponentParametersView());
+ assertTrue(fetchedComponents.isRight());
+ assertEquals(StorageOperationStatus.GENERAL_ERROR, fetchedComponents.right().value());
+ }
+
+ private List<GraphVertex> getMockVertices(int numOfVertices) {
+ return IntStream.range(0, numOfVertices).mapToObj(i -> getMockVertex()).collect(Collectors.toList());
+ }
+
+ private ToscaElement getResourceToscaElement(String id) {
+ ToscaElement toscaElement = new TopologyTemplate();
+ toscaElement.setMetadata(new HashMap<>());
+ toscaElement.getMetadata().put(JsonPresentationFields.COMPONENT_TYPE.getPresentation(), "RESOURCE");
+ toscaElement.getMetadata().put(JsonPresentationFields.UNIQUE_ID.getPresentation(), id);
+ return toscaElement;
+ }
+
+ private GraphVertex getMockVertex() {
+ GraphVertex graphVertex = new GraphVertex();
+ graphVertex.setLabel(VertexTypeEnum.TOPOLOGY_TEMPLATE);
+ return graphVertex;
+ }
+} \ No newline at end of file
ction.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
---
project: 'sdc'
project_creation_date: '2017-01-31'
lifecycle_state: 'Mature'
project_category: ''
project_lead: &onap_sdc_ptl
  name: 'Michael Morris'
  email: 'michael.morris@est.tech'
  company: 'Ericsson Software Technology (EST)'
  id: 'MichaelMorris'
  timezone: 'Europe/Dublin'
primary_contact: *onap_sdc_ptl
mailing_list:
  type: 'groups.io'
  url: 'lists.onap.org'
  tag: '<[sub-project_name]>'
realtime_discussion: ''
issue_tracking:
  type: 'jira'
  url: 'https://jira.onap.org/projects/SDC'
  key: 'SDC'
meetings:
  - type: 'zoom'
    agenda: ''
    url: 'https://wiki.onap.org/pages/viewpage.action?pageId=8230628'
    server: 'n/a'
    channel: 'n/a'
    repeats: 'weekly'
    time: '11:00 UTC'
repositories:
  - 'sdc'
committers:
  - <<: *onap_sdc_ptl
  - name: 'Vasyl Razinkov'
    email: 'vasyl.razinkov@est.tech'
    company: 'Ericsson Software Technology (EST)'
    id: 'vasraz'
    timezone: 'Europe/Dublin'
  - name: 'André Schmid'
    email: 'andre.schmid@est.tech'
    company: 'Ericsson Software Technology (EST)'
    id: 'andre.schmid'
    timezone: 'Europe/Dublin'
  - name: 'Michael Morris'
    email: 'michael.morris@est.tech'
    company: 'Ericsson Software Technology (EST)'
    id: 'MichaelMorris'
    timezone: 'Europe/Dublin'
tsc:
  approval: 'https://lists.onap.org/pipermail/onap-tsc'
  changes:
    - type: 'Addition'
      name: 'Ofir Sonsino'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=45305945'
    - type: 'Removal'
      name: 'Michael Lando'
      link: 'https://lists.onap.org/g/onap-tsc/message/4239'
    - type: 'Addition'
      name: 'Priyanshu Agarwal'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=48531570'
    - type: 'Removal'
      name: 'Vitaliy Emporopulo'
      link: 'https://lists.onap.org/g/onap-tsc/message/4239'
    - type: 'Removal'
      name: 'Priyanshu Agarwal'
      link: 'https://lists.onap.org/g/onap-tsc/message/5218'
    - type: 'Removal'
      name: 'Idan Amit'
      link: 'https://lists.onap.org/g/onap-tsc/message/5218'
    - type: 'Addition'
      name: 'Inna Manzon'
      link: 'https://lists.onap.org/g/onap-tsc/message/5218'
    - type: 'Addition'
      name: 'Piotr Darosz'
      link: 'https://lists.onap.org/g/onap-tsc/message/5218'
    - type: 'Addition'
      name: 'Tomasz Golabek'
      link: 'https://lists.onap.org/g/onap-tsc/message/5218'
    - type: 'Addition'
      name: 'Ojas Dubey'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=68536630'
    - type: 'Removal'
      name: 'Avi Gaffa'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=71838001'
    - type: 'Addition'
      name: 'Ilana Paktor'
      link: 'https://lists.onap.org/g/onap-tsc/topic/60777589#5665'
    - type: 'Removal'
      name: 'Piotr Darosz'
      link: 'https://lists.onap.org/g/onap-tsc/message/5218'
    - type: 'Removal'
      name: 'Tal Gitelman'
      link: 'https://lists.onap.org/g/onap-tsc/topic/73178098'
    - type: 'Removal'
      name: 'Oren Kleks'
      link: 'https://lists.onap.org/g/onap-tsc/topic/73178098'
    - type: 'Removal'
      name: 'Tomasz Golabek'
      link: 'https://lists.onap.org/g/onap-tsc/topic/73178098'
    - type: 'Removal'
      name: 'Einav Keidar'
      link: 'https://lists.onap.org/g/onap-tsc/topic/75373026#6714'
    - type: 'Addition'
      name: 'Christophe Closset'
      link: 'https://lists.onap.org/g/onap-tsc/topic/75373026#6714'
    - type: 'Addition'
      name: 'Sebastien Determe'
      link: 'https://lists.onap.org/g/onap-tsc/topic/75373026#6714'
    - type: 'Addition'
      name: 'Xue Gao'
      link: 'https://lists.onap.org/g/onap-tsc/topic/75373026#6714'
    - type: 'Addition'
      name: 'Julien Bertozzi'
      link: 'https://lists.onap.org/g/onap-tsc/topic/75373026#6714'
    - type: 'Removal'
      name: 'Inna Manzon'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=68535854'
    - type: 'Removal'
      name: 'Yuli Shlosberg'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=25435567'
    - type: 'Removal'
      name: 'Eli Levi'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=25435567'
    - type: 'Removal'
      name: 'Ofir Sonsino'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=45305945'
    - type: 'Addition'
      name: 'Vasyl Razinkov'
      link: 'https://lists.onap.org/g/onap-tsc/message/7233'
    - type: 'Addition'
      name: 'Tali Orenbach'
      link: 'https://lists.onap.org/g/onap-tsc/message/7233'
    - type: 'Addition'
      name: 'André Schmid'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=100893583'
    - type: 'Addition'
      name: 'Michael Morris'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=100893294'
    - type: 'Removal'
      name: 'Ojas Dubey'
      link: 'https://lists.onap.org/g/onap-tsc/message/7746'
    - type: 'Removal'
      name: 'Julien Bertozzi'
      link: 'https://lists.onap.org/g/onap-tsc/message/7746'
    - type: 'Removal'
      name: 'Tali Orenbach'
      link: 'https://lists.onap.org/g/onap-tsc/message/7746'
    - type: 'Addition'
      name: 'Anderson Ribeiro'
      link: 'https://wiki.onap.org/pages/viewpage.action?pageId=100895269'
    - type: 'Removal'
      name: 'Ilana Paktor'
      link: 'https://lists.onap.org/g/onap-tsc/message/8547'
    - type: 'Removal'
      name: 'Christophe Closset'
      link: 'https://lists.onap.org/g/onap-tsc/message/8547'
    - type: 'Removal'
      name: 'Sebastien Determe'
      link: 'https://lists.onap.org/g/onap-tsc/message/8547'
    - type: 'Removal'
      name: 'Xue Gao'
      link: 'https://lists.onap.org/g/onap-tsc/message/8547'
    - type: 'Removal'
      name: 'Anderson Ribeiro'
      link: 'https://lists.onap.org/g/onap-tsc/message/8547'