From f0d4dd5c846f1c56d8b2641934c028b8151b31b3 Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 15 Nov 2021 12:27:54 +0000 Subject: Fix test cases failing incorrectly https://gerrit.onap.org/r/c/sdc/+/124980 Change-Id: I9fbd8a0b5b83d04928feea7624e593b45441ac9b Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3757 --- .../operations/ArchiveOperationTest.java | 99 +++--- .../ExternalReferencesOperationTest.java | 80 ++--- .../operations/GroupsOperationTest.java | 41 ++- .../operations/InterfaceOperationTest.java | 87 +++--- .../operations/NodeTemplateOperationGraphTest.java | 148 ++++----- .../operations/PolicyOperationIntegrationTest.java | 54 ++-- ...TemplateOperationCapabilityIntegrationTest.java | 71 ++--- .../operations/ToscaElementOperationTest.java | 41 ++- .../ToscaOperationFacadePoliciesTest.java | 55 ++-- .../operations/UpgradeOperationTest.java | 76 ++--- .../impl/AdditionalInformationOperationTest.java | 66 ++-- .../impl/AnnotationTypeOperationsTest.java | 77 ++--- .../operations/impl/ArtifactOperationTest.java | 138 +++++---- .../impl/CapabilityTypeOperationTest.java | 169 ++++++----- .../operations/impl/GroupTypeOperationTest.java | 331 +++++++++++---------- .../impl/InterfaceLifecycleOperationTest.java | 85 +++--- .../operations/impl/PolicyTypeOperationTest.java | 74 +++-- .../impl/RelationshipTypeOperationTest.java | 270 ++++++++--------- .../impl/ToscaElementLifecycleOperationTest.java | 117 ++++---- 19 files changed, 1078 insertions(+), 1001 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArchiveOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArchiveOperationTest.java index 1bc067e0f4..761e61fe38 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArchiveOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ArchiveOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,15 +20,20 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; +import static org.assertj.core.api.Assertions.assertThat; + import fj.data.Either; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition; @@ -40,41 +45,26 @@ import org.openecomp.sdc.be.model.LifecycleStateEnum; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.jsonjanusgraph.enums.JsonConstantKeysEnum; import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Created by yavivi on 21/03/2018. */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(value = {"classpath:application-context-test.xml", "classpath:healing-context-test.xml"}) +@SpringJUnitConfig(locations = {"classpath:application-context-test.xml", "classpath:healing-context-test.xml"}) public class ArchiveOperationTest extends ModelTestBase { private static final String CI_UID_RES1_CP = "cp_uid"; private static final String CI_UID_RES2_VL = "vl_uid"; private static final String CI_UID_SVC_PROXY = "svc_proxy_uid"; - + GraphVertex archiveVertex; + GraphVertex catalogVertex; @Resource private ArchiveOperation archiveOperation; - @Resource private JanusGraphDao janusGraphDao; - private boolean isInitialized; - private GraphVertex serviceVertex1; private GraphVertex archivedVertex1; - - GraphVertex archiveVertex; - GraphVertex catalogVertex; - private GraphVertex serviceVertex1_0; private GraphVertex serviceVertex1_1; private GraphVertex serviceVertex2_0; @@ -98,14 +88,14 @@ public class ArchiveOperationTest extends ModelTestBase { private GraphVertex vfResource0_1; private GraphVertex vfResource0_2; private GraphVertex vfResource1_0; - private String csarUuid = "123456789";; + private String csarUuid = "123456789"; - @BeforeClass - public static void initTest(){ + @BeforeAll + public static void initTest() { ModelTestBase.init(); } - @Before + @BeforeEach public void beforeTest() { if (!isInitialized) { GraphTestUtils.clearGraph(janusGraphDao); @@ -115,7 +105,7 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testArchiveComponentSingleVersion(){ + public void testArchiveComponentSingleVersion() { String componentId = serviceVertex1.getUniqueId(); Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(componentId); assertThat(actionStatus.isLeft()).isTrue(); @@ -123,7 +113,7 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testArchiveComponentFailsWhenInCheckoutSingleVersion(){ + public void testArchiveComponentFailsWhenInCheckoutSingleVersion() { checkoutComponent(serviceVertex1); String componentId = serviceVertex1.getUniqueId(); Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(componentId); @@ -146,7 +136,7 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testScenario2_archive_1_0(){ + public void testScenario2_archive_1_0() { Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(serviceVertex1_0.getUniqueId()); assertThat(actionStatus.isLeft()).isTrue(); assertThat(actionStatus.left().value()).containsExactlyInAnyOrder(serviceVertex1_0.getUniqueId(), serviceVertex1_1.getUniqueId()); @@ -155,7 +145,7 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testScenario2_archive_1_1(){ + public void testScenario2_archive_1_1() { Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(serviceVertex1_1.getUniqueId()); assertThat(actionStatus.left().value()).containsExactlyInAnyOrder(serviceVertex1_0.getUniqueId(), serviceVertex1_1.getUniqueId()); assertArchived(serviceVertex1_0.getUniqueId()); @@ -163,9 +153,10 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testScenario4_oneLowOneHighestVersion(){ + public void testScenario4_oneLowOneHighestVersion() { Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(serviceVertex0_2.getUniqueId()); - assertThat(actionStatus.left().value()).containsExactlyInAnyOrder(serviceVertex0_2.getUniqueId(), serviceVertex0_1.getUniqueId(), serviceVertex0_3.getUniqueId(), serviceVertex0_4.getUniqueId(), serviceVertex0_5.getUniqueId()); + assertThat(actionStatus.left().value()).containsExactlyInAnyOrder(serviceVertex0_2.getUniqueId(), serviceVertex0_1.getUniqueId(), + serviceVertex0_3.getUniqueId(), serviceVertex0_4.getUniqueId(), serviceVertex0_5.getUniqueId()); assertArchived(serviceVertex0_1.getUniqueId()); assertArchived(serviceVertex0_2.getUniqueId()); assertArchived(serviceVertex0_3.getUniqueId()); @@ -174,13 +165,14 @@ public class ArchiveOperationTest extends ModelTestBase { actionStatus = this.archiveOperation.restoreComponent(serviceVertex0_2.getUniqueId()); assertThat(actionStatus.isLeft()).isTrue(); - assertThat(actionStatus.left().value()).containsExactlyInAnyOrder(serviceVertex0_2.getUniqueId(), serviceVertex0_1.getUniqueId(), serviceVertex0_3.getUniqueId(), serviceVertex0_4.getUniqueId(), serviceVertex0_5.getUniqueId()); + assertThat(actionStatus.left().value()).containsExactlyInAnyOrder(serviceVertex0_2.getUniqueId(), serviceVertex0_1.getUniqueId(), + serviceVertex0_3.getUniqueId(), serviceVertex0_4.getUniqueId(), serviceVertex0_5.getUniqueId()); } /////////////// Continue Here ////////////////// @Test - public void testScenario4_archiveFromNonHighest(){ + public void testScenario4_archiveFromNonHighest() { Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(serviceVertex0_2.getUniqueId()); assertArchived(serviceVertex0_1.getUniqueId()); assertArchived(serviceVertex0_2.getUniqueId()); @@ -197,14 +189,14 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testArchiveFailsWhenHighestVersionIsInCheckoutState(){ + public void testArchiveFailsWhenHighestVersionIsInCheckoutState() { checkoutComponent(serviceVertex0_5); Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(serviceVertex0_2.getUniqueId()); assertThat(actionStatus.right().value()).isEqualTo(ActionStatus.INVALID_SERVICE_STATE); } @Test - public void testScenario3_archive_3_0(){ + public void testScenario3_archive_3_0() { Either, ActionStatus> actionStatus = this.archiveOperation.archiveComponent(serviceVertex3_0.getUniqueId()); assertArchived(serviceVertex3_0.getUniqueId()); assertArchived(serviceVertex3_1.getUniqueId()); @@ -212,7 +204,7 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testArchivedOriginsCalculation(){ + public void testArchivedOriginsCalculation() { //Archive the CP resource this.archiveOperation.archiveComponent(this.compositionResource1.getUniqueId()); @@ -242,7 +234,7 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testNoArchivedOriginsCalculation(){ + public void testNoArchivedOriginsCalculation() { List ciWithArchivedOrigins = this.archiveOperation.setArchivedOriginsFlagInComponentInstances(this.compositionService); //Validate that method returns the CI of CP @@ -250,7 +242,7 @@ public class ArchiveOperationTest extends ModelTestBase { } @Test - public void testOnVspArchivedAndRestored(){ + public void testOnVspArchivedAndRestored() { this.archiveOperation.onVspArchived(csarUuid); //assertOnCommit(); @@ -290,7 +282,7 @@ public class ArchiveOperationTest extends ModelTestBase { assertOnCommit(); } - private void assertOnCommit(){ + private void assertOnCommit() { final JanusGraphOperationStatus commit = this.janusGraphDao.commit(); assertThat(commit).isEqualTo(JanusGraphOperationStatus.OK); } @@ -303,7 +295,7 @@ public class ArchiveOperationTest extends ModelTestBase { assertArchivedOrRestored(ArchiveOperation.Action.RESTORE, componentUniqueId); } - private void assertArchivedOrRestored(ArchiveOperation.Action action, String componentUniqueId) { + private void assertArchivedOrRestored(ArchiveOperation.Action action, String componentUniqueId) { GraphVertex v = janusGraphDao.getVertexById(componentUniqueId).left().value(); EdgeLabelEnum requiredEdge = action == ArchiveOperation.Action.ARCHIVE ? EdgeLabelEnum.ARCHIVE_ELEMENT : EdgeLabelEnum.CATALOG_ELEMENT; @@ -317,7 +309,8 @@ public class ArchiveOperationTest extends ModelTestBase { parent = janusGraphDao.getParentVertex(v, requiredEdge, JsonParseFlagEnum.NoParse).left().value(); otherLookup = janusGraphDao.getParentVertex(v, otherEdge, JsonParseFlagEnum.NoParse); assertThat(otherLookup.isRight()).isTrue(); //Verify that component is not linked to Catalog/Archive Root - assertThat(parent.getUniqueId()).isEqualTo(action == ArchiveOperation.Action.ARCHIVE ? this.archiveVertex.getUniqueId() : this.catalogVertex.getUniqueId()); //Verify that parent is indeed Archive Root + assertThat(parent.getUniqueId()).isEqualTo(action == ArchiveOperation.Action.ARCHIVE ? this.archiveVertex.getUniqueId() + : this.catalogVertex.getUniqueId()); //Verify that parent is indeed Archive Root } assertArchivedOrRestoredProps(action, v); @@ -325,13 +318,13 @@ public class ArchiveOperationTest extends ModelTestBase { private void assertArchivedProps(String uniqueId) { GraphVertex v = - janusGraphDao.getVertexById(uniqueId).left().value(); + janusGraphDao.getVertexById(uniqueId).left().value(); assertArchivedOrRestoredProps(ArchiveOperation.Action.ARCHIVE, v); } private void assertRestoredProps(String uniqueId) { GraphVertex v = - janusGraphDao.getVertexById(uniqueId).left().value(); + janusGraphDao.getVertexById(uniqueId).left().value(); assertArchivedOrRestoredProps(ArchiveOperation.Action.RESTORE, v); } @@ -418,7 +411,7 @@ public class ArchiveOperationTest extends ModelTestBase { .createEdge(catalogVertex, serviceVertex0_5, EdgeLabelEnum.CATALOG_ELEMENT, null); } - private void createResourcesForArchivedVsp(){ + private void createResourcesForArchivedVsp() { Map vfPropsNonHighest = propsForNonHighestVersion(); Map vfPropsHighest = propsForNonHighestVersion(); @@ -443,7 +436,7 @@ public class ArchiveOperationTest extends ModelTestBase { janusGraphDao.createEdge(archiveVertex, archivedVertex1, EdgeLabelEnum.ARCHIVE_ELEMENT, null); } - private void createServiceCompositionForCalculatingArchivedOrigins(){ + private void createServiceCompositionForCalculatingArchivedOrigins() { //Service that point to another service in composition this.compositionService = GraphTestUtils.createServiceVertex(janusGraphDao, propsForHighestVersion()); this.compositionAnotherService = GraphTestUtils.createServiceVertex(janusGraphDao, propsForHighestVersion()); @@ -487,7 +480,7 @@ public class ArchiveOperationTest extends ModelTestBase { instance.setUniqueId(CI_UID_SVC_PROXY); instance.setComponentUid(compositionServiceProxy.getUniqueId()); instances.put(CI_UID_SVC_PROXY, instance); - + //Add Instances to Composition composition.setComponentInstances(instances); //Add to full composition @@ -498,14 +491,14 @@ public class ArchiveOperationTest extends ModelTestBase { janusGraphDao.updateVertex(compositionService); } - private Map propsForHighestVersion(){ + private Map propsForHighestVersion() { Map props = new HashMap(); props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, true); props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); return props; } - private Map propsForNonHighestVersion(){ + private Map propsForNonHighestVersion() { Map props = new HashMap(); props.put(GraphPropertyEnum.IS_HIGHEST_VERSION, false); props.put(GraphPropertyEnum.STATE, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ExternalReferencesOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ExternalReferencesOperationTest.java index 2febef610f..505c13f2b6 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ExternalReferencesOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ExternalReferencesOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,16 +20,25 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + import fj.data.Either; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.JsonParseFlagEnum; import org.openecomp.sdc.be.datatypes.elements.MapComponentInstanceExternalRefs; @@ -37,20 +46,12 @@ import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils; import org.openecomp.sdc.be.model.jsonjanusgraph.utils.IdMapper; import org.openecomp.sdc.be.model.operations.StorageException; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.annotation.Resource; -import java.util.*; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Created by yavivi on 26/01/2018. */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class ExternalReferencesOperationTest extends ModelTestBase { private static final String COMPONENT_ID = "ci-MyComponentName"; @@ -83,12 +84,12 @@ public class ExternalReferencesOperationTest extends ModelTestBase { private IdMapper idMapper; - @BeforeClass - public static void initTest(){ + @BeforeAll + public static void initTest() { ModelTestBase.init(); } - @Before + @BeforeEach public void beforeTest() { idMapper = Mockito.mock(IdMapper.class); this.externalReferenceOperation.setIdMapper(idMapper); @@ -101,8 +102,9 @@ public class ExternalReferencesOperationTest extends ModelTestBase { } @Test - public void testAddComponentInstanceExternalRef(){ - Either addResult = externalReferenceOperation.addExternalReference(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_4); + public void testAddComponentInstanceExternalRef() { + Either addResult = externalReferenceOperation.addExternalReference(this.serviceVertexUuid, COMPONENT_ID, + MONITORING_OBJECT_TYPE, REF_4); assertThat(addResult.isLeft()).isEqualTo(true); //commit changes to janusgraph @@ -145,31 +147,38 @@ public class ExternalReferencesOperationTest extends ModelTestBase { assertThat(allExternalReferences.size()).isZero(); } - @Test(expected=StorageException.class) + @Test public void testGetAllCIExternalRefs_nonExitingService_throwsException() { - externalReferenceOperation.getAllExternalReferences("FAKE", COMPONENT_ID); + Assertions.assertThrows(StorageException.class, () -> externalReferenceOperation.getAllExternalReferences("FAKE", COMPONENT_ID)); } @Test - public void testGetComponentInstanceExternalRef(){ - assertThat(externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE).left().value()).contains(REF_1, REF_2, REF_3, REF_5); - assertThat(externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, WORKFLOW_OBJECT_TYPE).left().value()).containsExactly(REF_6); + public void testGetComponentInstanceExternalRef() { + assertThat( + externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE).left().value()).contains( + REF_1, REF_2, REF_3, REF_5); + assertThat(externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, WORKFLOW_OBJECT_TYPE).left() + .value()).containsExactly(REF_6); } @Test - public void testGetComponentInstanceExternalRefForNonExistingObjectId(){ - assertThat(externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE).left().value()).contains(REF_1, REF_2, REF_3, REF_5); - Either, ActionStatus> getResult = externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, "FAKE_OBJECT_TYPE"); + public void testGetComponentInstanceExternalRefForNonExistingObjectId() { + assertThat( + externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE).left().value()).contains( + REF_1, REF_2, REF_3, REF_5); + Either, ActionStatus> getResult = externalReferenceOperation.getExternalReferences(this.serviceVertexUuid, COMPONENT_ID, + "FAKE_OBJECT_TYPE"); assertThat(getResult.left().value()).isEmpty(); } @Test - public void testDeleteComponentInstanceExternalRef(){ + public void testDeleteComponentInstanceExternalRef() { //Test the precondition assertThat(getServiceExternalRefs()).contains(REF_5); //Remove REF 5 - Either deleteStatus = externalReferenceOperation.deleteExternalReference(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_5); + Either deleteStatus = externalReferenceOperation.deleteExternalReference(this.serviceVertexUuid, COMPONENT_ID, + MONITORING_OBJECT_TYPE, REF_5); assertThat(deleteStatus.isLeft()).isEqualTo(true); //commit changes to janusgraph @@ -181,12 +190,13 @@ public class ExternalReferencesOperationTest extends ModelTestBase { } @Test - public void testUpdateComponentInstanceExternalRef(){ + public void testUpdateComponentInstanceExternalRef() { //Test the precondition assertThat(getServiceExternalRefs()).contains(REF_5).doesNotContain(REF_4); //Update REF 5 with REF_4 - Either updateResult = externalReferenceOperation.updateExternalReference(this.serviceVertexUuid, COMPONENT_ID, MONITORING_OBJECT_TYPE, REF_5, REF_4); + Either updateResult = externalReferenceOperation.updateExternalReference(this.serviceVertexUuid, COMPONENT_ID, + MONITORING_OBJECT_TYPE, REF_5, REF_4); assertThat(updateResult.isLeft()).isEqualTo(true); @@ -198,7 +208,7 @@ public class ExternalReferencesOperationTest extends ModelTestBase { assertThat(getServiceExternalRefs()).doesNotContain(REF_5).contains(REF_1, REF_2, REF_3, REF_4); } - private List getServiceExternalRefs(){ + private List getServiceExternalRefs() { //Get service vertex final Either externalRefsVertexResult = this.janusGraphDao .getChildVertex(this.serviceVertex, EdgeLabelEnum.EXTERNAL_REFS, JsonParseFlagEnum.ParseJson); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationTest.java index bad361562b..ab4e991b7f 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/GroupsOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -25,15 +25,14 @@ import static org.assertj.core.api.Assertions.assertThat; import fj.data.Either; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.config.JanusGraphSpringConfig; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.GroupDefinition; @@ -42,30 +41,26 @@ import org.openecomp.sdc.be.model.Resource; import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) +@SpringJUnitConfig(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) public class GroupsOperationTest extends ModelTestBase { @Autowired - private GroupsOperation groupsOperation; - + private HealingJanusGraphDao janusGraphDao; @Autowired - HealingJanusGraphDao janusGraphDao; - + private GroupsOperation groupsOperation; @Autowired private ToscaOperationFacade toscaOperationFacade; private Component container; - @BeforeClass + @BeforeAll public static void initClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void setUp() throws Exception { container = new Resource(); container.setUniqueId(CONTAINER_ID); @@ -74,7 +69,7 @@ public class GroupsOperationTest extends ModelTestBase { } - @After + @AfterEach public void tearDown() throws Exception { janusGraphDao.rollback(); } @@ -90,8 +85,8 @@ public class GroupsOperationTest extends ModelTestBase { getGroupsFilter.setIgnoreGroups(false); Component cmptWithGroups = toscaOperationFacade.getToscaElement(CONTAINER_ID, getGroupsFilter).left().value(); assertThat(cmptWithGroups.getGroups()) - .usingElementComparatorOnFields("name", "uniqueId") - .containsExactlyInAnyOrder(g1, g2); + .usingElementComparatorOnFields("name", "uniqueId") + .containsExactlyInAnyOrder(g1, g2); } @Test @@ -109,8 +104,8 @@ public class GroupsOperationTest extends ModelTestBase { getGroupsFilter.setIgnoreGroups(false); Component cmptWithGroups = toscaOperationFacade.getToscaElement(CONTAINER_ID, getGroupsFilter).left().value(); assertThat(cmptWithGroups.getGroups()) - .usingElementComparatorOnFields("name", "uniqueId") - .containsExactlyInAnyOrder(g1, g2, g3, g4); + .usingElementComparatorOnFields("name", "uniqueId") + .containsExactlyInAnyOrder(g1, g2, g3, g4); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java index 4925c87ce4..7353c511db 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/InterfaceOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -31,15 +31,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.datatypes.elements.MapDataDefinition; @@ -64,11 +63,9 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.common.util.ValidationUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class InterfaceOperationTest extends ModelTestBase { private static final String RESOURCE_NAME = "Resource Name"; @@ -91,12 +88,12 @@ public class InterfaceOperationTest extends ModelTestBase { private ToscaElementLifecycleOperation lifecycleOperation; private GraphVertex ownerVertex; - @BeforeClass + @BeforeAll public static void initInterfacesOperation() { init(); } - @Before + @BeforeEach public void setupBefore() { GraphTestUtils.clearGraph(janusGraphDao); createUsers(); @@ -149,7 +146,7 @@ public class InterfaceOperationTest extends ModelTestBase { metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_CATEGORY.getName()); metadataProperties.put(GraphPropertyEnum.NAME, categoryName); metadataProperties - .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); + .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); cat.setMetadataProperties(metadataProperties); cat.updateMetadataJsonWithCurrentMetadataProperties(); @@ -161,14 +158,14 @@ public class InterfaceOperationTest extends ModelTestBase { metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.RESOURCE_SUBCATEGORY.getName()); metadataProperties.put(GraphPropertyEnum.NAME, subcategory); metadataProperties - .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory)); + .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(subcategory)); subCat.setMetadataProperties(metadataProperties); subCat.updateMetadataJsonWithCurrentMetadataProperties(); Either catRes = janusGraphDao.createVertex(cat); Either subCatRes = janusGraphDao.createVertex(subCat); janusGraphDao.createEdge(catRes.left().value().getVertex(), subCatRes.left().value().getVertex(), - EdgeLabelEnum.SUB_CATEGORY, new HashMap<>()); + EdgeLabelEnum.SUB_CATEGORY, new HashMap<>()); } private void createServiceCategory() { @@ -180,7 +177,7 @@ public class InterfaceOperationTest extends ModelTestBase { metadataProperties.put(GraphPropertyEnum.LABEL, VertexTypeEnum.SERVICE_CATEGORY.getName()); metadataProperties.put(GraphPropertyEnum.NAME, categoryName); metadataProperties - .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); + .put(GraphPropertyEnum.NORMALIZED_NAME, ValidationUtils.normalizeCategoryName4Uniqueness(categoryName)); cat.setMetadataProperties(metadataProperties); cat.updateMetadataJsonWithCurrentMetadataProperties(); janusGraphDao.createVertex(cat); @@ -197,7 +194,7 @@ public class InterfaceOperationTest extends ModelTestBase { vf.getMetadata().put(JsonPresentationFields.VERSION.getPresentation(), "1.0"); vf.getMetadata().put(JsonPresentationFields.TYPE.getPresentation(), ResourceTypeEnum.VFC.name()); vf.getMetadata() - .put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name()); + .put(JsonPresentationFields.LIFECYCLE_STATE.getPresentation(), LifecycleStateEnum.CERTIFIED.name()); vf.getMetadata().put(JsonPresentationFields.TOSCA_RESOURCE_NAME.getPresentation(), "root"); vf.getMetadata().put(JsonPresentationFields.HIGHEST_VERSION.getPresentation(), true); @@ -236,7 +233,7 @@ public class InterfaceOperationTest extends ModelTestBase { Either createVFRes = nodeTypeOperation.createNodeType(vf); Either getNodeTyeRes = - janusGraphDao.getVertexById(createVFRes.left().value().getUniqueId()); + janusGraphDao.getVertexById(createVFRes.left().value().getUniqueId()); getNodeTyeRes.left().value(); } @@ -280,10 +277,10 @@ public class InterfaceOperationTest extends ModelTestBase { Either createVFRes = nodeTypeOperation.createNodeType(vf); Either getNodeTyeRes = - janusGraphDao.getVertexById(createVFRes.left().value().getUniqueId()); + janusGraphDao.getVertexById(createVFRes.left().value().getUniqueId()); GraphVertex vfVertex = getNodeTyeRes.left().value(); StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, - VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME); + VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME); assertSame(StorageOperationStatus.OK, status); PropertyDataDefinition prop33 = new PropertyDataDefinition(); @@ -291,8 +288,8 @@ public class InterfaceOperationTest extends ModelTestBase { prop33.setDefaultValue("def33"); status = nodeTypeOperation - .addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, - prop33, JsonPresentationFields.NAME); + .addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, + prop33, JsonPresentationFields.NAME); assertSame(StorageOperationStatus.OK, status); PropertyDataDefinition prop44 = new PropertyDataDefinition(); @@ -300,7 +297,7 @@ public class InterfaceOperationTest extends ModelTestBase { prop44.setDefaultValue("def44"); status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, - VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME); + VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME); assertSame(StorageOperationStatus.OK, status); PropertyDataDefinition capProp = new PropertyDataDefinition(); @@ -314,13 +311,13 @@ public class InterfaceOperationTest extends ModelTestBase { capProps.put("capName", dataToCreate); nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, - EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); + EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); List pathKeys = new ArrayList<>(); pathKeys.add("capName"); capProp.setDefaultValue("BBBB"); nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, - VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); + VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); } private void createTopologyTemplate(String name) { @@ -341,14 +338,14 @@ public class InterfaceOperationTest extends ModelTestBase { service.setComponentType(ComponentTypeEnum.SERVICE); Either createRes = - topologyTemplateOperation.createTopologyTemplate(service); + topologyTemplateOperation.createTopologyTemplate(service); Either getNodeTyeRes = - janusGraphDao.getVertexById(createRes.left().value().getUniqueId()); + janusGraphDao.getVertexById(createRes.left().value().getUniqueId()); getNodeTyeRes.left().value(); } - @After + @AfterEach public void cleanAfter() { GraphTestUtils.clearGraph(janusGraphDao); } @@ -361,9 +358,9 @@ public class InterfaceOperationTest extends ModelTestBase { private void testAddSingleInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1"); Either, StorageOperationStatus> res = interfaceOperation - .addInterfaces(component.getUniqueId(), - Collections.singletonList( - interfaceDefinition)); + .addInterfaces(component.getUniqueId(), + Collections.singletonList( + interfaceDefinition)); Assert.assertTrue(res.isLeft()); Assert.assertEquals("1", res.left().value().get(0).getUniqueId()); } @@ -402,7 +399,7 @@ public class InterfaceOperationTest extends ModelTestBase { interfaceDefinitions.add(interfaceDefinition1); interfaceDefinitions.add(interfaceDefinition2); Either, StorageOperationStatus> res = - interfaceOperation.addInterfaces(component.getUniqueId(), interfaceDefinitions); + interfaceOperation.addInterfaces(component.getUniqueId(), interfaceDefinitions); Assert.assertTrue(res.isLeft()); Assert.assertEquals(2, res.left().value().size()); } @@ -415,16 +412,16 @@ public class InterfaceOperationTest extends ModelTestBase { private void testUpdateInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1"); Either, StorageOperationStatus> res = interfaceOperation - .addInterfaces(component.getUniqueId(), - Collections.singletonList( - interfaceDefinition)); + .addInterfaces(component.getUniqueId(), + Collections.singletonList( + interfaceDefinition)); Assert.assertTrue(res.isLeft()); List value = res.left().value(); InterfaceDefinition createdInterfaceDef = value.get(0); String newDescription = "New Description"; createdInterfaceDef.setDescription(newDescription); res = interfaceOperation - .updateInterfaces(component.getUniqueId(), Collections.singletonList(createdInterfaceDef)); + .updateInterfaces(component.getUniqueId(), Collections.singletonList(createdInterfaceDef)); assertTrue(res.isLeft()); assertEquals(newDescription, res.left().value().get(0).getDescription()); } @@ -442,13 +439,13 @@ public class InterfaceOperationTest extends ModelTestBase { private void testDeleteInterface(Component component) { InterfaceDefinition interfaceDefinition = buildInterfaceDefinition("1"); Either, StorageOperationStatus> res = interfaceOperation - .addInterfaces(component.getUniqueId(), - Collections.singletonList( - interfaceDefinition)); + .addInterfaces(component.getUniqueId(), + Collections.singletonList( + interfaceDefinition)); Assert.assertTrue(res.isLeft()); List value = res.left().value(); Either deleteInterfaceOperationRes = - interfaceOperation.deleteInterface(component.getUniqueId(), value.get(0).getUniqueId()); + interfaceOperation.deleteInterface(component.getUniqueId(), value.get(0).getUniqueId()); assertTrue(deleteInterfaceOperationRes.isLeft()); } @@ -463,7 +460,7 @@ public class InterfaceOperationTest extends ModelTestBase { InterfaceDefinition interfaceDefinition = buildInterfaceDefinitionWithoutOperation(); interfaceDefinition.setOperationsMap(createMockOperationMap()); Either, StorageOperationStatus> res = interfaceOperation.updateInterfaces( - component.getUniqueId(), Collections.singletonList(interfaceDefinition)); + component.getUniqueId(), Collections.singletonList(interfaceDefinition)); Assert.assertTrue(res.isRight()); } @@ -499,7 +496,7 @@ public class InterfaceOperationTest extends ModelTestBase { } private InterfaceDefinition createInterface(String uniqueId, String description, String type, - String toscaResourceName, Map op) { + String toscaResourceName, Map op) { InterfaceDefinition id = new InterfaceDefinition(); id.setType(type); id.setDescription(description); @@ -509,7 +506,7 @@ public class InterfaceOperationTest extends ModelTestBase { return id; } - @After + @AfterEach public void teardown() { GraphTestUtils.clearGraph(janusGraphDao); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java index 576aa8a680..b2db75933a 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/NodeTemplateOperationGraphTest.java @@ -7,9 +7,9 @@ * 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. @@ -25,8 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.core.JanusGraphVertex; import fj.data.Either; import java.io.BufferedOutputStream; import java.io.File; @@ -42,15 +40,16 @@ import org.apache.tinkerpop.gremlin.structure.Direction; import org.apache.tinkerpop.gremlin.structure.Edge; import org.apache.tinkerpop.gremlin.structure.Vertex; import org.apache.tinkerpop.gremlin.structure.io.IoCore; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphVertex; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.config.JanusGraphSpringConfig; +import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.EdgePropertyEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; @@ -59,100 +58,99 @@ import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) -public class NodeTemplateOperationGraphTest extends ModelTestBase{ +@SpringJUnitConfig(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) +public class NodeTemplateOperationGraphTest extends ModelTestBase { + + String outputDirectory = "C:\\Output"; @Resource private HealingJanusGraphDao janusGraphDao; @Resource private NodeTemplateOperation nodeTemplateOperation; - private JanusGraph graphT; - private GraphVertex containerVertex; + private GraphVertex containerVertex; private String containeId; - - @BeforeClass + + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before - public void before(){ - + + @BeforeEach + public void before() { + Either graph = janusGraphDao.getGraph(); graphT = graph.left().value(); - + containerVertex = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE); containeId = "containerId"; containerVertex.setUniqueId(containeId); Either createVertex = janusGraphDao.createVertex(containerVertex); assertTrue(createVertex.isLeft()); } - - @After - public void after(){ + + @AfterEach + public void after() { janusGraphDao.rollback(); - + } - - - String outputDirectory = "C:\\Output"; - + @Test - public void testCreateInstanceEdge(){ - + public void testCreateInstanceEdge() { + Map> mapOriginToInstId = new HashMap<>(); createIntancesFromSameResource(mapOriginToInstId, 1, 3); createIntancesFromSameResource(mapOriginToInstId, 2, 4); createIntancesFromSameResource(mapOriginToInstId, 3, 1); - + // exportGraphMl(graphT); - + validateOnGraph(mapOriginToInstId, 3); } - + @Test - public void testRemoveInstanceEdge(){ + public void testRemoveInstanceEdge() { //create 3 instances from same resource orig1 Map> mapOriginToInstId = new HashMap<>(); String originId = createIntancesFromSameResource(mapOriginToInstId, 1, 3); validateOnGraph(mapOriginToInstId, 1); - + //remove instance 2 - String instanceId = removeInstanceEdge(containerVertex, originId, 1, 1); + String instanceId = removeInstanceEdge(containerVertex, originId, 1, 1); mapOriginToInstId.get(originId).remove(instanceId); validateOnGraph(mapOriginToInstId, 1); - + //create new instance from orig1 - instanceId = createInstanceEdge(containerVertex, originId, 1, 4, false, null); + instanceId = createInstanceEdge(containerVertex, originId, 1, 4, false, null); mapOriginToInstId.get(originId).add(instanceId); validateOnGraph(mapOriginToInstId, 1); - + //create 1 instance from same resource orig2 originId = createIntancesFromSameResource(mapOriginToInstId, 2, 1); validateOnGraph(mapOriginToInstId, 2); - + //remove instance of orig 2 - instanceId = removeInstanceEdge(containerVertex, originId, 2, 1); + instanceId = removeInstanceEdge(containerVertex, originId, 2, 1); mapOriginToInstId.get(originId).remove(instanceId); validateOnGraph(mapOriginToInstId, 1); - + } - + @Test - public void testProxyInstanceEdge(){ + public void testProxyInstanceEdge() { Map> mapOriginToInstId = new HashMap<>(); - String proxyId = createOrigin(2); + String proxyId = createOrigin(2); createIntancesFromSameResource(mapOriginToInstId, 1, 1, true, proxyId); - - validateOnGraph(mapOriginToInstId, 1); + + validateOnGraph(mapOriginToInstId, 1); } + private void validateOnGraph(Map> mapOriginToInstId, int expectedEdgeCount) { validateOnGraph(mapOriginToInstId, expectedEdgeCount, false); } + private void validateOnGraph(Map> mapOriginToInstId, int expectedEdgeCount, boolean validateProxy) { Iterable vertices = graphT.query().has(GraphPropertyEnum.UNIQUE_ID.getProperty(), containeId).vertices(); assertNotNull(vertices); @@ -160,44 +158,46 @@ public class NodeTemplateOperationGraphTest extends ModelTestBase{ assertTrue(iterator.hasNext()); Vertex containerV = iterator.next(); validatePerEdgeType(mapOriginToInstId, expectedEdgeCount, containerV, EdgeLabelEnum.INSTANCE_OF); - if ( validateProxy ){ + if (validateProxy) { validatePerEdgeType(mapOriginToInstId, expectedEdgeCount, containerV, EdgeLabelEnum.PROXY_OF); } } + private void validatePerEdgeType(Map> mapOriginToInstId, int expectedEdgeCount, Vertex containerV, EdgeLabelEnum edgeLabel) { Iterator edges = containerV.edges(Direction.OUT, edgeLabel.name()); assertNotNull(edges); - + int counter = 0; - while (edges.hasNext()){ + while (edges.hasNext()) { Edge edge = edges.next(); counter++; validateEdge(edge, mapOriginToInstId); } assertEquals("check edge size", expectedEdgeCount, counter); } - - + + private String createIntancesFromSameResource(Map> mapOriginToInstId, int originIndex, int countInstances) { - return createIntancesFromSameResource(mapOriginToInstId, originIndex, countInstances, false, null); + return createIntancesFromSameResource(mapOriginToInstId, originIndex, countInstances, false, null); } - - private String createIntancesFromSameResource(Map> mapOriginToInstId, int originIndex, int countInstances, boolean isProxy, String proxyId) { - + + private String createIntancesFromSameResource(Map> mapOriginToInstId, int originIndex, int countInstances, boolean isProxy, + String proxyId) { + List exp = new ArrayList(); String originId = createOrigin(originIndex); - - for ( int i = 0; i < countInstances; i++){ - String instanceId = createInstanceEdge(containerVertex, originId, originIndex, i+1, isProxy, proxyId); + + for (int i = 0; i < countInstances; i++) { + String instanceId = createInstanceEdge(containerVertex, originId, originIndex, i + 1, isProxy, proxyId); exp.add(instanceId); } mapOriginToInstId.put(originId, exp); - if ( isProxy ){ - mapOriginToInstId.put(proxyId, exp); + if (isProxy) { + mapOriginToInstId.put(proxyId, exp); } return originId; } - + private String createInstanceEdge(GraphVertex containerVertex, String originId, int originIndex, int insIndex, boolean isProxy, String proxyId) { ComponentInstanceDataDefinition componentInstance = new ComponentInstanceDataDefinition(); componentInstance.setComponentUid(originId); @@ -209,12 +209,13 @@ public class NodeTemplateOperationGraphTest extends ModelTestBase{ assertEquals("assertion createInstanceEdge", StorageOperationStatus.OK, edgeStatus); return instanceId; } - + private String buildInstanceId(int originIndex, int insIndex) { StringBuilder sb = new StringBuilder("instanceId_"); sb.append(originIndex).append("-").append(insIndex); - return sb.toString(); + return sb.toString(); } + private String removeInstanceEdge(GraphVertex containerVertex, String originId, int originIndex, int insIndex) { ComponentInstanceDataDefinition componentInstance = new ComponentInstanceDataDefinition(); componentInstance.setComponentUid(originId); @@ -224,8 +225,8 @@ public class NodeTemplateOperationGraphTest extends ModelTestBase{ assertEquals("assertion removeInstanceEdge", StorageOperationStatus.OK, edgeStatus); return instanceId; } - - + + private String createOrigin(int index) { Either createVertex; GraphVertex originVertex = new GraphVertex(VertexTypeEnum.NODE_TYPE); @@ -235,18 +236,19 @@ public class NodeTemplateOperationGraphTest extends ModelTestBase{ assertTrue(createVertex.isLeft()); return originId; } + private void validateEdge(Edge edge, Map> mapOriginToInstId) { List expextedInList; - + Vertex originV = edge.inVertex(); - String id = (String) janusGraphDao.getProperty((JanusGraphVertex)originV, GraphPropertyEnum.UNIQUE_ID.getProperty()); + String id = (String) janusGraphDao.getProperty((JanusGraphVertex) originV, GraphPropertyEnum.UNIQUE_ID.getProperty()); expextedInList = mapOriginToInstId.get(id); - + List list = (List) janusGraphDao.getProperty(edge, EdgePropertyEnum.INSTANCES); assertThat(list).hasSameSizeAs(expextedInList); assertThat(list).containsOnlyElementsOf(expextedInList); } - + private String exportGraphMl(JanusGraph graph) { String result = null; String outputFile = outputDirectory + File.separator + "exportGraph." + System.currentTimeMillis() + ".graphml"; diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/PolicyOperationIntegrationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/PolicyOperationIntegrationTest.java index 37e360c5c2..64cad65301 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/PolicyOperationIntegrationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/PolicyOperationIntegrationTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,15 +20,22 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; +import static org.apache.commons.collections.ListUtils.union; +import static org.assertj.core.api.Assertions.assertThat; + import fj.data.Either; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.config.JanusGraphSpringConfig; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition; @@ -43,24 +50,13 @@ import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import javax.annotation.Resource; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.apache.commons.collections.ListUtils.union; -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) +@SpringJUnitConfig(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) public class PolicyOperationIntegrationTest extends ModelTestBase { - private static final String CONTAINER_ID = "container"; public static final String POLICY_ID = "policy"; + private static final String CONTAINER_ID = "container"; @Resource private TopologyTemplateOperation topologyTemplateOperation; @Resource @@ -70,13 +66,13 @@ public class PolicyOperationIntegrationTest extends ModelTestBase { private PropertyDataDefinition prop1, prop2; private PolicyDefinition policy; - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void setUp() throws Exception { prop1 = new PropertyDataDefinition(); prop1.setUniqueId("prop1"); @@ -97,11 +93,12 @@ public class PolicyOperationIntegrationTest extends ModelTestBase { resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID); janusGraphDao.createVertex(resource); GraphVertex loadedResource = janusGraphDao.getVertexById(CONTAINER_ID).left().value(); - topologyTemplateOperation.addToscaDataToToscaElement(loadedResource, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policy, JsonPresentationFields.UNIQUE_ID); + topologyTemplateOperation.addToscaDataToToscaElement(loadedResource, EdgeLabelEnum.POLICIES, VertexTypeEnum.POLICIES, policy, + JsonPresentationFields.UNIQUE_ID); // janusGraphDao.commit(); } - @After + @AfterEach public void tearDown() { janusGraphDao.rollback(); } @@ -134,7 +131,8 @@ public class PolicyOperationIntegrationTest extends ModelTestBase { ComponentParametersView componentParametersView = new ComponentParametersView(); componentParametersView.disableAll(); componentParametersView.setIgnorePolicies(false); - Either loadedCmptEither = topologyTemplateOperation.getToscaElement(CONTAINER_ID, componentParametersView); + Either loadedCmptEither = topologyTemplateOperation.getToscaElement(CONTAINER_ID, + componentParametersView); assertThat(loadedCmptEither.isLeft()).isTrue(); ToscaElement loadedCmpt = loadedCmptEither.left().value(); @@ -148,6 +146,6 @@ public class PolicyOperationIntegrationTest extends ModelTestBase { PolicyDataDefinition policy = policies.get(POLICY_ID); List policyProperties = policy.getProperties(); assertThat(policyProperties).usingElementComparatorOnFields("value") - .containsAll(expectedUpdatedProperties); + .containsAll(expectedUpdatedProperties); } } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationCapabilityIntegrationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationCapabilityIntegrationTest.java index bfa3dd6175..5dbb96e4f2 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationCapabilityIntegrationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/TopologyTemplateOperationCapabilityIntegrationTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,14 +20,20 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.annotation.Resource; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.config.JanusGraphSpringConfig; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.jsongraph.types.EdgeLabelEnum; import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; import org.openecomp.sdc.be.datatypes.elements.MapCapabilityProperty; @@ -40,19 +46,9 @@ import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import javax.annotation.Resource; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) +@SpringJUnitConfig(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTestBase { private static final String CONTAINER_ID = "id"; @@ -68,13 +64,13 @@ public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTes private CapabilityPropertyDataObject capabilityProperty2; private CapabilityPropertyDataObject capabilityProperty3; - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void setUp() throws Exception { capabilitiesPropsMap = new HashMap<>(); @@ -83,22 +79,24 @@ public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTes capabilityProperty3 = new CapabilityPropertyDataObject("instance2", "capability3", "prop3", "val3"); capabilitiesProperties = Arrays.asList(capabilityProperty1, capabilityProperty2, capabilityProperty3); - //capablities props == Map>> capabilitiesProperties.forEach(capabilitiesProperty -> { capabilitiesPropsMap.computeIfAbsent(capabilitiesProperty.getInstanceId(), k -> new MapCapabilityProperty(new HashMap<>())) - .getMapToscaDataDefinition().computeIfAbsent(capabilitiesProperty.getCapabilityId(), k -> new MapPropertiesDataDefinition(new HashMap<>())) - .getMapToscaDataDefinition().computeIfAbsent(capabilitiesProperty.getPropName(), k -> new PropertyDefinition(createPropWithValue(capabilitiesProperty.getPropValue()))); + .getMapToscaDataDefinition() + .computeIfAbsent(capabilitiesProperty.getCapabilityId(), k -> new MapPropertiesDataDefinition(new HashMap<>())) + .getMapToscaDataDefinition().computeIfAbsent(capabilitiesProperty.getPropName(), + k -> new PropertyDefinition(createPropWithValue(capabilitiesProperty.getPropValue()))); }); GraphVertex resource = new GraphVertex(VertexTypeEnum.TOPOLOGY_TEMPLATE); resource.addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, CONTAINER_ID); janusGraphDao.createVertex(resource); GraphVertex loadedResource = janusGraphDao.getVertexById(CONTAINER_ID).left().value(); - topologyTemplateOperation.associateElementToData(loadedResource, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap).left().value(); + topologyTemplateOperation.associateElementToData(loadedResource, VertexTypeEnum.CALCULATED_CAP_PROPERTIES, + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap).left().value(); } - @After + @AfterEach public void tearDown() { janusGraphDao.rollback(); } @@ -111,7 +109,8 @@ public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTes capabilityProperty3.setPropValue("newVal3"); setPropertyValue(capabilitiesPropsMap, capabilityProperty1); setPropertyValue(capabilitiesPropsMap, capabilityProperty3); - StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap); + StorageOperationStatus storageOperationStatus = topologyTemplateOperation.overrideToscaDataOfToscaElement(CONTAINER_ID, + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, capabilitiesPropsMap); assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); Map updatedCapPropsMap = fetchCapabilitiesProps(CONTAINER_ID); compareCapabilitiesProperties(capabilitiesProperties, updatedCapPropsMap); @@ -132,7 +131,8 @@ public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTes Component component = new org.openecomp.sdc.be.model.Resource(); component.setUniqueId(CONTAINER_ID); - StorageOperationStatus updateStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instance1Props, "instance1"); + StorageOperationStatus updateStatus = topologyTemplateOperation.updateToscaDataDeepElementsBlockToToscaElement(CONTAINER_ID, + EdgeLabelEnum.CALCULATED_CAP_PROPERTIES, instance1Props, "instance1"); assertThat(updateStatus).isEqualTo(StorageOperationStatus.OK); assertCapabilityPropValue(capabilityProperty1, "newVal1"); @@ -143,13 +143,15 @@ public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTes private Map fetchCapabilitiesProps(String containerId) { ComponentParametersView capabilityPropsFilter = new ComponentParametersView(true); capabilityPropsFilter.setIgnoreCapabiltyProperties(false); - return ((TopologyTemplate) topologyTemplateOperation.getToscaElement(containerId, capabilityPropsFilter).left().value()).getCalculatedCapabilitiesProperties(); + return ((TopologyTemplate) topologyTemplateOperation.getToscaElement(containerId, capabilityPropsFilter).left() + .value()).getCalculatedCapabilitiesProperties(); } private void compareCapabilitiesProperties(List expected, Map actual) { expected.forEach(expectedCapabilityProp -> { - assertThat(getPropertyValue(actual, expectedCapabilityProp.instanceId, expectedCapabilityProp.capabilityId, expectedCapabilityProp.propName)) - .isEqualTo(expectedCapabilityProp.propValue); + assertThat( + getPropertyValue(actual, expectedCapabilityProp.instanceId, expectedCapabilityProp.capabilityId, expectedCapabilityProp.propName)) + .isEqualTo(expectedCapabilityProp.propValue); }); } @@ -164,8 +166,8 @@ public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTes private void setPropertyValue(MapCapabilityProperty capabilitiesInstanceProperties, CapabilityPropertyDataObject capabilityProperty) { capabilitiesInstanceProperties.getMapToscaDataDefinition().get(capabilityProperty.getCapabilityId()) - .getMapToscaDataDefinition().get(capabilityProperty.getPropName()) - .setValue(capabilityProperty.getPropValue()); + .getMapToscaDataDefinition().get(capabilityProperty.getPropName()) + .setValue(capabilityProperty.getPropValue()); } private void assertCapabilityPropValue(CapabilityPropertyDataObject prop, String expectedValue) { @@ -182,6 +184,7 @@ public class TopologyTemplateOperationCapabilityIntegrationTest extends ModelTes } private static class CapabilityPropertyDataObject { + private String instanceId; private String capabilityId; private String propName; diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java index 3da37c098a..821f23e191 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperationTest.java @@ -20,16 +20,24 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import fj.data.Either; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.rules.TestName; -import org.junit.runner.RunWith; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; @@ -44,42 +52,31 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.EntryData; import org.openecomp.sdc.be.utils.TypeUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.*; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Created by chaya on 6/12/2017. */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class ToscaElementOperationTest extends ModelTestBase { + @Rule + public TestName testName = new TestName(); private List allVertices = new ArrayList<>(); private boolean isInitialized = false; - @javax.annotation.Resource private ToscaElementOperationTestImpl toscaElementOperation; - @javax.annotation.Resource private JanusGraphDao janusGraphDao; - @BeforeClass + @BeforeAll public static void initTest() { ModelTestBase.init(); } - @Rule - public TestName testName = new TestName(); - - @Before + @BeforeEach public void beforeTest() { if (!isInitialized) { GraphTestUtils.clearGraph(janusGraphDao); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadePoliciesTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadePoliciesTest.java index d60a574064..3cb2208c30 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadePoliciesTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacadePoliciesTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,16 +20,25 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertTrue; + import fj.data.Either; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.config.JanusGraphSpringConfig; +import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphDao; import org.openecomp.sdc.be.datatypes.elements.PolicyTargetType; import org.openecomp.sdc.be.model.Component; import org.openecomp.sdc.be.model.ComponentParametersView; @@ -38,22 +47,9 @@ import org.openecomp.sdc.be.model.PolicyDefinition; import org.openecomp.sdc.be.model.config.ModelOperationsSpringConfig; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) +@SpringJUnitConfig(classes = {JanusGraphSpringConfig.class, ModelOperationsSpringConfig.class}) public class ToscaOperationFacadePoliciesTest extends ModelTestBase { @Autowired @@ -63,12 +59,12 @@ public class ToscaOperationFacadePoliciesTest extends ModelTestBase { private PolicyDefinition policy1, policy2; - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void setUp() throws Exception { policy1 = createPolicyDefinition("type1"); policy2 = createPolicyDefinition("type2"); @@ -76,7 +72,7 @@ public class ToscaOperationFacadePoliciesTest extends ModelTestBase { createPoliciesOnGraph(policy1, policy2); } - private void createPoliciesOnGraph(PolicyDefinition ... policies) { + private void createPoliciesOnGraph(PolicyDefinition... policies) { for (int i = 0; i < policies.length; i++) { PolicyDefinition policy = policies[i]; Either createdPolicy = toscaOperationFacade.associatePolicyToComponent(CONTAINER_ID, policy, i); @@ -84,7 +80,7 @@ public class ToscaOperationFacadePoliciesTest extends ModelTestBase { } } - @After + @AfterEach public void tearDown() { janusGraphDao.rollback(); } @@ -117,14 +113,15 @@ public class ToscaOperationFacadePoliciesTest extends ModelTestBase { private PolicyDefinition clonePolicyWithTargets(PolicyDefinition policy) { PolicyDefinition originalPolicy = new PolicyDefinition(policy); - Map> clonedTargetMap = policy.getTargets().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> new ArrayList<>(entry.getValue()))); + Map> clonedTargetMap = policy.getTargets().entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> new ArrayList<>(entry.getValue()))); originalPolicy.setTargets(clonedTargetMap); return originalPolicy; } private void verifyPolicyTargets(PolicyDefinition updatedPolicy, PolicyDefinition expectedPolicy) { assertThat(updatedPolicy.getTargets()) - .isEqualTo(expectedPolicy.getTargets()); + .isEqualTo(expectedPolicy.getTargets()); } private void updatePolicyTypeTargetsIds(PolicyDefinition policy, PolicyTargetType targetType, List updatedTargetIds) { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/UpgradeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/UpgradeOperationTest.java index 1494f206f6..6a069a04b9 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/UpgradeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/UpgradeOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,12 +20,16 @@ package org.openecomp.sdc.be.model.jsonjanusgraph.operations; +import static org.assertj.core.api.Assertions.assertThat; + import fj.data.Either; +import java.util.ArrayList; +import java.util.List; +import javax.annotation.Resource; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.jsongraph.utils.IdBuilderUtils; @@ -33,7 +37,11 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.ComponentDependency; +import org.openecomp.sdc.be.model.ComponentInstance; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.ModelTestBase; +import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; @@ -41,17 +49,9 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils; import org.openecomp.sdc.be.model.operations.api.IElementOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.UserAdminOperation; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class UpgradeOperationTest extends ModelTestBase { private boolean isInitialized; @@ -64,7 +64,7 @@ public class UpgradeOperationTest extends ModelTestBase { @Resource private NodeTemplateOperation nodeTemplateOperation; @Resource - private UserAdminOperation userAdminOperation; + private UserAdminOperation userAdminOperation; @javax.annotation.Resource private IElementOperation elementOperation; @@ -72,14 +72,14 @@ public class UpgradeOperationTest extends ModelTestBase { private CategoryDefinition resourceCategory; private CategoryDefinition serviceCategory; - - @BeforeClass + + @BeforeAll public static void initTest() { ModelTestBase.init(); } - @Before + @BeforeEach public void beforeTest() { if (!isInitialized) { GraphTestUtils.clearGraph(janusGraphDao); @@ -90,22 +90,21 @@ public class UpgradeOperationTest extends ModelTestBase { @Test public void testGetSimpleDependency() { - + TopologyTemplate vf = createVf("vf1"); - + TopologyTemplate service = createServiceWitnInstance("service1", vf); - Either, StorageOperationStatus> result = upgradeOperation.getComponentDependencies(vf.getUniqueId()); assertThat(result.isLeft()).isTrue(); List dependencies = result.left().value(); assertThat(dependencies).hasSize(1); - + ComponentDependency dependency = dependencies.get(0); assertThat(dependency.getName()).isEqualTo(vf.getName()); assertThat(dependency.getVersion()).isEqualTo(vf.getVersion()); assertThat(dependency.getDependencies()).hasSize(1); - + ComponentDependency container = dependency.getDependencies().get(0); assertThat(container.getName()).isEqualTo(service.getName()); assertThat(container.getVersion()).isEqualTo(service.getVersion()); @@ -123,12 +122,12 @@ public class UpgradeOperationTest extends ModelTestBase { GraphTestUtils.createRootCatalogVertex(janusGraphDao); resourceCategory = createResourceCategories(); - serviceCategory = createServiceCategory(); - + serviceCategory = createServiceCategory(); + } private TopologyTemplate createServiceWitnInstance(String name, TopologyTemplate createdVf) { - + TopologyTemplate serviceNew = createTopologyTemplate(ComponentTypeEnum.SERVICE, name); List categoriesService = new ArrayList<>(); categoriesService.add(serviceCategory); @@ -136,12 +135,13 @@ public class UpgradeOperationTest extends ModelTestBase { Either createService = topologyTemplateOperation.createTopologyTemplate(serviceNew); assertThat(createService.isLeft()).isTrue(); - + ComponentInstance vfInstance = new ComponentInstance(); vfInstance.setUniqueId(createdVf.getUniqueId() + createdVf.getName()); vfInstance.setComponentUid(createdVf.getUniqueId()); vfInstance.setName(createdVf.getName()); - Either, StorageOperationStatus> addInstance = nodeTemplateOperation.addComponentInstanceToTopologyTemplate(serviceNew, createdVf, "0", vfInstance, false, user); + Either, StorageOperationStatus> addInstance = nodeTemplateOperation.addComponentInstanceToTopologyTemplate( + serviceNew, createdVf, "0", vfInstance, false, user); assertThat(addInstance.isLeft()).isTrue(); return serviceNew; } @@ -151,14 +151,14 @@ public class UpgradeOperationTest extends ModelTestBase { categoryService.setName("servicecategory"); categoryService.setNormalizedName("servicecategory"); categoryService.setUniqueId("servicecategory"); - Either createCategory = elementOperation.createCategory(categoryService , NodeTypeEnum.ServiceNewCategory); - + Either createCategory = elementOperation.createCategory(categoryService, NodeTypeEnum.ServiceNewCategory); + assertThat(createCategory.isLeft()).isTrue(); return categoryService; } private TopologyTemplate createVf(String name) { - + TopologyTemplate resource = createTopologyTemplate(ComponentTypeEnum.RESOURCE, name); resource.setResourceType(ResourceTypeEnum.VF); @@ -166,7 +166,7 @@ public class UpgradeOperationTest extends ModelTestBase { categories.add(resourceCategory); resource.setCategories(categories); Either createVf = topologyTemplateOperation.createTopologyTemplate(resource); - assertThat( createVf.isLeft()).isTrue(); + assertThat(createVf.isLeft()).isTrue(); return resource; } @@ -175,11 +175,11 @@ public class UpgradeOperationTest extends ModelTestBase { category.setName("category1"); category.setNormalizedName("category1"); category.setUniqueId("category1"); - Either createCategory = elementOperation.createCategory(category , NodeTypeEnum.ResourceNewCategory); + Either createCategory = elementOperation.createCategory(category, NodeTypeEnum.ResourceNewCategory); assertThat(createCategory.isLeft()).isTrue(); - + SubCategoryDefinition subCategory = new SubCategoryDefinition(); - + subCategory.setName("subcategory1"); subCategory.setNormalizedName("subcategory1"); subCategory.setUniqueId("subcategory1"); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperationTest.java index 169a844e3a..b61ff3224b 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AdditionalInformationOperationTest.java @@ -20,16 +20,21 @@ package org.openecomp.sdc.be.model.operations.impl; -import org.janusgraph.core.JanusGraphEdge; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.core.JanusGraphVertex; -import fj.data.Either; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import fj.data.Either; +import java.util.Iterator; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphEdge; +import org.janusgraph.core.JanusGraphVertex; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; @@ -40,20 +45,11 @@ import org.openecomp.sdc.be.model.AdditionalInformationDefinition; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil; import org.openecomp.sdc.be.resources.data.UserData; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import java.util.Iterator; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class AdditionalInformationOperationTest extends ModelTestBase { + private static final JanusGraphGenericDao JANUS_GRAPH_GENERIC_DAO = mock(JanusGraphGenericDao.class); private static String USER_ID = "muUserId"; private static String CATEGORY_NAME = "category/mycategory"; @@ -66,20 +62,20 @@ public class AdditionalInformationOperationTest extends ModelTestBase { @javax.annotation.Resource(name = "additional-information-operation") private AdditionalInformationOperation additionalInformationOperation; - @Before - public void createUserAndCategory() { - deleteAndCreateCategory(CATEGORY_NAME); - deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID); - - } - - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } + @BeforeEach + public void createUserAndCategory() { + deleteAndCreateCategory(CATEGORY_NAME); + deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID); + + } + @Test public void testDummy() { @@ -88,24 +84,24 @@ public class AdditionalInformationOperationTest extends ModelTestBase { } @Test - public void testAddInfoParameter_InvalidId(){ + public void testAddInfoParameter_InvalidId() { Either result; String uid = "uid"; String componentId = "componentId"; - when(JANUS_GRAPH_GENERIC_DAO.getVertexByProperty(eq(uid),eq(componentId))).thenReturn(Either.left(janusGraphVertex)); + when(JANUS_GRAPH_GENERIC_DAO.getVertexByProperty(eq(uid), eq(componentId))).thenReturn(Either.left(janusGraphVertex)); result = additionalInformationOperation.addAdditionalInformationParameter - (NodeTypeEnum.Resource,componentId,"key","value"); + (NodeTypeEnum.Resource, componentId, "key", "value"); assertThat(result.isRight()); } @Test - public void testUpdateInfoParameter_InvalidId(){ + public void testUpdateInfoParameter_InvalidId() { Either result; String uid = "uid"; String componentId = "componentId"; - when(JANUS_GRAPH_GENERIC_DAO.getVertexByProperty(eq(uid),eq(componentId))).thenReturn(Either.left(janusGraphVertex)); + when(JANUS_GRAPH_GENERIC_DAO.getVertexByProperty(eq(uid), eq(componentId))).thenReturn(Either.left(janusGraphVertex)); result = additionalInformationOperation.updateAdditionalInformationParameter - (NodeTypeEnum.Resource,componentId,"id","key","value"); + (NodeTypeEnum.Resource, componentId, "id", "key", "value"); assertTrue(result.isRight()); } @@ -119,7 +115,7 @@ public class AdditionalInformationOperationTest extends ModelTestBase { v1.property("uid", componentId); v1.property(GraphPropertiesDictionary.LABEL.getProperty(), "resource"); JanusGraphVertex v2 = graph.addVertex(); - v2.property(id,id); + v2.property(id, id); JanusGraphEdge addEdge = v1.addEdge(GraphEdgeLabels.ADDITIONAL_INFORMATION.getProperty(), v2); addEdge.property("edgeProp", "resource"); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AnnotationTypeOperationsTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AnnotationTypeOperationsTest.java index df164b9d31..8919f2c6ec 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AnnotationTypeOperationsTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/AnnotationTypeOperationsTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,27 +20,24 @@ package org.openecomp.sdc.be.model.operations.impl; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; + +import javax.annotation.Resource; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.model.AnnotationTypeDefinition; import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.utils.TypeUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import javax.annotation.Resource; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class AnnotationTypeOperationsTest extends ModelTestBase { static final String TYPE = "org.openecomp.annotations.source"; @@ -60,18 +57,18 @@ public class AnnotationTypeOperationsTest extends ModelTestBase { private PropertyDefinition prop1, prop2; private AnnotationTypeDefinition initialAnnotationDefinition; - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void initTestData() { removeGraphVertices(janusGraphGenericDao.getGraph()); prop1 = createSimpleProperty("val1", "prop1", "string"); } - @After + @AfterEach public void tearDown() { janusGraphGenericDao.rollback(); } @@ -83,14 +80,14 @@ public class AnnotationTypeOperationsTest extends ModelTestBase { AnnotationTypeDefinition result = annotationTypeOperations.addType(initialAnnotationDefinition); assertThat(result.getUniqueId()).isNotEmpty(); assertThat(result) - .isEqualToComparingOnlyGivenFields(initialAnnotationDefinition, "description", "type"); + .isEqualToComparingOnlyGivenFields(initialAnnotationDefinition, "description", "type"); assertThat(result.getProperties()) - .usingElementComparatorOnFields("defaultValue", "name", "type") - .containsExactlyInAnyOrder(prop1); + .usingElementComparatorOnFields("defaultValue", "name", "type") + .containsExactlyInAnyOrder(prop1); assertThat(result.isHighestVersion()).isTrue(); } - @Test + @Test public void testGetLatestType_TypeDoesntExist_shouldReturnNull() { AnnotationTypeDefinition latestType = annotationTypeOperations.getLatestType(TYPE); assertThat(latestType).isNull(); @@ -155,8 +152,8 @@ public class AnnotationTypeOperationsTest extends ModelTestBase { AnnotationTypeDefinition updatedType = annotationTypeOperations.updateType(initialAnnotationDefinition, advancedDefinition); assertThat(updatedType.getDescription()).isEqualTo(NEW_DESCRIPTION); assertThat(updatedType.getProperties()) - .usingElementComparatorOnFields("defaultValue", "name", "type") - .containsExactlyInAnyOrder(prop1, prop2); + .usingElementComparatorOnFields("defaultValue", "name", "type") + .containsExactlyInAnyOrder(prop1, prop2); } @Test @@ -166,8 +163,8 @@ public class AnnotationTypeOperationsTest extends ModelTestBase { AnnotationTypeDefinition advancedDefinition = buildAnnotationDefinition(DESCRIPTION, TYPE, prop2); AnnotationTypeDefinition updatedType = annotationTypeOperations.updateType(initialAnnotationDefinition, advancedDefinition); assertThat(updatedType.getProperties()) - .usingElementComparatorOnFields("defaultValue", "name", "type") - .containsExactlyInAnyOrder(prop2); + .usingElementComparatorOnFields("defaultValue", "name", "type") + .containsExactlyInAnyOrder(prop2); } @Test @@ -178,34 +175,38 @@ public class AnnotationTypeOperationsTest extends ModelTestBase { AnnotationTypeDefinition advancedDefinition = buildAnnotationDefinition(DESCRIPTION, TYPE, prop2); AnnotationTypeDefinition updatedType = annotationTypeOperations.updateType(initialAnnotationDefinition, advancedDefinition); assertThat(updatedType.getProperties()) - .usingElementComparatorOnFields("defaultValue", "name", "type", "description") - .containsExactlyInAnyOrder(prop2); + .usingElementComparatorOnFields("defaultValue", "name", "type", "description") + .containsExactlyInAnyOrder(prop2); } - @Test(expected = StorageException.class) + @Test public void testUpdateType_propertyTypeModification_shouldFail() { + Assertions.assertThrows(StorageException.class,()->{ addAnnotationType(); prop2 = createSimpleProperty("val1", "prop1", "int"); AnnotationTypeDefinition advancedDefinition = buildAnnotationDefinition(DESCRIPTION, TYPE, prop2); annotationTypeOperations.updateType(initialAnnotationDefinition, advancedDefinition); + }); } - @Test(expected = StorageException.class) + @Test public void testUpdateType_propertyRemoved_shouldFail() { - addAnnotationType(); - prop2 = createSimpleProperty("val1", "prop2", "int"); - AnnotationTypeDefinition advancedDefinition = buildAnnotationDefinition(DESCRIPTION, TYPE, prop2); - annotationTypeOperations.updateType(initialAnnotationDefinition, advancedDefinition); + Assertions.assertThrows(StorageException.class,()->{ + addAnnotationType(); + prop2 = createSimpleProperty("val1", "prop2", "int"); + AnnotationTypeDefinition advancedDefinition = buildAnnotationDefinition(DESCRIPTION, TYPE, prop2); + annotationTypeOperations.updateType(initialAnnotationDefinition, advancedDefinition); + }); } private void prepareInitialType() { initialAnnotationDefinition = buildAnnotationDefinition(DESCRIPTION, - TYPE, - prop1); + TYPE, + prop1); initialAnnotationDefinition.setVersion(TypeUtils.getFirstCertifiedVersionVersion()); } - private AnnotationTypeDefinition buildAnnotationDefinition(String description, String type, PropertyDefinition ... properties) { + private AnnotationTypeDefinition buildAnnotationDefinition(String description, String type, PropertyDefinition... properties) { AnnotationTypeDefinition annotationTypeDefinition = new AnnotationTypeDefinition(); annotationTypeDefinition.setDescription(description); annotationTypeDefinition.setType(type); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java index d6414c5f25..25e1f28612 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ArtifactOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,55 +20,56 @@ package org.openecomp.sdc.be.model.operations.impl; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import fj.data.Either; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; -import org.openecomp.sdc.be.model.*; +import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.HeatParameterDefinition; +import org.openecomp.sdc.be.model.ModelTestBase; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.util.OperationTestsUtil; -import org.openecomp.sdc.be.resources.data.*; +import org.openecomp.sdc.be.resources.data.ArtifactData; +import org.openecomp.sdc.be.resources.data.HeatParameterData; +import org.openecomp.sdc.be.resources.data.ResourceMetadataData; +import org.openecomp.sdc.be.resources.data.UniqueIdData; +import org.openecomp.sdc.be.resources.data.UserData; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import static org.junit.Assert.*; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class ArtifactOperationTest extends ModelTestBase { private static final String ARTIFACT_NAME = "myHeatArtifact"; - + private static final String RESOURCE_ID = "resourceId"; + private static final String RESOURCE_ID_2 = "resourceId2"; + private static final String USER_ID = "muUserId"; @javax.annotation.Resource(name = "janusgraph-generic-dao") private JanusGraphGenericDao janusGraphDao; - @javax.annotation.Resource private ArtifactOperation artifactOperation; - private static final String RESOURCE_ID = "resourceId"; - private static final String RESOURCE_ID_2 = "resourceId2"; - - private static final String USER_ID = "muUserId"; - - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void createUserAndCategory() { String CATEGORY_NAME = "category/mycategory"; deleteAndCreateCategory(CATEGORY_NAME); @@ -84,17 +85,21 @@ public class ArtifactOperationTest extends ModelTestBase { assertEquals(1, heatParameters.size()); HeatParameterDefinition parameter = heatParameters.get(0); HeatParameterData parameterData = new HeatParameterData(parameter); - Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNode.isLeft()); - Either removeArifact = artifactOperation.removeArifactFromResource(RESOURCE_ID, artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, true, false); + Either removeArifact = artifactOperation.removeArifactFromResource(RESOURCE_ID, + artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, true, false); assertTrue(removeArifact.isLeft()); ArtifactData artifactData = new ArtifactData(artifactWithHeat); - Either artifactAfterDelete = janusGraphDao.getNode(artifactData.getUniqueIdKey(), artifactData.getUniqueId(), ArtifactData.class); + Either artifactAfterDelete = janusGraphDao.getNode(artifactData.getUniqueIdKey(), + artifactData.getUniqueId(), ArtifactData.class); assertTrue(artifactAfterDelete.isRight()); - Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNodeAfterDelete.isRight()); janusGraphDao.deleteNode(new UniqueIdData(NodeTypeEnum.Resource, RESOURCE_ID), ResourceMetadataData.class); @@ -109,7 +114,8 @@ public class ArtifactOperationTest extends ModelTestBase { assertEquals(1, heatParameters.size()); HeatParameterDefinition parameter = heatParameters.get(0); HeatParameterData parameterData = new HeatParameterData(parameter); - Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNode.isLeft()); // update to artifact without params @@ -119,17 +125,20 @@ public class ArtifactOperationTest extends ModelTestBase { artifactNoParams.setArtifactVersion("2"); artifactNoParams.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); - Either updateArifact = artifactOperation.updateArifactOnResource(artifactNoParams, RESOURCE_ID, artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, false); + Either updateArifact = artifactOperation.updateArifactOnResource(artifactNoParams, RESOURCE_ID, + artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, false); assertTrue(updateArifact.isLeft()); ArtifactData artifactData = new ArtifactData(artifactWithHeat); - Either artifactAfterUpdate = janusGraphDao.getNode(artifactData.getUniqueIdKey(), artifactData.getUniqueId(), ArtifactData.class); + Either artifactAfterUpdate = janusGraphDao.getNode(artifactData.getUniqueIdKey(), + artifactData.getUniqueId(), ArtifactData.class); assertTrue(artifactAfterUpdate.isLeft()); ArtifactData artifactAfterUpdateValue = artifactAfterUpdate.left().value(); assertEquals(artifactNoParams.getArtifactVersion(), artifactAfterUpdateValue.getArtifactDataDefinition() - .getArtifactVersion()); + .getArtifactVersion()); - Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNodeAfterDelete.isRight()); artifactOperation.removeArifactFromResource(RESOURCE_ID, artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, true, false); @@ -147,7 +156,8 @@ public class ArtifactOperationTest extends ModelTestBase { assertEquals(1, heatParameters.size()); HeatParameterDefinition parameter = heatParameters.get(0); HeatParameterData parameterData = new HeatParameterData(parameter); - Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNode.isLeft()); // update to artifact without params @@ -155,17 +165,20 @@ public class ArtifactOperationTest extends ModelTestBase { artifactWithHeat.setArtifactChecksum(null); artifactWithHeat.setPayloadData(null); - Either updateArifact = artifactOperation.updateArifactOnResource(artifactWithHeat, RESOURCE_ID, artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, false); + Either updateArifact = artifactOperation.updateArifactOnResource(artifactWithHeat, RESOURCE_ID, + artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, false); assertTrue(updateArifact.isLeft()); ArtifactData artifactData = new ArtifactData(artifactWithHeat); - Either artifactAfterUpdate = janusGraphDao.getNode(artifactData.getUniqueIdKey(), artifactData.getUniqueId(), ArtifactData.class); + Either artifactAfterUpdate = janusGraphDao.getNode(artifactData.getUniqueIdKey(), + artifactData.getUniqueId(), ArtifactData.class); assertTrue(artifactAfterUpdate.isLeft()); ArtifactData artifactAfterUpdateValue = artifactAfterUpdate.left().value(); assertEquals(artifactWithHeat.getArtifactVersion(), artifactAfterUpdateValue.getArtifactDataDefinition() - .getArtifactVersion()); + .getArtifactVersion()); - Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNodeAfterDelete.isLeft()); artifactOperation.removeArifactFromResource(RESOURCE_ID_2, artifactAfterUpdateValue.getUniqueId(), NodeTypeEnum.Resource, true, false); @@ -181,7 +194,8 @@ public class ArtifactOperationTest extends ModelTestBase { ResourceMetadataData resource2 = createResource(RESOURCE_ID_2); Map props = new HashMap<>(); props.put(GraphEdgePropertiesDictionary.NAME.getProperty(), ArtifactGroupTypeEnum.DEPLOYMENT.name()); - Either createRelation = janusGraphDao.createRelation(resource2, new ArtifactData(artifactWithHeat), GraphEdgeLabels.ARTIFACT_REF, props); + Either createRelation = janusGraphDao.createRelation(resource2, new ArtifactData(artifactWithHeat), + GraphEdgeLabels.ARTIFACT_REF, props); assertTrue(createRelation.isLeft()); List heatParameters = artifactWithHeat.getListHeatParameters(); @@ -189,7 +203,8 @@ public class ArtifactOperationTest extends ModelTestBase { assertEquals(1, heatParameters.size()); HeatParameterDefinition parameter = heatParameters.get(0); HeatParameterData parameterData = new HeatParameterData(parameter); - Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNode = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNode.isLeft()); ArtifactDefinition atifactToUpdate = new ArtifactDefinition(artifactWithHeat); @@ -205,28 +220,32 @@ public class ArtifactOperationTest extends ModelTestBase { heatParametersUpdated.add(heatParamUpdate); atifactToUpdate.setListHeatParameters(heatParametersUpdated); - Either updateArifact = artifactOperation.updateArifactOnResource(atifactToUpdate, RESOURCE_ID_2, atifactToUpdate.getUniqueId(), NodeTypeEnum.Resource, false); + Either updateArifact = artifactOperation.updateArifactOnResource(atifactToUpdate, RESOURCE_ID_2, + atifactToUpdate.getUniqueId(), NodeTypeEnum.Resource, false); assertTrue(updateArifact.isLeft()); // verify old artifact and parameter still exist ArtifactData artifactData = new ArtifactData(artifactWithHeat); - Either origArtifact = janusGraphDao.getNode(artifactData.getUniqueIdKey(), artifactData.getUniqueId(), ArtifactData.class); + Either origArtifact = janusGraphDao.getNode(artifactData.getUniqueIdKey(), + artifactData.getUniqueId(), ArtifactData.class); assertTrue(origArtifact.isLeft()); ArtifactData origArtifactData = origArtifact.left().value(); assertEquals(artifactWithHeat.getArtifactVersion(), origArtifactData.getArtifactDataDefinition() - .getArtifactVersion()); + .getArtifactVersion()); - Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); + Either parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), + parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNodeAfterDelete.isLeft()); // verify new artifact and new parameter ArtifactDefinition artifactDefinitionUpdated = updateArifact.left().value(); ArtifactData artifactDataUpdated = new ArtifactData(artifactDefinitionUpdated); - Either updatedArtifact = janusGraphDao.getNode(artifactDataUpdated.getUniqueIdKey(), artifactDataUpdated.getUniqueId(), ArtifactData.class); + Either updatedArtifact = janusGraphDao.getNode(artifactDataUpdated.getUniqueIdKey(), + artifactDataUpdated.getUniqueId(), ArtifactData.class); assertTrue(updatedArtifact.isLeft()); ArtifactData updatedArtifactData = updatedArtifact.left().value(); assertEquals(atifactToUpdate.getArtifactVersion(), updatedArtifactData.getArtifactDataDefinition() - .getArtifactVersion()); + .getArtifactVersion()); assertFalse(updatedArtifactData.getUniqueId().equalsIgnoreCase(origArtifactData.getUniqueId())); List heatParametersAfterUpdate = artifactDefinitionUpdated.getListHeatParameters(); @@ -234,11 +253,13 @@ public class ArtifactOperationTest extends ModelTestBase { assertEquals(1, heatParametersAfterUpdate.size()); HeatParameterDefinition UpdatedHeatParameter = heatParametersAfterUpdate.get(0); assertFalse(UpdatedHeatParameter.getUniqueId().equalsIgnoreCase(parameterData.getUniqueId())); - Either parameterNodeAfterUpdate = janusGraphDao.getNode(new HeatParameterData(UpdatedHeatParameter).getUniqueIdKey(), UpdatedHeatParameter.getUniqueId(), HeatParameterData.class); + Either parameterNodeAfterUpdate = janusGraphDao.getNode( + new HeatParameterData(UpdatedHeatParameter).getUniqueIdKey(), UpdatedHeatParameter.getUniqueId(), HeatParameterData.class); assertTrue(parameterNodeAfterUpdate.isLeft()); // delete new artifact - Either removeArifact = artifactOperation.removeArifactFromResource(RESOURCE_ID_2, artifactDefinitionUpdated.getUniqueId(), NodeTypeEnum.Resource, true, false); + Either removeArifact = artifactOperation.removeArifactFromResource(RESOURCE_ID_2, + artifactDefinitionUpdated.getUniqueId(), NodeTypeEnum.Resource, true, false); assertTrue(removeArifact.isLeft()); // verify old artifact and parameter still exist @@ -246,16 +267,18 @@ public class ArtifactOperationTest extends ModelTestBase { assertTrue(origArtifact.isLeft()); origArtifactData = origArtifact.left().value(); assertEquals(artifactWithHeat.getArtifactVersion(), origArtifactData.getArtifactDataDefinition() - .getArtifactVersion()); + .getArtifactVersion()); parameterNodeAfterDelete = janusGraphDao.getNode(parameterData.getUniqueIdKey(), parameterData.getUniqueId(), HeatParameterData.class); assertTrue(parameterNodeAfterDelete.isLeft()); // verify new artifact is deleted - Either artifactAfterDelete = janusGraphDao.getNode(artifactDataUpdated.getUniqueIdKey(), artifactDataUpdated.getUniqueId(), ArtifactData.class); + Either artifactAfterDelete = janusGraphDao.getNode(artifactDataUpdated.getUniqueIdKey(), + artifactDataUpdated.getUniqueId(), ArtifactData.class); assertTrue(artifactAfterDelete.isRight()); - parameterNodeAfterDelete = janusGraphDao.getNode(new HeatParameterData(UpdatedHeatParameter).getUniqueIdKey(), new HeatParameterData(UpdatedHeatParameter).getUniqueId(), HeatParameterData.class); + parameterNodeAfterDelete = janusGraphDao.getNode(new HeatParameterData(UpdatedHeatParameter).getUniqueIdKey(), + new HeatParameterData(UpdatedHeatParameter).getUniqueId(), HeatParameterData.class); assertTrue(parameterNodeAfterDelete.isRight()); artifactOperation.removeArifactFromResource(RESOURCE_ID, artifactWithHeat.getUniqueId(), NodeTypeEnum.Resource, true, false); @@ -279,7 +302,8 @@ public class ArtifactOperationTest extends ModelTestBase { heatParams.add(heatParam); artifactDefinition.setListHeatParameters(heatParams); - Either artifact = artifactOperation.addArifactToComponent(artifactDefinition, RESOURCE_ID, NodeTypeEnum.Resource, true, false); + Either artifact = artifactOperation.addArifactToComponent(artifactDefinition, RESOURCE_ID, + NodeTypeEnum.Resource, true, false); assertTrue(artifact.isLeft()); return artifact.left().value(); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java index 6ed482f948..8b8e813501 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/CapabilityTypeOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -25,8 +25,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import org.janusgraph.core.JanusGraph; -import org.janusgraph.core.JanusGraphVertex; import fj.data.Either; import java.util.ArrayList; import java.util.HashMap; @@ -39,14 +37,15 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.Resource; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphVertex; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; -import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels; import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.model.CapabilityTypeDefinition; @@ -60,14 +59,9 @@ import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint; import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint; import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint; import org.openecomp.sdc.be.resources.data.CapabilityTypeData; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class CapabilityTypeOperationTest extends ModelTestBase { @Resource(name = "janusgraph-generic-dao") @@ -75,16 +69,20 @@ public class CapabilityTypeOperationTest extends ModelTestBase { @Resource(name = "capability-type-operation") private CapabilityTypeOperation capabilityTypeOperation; - + @Resource(name = "model-operation") private ModelOperation modelOperation; - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - - @Before + + private static Map asMap(PropertyDefinition... props) { + return Stream.of(props).collect(Collectors.toMap(PropertyDefinition::getName, Function.identity())); + } + + @BeforeEach public void cleanUp() { HealingJanusGraphGenericDao janusGraphGenericDao = capabilityTypeOperation.janusGraphGenericDao; Either graphResult = janusGraphGenericDao.getGraph(); @@ -114,21 +112,24 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeDefinition.setDescription("desc1"); capabilityTypeDefinition.setType("tosca.capabilities.Container1"); - Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); + Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType( + capabilityTypeDefinition, true); assertTrue("check capability type added", addCapabilityType1.isLeft()); CapabilityTypeDefinition capabilityTypeAdded = addCapabilityType1.left().value(); compareBetweenCreatedToSent(capabilityTypeDefinition, capabilityTypeAdded); - Either capabilityTypeByUid = capabilityTypeOperation.getCapabilityTypeByUid(capabilityTypeAdded.getUniqueId()); + Either capabilityTypeByUid = capabilityTypeOperation.getCapabilityTypeByUid( + capabilityTypeAdded.getUniqueId()); compareBetweenCreatedToSent(capabilityTypeByUid.left().value(), capabilityTypeDefinition); - Either addCapabilityType2 = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); + Either addCapabilityType2 = capabilityTypeOperation.addCapabilityType( + capabilityTypeDefinition, true); assertTrue("check capability type failed", addCapabilityType2.isRight()); assertEquals("check returned error", StorageOperationStatus.SCHEMA_VIOLATION, addCapabilityType2.right().value()); } - + @Test public void testAddCapabilityTypeWithModel() { @@ -136,28 +137,31 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeDefinition.setDescription("desc1"); capabilityTypeDefinition.setType("tosca.capabilities.Container1"); capabilityTypeDefinition.setModel("testModel"); - + Model model = new Model("testModel", ModelTypeEnum.NORMATIVE); - modelOperation.createModel(model , true); + modelOperation.createModel(model, true); - Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); + Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType( + capabilityTypeDefinition, true); assertTrue("check capability type added", addCapabilityType1.isLeft()); CapabilityTypeDefinition capabilityTypeAdded = addCapabilityType1.left().value(); compareBetweenCreatedToSent(capabilityTypeDefinition, capabilityTypeAdded); - Either capabilityTypeByUid = capabilityTypeOperation.getCapabilityTypeByUid(capabilityTypeAdded.getUniqueId()); + Either capabilityTypeByUid = capabilityTypeOperation.getCapabilityTypeByUid( + capabilityTypeAdded.getUniqueId()); compareBetweenCreatedToSent(capabilityTypeByUid.left().value(), capabilityTypeDefinition); - + CapabilityTypeDefinition capabilityTypeWithDerivedFrom = new CapabilityTypeDefinition(); capabilityTypeWithDerivedFrom.setDescription("desc2"); capabilityTypeWithDerivedFrom.setType("tosca.capabilities.Container2"); capabilityTypeWithDerivedFrom.setDerivedFrom("tosca.capabilities.Container1"); capabilityTypeWithDerivedFrom.setModel("testModel"); - Either addCapabilityType2 = capabilityTypeOperation.addCapabilityType(capabilityTypeWithDerivedFrom, true); + Either addCapabilityType2 = capabilityTypeOperation.addCapabilityType( + capabilityTypeWithDerivedFrom, true); assertTrue("check capability type added", addCapabilityType2.isLeft()); - + capabilityTypeAdded = addCapabilityType2.left().value(); compareBetweenCreatedToSent(capabilityTypeWithDerivedFrom, capabilityTypeAdded); @@ -168,7 +172,8 @@ public class CapabilityTypeOperationTest extends ModelTestBase { CapabilityTypeDefinition capabilityTypeDefinition = createCapabilityTypeDef("tosca.capabilities.Container2", "desc1", "derivedFrom"); - Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); + Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType( + capabilityTypeDefinition, true); // assertEquals("check capability type parent not exist", // StorageOperationStatus.INVALID_ID, // addCapabilityType1.right().value()); @@ -197,10 +202,12 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeDefinition.setProperties(properties); - Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); + Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType( + capabilityTypeDefinition, true); CapabilityTypeDefinition capabilityTypeDefinitionCreated = addCapabilityType1.left().value(); - Either capabilityType = capabilityTypeOperation.getCapabilityType(capabilityTypeDefinitionCreated.getUniqueId(), true); + Either capabilityType = capabilityTypeOperation.getCapabilityType( + capabilityTypeDefinitionCreated.getUniqueId(), true); assertTrue("check capability type fetched", capabilityType.isLeft()); CapabilityTypeDefinition fetchedCTD = capabilityType.left().value(); @@ -234,10 +241,12 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeDefinition.setProperties(properties); - Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); + Either addCapabilityType1 = capabilityTypeOperation.addCapabilityType( + capabilityTypeDefinition, true); CapabilityTypeDefinition capabilityTypeDefinitionCreated = addCapabilityType1.left().value(); - Either capabilityType = capabilityTypeOperation.getCapabilityType(capabilityTypeDefinitionCreated.getUniqueId()); + Either capabilityType = capabilityTypeOperation.getCapabilityType( + capabilityTypeDefinitionCreated.getUniqueId()); assertTrue("check capability type fetched", capabilityType.isLeft()); CapabilityTypeDefinition fetchedCTD = capabilityType.left().value(); @@ -274,14 +283,13 @@ public class CapabilityTypeOperationTest extends ModelTestBase { assertEquals("check not found is returned", StorageOperationStatus.NOT_FOUND, capabilityType.right().value()); } - - - + @Test public void updateCapabilityType_returnNotFoundErrorIfTryingToUpdateANonExistingType() { CapabilityTypeDefinition currType = createCapabilityTypeDef(); CapabilityTypeDefinition updatedType = createCapabilityTypeDef(); - Either updateCapabilityTypeRes = capabilityTypeOperation.updateCapabilityType(updatedType, currType); + Either updateCapabilityTypeRes = capabilityTypeOperation.updateCapabilityType(updatedType, + currType); assertThat(updateCapabilityTypeRes.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND); } @@ -293,7 +301,8 @@ public class CapabilityTypeOperationTest extends ModelTestBase { CapabilityTypeDefinition updatedType = createCapabilityTypeDef("type1", "description2"); capabilityTypeOperation.updateCapabilityType(updatedType, currCapabilityType.left().value()); - Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType(createdType.getType()); + Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType( + createdType.getType()); CapabilityTypeDefinition fetchedCapabilityType = fetchedUpdatedType.left().value(); assertThat(fetchedCapabilityType.getProperties()).isNullOrEmpty(); assertThat(fetchedCapabilityType.getDerivedFrom()).isNullOrEmpty(); @@ -314,17 +323,18 @@ public class CapabilityTypeOperationTest extends ModelTestBase { PropertyDefinition prop3 = createSimpleProperty("val3", "prop3", "string"); CapabilityTypeDefinition updatedCapabilityType = createCapabilityTypeDef(asMap(updatedProp1, prop3)); - Either updatedCapabilityTypeRes = - capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); - + Either updatedCapabilityTypeRes = + capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); + assertTrue(updatedCapabilityTypeRes.isRight()); assertEquals(StorageOperationStatus.MATCH_NOT_FOUND, updatedCapabilityTypeRes.right().value()); - Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType(capabilityType.getType()); + Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType( + capabilityType.getType()); assertEquals(fetchedUpdatedType.left().value().getProperties(), asMap(prop1)); } - + @Test public void updateCapabilityType_updatePropertiesFailedDueDeletedProp() { PropertyDefinition prop1 = createSimpleProperty("val1", "prop1", "string"); @@ -334,17 +344,18 @@ public class CapabilityTypeOperationTest extends ModelTestBase { PropertyDefinition prop3 = createSimpleProperty("val3", "prop3", "string"); CapabilityTypeDefinition updatedCapabilityType = createCapabilityTypeDef(asMap(prop3)); - Either updatedCapabilityTypeRes = - capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); - + Either updatedCapabilityTypeRes = + capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); + assertTrue(updatedCapabilityTypeRes.isRight()); assertEquals(StorageOperationStatus.MATCH_NOT_FOUND, updatedCapabilityTypeRes.right().value()); - Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType(capabilityType.getType()); + Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType( + capabilityType.getType()); assertEquals(fetchedUpdatedType.left().value().getProperties(), asMap(prop1)); } - + @Test public void updateCapabilityType_updateProperties() { PropertyDefinition prop1 = createSimpleProperty("val1", "prop1", "string"); @@ -355,11 +366,12 @@ public class CapabilityTypeOperationTest extends ModelTestBase { PropertyDefinition prop3 = createSimpleProperty("val3", "prop3", "string"); CapabilityTypeDefinition updatedCapabilityType = createCapabilityTypeDef(asMap(updatedProp1, prop3)); - Either updatedCapabilityTypeRes = - capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); + Either updatedCapabilityTypeRes = + capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); assertTrue(updatedCapabilityTypeRes.isLeft()); - - Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType(capabilityType.getType()); + + Either fetchedUpdatedType = capabilityTypeOperation.getCapabilityType( + capabilityType.getType()); assertEquals(fetchedUpdatedType.left().value().getProperties(), asMap(updatedProp1, prop3)); } @@ -373,7 +385,8 @@ public class CapabilityTypeOperationTest extends ModelTestBase { Either currCapabilityType = capabilityTypeOperation.addCapabilityType(capabilityType1); capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); - Either latestCapabilityType = capabilityTypeOperation.getCapabilityType(capabilityType1.getType()); + Either latestCapabilityType = capabilityTypeOperation.getCapabilityType( + capabilityType1.getType()); assertThat(latestCapabilityType.left().value().getDerivedFrom()).isEqualTo(rootCapabilityType.getType()); verifyDerivedFromNodeEqualsToRootCapabilityType(rootCapabilityType, latestCapabilityType.left().value().getUniqueId()); } @@ -386,12 +399,13 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeOperation.addCapabilityType(rootCapabilityType); Either currCapabilityType = capabilityTypeOperation.addCapabilityType(capabilityType1); - Either updateRes = - capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); - + Either updateRes = + capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); + assertThat(updateRes.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND); - Either latestCapabilityType = capabilityTypeOperation.getCapabilityType(capabilityType1.getType()); + Either latestCapabilityType = capabilityTypeOperation.getCapabilityType( + capabilityType1.getType()); assertThat(latestCapabilityType.left().value().getDerivedFrom()).isEqualTo(rootCapabilityType.getType()); } @@ -408,11 +422,12 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); - Either latestCapabilityType = capabilityTypeOperation.getCapabilityType(capabilityType1.getType()); + Either latestCapabilityType = capabilityTypeOperation.getCapabilityType( + capabilityType1.getType()); assertThat(latestCapabilityType.left().value().getDerivedFrom()).isEqualTo(derivedType1.getType()); verifyDerivedFromNodeEqualsToRootCapabilityType(derivedType1, latestCapabilityType.left().value().getUniqueId()); } - + @Test public void updateCapabilityType_updateDerivedFrom_Failed_NewParentIsNotChildOfOldOne() { CapabilityTypeDefinition rootCapabilityType = createCapabilityTypeDef(); @@ -424,23 +439,26 @@ public class CapabilityTypeOperationTest extends ModelTestBase { capabilityTypeOperation.addCapabilityType(notDerivedType); Either currCapabilityType = capabilityTypeOperation.addCapabilityType(capabilityType1); - Either result = capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, currCapabilityType.left().value()); + Either result = capabilityTypeOperation.updateCapabilityType(updatedCapabilityType, + currCapabilityType.left().value()); assertThat(result.right().value()).isEqualTo(StorageOperationStatus.CANNOT_UPDATE_EXISTING_ENTITY); - Either latestCapabilityType = capabilityTypeOperation.getCapabilityType(capabilityType1.getType()); + Either latestCapabilityType = capabilityTypeOperation.getCapabilityType( + capabilityType1.getType()); assertThat(latestCapabilityType.left().value().getDerivedFrom()).isEqualTo(rootCapabilityType.getType()); verifyDerivedFromNodeEqualsToRootCapabilityType(rootCapabilityType, latestCapabilityType.left().value().getUniqueId()); } - + private CapabilityTypeDefinition createCapabilityTypeDef() { - return createCapabilityTypeDef("tosca.capabilities.Root", "The TOSCA root Capability Type all other TOSCA base Capability Types derived from", null, new HashMap<>()); + return createCapabilityTypeDef("tosca.capabilities.Root", "The TOSCA root Capability Type all other TOSCA base Capability Types derived from", + null, new HashMap<>()); } private CapabilityTypeDefinition createCapabilityTypeDef(Map properties) { return createCapabilityTypeDef("tosca.capabilities.Root", - "The TOSCA root Capability Type all other TOSCA base Capability Types derived from", null, properties); + "The TOSCA root Capability Type all other TOSCA base Capability Types derived from", null, properties); } - + private CapabilityTypeDefinition createCapabilityTypeDef(String type, String description) { return createCapabilityTypeDef(type, description, null, null); } @@ -449,8 +467,8 @@ public class CapabilityTypeOperationTest extends ModelTestBase { return createCapabilityTypeDef(type, description, derivedFrom, null); } - - private CapabilityTypeDefinition createCapabilityTypeDef(String type, String description, String derivedFrom, Map properties) { + private CapabilityTypeDefinition createCapabilityTypeDef(String type, String description, String derivedFrom, + Map properties) { CapabilityTypeDefinition capabilityTypeDefinition = new CapabilityTypeDefinition(); capabilityTypeDefinition.setDescription(description); capabilityTypeDefinition.setType(type); @@ -470,15 +488,12 @@ public class CapabilityTypeOperationTest extends ModelTestBase { return updatedProp1; } - private static Map asMap(PropertyDefinition ... props) { - return Stream.of(props).collect(Collectors.toMap(PropertyDefinition::getName, Function.identity())); - } - private void verifyDerivedFromNodeEqualsToRootCapabilityType(CapabilityTypeDefinition rootCapabilityType, String parentCapabilityId) { - Either, JanusGraphOperationStatus> derivedFromRelation = janusGraphDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), parentCapabilityId, GraphEdgeLabels.DERIVED_FROM, - NodeTypeEnum.CapabilityType, CapabilityTypeData.class); + Either, JanusGraphOperationStatus> derivedFromRelation = janusGraphDao.getChild( + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.CapabilityType), parentCapabilityId, GraphEdgeLabels.DERIVED_FROM, + NodeTypeEnum.CapabilityType, CapabilityTypeData.class); assertThat(derivedFromRelation.left().value().getLeft().getCapabilityTypeDataDefinition()) - .isEqualToComparingFieldByField(rootCapabilityType); + .isEqualToComparingFieldByField(rootCapabilityType); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java index 19812e6d61..546506aa92 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -38,10 +38,9 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.tinkerpop.gremlin.structure.Edge; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphVertex; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; @@ -61,11 +60,9 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.tosca.ToscaType; import org.openecomp.sdc.be.resources.data.CapabilityTypeData; import org.openecomp.sdc.be.resources.data.GroupTypeData; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class GroupTypeOperationTest extends ModelTestBase { private static final String TOSCA_GROUPS_ROOT = "tosca.groups.Root"; @@ -73,22 +70,22 @@ public class GroupTypeOperationTest extends ModelTestBase { @Resource(name = "janusgraph-generic-dao") private HealingJanusGraphGenericDao janusGraphDao; - + @Resource(name = "capability-type-operation") private CapabilityTypeOperation capabilityTypeOperation; - + @Resource(name = "group-type-operation") private GroupTypeOperation groupTypeOperation; @Resource(name = "model-operation") private ModelOperation modelOperation; - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @After + @AfterEach public void tearDown() { janusGraphDao.rollback(); cleanUp(); @@ -105,8 +102,8 @@ public class GroupTypeOperationTest extends ModelTestBase { List allGroupTypesNoExclusion = groupTypeOperation.getAllGroupTypes(null, null); assertThat(allGroupTypesNoExclusion) - .usingElementComparatorOnFields("type", "icon", "name") - .containsExactlyInAnyOrder(rootGroupDefinition, type1, type2); + .usingElementComparatorOnFields("type", "icon", "name") + .containsExactlyInAnyOrder(rootGroupDefinition, type1, type2); } @Test @@ -120,45 +117,45 @@ public class GroupTypeOperationTest extends ModelTestBase { List allGroupTypes = groupTypeOperation.getAllGroupTypes(newHashSet("type1", "type2"), null); assertThat(allGroupTypes) - .usingElementComparatorOnFields("type") - .containsExactly(rootGroupDefinition); + .usingElementComparatorOnFields("type") + .containsExactly(rootGroupDefinition); } @Test public void groupTypeWithoutCapabilityCreated() { GroupTypeData rootNode = getOrCreateRootGroupTypeNode(); - + GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); groupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT); groupTypeDefinition.setDescription("groups l3-networks in network collection"); groupTypeDefinition.setType("org.openecomp.groups.NetworkCollection"); groupTypeDefinition.setVersion("1.0"); - + List properties = asList( - buildProperty("network_collection_type", "l3-network", "network collection type, defined with default value"), - buildProperty("network_collection_subtype", "sub-interface", "network collection subtype, defined with default value"), - buildProperty("network_collection_role", null, "network collection role"), - buildProperty("network_collection_description", null, "network collection description, free format text")); - - groupTypeDefinition.setProperties(properties ); - - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + buildProperty("network_collection_type", "l3-network", "network collection type, defined with default value"), + buildProperty("network_collection_subtype", "sub-interface", "network collection subtype, defined with default value"), + buildProperty("network_collection_role", null, "network collection role"), + buildProperty("network_collection_description", null, "network collection description, free format text")); + + groupTypeDefinition.setProperties(properties); + + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - + addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.NetworkCollection", "1.0", null); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - + Either groupTypeResult = janusGraphDao .getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupTypeDefinition.getType(), GroupTypeData.class); GroupTypeData groupTypeNode = extractVal(groupTypeResult); - + Either edgeResult = janusGraphDao .getEdgeByNodes(groupTypeNode, rootNode, GraphEdgeLabels.DERIVED_FROM); validate(edgeResult); } - + @Test public void groupTypeWithCapabilityAndPropsButCapTypeWithoutProps() { getOrCreateRootGroupTypeNode(); @@ -176,21 +173,20 @@ public class GroupTypeOperationTest extends ModelTestBase { Map mapCapabilities = new HashMap<>(); ComponentInstanceProperty property = new ComponentInstanceProperty( - buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance")); + buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance")); CapabilityDefinition capabilityDef = buildCapabilityDefintion(asList(property)); mapCapabilities.put("vlan_assignment", capabilityDef); groupTypeDefinition.setCapabilities(mapCapabilities); - List properties = asList( - buildProperty("vfc_instance_group_role", null, "role of this VFC group"), - buildProperty("vfc_parent_port_role", null, "common role of parent ports of VFCs in this group"), - buildProperty("network_collection_role", null, "network collection role assigned to this group"), - buildProperty("subinterface_role", null, "common role of subinterfaces of VFCs in this group, criteria the group is created")); + buildProperty("vfc_instance_group_role", null, "role of this VFC group"), + buildProperty("vfc_parent_port_role", null, "common role of parent ports of VFCs in this group"), + buildProperty("network_collection_role", null, "network collection role assigned to this group"), + buildProperty("subinterface_role", null, "common role of subinterfaces of VFCs in this group, criteria the group is created")); - groupTypeDefinition.setProperties(properties ); + groupTypeDefinition.setProperties(properties); - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue(addGroupTypeResult.isRight()); assertEquals(StorageOperationStatus.MATCH_NOT_FOUND, addGroupTypeResult.right().value()); } @@ -198,16 +194,16 @@ public class GroupTypeOperationTest extends ModelTestBase { @Test public void groupTypeWithCapabilityTypeAndEdgeCreated() { GroupTypeData rootNode = getOrCreateRootGroupTypeNode(); - + Map capTypeProperties = new HashMap<>(); capTypeProperties.put("vfc_instance_group_reference", - buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance")); + buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance")); CapabilityTypeDefinition capabilityTypeDef = createCapabilityType(capTypeProperties); Either capabilityTypeResult = janusGraphDao .getNode(GraphPropertiesDictionary.TYPE.getProperty(), capabilityTypeDef.getType(), CapabilityTypeData.class); extractVal(capabilityTypeResult); - + GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); groupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT); groupTypeDefinition.setDescription("groups l3-networks in network collection"); @@ -215,28 +211,27 @@ public class GroupTypeOperationTest extends ModelTestBase { Map mapCapabilities = new HashMap<>(); ComponentInstanceProperty property = new ComponentInstanceProperty( - buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance")); + buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance")); CapabilityDefinition capabilityDef = buildCapabilityDefintion(asList(property)); mapCapabilities.put("vlan_assignment", capabilityDef); groupTypeDefinition.setCapabilities(mapCapabilities); - - + List properties = asList( - buildProperty("vfc_instance_group_role", null, "role of this VFC group"), - buildProperty("vfc_parent_port_role", null, "common role of parent ports of VFCs in this group"), - buildProperty("network_collection_role", null, "network collection role assigned to this group"), - buildProperty("subinterface_role", null, "common role of subinterfaces of VFCs in this group, criteria the group is created")); - - groupTypeDefinition.setProperties(properties ); - - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + buildProperty("vfc_instance_group_role", null, "role of this VFC group"), + buildProperty("vfc_parent_port_role", null, "common role of parent ports of VFCs in this group"), + buildProperty("network_collection_role", null, "network collection role assigned to this group"), + buildProperty("subinterface_role", null, "common role of subinterfaces of VFCs in this group, criteria the group is created")); + + groupTypeDefinition.setProperties(properties); + + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - + Either groupTypeResult = janusGraphDao .getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupTypeDefinition.getType(), GroupTypeData.class); GroupTypeData groupTypeNode = extractVal(groupTypeResult); - + Either groupTypeDefResult = groupTypeOperation.getGroupTypeByUid(groupTypeNode.getUniqueId()); assertTrue(groupTypeDefResult.isLeft()); GroupTypeDefinition groupTypeDefinitionRetrieved = groupTypeDefResult.left().value(); @@ -247,17 +242,18 @@ public class GroupTypeOperationTest extends ModelTestBase { assertTrue(capabilityDefs.containsKey("vlan_assignment")); CapabilityDefinition updatedCapabilityDef = capabilityDefs.get("vlan_assignment"); assertEquals(2, updatedCapabilityDef.getProperties().size()); - + Either edgeDerivedFromResult = janusGraphDao .getEdgeByNodes(groupTypeNode, rootNode, GraphEdgeLabels.DERIVED_FROM); validate(edgeDerivedFromResult); } - + @Test public void groupTypeWithCapabilityTypeAndEdgeCreated_OverrideDefaultCapabilityTypeValue() { getOrCreateRootGroupTypeNode(); - PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance"); + PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, + "Ability to recognize capability per vfc instance group on vnf instance"); Map capTypeProperties = new HashMap<>(); capTypeProperties.put("vfc_instance_group_reference", property); @@ -278,16 +274,15 @@ public class GroupTypeOperationTest extends ModelTestBase { mapCapabilities.put("vlan_assignment", capabilityDef); groupTypeDefinition.setCapabilities(mapCapabilities); - List properties = asList( - buildProperty("vfc_instance_group_role", null, "role of this VFC group"), - buildProperty("vfc_parent_port_role", null, "common role of parent ports of VFCs in this group"), - buildProperty("network_collection_role", null, "network collection role assigned to this group"), - buildProperty("subinterface_role", null, "common role of subinterfaces of VFCs in this group, criteria the group is created")); + buildProperty("vfc_instance_group_role", null, "role of this VFC group"), + buildProperty("vfc_parent_port_role", null, "common role of parent ports of VFCs in this group"), + buildProperty("network_collection_role", null, "network collection role assigned to this group"), + buildProperty("subinterface_role", null, "common role of subinterfaces of VFCs in this group, criteria the group is created")); - groupTypeDefinition.setProperties(properties ); + groupTypeDefinition.setProperties(properties); - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); @@ -308,13 +303,14 @@ public class GroupTypeOperationTest extends ModelTestBase { assertEquals("new_value", capDefinition.getProperties().get(0).getValue()); assertEquals(2, capDefinition.getProperties().size()); } - - + + @Test public void updateGroupTypeWithCapability_FailedDueToCapabilityDeleteAttempt() { createRootGroupTypeNode(); - PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance"); + PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, + "Ability to recognize capability per vfc instance group on vnf instance"); Map capTypeProperties = new HashMap<>(); capTypeProperties.put("vfc_instance_group_reference", property); @@ -335,24 +331,26 @@ public class GroupTypeOperationTest extends ModelTestBase { mapCapabilities.put("vlan_assignment", capabilityDef); groupTypeDefinition.setCapabilities(mapCapabilities); - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition); + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition); assertTrue(addGroupTypeResult.isLeft()); - + GroupTypeDefinition newGroupTypeDefinition = new GroupTypeDefinition(); newGroupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT); newGroupTypeDefinition.setDescription("groups l3-networks in network collection"); newGroupTypeDefinition.setType("org.openecomp.groups.NetworkCollection"); - Either updateGroupTypeResult = groupTypeOperation.updateGroupType(newGroupTypeDefinition, addGroupTypeResult.left().value()); + Either updateGroupTypeResult = groupTypeOperation.updateGroupType(newGroupTypeDefinition, + addGroupTypeResult.left().value()); assertTrue(updateGroupTypeResult.isRight()); assertEquals(StorageOperationStatus.MATCH_NOT_FOUND, updateGroupTypeResult.right().value()); } - + @Test public void updateGroupTypeWithCapability_FailedDueToCapabilityChangeTypeAttempt() { createRootGroupTypeNode(); - PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance"); + PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, + "Ability to recognize capability per vfc instance group on vnf instance"); Map capTypeProperties = new HashMap<>(); capTypeProperties.put("vfc_instance_group_reference", property); @@ -373,14 +371,14 @@ public class GroupTypeOperationTest extends ModelTestBase { mapCapabilities.put("vlan_assignment", capabilityDef); groupTypeDefinition.setCapabilities(mapCapabilities); - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition); + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition); assertTrue(addGroupTypeResult.isLeft()); - + GroupTypeDefinition newGroupTypeDefinition = new GroupTypeDefinition(); newGroupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT); newGroupTypeDefinition.setDescription("groups l3-networks in network collection"); newGroupTypeDefinition.setType("org.openecomp.groups.NetworkCollection"); - + Map updatedMapCapabilities = new HashMap<>(); property.setValue("new_value"); ComponentInstanceProperty newCapDefProperty = new ComponentInstanceProperty(property); @@ -388,17 +386,19 @@ public class GroupTypeOperationTest extends ModelTestBase { updatedCapabilityDef.setType("Another type"); updatedMapCapabilities.put("vlan_assignment", updatedCapabilityDef); newGroupTypeDefinition.setCapabilities(updatedMapCapabilities); - - Either updateGroupTypeResult = groupTypeOperation.updateGroupType(newGroupTypeDefinition, addGroupTypeResult.left().value()); + + Either updateGroupTypeResult = groupTypeOperation.updateGroupType(newGroupTypeDefinition, + addGroupTypeResult.left().value()); assertTrue(updateGroupTypeResult.isRight()); assertEquals(StorageOperationStatus.MATCH_NOT_FOUND, updateGroupTypeResult.right().value()); } - + @Test public void updateGroupTypeWithCapability_Success() { createRootGroupTypeNode(); - PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, "Ability to recognize capability per vfc instance group on vnf instance"); + PropertyDefinition property = buildProperty("vfc_instance_group_reference", null, + "Ability to recognize capability per vfc instance group on vnf instance"); Map capTypeProperties = new HashMap<>(); capTypeProperties.put("vfc_instance_group_reference", property); @@ -419,22 +419,23 @@ public class GroupTypeOperationTest extends ModelTestBase { mapCapabilities.put("vlan_assignment", capabilityDef); groupTypeDefinition.setCapabilities(mapCapabilities); - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition); + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition); assertTrue(addGroupTypeResult.isLeft()); - + GroupTypeDefinition newGroupTypeDefinition = new GroupTypeDefinition(); newGroupTypeDefinition.setDerivedFrom(TOSCA_GROUPS_ROOT); newGroupTypeDefinition.setDescription("groups l3-networks in network collection"); newGroupTypeDefinition.setType("org.openecomp.groups.NetworkCollection"); - + Map updatedMapCapabilities = new HashMap<>(); property.setValue("another_value"); ComponentInstanceProperty newCapDefProperty = new ComponentInstanceProperty(property); CapabilityDefinition updatedCapabilityDef = buildCapabilityDefintion(asList(newCapDefProperty)); updatedMapCapabilities.put("vlan_assignment", updatedCapabilityDef); newGroupTypeDefinition.setCapabilities(updatedMapCapabilities); - - Either updateGroupTypeResult = groupTypeOperation.updateGroupType(newGroupTypeDefinition, addGroupTypeResult.left().value()); + + Either updateGroupTypeResult = groupTypeOperation.updateGroupType(newGroupTypeDefinition, + addGroupTypeResult.left().value()); assertTrue(updateGroupTypeResult.isLeft()); } @@ -448,23 +449,24 @@ public class GroupTypeOperationTest extends ModelTestBase { groupTypeDefinition.setVersion("1.0"); List properties = singletonList( - buildProperty("network_collection_type", "l2-network", "network collection type, defined with default value")); - - groupTypeDefinition.setProperties(properties ); - - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + buildProperty("network_collection_type", "l2-network", "network collection type, defined with default value")); + + groupTypeDefinition.setProperties(properties); + + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - + addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.PrivateCollection", "1.0", null); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - - Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, groupTypeDefinition); + + Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, + groupTypeDefinition); assertNotNull(upgradeResult); assertTrue(upgradeResult.isLeft()); } - + @Test public void testUpdateNonExistingGroupType() { GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); @@ -472,70 +474,74 @@ public class GroupTypeOperationTest extends ModelTestBase { groupTypeDefinition.setDescription("groups l2-networks in network collection"); groupTypeDefinition.setType("org.openecomp.groups.MyCollection"); groupTypeDefinition.setVersion("1.0"); - - Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, groupTypeDefinition); + + Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, + groupTypeDefinition); assertNotNull(upgradeResult); assertTrue(upgradeResult.isRight()); } - + @Test public void testUpdateNotDerivedGroupType() { GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); groupTypeDefinition.setDescription("groups social-networks in school"); groupTypeDefinition.setType("org.openecomp.groups.Teachers"); groupTypeDefinition.setVersion("1.0"); - - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - - Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, groupTypeDefinition); + + Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, + groupTypeDefinition); assertNotNull(upgradeResult); assertTrue(upgradeResult.isLeft()); assertThat(groupTypeDefinition).isEqualToIgnoringGivenFields(upgradeResult.left().value(), "properties", "capabilities"); } - + @Test public void testUpdateGroupTypeWithNonExistingParent() { GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); groupTypeDefinition.setDescription("groups social-networks in work"); groupTypeDefinition.setType("org.openecomp.groups.Cowokers"); groupTypeDefinition.setVersion("1.0"); - - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - + groupTypeDefinition.setDerivedFrom("Non.existing.parent"); - Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, groupTypeDefinition); + Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, + groupTypeDefinition); assertNotNull(upgradeResult); assertTrue(upgradeResult.isRight()); } - + @Test public void testUpgradeGroupType() { GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); groupTypeDefinition.setDescription("groups social-networks in university"); groupTypeDefinition.setType("org.openecomp.groups.Students"); groupTypeDefinition.setVersion("1.0"); - - Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); + + Either addGroupTypeResult = groupTypeOperation.addGroupType(groupTypeDefinition, true); assertTrue("check group type added", addGroupTypeResult.isLeft()); compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value()); - + GroupTypeDefinition parentGroupTypeDefinition = new GroupTypeDefinition(); parentGroupTypeDefinition.setDescription("groups social-networks in university"); parentGroupTypeDefinition.setType("org.openecomp.groups.Parents"); parentGroupTypeDefinition.setVersion("1.0"); parentGroupTypeDefinition.setHighestVersion(true); - - Either addParentGroupTypeResult = groupTypeOperation.addGroupType(parentGroupTypeDefinition, true); + Either addParentGroupTypeResult = groupTypeOperation.addGroupType(parentGroupTypeDefinition, + true); assertTrue("check group type added", addParentGroupTypeResult.isLeft()); compareBetweenCreatedToSent(parentGroupTypeDefinition, addParentGroupTypeResult.left().value()); - + groupTypeDefinition.setDerivedFrom("org.openecomp.groups.Parents"); - Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, addGroupTypeResult.left().value()); + Either upgradeResult = groupTypeOperation.updateGroupType(groupTypeDefinition, + addGroupTypeResult.left().value()); assertNotNull(upgradeResult); assertTrue(upgradeResult.isLeft()); assertThat(groupTypeDefinition).isEqualToIgnoringGivenFields(upgradeResult.left().value(), "properties", "capabilities"); @@ -546,37 +552,37 @@ public class GroupTypeOperationTest extends ModelTestBase { GroupTypeDefinition groupTypeDefinition = createGroupTypeDef(); groupTypeDefinition.setModel("testModel"); Model model = new Model("testModel", ModelTypeEnum.NORMATIVE); - modelOperation.createModel(model , true); + modelOperation.createModel(model, true); Either addGroupType = groupTypeOperation.addGroupType(groupTypeDefinition); assertTrue(addGroupType.isLeft()); Either eitherGroupTypeFetched = - groupTypeOperation.getLatestGroupTypeByType(groupTypeDefinition.getType(), groupTypeDefinition.getModel()); + groupTypeOperation.getLatestGroupTypeByType(groupTypeDefinition.getType(), groupTypeDefinition.getModel()); assertTrue(eitherGroupTypeFetched.isLeft()); assertEquals(groupTypeDefinition.getModel(), eitherGroupTypeFetched.left().value().getModel()); } - + private GroupTypeData getOrCreateRootGroupTypeNode() { Either groupTypeResult = janusGraphDao .getNode(GraphPropertiesDictionary.TYPE.getProperty(), TOSCA_GROUPS_ROOT, GroupTypeData.class); - if(groupTypeResult.isLeft()) { + if (groupTypeResult.isLeft()) { return groupTypeResult.left().value(); } - + return createRootGroupTypeNode(); } - + private GroupTypeData createRootGroupTypeNode() { GroupTypeDefinition rootGroupDefinition = createRootGroupDefinition(); - Either addGroupTypeResult = groupTypeOperation.addGroupType(rootGroupDefinition, false); + Either addGroupTypeResult = groupTypeOperation.addGroupType(rootGroupDefinition, false); assertTrue("check group type added", addGroupTypeResult.isLeft()); - + Either groupTypeResult = janusGraphDao .getNode(GraphPropertiesDictionary.TYPE.getProperty(), rootGroupDefinition.getType(), GroupTypeData.class); - return extractVal(groupTypeResult); + return extractVal(groupTypeResult); } - + private GroupTypeDefinition createRootGroupDefinition() { GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition(); groupTypeDefinition.setDescription("The TOSCA Group Type all other TOSCA Group Types derive from"); @@ -593,7 +599,7 @@ public class GroupTypeOperationTest extends ModelTestBase { groupTypeDefinition.setIcon(type + "icon"); return groupTypeDefinition; } - + private CapabilityTypeDefinition createCapabilityType(Map properties) { CapabilityTypeDefinition rootCapabilityTypeDefinition = new CapabilityTypeDefinition(); rootCapabilityTypeDefinition.setType("tosca.capabilities.Root"); @@ -601,7 +607,6 @@ public class GroupTypeOperationTest extends ModelTestBase { rootCapabilityTypeDefinition.setVersion("1.0"); capabilityTypeOperation.addCapabilityType(rootCapabilityTypeDefinition, true); - CapabilityTypeDefinition parentCapabilityTypeDefinition = new CapabilityTypeDefinition(); parentCapabilityTypeDefinition.setType("tosca.capabilities.Parent"); parentCapabilityTypeDefinition.setDescription("Dummy parent type"); @@ -613,7 +618,6 @@ public class GroupTypeOperationTest extends ModelTestBase { parentCapabilityTypeDefinition.setProperties(capTypeProperties); capabilityTypeOperation.addCapabilityType(parentCapabilityTypeDefinition, true); - CapabilityTypeDefinition capabilityTypeDefinition = new CapabilityTypeDefinition(); capabilityTypeDefinition.setDescription("ability to expose routing information of the internal network"); capabilityTypeDefinition.setType("org.openecomp.capabilities.VLANAssignment"); @@ -622,15 +626,16 @@ public class GroupTypeOperationTest extends ModelTestBase { capabilityTypeDefinition.setProperties(properties); - Either addCapabilityTypeResult = capabilityTypeOperation.addCapabilityType(capabilityTypeDefinition, true); + Either addCapabilityTypeResult = capabilityTypeOperation.addCapabilityType( + capabilityTypeDefinition, true); assertTrue("check capability type added", addCapabilityTypeResult.isLeft()); CapabilityTypeDefinition capabilityTypeAdded = addCapabilityTypeResult.left().value(); compareBetweenCreatedToSent(capabilityTypeDefinition, capabilityTypeAdded); - + return capabilityTypeDefinition; } - + private CapabilityDefinition buildCapabilityDefintion(List properties) { CapabilityDefinition capabilityDefinition = new CapabilityDefinition(); capabilityDefinition.setName("vlan_assignment"); @@ -650,27 +655,27 @@ public class GroupTypeOperationTest extends ModelTestBase { return property; } - + private void compareBetweenCreatedToSent(CapabilityTypeDefinition expected, CapabilityTypeDefinition actual) { assertEquals(expected.getDerivedFrom(), actual.getDerivedFrom()); assertEquals(expected.getType(), actual.getType()); assertEquals(expected.getDescription(), actual.getDescription()); } - + private void compareBetweenCreatedToSent(GroupTypeDefinition expected, GroupTypeDefinition actual) { assertEquals(expected.getType(), actual.getType()); assertEquals(expected.getDescription(), actual.getDescription()); } - + private void validate(Either result) { extractVal(result); } - + private T extractVal(Either result) { assertTrue(result.isLeft()); T t = result.left().value(); assertNotNull(t); - + return t; } @@ -709,11 +714,12 @@ public class GroupTypeOperationTest extends ModelTestBase { updatedType.setIcon("icon"); groupTypeOperation.updateGroupType(updatedType, currGroupType.left().value()); - Either fetchedUpdatedType = groupTypeOperation.getLatestGroupTypeByType(createdType.getType(), createdType.getModel()); + Either fetchedUpdatedType = groupTypeOperation.getLatestGroupTypeByType(createdType.getType(), + createdType.getModel()); GroupTypeDefinition fetchedGroupType = fetchedUpdatedType.left().value(); assertThat(fetchedGroupType.getProperties()).isEmpty(); assertThat(fetchedGroupType) - .isEqualToIgnoringGivenFields(updatedType, "properties", "capabilities"); + .isEqualToIgnoringGivenFields(updatedType, "properties", "capabilities"); } @@ -727,25 +733,26 @@ public class GroupTypeOperationTest extends ModelTestBase { PropertyDefinition prop3 = createSimpleProperty("val3", "prop3", "string"); GroupTypeDefinition updatedGroupType = createGroupTypeDef(updatedProp1, prop3); - Either updatedGroupTypeRetrieved = groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value()); + Either updatedGroupTypeRetrieved = groupTypeOperation.updateGroupType(updatedGroupType, + currGroupType.left().value()); assertEquals(StorageOperationStatus.MATCH_NOT_FOUND, updatedGroupTypeRetrieved.right().value()); } - + @Test public void validateGroupType_FailedDueAttempToCreateGroupTypeWithPropertyWhichTypeIsDifferentFromTypeOfParentPropertyWithTheSameName() { GroupTypeDefinition rootGroupType = createGroupTypeDef(); Either rootGroupTypeRes = groupTypeOperation.addGroupType(rootGroupType); assertTrue(rootGroupTypeRes.isLeft()); - + PropertyDefinition prop = createSimpleProperty("val1", "prop", "string"); GroupTypeDefinition groupType1 = createGroupTypeDef("type1", "descr1", rootGroupType.getType(), prop); Either groupType1Res = groupTypeOperation.addGroupType(groupType1); assertTrue(groupType1Res.isLeft()); - + PropertyDefinition prop1 = createSimpleProperty("33", "prop", "int"); PropertyDefinition prop2 = createSimpleProperty("val2", "prop2", "string"); GroupTypeDefinition groupType2 = createGroupTypeDef("type2", "descr", groupType1.getType(), prop1, prop2); - + Either updatedGroupTypeRetrieved = groupTypeOperation.validateUpdateProperties(groupType2); assertEquals(StorageOperationStatus.PROPERTY_NAME_ALREADY_EXISTS, updatedGroupTypeRetrieved.right().value()); } @@ -759,7 +766,8 @@ public class GroupTypeOperationTest extends ModelTestBase { Either currGroupType = groupTypeOperation.addGroupType(groupType1); groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value()); - Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), groupType1.getModel()); + Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), + groupType1.getModel()); assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(rootGroupType.getType()); verifyDerivedFromNodeEqualsToRootGroupType(rootGroupType, latestGroupType.left().value().getUniqueId()); } @@ -772,10 +780,12 @@ public class GroupTypeOperationTest extends ModelTestBase { groupTypeOperation.addGroupType(rootGroupType); Either currGroupType = groupTypeOperation.addGroupType(groupType1); - Either updateGroupTypeRes = groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value()); + Either updateGroupTypeRes = groupTypeOperation.updateGroupType(updatedGroupType, + currGroupType.left().value()); assertThat(updateGroupTypeRes.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND); - Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), groupType1.getModel()); + Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), + groupType1.getModel()); assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(rootGroupType.getType()); } @@ -792,10 +802,11 @@ public class GroupTypeOperationTest extends ModelTestBase { groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value()); - Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), groupType1.getModel()); + Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), + groupType1.getModel()); assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(derivedType1.getType()); } - + @Test public void updateGroupType_updateDerivedFrom_CauseEndlessRecursion() { GroupTypeDefinition rootGroupType = createGroupTypeDef(); @@ -807,10 +818,12 @@ public class GroupTypeOperationTest extends ModelTestBase { Either currGroupType = groupTypeOperation.addGroupType(derivedType1); groupTypeOperation.addGroupType(groupType1); - Either updateResult = groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value()); + Either updateResult = groupTypeOperation.updateGroupType(updatedGroupType, + currGroupType.left().value()); assertThat(updateResult.right().value()).isEqualTo(StorageOperationStatus.GENERAL_ERROR); - Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(updatedGroupType.getType(), updatedGroupType.getModel()); + Either latestGroupType = groupTypeOperation.getLatestGroupTypeByType(updatedGroupType.getType(), + updatedGroupType.getModel()); assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(rootGroupType.getType()); } @@ -827,7 +840,7 @@ public class GroupTypeOperationTest extends ModelTestBase { .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.GroupType), parentGroupId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.GroupType, GroupTypeData.class); assertThat(derivedFromRelation.left().value().getLeft().getGroupTypeDataDefinition()) - .isEqualToComparingFieldByField(rootGroupType); + .isEqualToComparingFieldByField(rootGroupType); } private void verifyDerivedFromRelationDoesntExist(String parentGroupId) { @@ -835,19 +848,21 @@ public class GroupTypeOperationTest extends ModelTestBase { .getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.GroupType), parentGroupId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.GroupType, GroupTypeData.class); assertThat(derivedFromRelation.right().value()) - .isEqualTo(JanusGraphOperationStatus.NOT_FOUND); + .isEqualTo(JanusGraphOperationStatus.NOT_FOUND); } private GroupTypeDefinition createGroupTypeDef() { - return createGroupTypeDef("tosca.groups.Root", "description: The TOSCA Group Type all other TOSCA Group Types derive from", null, new PropertyDefinition[]{}); + return createGroupTypeDef("tosca.groups.Root", "description: The TOSCA Group Type all other TOSCA Group Types derive from", null, + new PropertyDefinition[]{}); } - private GroupTypeDefinition createGroupTypeDef(PropertyDefinition ... props) { - return createGroupTypeDef("tosca.groups.Root", null, props); + private GroupTypeDefinition createGroupTypeDef(PropertyDefinition... props) { + return createGroupTypeDef("tosca.groups.Root", null, props); } - private GroupTypeDefinition createGroupTypeDef(String type, String derivedFrom, PropertyDefinition ... props) { - GroupTypeDefinition groupType = createGroupTypeDef(type, "description: The TOSCA Group Type all other TOSCA Group Types derive from", derivedFrom); + private GroupTypeDefinition createGroupTypeDef(String type, String derivedFrom, PropertyDefinition... props) { + GroupTypeDefinition groupType = createGroupTypeDef(type, "description: The TOSCA Group Type all other TOSCA Group Types derive from", + derivedFrom); groupType.setProperties(asList(props)); return groupType; } @@ -856,7 +871,7 @@ public class GroupTypeOperationTest extends ModelTestBase { return createGroupTypeDef(type, description, derivedFrom, null); } - private GroupTypeDefinition createGroupTypeDef(String type, String description, String derivedFrom, PropertyDefinition ... props) { + private GroupTypeDefinition createGroupTypeDef(String type, String description, String derivedFrom, PropertyDefinition... props) { GroupTypeDataDefinition groupTypeDataDefinition = new GroupTypeDataDefinition(); groupTypeDataDefinition.setDescription(description); groupTypeDataDefinition.setType(type); diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java index 1a7f1c8ba3..7ccf1f6d6b 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/InterfaceLifecycleOperationTest.java @@ -7,9 +7,9 @@ * 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. @@ -26,18 +26,17 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; +import fj.data.Either; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; - import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -60,14 +59,11 @@ import org.openecomp.sdc.be.resources.data.OperationData; import org.openecomp.sdc.be.resources.data.ResourceMetadataData; import org.openecomp.sdc.be.resources.data.UserData; import org.openecomp.sdc.be.resources.data.category.CategoryData; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import fj.data.Either; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class InterfaceLifecycleOperationTest { + private static String USER_ID = "muUserId"; private static String CATEGORY_NAME = "category/mycategory"; private static String MODEL_NAME = "Test"; @@ -77,20 +73,20 @@ public class InterfaceLifecycleOperationTest { @InjectMocks private InterfaceLifecycleOperation interfaceLifecycleOperation = new InterfaceLifecycleOperation(); - @Before + @BeforeAll + public static void setupBeforeClass() { + ModelTestBase.init(); + } + + @BeforeEach public void createUserAndCategory() { MockitoAnnotations.initMocks(this); CategoryData categoryData = new CategoryData(NodeTypeEnum.ResourceCategory); - when(janusGraphGenericDao.createNode(any(),any())).thenReturn(Either.left(categoryData)); + when(janusGraphGenericDao.createNode(any(), any())).thenReturn(Either.left(categoryData)); deleteAndCreateCategory(CATEGORY_NAME); deleteAndCreateUser(USER_ID, "first_" + USER_ID, "last_" + USER_ID); } - @BeforeClass - public static void setupBeforeClass() { - ModelTestBase.init(); - } - @Test public void testDummy() { assertNotNull(interfaceLifecycleOperation); @@ -125,24 +121,31 @@ public class InterfaceLifecycleOperationTest { @Test public void createInterfaceOnResourceTest() { - when(janusGraphGenericDao.getChildrenNodes(any(), any(), any(), any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE)); - when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + when(janusGraphGenericDao.getChildrenNodes(any(), any(), any(), any(), eq(InterfaceData.class))).thenReturn( + Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE)); + when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn( + Either.right(JanusGraphOperationStatus.NOT_FOUND)); when(janusGraphGenericDao.getNode(any(), any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST)); when(janusGraphGenericDao.createNode(any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST)); - when(janusGraphGenericDao.createRelation(any(), any(), eq(GraphEdgeLabels.INTERFACE), any())).thenReturn(Either.right(JanusGraphOperationStatus.OK)); + when(janusGraphGenericDao.createRelation(any(), any(), eq(GraphEdgeLabels.INTERFACE), any())).thenReturn( + Either.right(JanusGraphOperationStatus.OK)); Assert.assertTrue(interfaceLifecycleOperation.createInterfaceOnResource(buildInterfaceDefinition(), "", "", false, false).isRight()); - when(janusGraphGenericDao.createRelation(any(), any(), eq(GraphEdgeLabels.INTERFACE), any())).thenReturn(Either.left(Mockito.mock(GraphRelation.class))); + when(janusGraphGenericDao.createRelation(any(), any(), eq(GraphEdgeLabels.INTERFACE), any())).thenReturn( + Either.left(Mockito.mock(GraphRelation.class))); Assert.assertTrue(interfaceLifecycleOperation.createInterfaceOnResource(buildInterfaceDefinition(), "", "", false, false).isRight()); } @Test public void getAllInterfacesOfResourceTest() { assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource(null, true).isRight()); - when(janusGraphGenericDao.getChildrenNodes(any(), any(), any(), any(), eq(InterfaceData.class))).thenReturn(Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE)); - when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + when(janusGraphGenericDao.getChildrenNodes(any(), any(), any(), any(), eq(InterfaceData.class))).thenReturn( + Either.right(JanusGraphOperationStatus.GRAPH_IS_NOT_AVAILABLE)); + when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn( + Either.right(JanusGraphOperationStatus.NOT_FOUND)); assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource("null", true).isLeft()); - when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn(Either.right(JanusGraphOperationStatus.ALREADY_EXIST)); + when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))).thenReturn( + Either.right(JanusGraphOperationStatus.ALREADY_EXIST)); assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource("null", true).isRight()); ResourceMetadataData key = Mockito.mock(ResourceMetadataData.class); @@ -151,8 +154,8 @@ public class InterfaceLifecycleOperationTest { when(key.getMetadataDataDefinition()).thenReturn(def); ImmutablePair pair = new ImmutablePair<>(key, Mockito.mock(GraphEdge.class)); when(janusGraphGenericDao.getChild(any(), any(), any(), eq(NodeTypeEnum.Resource), eq(ResourceMetadataData.class))) - .thenReturn(Either.left(pair)) - .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + .thenReturn(Either.left(pair)) + .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); assertTrue(interfaceLifecycleOperation.getAllInterfacesOfResource("null", true).isLeft()); } @@ -160,7 +163,8 @@ public class InterfaceLifecycleOperationTest { public void testGetAllInterfaceLifecycleTypes_TypesNotFound() { when(janusGraphGenericDao.getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), StringUtils.EMPTY, InterfaceData.class)).thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(StringUtils.EMPTY); + Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes( + StringUtils.EMPTY); Assert.assertEquals(types.isRight(), Boolean.TRUE); } @@ -175,15 +179,18 @@ public class InterfaceLifecycleOperationTest { interfaceDataList.add(interfaceData); Either, JanusGraphOperationStatus> allInterfaceTypes = Either.left(interfaceDataList); when(janusGraphGenericDao - .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), StringUtils.EMPTY, InterfaceData.class)).thenReturn(allInterfaceTypes); + .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), StringUtils.EMPTY, InterfaceData.class)).thenReturn( + allInterfaceTypes); List> list = new ArrayList<>(); Either>, JanusGraphOperationStatus> childrenNodes = Either.left(list); - when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(childrenNodes); + when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, + NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(childrenNodes); when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any())) - .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); - Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(StringUtils.EMPTY); - Assert.assertEquals(types.left().value().size(),1); + .thenReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)); + Either, StorageOperationStatus> types = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes( + StringUtils.EMPTY); + Assert.assertEquals(types.left().value().size(), 1); } @Test @@ -200,10 +207,12 @@ public class InterfaceLifecycleOperationTest { interfaceTypes.add(interfaceData); when(janusGraphGenericDao.getParentNode(any(), any(), any(), any(), any())) - .thenReturn(Either.left(modelNode)); + .thenReturn(Either.left(modelNode)); when(janusGraphGenericDao - .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), MODEL_NAME, InterfaceData.class)).thenReturn(Either.left(interfaceTypes)); - when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(Either.left(Collections.emptyList())); + .getByCriteriaForModel(NodeTypeEnum.Interface, Collections.emptyMap(), MODEL_NAME, InterfaceData.class)).thenReturn( + Either.left(interfaceTypes)); + when(janusGraphGenericDao.getChildrenNodes(interfaceData.getUniqueIdKey(), interfaceData.getUniqueId(), GraphEdgeLabels.INTERFACE_OPERATION, + NodeTypeEnum.InterfaceOperation, OperationData.class)).thenReturn(Either.left(Collections.emptyList())); Assert.assertEquals(1, interfaceLifecycleOperation.getAllInterfaceLifecycleTypes(MODEL_NAME).left().value().size()); } diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java index a6b2aa687a..9fd929852a 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java @@ -25,6 +25,8 @@ import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + +import fj.data.Either; import java.util.Iterator; import java.util.List; import java.util.stream.Stream; @@ -32,10 +34,9 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphVertex; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge; import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao; @@ -51,12 +52,9 @@ import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.resources.data.PolicyTypeData; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import fj.data.Either; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class PolicyTypeOperationTest extends ModelTestBase { private static final String NULL_STRING = null; @@ -68,13 +66,13 @@ public class PolicyTypeOperationTest extends ModelTestBase { @Autowired private HealingJanusGraphGenericDao janusGraphGenericDao; - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void cleanUp() { JanusGraphGenericDao janusGraphGenericDao = policyTypeOperation.janusGraphGenericDao; Either graphResult = janusGraphGenericDao.getGraph(); @@ -107,7 +105,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { @Test public void testGetLatestPolicyTypeByType() { PolicyTypeDefinition policyTypeCreated = policyTypeOperation.addPolicyType(createPolicyTypeDef()).left().value(); - Either eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType(policyTypeCreated.getType(), policyTypeCreated.getModel()); + Either eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType( + policyTypeCreated.getType(), policyTypeCreated.getModel()); assertTrue(eitherPolicyTypeFetched.isLeft()); PolicyTypeDefinition policyTypeFetched = eitherPolicyTypeFetched.left().value(); assertEquals(policyTypeFetched.toString(), policyTypeCreated.toString()); @@ -118,7 +117,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { PolicyTypeDefinition policyTypeDefinition = createPolicyTypeDef(); policyTypeDefinition.setModel("testModel"); Model model = new Model("testModel", ModelTypeEnum.NORMATIVE); - modelOperation.createModel(model , true); + modelOperation.createModel(model, true); Either addPolicyType = policyTypeOperation.addPolicyType(policyTypeDefinition); assertTrue(addPolicyType.isLeft()); @@ -134,7 +133,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { String derivedFromRootType = rootPolicyType.getType(); PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", "desc1", derivedFromRootType); policyTypeOperation.addPolicyType(policyType1); - Either eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel()); + Either eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType( + policyType1.getType(), policyType1.getModel()); assertThat(eitherPolicyTypeFetched.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType()); } @@ -145,7 +145,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", null, prop1, prop2); PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.type2", "desc3", policyType1.getType(), null); addPolicyTypesToDB(policyType1, policyType2); - Either latestPolicyType2 = policyTypeOperation.getLatestPolicyTypeByType(policyType2.getType(), policyType2.getModel()); + Either latestPolicyType2 = policyTypeOperation.getLatestPolicyTypeByType(policyType2.getType(), + policyType2.getModel()); assertThat(latestPolicyType2.isLeft()).isTrue(); assertThat(latestPolicyType2.left().value().getProperties()) .usingElementComparatorOnFields("defaultValue", "name", "type") @@ -166,7 +167,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { addPolicyTypesToDB(rootPolicyType, policyType1, policyType2, policyType3, policyType4); - Either latestPolicyType3 = policyTypeOperation.getLatestPolicyTypeByType(policyType4.getType(), policyType4.getModel()); + Either latestPolicyType3 = policyTypeOperation.getLatestPolicyTypeByType(policyType4.getType(), + policyType4.getModel()); assertThat(latestPolicyType3.isLeft()).isTrue(); assertThat(latestPolicyType3.left().value().getProperties()) .usingElementComparatorOnFields("defaultValue", "name", "type") @@ -220,7 +222,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { Either addedPolicyTypeResult = policyTypeOperation.addPolicyType(policyType1); assertThat(addedPolicyTypeResult.isLeft()).isTrue(); - Either fetchedPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel()); + Either fetchedPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), + policyType1.getModel()); PolicyTypeDefinition fetchedPolicyTypeVal = fetchedPolicyType.left().value(); assertThat(fetchedPolicyTypeVal.getDerivedFrom()).isEqualTo(derivedFromRootType); verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, fetchedPolicyTypeVal.getUniqueId()); @@ -245,7 +248,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { updatedType.setIcon("icon"); policyTypeOperation.updatePolicyType(updatedType, currPolicyType.left().value()); - Either fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(createdType.getType(), createdType.getModel()); + Either fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(createdType.getType(), + createdType.getModel()); PolicyTypeDefinition fetchedPolicyType = fetchedUpdatedType.left().value(); assertThat(fetchedPolicyType.getProperties()).isEmpty(); assertThat(fetchedPolicyType) @@ -266,7 +270,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value()); - Either fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(policyType.getType(), policyType.getModel()); + Either fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(policyType.getType(), + policyType.getModel()); assertThat(fetchedUpdatedType.left().value().getProperties()) .usingElementComparatorOnFields("name", "defaultValue", "type") .containsExactlyInAnyOrder(updatedProp1, prop3); @@ -282,7 +287,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { Either currPolicyType = policyTypeOperation.addPolicyType(policyType1); policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value()); - Either latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel()); + Either latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), + policyType1.getModel()); assertThat(latestPolicyType.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType()); verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, latestPolicyType.left().value().getUniqueId()); } @@ -297,7 +303,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value()); - Either latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel()); + Either latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), + policyType1.getModel()); assertThat(latestPolicyType.left().value().getDerivedFrom()).isNull(); verifyDerivedFromRelationDoesntExist(latestPolicyType.left().value().getUniqueId()); } @@ -315,7 +322,8 @@ public class PolicyTypeOperationTest extends ModelTestBase { policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value()); - Either latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel()); + Either latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), + policyType1.getModel()); assertThat(latestPolicyType.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType()); verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, latestPolicyType.left().value().getUniqueId()); } @@ -329,14 +337,16 @@ public class PolicyTypeOperationTest extends ModelTestBase { } private void verifyDerivedFromNodeEqualsToRootPolicyType(PolicyTypeDefinition rootPolicyType, String parentPolicyId) { - Either, JanusGraphOperationStatus> derivedFromRelation = janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM, + Either, JanusGraphOperationStatus> derivedFromRelation = janusGraphGenericDao.getChild( + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.PolicyType, PolicyTypeData.class); assertThat(derivedFromRelation.left().value().getLeft().getPolicyTypeDataDefinition()) .isEqualToComparingFieldByField(rootPolicyType); } private void verifyDerivedFromRelationDoesntExist(String parentPolicyId) { - Either, JanusGraphOperationStatus> derivedFromRelation = janusGraphGenericDao.getChild(UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM, + Either, JanusGraphOperationStatus> derivedFromRelation = janusGraphGenericDao.getChild( + UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), parentPolicyId, GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.PolicyType, PolicyTypeData.class); assertThat(derivedFromRelation.right().value()) .isEqualTo(JanusGraphOperationStatus.NOT_FOUND); @@ -350,15 +360,17 @@ public class PolicyTypeOperationTest extends ModelTestBase { } private PolicyTypeDefinition createPolicyTypeDef() { - return createPolicyTypeDef("tosca.policies.Root", "description: The TOSCA Policy Type all other TOSCA Policy Types derive from", null, new PropertyDefinition[]{}); + return createPolicyTypeDef("tosca.policies.Root", "description: The TOSCA Policy Type all other TOSCA Policy Types derive from", null, + new PropertyDefinition[]{}); } - private PolicyTypeDefinition createPolicyTypeDef(PropertyDefinition ... props) { - return createPolicyTypeDef("tosca.policies.Root", null, props); + private PolicyTypeDefinition createPolicyTypeDef(PropertyDefinition... props) { + return createPolicyTypeDef("tosca.policies.Root", null, props); } - private PolicyTypeDefinition createPolicyTypeDef(String type, String derivedFrom, PropertyDefinition ... props) { - PolicyTypeDefinition policyType = createPolicyTypeDef(type, "description: The TOSCA Policy Type all other TOSCA Policy Types derive from", derivedFrom); + private PolicyTypeDefinition createPolicyTypeDef(String type, String derivedFrom, PropertyDefinition... props) { + PolicyTypeDefinition policyType = createPolicyTypeDef(type, "description: The TOSCA Policy Type all other TOSCA Policy Types derive from", + derivedFrom); policyType.setProperties(asList(props)); return policyType; } @@ -367,7 +379,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { return createPolicyTypeDef(type, description, derivedFrom, null); } - private PolicyTypeDefinition createPolicyTypeDef(String type, String description, String derivedFrom, PropertyDefinition ... props) { + private PolicyTypeDefinition createPolicyTypeDef(String type, String description, String derivedFrom, PropertyDefinition... props) { PolicyTypeDataDefinition policyTypeDataDefinition = new PolicyTypeDataDefinition(); policyTypeDataDefinition.setDescription(description); policyTypeDataDefinition.setType(type); @@ -383,7 +395,7 @@ public class PolicyTypeOperationTest extends ModelTestBase { return policyTypeDefinition; } - private void addPolicyTypesToDB(PolicyTypeDefinition ... policyTypeDefinitions) { + private void addPolicyTypesToDB(PolicyTypeDefinition... policyTypeDefinitions) { Stream.of(policyTypeDefinitions).forEach(policyTypeOperation::addPolicyType); } } \ No newline at end of file diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java index 371c3edfe5..ee3ea9e026 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/RelationshipTypeOperationTest.java @@ -24,21 +24,18 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import fj.data.Either; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; - -import fj.data.Either; -import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -64,11 +61,9 @@ import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint; import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint; import org.openecomp.sdc.be.resources.data.ModelData; import org.openecomp.sdc.be.resources.data.RelationshipTypeData; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class RelationshipTypeOperationTest extends ModelTestBase { private static final String PROP = "prop"; @@ -98,12 +93,12 @@ public class RelationshipTypeOperationTest extends ModelTestBase { relationshipTypeDefinition.setUniqueId("tosca.relationships.Container1"); } - @BeforeClass + @BeforeAll public static void setupBeforeClass() { ModelTestBase.init(); } - @Before + @BeforeEach public void setUp() throws Exception { MockitoAnnotations.initMocks(this); @@ -119,18 +114,17 @@ public class RelationshipTypeOperationTest extends ModelTestBase { @Test public void testAddRelationshipTypeValidationFailStatusNullInTransactionFalse() { Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_CONNECTED)) - .when(propertyOperation) - .getAllTypePropertiesFromAllDerivedFrom(Mockito.anyString(), Mockito.any(), Mockito.any()); - + .when(propertyOperation) + .getAllTypePropertiesFromAllDerivedFrom(Mockito.anyString(), Mockito.any(), Mockito.any()); + Mockito.doReturn(Either.left(new RelationshipTypeData(relationshipTypeDefinition))) - .when(janusGraphGenericDao).getNode(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); - - Mockito.doReturn(Either.left(Collections.singletonMap("derivedFromProp1", new PropertyDefinition()))).when(propertyOperation) - .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); + .when(janusGraphGenericDao).getNode(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doReturn(Either.left(Collections.singletonMap("derivedFromProp1", new PropertyDefinition()))).when(propertyOperation) + .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); Either addRelationshipType = - relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, false); + relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, false); assertTrue(addRelationshipType.isRight()); } @@ -138,18 +132,18 @@ public class RelationshipTypeOperationTest extends ModelTestBase { @Test public void testAddRelationshipTypeValidationFailStatusPropertiesReturnedInTransactionFalse() { Mockito.doReturn(Either.left(Collections.singletonMap("prop1", new PropertyDefinition()))).when(propertyOperation) - .getAllTypePropertiesFromAllDerivedFrom(Mockito.anyString(), Mockito.any(), Mockito.any()); + .getAllTypePropertiesFromAllDerivedFrom(Mockito.anyString(), Mockito.any(), Mockito.any()); Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(propertyOperation) - .validatePropertiesUniqueness(Mockito.any(), Mockito.any()); - + .validatePropertiesUniqueness(Mockito.any(), Mockito.any()); + Mockito.doReturn(Either.left(new RelationshipTypeData(relationshipTypeDefinition))) - .when(janusGraphGenericDao).getNode(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); - + .when(janusGraphGenericDao).getNode(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doReturn(Either.left(Collections.singletonMap("derivedFromProp1", new PropertyDefinition()))).when(propertyOperation) - .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); + .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); Either addRelationshipType = - relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, false); + relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, false); assertTrue(addRelationshipType.isRight()); } @@ -158,7 +152,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { public void testGetAllRelationshipTypesNotFound() { Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when( janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null, - RelationshipTypeData.class); + RelationshipTypeData.class); Either, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(null); assertTrue(either.isLeft() && MapUtils.isEmpty(either.left().value())); @@ -168,7 +162,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { public void testGetAllRelationshipTypesNotConnnected() { Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_CONNECTED)).when( janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null, - RelationshipTypeData.class); + RelationshipTypeData.class); Either, JanusGraphOperationStatus> either = relationshipTypeOperation.getAllRelationshipTypes(null); assertTrue(either.isRight() && JanusGraphOperationStatus.NOT_CONNECTED == either.right().value()); @@ -187,33 +181,33 @@ public class RelationshipTypeOperationTest extends ModelTestBase { relationshipTypeDataList.add(relationshipTypeData1); Mockito.doReturn(Either.left(relationshipTypeDataList)) - .when(janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null, + .when(janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, null, RelationshipTypeData.class); Mockito.doReturn(Either.left(relationshipTypeData1)).when(janusGraphGenericDao) - .getNode(Mockito.anyString(), Mockito.anyString(), Mockito.eq(RelationshipTypeData.class)); + .getNode(Mockito.anyString(), Mockito.anyString(), Mockito.eq(RelationshipTypeData.class)); Mockito.doReturn(Either.left(createPropertyData("prop1"))).when(propertyOperation) - .findPropertiesOfNode(NodeTypeEnum.RelationshipType, "tosca.relationships.Root1"); + .findPropertiesOfNode(NodeTypeEnum.RelationshipType, "tosca.relationships.Root1"); RelationshipInstDataDefinition derivedFromRelationshipTypeDefinition = new RelationshipInstDataDefinition(); derivedFromRelationshipTypeDefinition.setUniqueId("tosca.relationships.Root1"); derivedFromRelationshipTypeDefinition.setType("tosca.relationships.Parent"); Mockito.doReturn(Either.left(new RelationshipTypeData(derivedFromRelationshipTypeDefinition))) - .when(derivedFromOperation) - .getDerivedFromChild("tosca.relationships.Root1", NodeTypeEnum.RelationshipType, RelationshipTypeData.class); + .when(derivedFromOperation) + .getDerivedFromChild("tosca.relationships.Root1", NodeTypeEnum.RelationshipType, RelationshipTypeData.class); Either, JanusGraphOperationStatus> either = - relationshipTypeOperation.getAllRelationshipTypes(null); + relationshipTypeOperation.getAllRelationshipTypes(null); assertTrue(either.isLeft()); RelationshipTypeDefinition relationshipTypeDefinition = either.left().value().get("tosca.relationships.Root1"); assertEquals("tosca.relationships.Parent", relationshipTypeDefinition.getDerivedFrom()); - + Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)) .when(janusGraphGenericDao).getByCriteriaForModel(NodeTypeEnum.RelationshipType, null, "modelA", - RelationshipTypeData.class); + RelationshipTypeData.class); either = relationshipTypeOperation.getAllRelationshipTypes("modelA"); assertTrue(either.isLeft()); assertTrue(MapUtils.isEmpty(either.left().value())); @@ -241,11 +235,11 @@ public class RelationshipTypeOperationTest extends ModelTestBase { relationshipTypeDefinition.setProperties(properties); Either addRelationshipType1 = - relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, true); + relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, true); RelationshipTypeDefinition relationshipTypeDefinitionCreated = addRelationshipType1.left().value(); Either relationshipType = - relationshipTypeOperation.getRelationshipType(relationshipTypeDefinitionCreated.getUniqueId(), true); + relationshipTypeOperation.getRelationshipType(relationshipTypeDefinitionCreated.getUniqueId(), true); assertTrue("check relationship type fetched", relationshipType.isLeft()); RelationshipTypeDefinition fetchedCTD = relationshipType.left().value(); @@ -260,7 +254,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { private void compareProperties(Map first, Map second) { assertTrue("check properties are full or empty", - ((first == null && second == null) || (first != null && second != null))); + ((first == null && second == null) || (first != null && second != null))); if (first != null) { assertEquals("check properties size", first.size(), second.size()); @@ -282,11 +276,11 @@ public class RelationshipTypeOperationTest extends ModelTestBase { private void comparePropertyDefinition(PropertyDefinition first, PropertyDefinition second) { assertTrue("check objects are full or empty", - ((first == null && second == null) || (first != null && second != null))); + ((first == null && second == null) || (first != null && second != null))); if (first != null) { assertTrue("check property description", compareValue(first.getDescription(), second.getDescription())); assertTrue("check property default value", compareValue((String) first.getDefaultValue(), - (String) second.getDefaultValue())); + (String) second.getDefaultValue())); assertTrue("check property type", compareValue(first.getType(), second.getType())); compareList(first.getConstraints(), second.getConstraints()); } @@ -296,7 +290,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { private void compareList(List first, List second) { assertTrue("check lists are full or empty", - ((first == null && second == null) || (first != null && second != null))); + ((first == null && second == null) || (first != null && second != null))); if (first != null) { assertEquals("check list size", first.size(), second.size()); } @@ -321,7 +315,7 @@ public class RelationshipTypeOperationTest extends ModelTestBase { PropertyDefinition property1 = new PropertyDefinition(); property1.setDefaultValue("10"); property1.setDescription("Size of the local disk, in Gigabytes (GB), " - + "available to applications running on the Compute node."); + + "available to applications running on the Compute node."); property1.setType(ToscaType.INTEGER.name().toLowerCase()); List constraints = new ArrayList<>(); GreaterThanConstraint propertyConstraint1 = new GreaterThanConstraint("0"); @@ -362,55 +356,53 @@ public class RelationshipTypeOperationTest extends ModelTestBase { RelationshipTypeDefinition relationshipTypeDefinition = new RelationshipTypeDefinition(relationshipTypeData); relationshipTypeDefinition.setProperties(createPropertyData("prop1")); relationshipTypeDefinition.setDerivedFrom("tosca.relationships.Root"); - - Mockito.doReturn(Either.left(Collections.singletonMap("prop1", new PropertyDefinition()))).when(propertyOperation) - .getAllTypePropertiesFromAllDerivedFrom(Mockito.anyString(), Mockito.any(), Mockito.any()); + .getAllTypePropertiesFromAllDerivedFrom(Mockito.anyString(), Mockito.any(), Mockito.any()); Mockito.doReturn(Either.left(new ArrayList<>(relationshipTypeDefinition.getProperties().values()))).when(propertyOperation) - .validatePropertiesUniqueness(Mockito.any(), Mockito.any()); + .validatePropertiesUniqueness(Mockito.any(), Mockito.any()); Mockito.doReturn(Either.left(relationshipTypeData)).when(janusGraphGenericDao) - .createNode(Mockito.any(), Mockito.eq(RelationshipTypeData.class)); - + .createNode(Mockito.any(), Mockito.eq(RelationshipTypeData.class)); + Mockito.doReturn(Either.left(new HashMap())).when(propertyOperation) - .addPropertiesToElementType(Mockito.anyString(), Mockito.any(), Mockito.anyMap()); + .addPropertiesToElementType(Mockito.anyString(), Mockito.any(), Mockito.anyMap()); Mockito.doReturn(Either.left(relationshipTypeDefinition)) - .when(relationshipTypeOperation).getRelationshipTypeByUid(Mockito.anyString()); + .when(relationshipTypeOperation).getRelationshipTypeByUid(Mockito.anyString()); Mockito.doReturn(Either.left(new GraphRelation())) - .when(derivedFromOperation) - .addDerivedFromRelation(Mockito.anyString(), Mockito.anyString(), Mockito.any()); + .when(derivedFromOperation) + .addDerivedFromRelation(Mockito.anyString(), Mockito.anyString(), Mockito.any()); Mockito.doReturn(Either.left(relationshipTypeDefinition)) - .when(relationshipTypeOperation).getRelationshipType(Mockito.anyString(), Mockito.anyBoolean()); + .when(relationshipTypeOperation).getRelationshipType(Mockito.anyString(), Mockito.anyBoolean()); Mockito.doReturn(Either.left(Collections.singletonMap("derivedFromProp1", new PropertyDefinition()))).when(propertyOperation) - .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); - + .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao) - .getChild(Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); - + .getChild(Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); + Mockito.doReturn(Either.left(new RelationshipTypeData(relationshipTypeDefinition))) - .when(janusGraphGenericDao).getNode(Mockito.anyString(), Mockito.any(), Mockito.eq(RelationshipTypeData.class), Mockito.any()); - - + .when(janusGraphGenericDao).getNode(Mockito.anyString(), Mockito.any(), Mockito.eq(RelationshipTypeData.class), Mockito.any()); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) - .when(janusGraphGenericDao).getParentNode("uid", relationshipInstDataDefinition1.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); - + .when(janusGraphGenericDao) + .getParentNode("uid", relationshipInstDataDefinition1.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); + Either either = - relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, true); + relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, true); assertTrue(either.isLeft()); } - + @Test public void testAddRelationshipTypeToModel() { - + final String relationshipName = "tosca.relationships.MyRelationship"; final String derivedFromRelationshipName = "tosca.relationships.Root"; final String modelName = "modelA"; @@ -421,66 +413,72 @@ public class RelationshipTypeOperationTest extends ModelTestBase { relationshipTypeDefinition.setType(relationshipName); relationshipTypeDefinition.setModel(modelName); relationshipTypeDefinition.setDerivedFrom(derivedFromRelationshipName); - + RelationshipTypeData derivedFromRelationshipTypeData = new RelationshipTypeData(); RelationshipInstDataDefinition dervideFromRelationshipInstDataDefinition = new RelationshipInstDataDefinition(); dervideFromRelationshipInstDataDefinition.setUniqueId("modelA.tosca.relationships.Root"); dervideFromRelationshipInstDataDefinition.setType("tosca.relationships.Root"); derivedFromRelationshipTypeData.setRelationshipTypeDataDefinition(dervideFromRelationshipInstDataDefinition); - + Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)) - .when(janusGraphGenericDao).getNode("uid", relationshipTypeDefinition.getUniqueId(), RelationshipTypeData.class); - + .when(janusGraphGenericDao).getNode("uid", relationshipTypeDefinition.getUniqueId(), RelationshipTypeData.class); + Mockito.doReturn(Either.left(derivedFromRelationshipTypeData)) - .when(janusGraphGenericDao).getNode("type", "tosca.relationships.Root", RelationshipTypeData.class, "modelA"); - + .when(janusGraphGenericDao).getNode("type", "tosca.relationships.Root", RelationshipTypeData.class, "modelA"); + Mockito.doReturn(Either.left(Collections.singletonMap("prop1", new PropertyDefinition()))).when(propertyOperation) - .getAllTypePropertiesFromAllDerivedFrom(modelName + DOT + derivedFromRelationshipName, NodeTypeEnum.RelationshipType, RelationshipTypeData.class); - + .getAllTypePropertiesFromAllDerivedFrom(modelName + DOT + derivedFromRelationshipName, NodeTypeEnum.RelationshipType, + RelationshipTypeData.class); + Mockito.doReturn(Either.left(new ArrayList<>(relationshipTypeDefinition.getProperties().values()))).when(propertyOperation) - .validatePropertiesUniqueness(Mockito.any(), Mockito.any()); - + .validatePropertiesUniqueness(Mockito.any(), Mockito.any()); + Mockito.doReturn(Either.left(new RelationshipTypeData(relationshipTypeDefinition))).when(janusGraphGenericDao) - .createNode(Mockito.any(), Mockito.eq(RelationshipTypeData.class)); - + .createNode(Mockito.any(), Mockito.eq(RelationshipTypeData.class)); + Mockito.doReturn(Either.left(new HashMap())).when(propertyOperation) - .addPropertiesToElementType(Mockito.anyString(), Mockito.any(), Mockito.anyMap()); - + .addPropertiesToElementType(Mockito.anyString(), Mockito.any(), Mockito.anyMap()); + Mockito.doReturn(Either.left(new GraphRelation())).when(janusGraphGenericDao) - .createRelation(Mockito.any(), Mockito.any(), Mockito.eq(GraphEdgeLabels.MODEL_ELEMENT), Mockito.any()); - + .createRelation(Mockito.any(), Mockito.any(), Mockito.eq(GraphEdgeLabels.MODEL_ELEMENT), Mockito.any()); + Mockito.doReturn(Either.left(Collections.singletonMap("derivedFromProp1", new PropertyDefinition()))).when(propertyOperation) - .findPropertiesOfNode(NodeTypeEnum.RelationshipType, derivedFromRelationshipTypeData.getUniqueId()); - + .findPropertiesOfNode(NodeTypeEnum.RelationshipType, derivedFromRelationshipTypeData.getUniqueId()); + Mockito.doReturn(Either.left(Collections.singletonMap("prop1", new PropertyDefinition()))).when(propertyOperation) - .findPropertiesOfNode(NodeTypeEnum.RelationshipType, relationshipTypeDefinition.getUniqueId()); - + .findPropertiesOfNode(NodeTypeEnum.RelationshipType, relationshipTypeDefinition.getUniqueId()); + Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao) - .getChild("uid", derivedFromRelationshipTypeData.getUniqueId(), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.RelationshipType, RelationshipTypeData.class); - + .getChild("uid", derivedFromRelationshipTypeData.getUniqueId(), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.RelationshipType, + RelationshipTypeData.class); + Mockito.doReturn(Either.left(new ImmutablePair(new RelationshipTypeData(relationshipTypeDefinition), null))).when(janusGraphGenericDao) - .getChild("uid", relationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.RelationshipType, RelationshipTypeData.class); - - + .getChild("uid", relationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.DERIVED_FROM, NodeTypeEnum.RelationshipType, + RelationshipTypeData.class); + Mockito.doReturn(Either.left(new GraphRelation())).when(derivedFromOperation) - .addDerivedFromRelation(relationshipTypeDefinition.getUniqueId(), derivedFromRelationshipTypeData.getUniqueId(), NodeTypeEnum.RelationshipType); - + .addDerivedFromRelation(relationshipTypeDefinition.getUniqueId(), derivedFromRelationshipTypeData.getUniqueId(), + NodeTypeEnum.RelationshipType); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) - .when(janusGraphGenericDao).getParentNode("uid", dervideFromRelationshipInstDataDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); - + .when(janusGraphGenericDao) + .getParentNode("uid", dervideFromRelationshipInstDataDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, + ModelData.class); + Mockito.doReturn(Either.left(pair)) - .when(janusGraphGenericDao).getParentNode("uid", relationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); - + .when(janusGraphGenericDao) + .getParentNode("uid", relationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); + Mockito.doReturn(Either.left(new RelationshipTypeData(relationshipTypeDefinition))) - .when(janusGraphGenericDao).getNode("uid", relationshipTypeDefinition.getUniqueId(), RelationshipTypeData.class); - + .when(janusGraphGenericDao).getNode("uid", relationshipTypeDefinition.getUniqueId(), RelationshipTypeData.class); + Mockito.doReturn(Either.left(new RelationshipTypeData(relationshipTypeDefinition))) - .when(janusGraphGenericDao).getNode("type", relationshipTypeDefinition.getUniqueId(), RelationshipTypeData.class, "modelA"); - + .when(janusGraphGenericDao).getNode("type", relationshipTypeDefinition.getUniqueId(), RelationshipTypeData.class, "modelA"); + Either either = - relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, true); + relationshipTypeOperation.addRelationshipType(relationshipTypeDefinition, true); assertTrue(either.isLeft()); } @@ -488,10 +486,10 @@ public class RelationshipTypeOperationTest extends ModelTestBase { @Test public void testGetRelationshipTypeNotConnected() { Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_CONNECTED)) - .when(relationshipTypeOperation).getRelationshipTypeByUid(Mockito.anyString()); + .when(relationshipTypeOperation).getRelationshipTypeByUid(Mockito.anyString()); Either either = - relationshipTypeOperation.getRelationshipType(Mockito.anyString(), Mockito.anyBoolean()); + relationshipTypeOperation.getRelationshipType(Mockito.anyString(), Mockito.anyBoolean()); assertTrue(either.isRight()); } @@ -499,10 +497,10 @@ public class RelationshipTypeOperationTest extends ModelTestBase { @Test public void testGetRelationshipTypeSuccess() { Mockito.doReturn(Either.left(relationshipTypeDefinition)) - .when(relationshipTypeOperation).getRelationshipTypeByUid(Mockito.anyString()); + .when(relationshipTypeOperation).getRelationshipTypeByUid(Mockito.anyString()); Either either = - relationshipTypeOperation.getRelationshipType(Mockito.anyString(), Mockito.anyBoolean()); + relationshipTypeOperation.getRelationshipType(Mockito.anyString(), Mockito.anyBoolean()); assertTrue(either.isLeft()); } @@ -517,42 +515,43 @@ public class RelationshipTypeOperationTest extends ModelTestBase { newRelationshipTypeDefinition.setProperties(createPropertyData("prop1")); Mockito.doReturn(Either.left(new RelationshipTypeData(newRelationshipTypeDefinition))).when( - janusGraphGenericDao) - .updateNode(Mockito.any(), Mockito.eq(RelationshipTypeData.class)); + janusGraphGenericDao) + .updateNode(Mockito.any(), Mockito.eq(RelationshipTypeData.class)); Mockito.doReturn(Either.left(newRelationshipTypeDefinition.getProperties())) - .when(propertyOperation).deletePropertiesAssociatedToNode(Mockito.any(), Mockito.anyString()); + .when(propertyOperation).deletePropertiesAssociatedToNode(Mockito.any(), Mockito.anyString()); Mockito.doReturn(Either.left(newRelationshipTypeDefinition.getProperties())) - .when(propertyOperation).addPropertiesToElementType(Mockito.anyString(), Mockito.any(), Mockito.anyMap()); + .when(propertyOperation).addPropertiesToElementType(Mockito.anyString(), Mockito.any(), Mockito.anyMap()); Mockito.doReturn(Either.left(newRelationshipTypeDefinition)).when(relationshipTypeOperation) - .getRelationshipTypeByUid(Mockito.anyString()); + .getRelationshipTypeByUid(Mockito.anyString()); Mockito.doReturn(StorageOperationStatus.OK).when(derivedFromOperation) - .removeDerivedFromRelation(Mockito.anyString(), Mockito.anyString(), Mockito.any()); + .removeDerivedFromRelation(Mockito.anyString(), Mockito.anyString(), Mockito.any()); Mockito.doReturn(Either.left(new GraphRelation())) - .when(derivedFromOperation) - .addDerivedFromRelation(Mockito.anyString(), Mockito.anyString(), Mockito.any()); - + .when(derivedFromOperation) + .addDerivedFromRelation(Mockito.anyString(), Mockito.anyString(), Mockito.any()); + Mockito.doReturn(Either.left(new RelationshipTypeData(relationshipTypeDefinition))) - .when(janusGraphGenericDao).getNode(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); - + .when(janusGraphGenericDao).getNode(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doReturn(Either.left(Collections.singletonMap("derivedFromProp1", new PropertyDefinition()))).when(propertyOperation) - .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); - + .findPropertiesOfNode(Mockito.any(), Mockito.anyString()); + Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao) - .getChild(Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); - + .getChild(Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) - .when(janusGraphGenericDao).getParentNode("uid", newRelationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); + .when(janusGraphGenericDao) + .getParentNode("uid", newRelationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); Either either = - relationshipTypeOperation.updateRelationshipType(relationshipTypeDefinition, - newRelationshipTypeDefinition, false); + relationshipTypeOperation.updateRelationshipType(relationshipTypeDefinition, + newRelationshipTypeDefinition, false); assertTrue(either.isLeft()); } @@ -562,29 +561,30 @@ public class RelationshipTypeOperationTest extends ModelTestBase { RelationshipTypeData relationshipTypeData = new RelationshipTypeData(relationshipTypeDefinition); Mockito.doReturn(Either.left(relationshipTypeData)).when(janusGraphGenericDao) - .getNode(Mockito.anyString(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); + .getNode(Mockito.anyString(), Mockito.any(), Mockito.eq(RelationshipTypeData.class)); Mockito.doReturn(Either.left(relationshipTypeDefinition.getProperties())) - .when(propertyOperation).findPropertiesOfNode(Mockito.any(), Mockito.anyString()); + .when(propertyOperation).findPropertiesOfNode(Mockito.any(), Mockito.anyString()); RelationshipTypeDefinition childRelationshipTypeDefinition = new RelationshipTypeDefinition(); childRelationshipTypeDefinition.setType("tosca.relationships.ContainerChild"); Mockito.doReturn(Either.left(new ImmutablePair(new RelationshipTypeData(childRelationshipTypeDefinition), null))).when( - janusGraphGenericDao) - .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), - Mockito.eq(RelationshipTypeData.class)); - + janusGraphGenericDao) + .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), + Mockito.eq(RelationshipTypeData.class)); + ModelData modelData = new ModelData("modelA", "modelA", ModelTypeEnum.NORMATIVE); ImmutablePair pair = new ImmutablePair<>(modelData, new GraphEdge()); Mockito.doReturn(Either.left(pair)) - .when(janusGraphGenericDao).getParentNode("uid", relationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); + .when(janusGraphGenericDao) + .getParentNode("uid", relationshipTypeDefinition.getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT, NodeTypeEnum.Model, ModelData.class); Either either = - relationshipTypeOperation.getRelationshipTypeByUid("tosca.relationships.Container1"); + relationshipTypeOperation.getRelationshipTypeByUid("tosca.relationships.Container1"); assertTrue(either.isLeft() - && "tosca.relationships.ContainerChild".equals(either.left().value().getDerivedFrom())); + && "tosca.relationships.ContainerChild".equals(either.left().value().getDerivedFrom())); } private Map createPropertyData(String value) { diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java index 4817f7a1c4..abb5a1888b 100644 --- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java +++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/ToscaElementLifecycleOperationTest.java @@ -37,13 +37,12 @@ import java.util.Map; import org.apache.tinkerpop.gremlin.structure.io.IoCore; import org.janusgraph.core.JanusGraph; import org.janusgraph.core.JanusGraphVertex; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.rules.TestName; -import org.junit.runner.RunWith; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -74,44 +73,36 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaElementLifecycl import org.openecomp.sdc.be.model.jsonjanusgraph.utils.GraphTestUtils; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.common.util.ValidationUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration("classpath:application-context-test.xml") +@SpringJUnitConfig(locations = "classpath:application-context-test.xml") public class ToscaElementLifecycleOperationTest extends ModelTestBase { + @Rule + public TestName name = new TestName(); @javax.annotation.Resource protected JanusGraphDao janusGraphDao; - + String categoryName = "category"; + String subcategory = "mycategory"; + String outputDirectory = "C:\\Output"; @javax.annotation.Resource private NodeTypeOperation nodeTypeOperation; - @javax.annotation.Resource private TopologyTemplateOperation topologyTemplateOperation; - @javax.annotation.Resource private ToscaElementLifecycleOperation lifecycleOperation; - - String categoryName = "category"; - String subcategory = "mycategory"; - String outputDirectory = "C:\\Output"; - - @Rule - public TestName name = new TestName(); - - @BeforeClass - public static void initLifecycleOperation() { - ModelTestBase.init(); - } - private GraphVertex ownerVertex; private GraphVertex modifierVertex; private GraphVertex vfVertex; private GraphVertex serviceVertex; private GraphVertex rootVertex; - @Before + @BeforeAll + public static void initLifecycleOperation() { + ModelTestBase.init(); + } + + @BeforeEach public void setupBefore() { clearGraph(); createUsers(); @@ -125,8 +116,10 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { @Test public void lifecycleTest() { - Either res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), modifierVertex.getUniqueId(), - ownerVertex.getUniqueId()); + Either res = lifecycleOperation.checkinToscaELement( + LifecycleStateEnum.findState((String) vfVertex.getMetadataProperty(GraphPropertyEnum.STATE)), vfVertex.getUniqueId(), + modifierVertex.getUniqueId(), + ownerVertex.getUniqueId()); StorageOperationStatus status; assertTrue(res.isLeft()); @@ -147,7 +140,8 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { prop55.setName("prop55"); prop55.setDefaultValue("def55"); - status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); CapabilityDataDefinition cap1 = new CapabilityDataDefinition(); @@ -155,10 +149,12 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { cap1.setDescription("create"); cap1.setUniqueId(UniqueIdBuilder.buildCapabilityUid(id, "cap1")); - status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); - res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId()); + res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), + ownerVertex.getUniqueId()); assertTrue(res.isLeft()); id = res.left().value().getUniqueId(); @@ -167,19 +163,22 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { id = res.left().value().getUniqueId(); prop55.setDefaultValue("AAAAAAAA"); - status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, JsonPresentationFields.NAME); + status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop55, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); cap1.setDescription("update"); - status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, JsonPresentationFields.NAME); + status = nodeTypeOperation.updateToscaDataOfToscaElement(id, EdgeLabelEnum.CAPABILITIES, VertexTypeEnum.CAPABILITIES, cap1, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition prop66 = new PropertyDataDefinition(); prop66.setName("prop66"); prop66.setDefaultValue("def66"); - status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop66, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); @@ -198,10 +197,12 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { prop77.setName("prop77"); prop77.setDefaultValue("def77"); - status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop77, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); - res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), ownerVertex.getUniqueId()); + res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT, id, ownerVertex.getUniqueId(), + ownerVertex.getUniqueId()); assertTrue(res.isLeft()); id = res.left().value().getUniqueId(); @@ -213,7 +214,8 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { prop88.setName("prop88"); prop88.setDefaultValue("def88"); - status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop88, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); res = lifecycleOperation.certifyToscaElement(id, modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); @@ -231,10 +233,12 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { prop99.setName("prop99"); prop99.setDefaultValue("def99"); - status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop99, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); - status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", JsonPresentationFields.NAME); + status = nodeTypeOperation.deleteToscaDataElement(id, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, "prop99", + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); verifyInCatalogData(4, null); @@ -242,8 +246,9 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { @Test public void serviceConformanceLevelTest() { - Either res = lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(), - modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); + Either res = lifecycleOperation.checkinToscaELement( + LifecycleStateEnum.findState((String) serviceVertex.getMetadataProperty(GraphPropertyEnum.STATE)), serviceVertex.getUniqueId(), + modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); assertTrue(res.isLeft()); String id = res.left().value().getUniqueId(); @@ -277,22 +282,25 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { expectedIds.add(vertex4.getUniqueId()); verifyInCatalogData(4, expectedIds); - lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); - Either certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); + lifecycleOperation.checkinToscaELement(LifecycleStateEnum.findState((String) vertex4.getMetadataProperty(GraphPropertyEnum.STATE)), + vertex4.getUniqueId(), modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); + Either certifyToscaElement = lifecycleOperation.certifyToscaElement(vertex4.getUniqueId(), + modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); assertTrue(certifyToscaElement.isLeft()); expectedIds.remove(vertex4.getUniqueId()); String certifiedId = certifyToscaElement.left().value().getUniqueId(); expectedIds.add(certifiedId); verifyInCatalogData(4, expectedIds); - Either res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), ownerVertex.getUniqueId()); + Either res = lifecycleOperation.checkoutToscaElement(certifiedId, modifierVertex.getUniqueId(), + ownerVertex.getUniqueId()); assertTrue(certifyToscaElement.isLeft()); expectedIds.add(res.left().value().getUniqueId()); verifyInCatalogData(5, expectedIds); } @Test - public void testGetToscaElOwner_Fail(){ + public void testGetToscaElOwner_Fail() { Either result; String toscaEleId = "toscaElementId"; janusGraphDao.getVertexById(toscaEleId, JsonParseFlagEnum.NoParse); @@ -453,21 +461,24 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { prop22.setDefaultValue("def22"); addProperties.add(prop22); - StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, addProperties, JsonPresentationFields.NAME); + StorageOperationStatus status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, + addProperties, JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition prop33 = new PropertyDataDefinition(); prop33.setName("prop33"); prop33.setDefaultValue("def33"); - status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex, EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop33, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition prop44 = new PropertyDataDefinition(); prop44.setName("prop44"); prop44.setDefaultValue("def44"); - status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, JsonPresentationFields.NAME); + status = nodeTypeOperation.addToscaDataToToscaElement(vfVertex.getUniqueId(), EdgeLabelEnum.PROPERTIES, VertexTypeEnum.PROPERTIES, prop44, + JsonPresentationFields.NAME); assertSame(status, StorageOperationStatus.OK); PropertyDataDefinition capProp = new PropertyDataDefinition(); @@ -480,14 +491,16 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { Map capProps = new HashMap(); capProps.put("capName", dataToCreate); - Either res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); + Either res = nodeTypeOperation.associateElementToData(vfVertex, VertexTypeEnum.CAPABILITIES_PROPERTIES, + EdgeLabelEnum.CAPABILITIES_PROPERTIES, capProps); // exportGraphMl(janusGraphDao.getGraph().left().value()); List pathKeys = new ArrayList<>(); pathKeys.add("capName"); capProp.setDefaultValue("BBBB"); - status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); + status = nodeTypeOperation.updateToscaDataDeepElementOfToscaElement(vfVertex, EdgeLabelEnum.CAPABILITIES_PROPERTIES, + VertexTypeEnum.CAPABILITIES_PROPERTIES, capProp, pathKeys, JsonPresentationFields.NAME); return vf; } @@ -587,7 +600,7 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { public void verifyInCatalogData(int expected, List expectedIds) { - Either, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null); + Either, StorageOperationStatus> highestResourcesRes = topologyTemplateOperation.getElementCatalogData(true, null); assertTrue(highestResourcesRes.isLeft()); List highestResources = highestResourcesRes.left().value(); // calculate expected count value @@ -597,7 +610,7 @@ public class ToscaElementLifecycleOperationTest extends ModelTestBase { } } - @After + @AfterEach public void teardown() { clearGraph(); } -- cgit 1.2.3-korg