From b2c0528da052b5c73e3fc1f7f98d22578acd91f0 Mon Sep 17 00:00:00 2001 From: xuegao Date: Fri, 19 Mar 2021 14:04:17 +0100 Subject: Improve test coverage Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I29a8f1d49f1dfd6bca79f3d873d1e1ff7adc4fb2 Signed-off-by: xuegao --- .../sdc/be/auditing/impl/AuditingManagerTest.java | 49 +++++--- .../AuditGetCategoryHierarchyEventFactoryTest.java | 33 ++---- .../AuditGetUsersListEventFactoryTest.java | 30 ++--- .../AuditUserAccessEventFactoryTest.java | 29 ++--- .../sdc/be/components/csar/CsarInfoTest.java | 23 +++- ...mponentInstanceInputPropertyDeclaratorTest.java | 47 ++++---- .../ComponentInstancePropertyDeclaratorTest.java | 91 +++++++------- .../property/ComponentPropertyDeclaratorTest.java | 132 +++++++++++++++++++-- .../ComponentPropertyToPolicyDeclaratorTest.java | 26 ++-- .../property/GroupPropertyDeclaratorTest.java | 62 +++++----- .../property/PolicyPropertyDeclaratorTest.java | 56 ++++----- .../property/PropertyDeclaratorTestBase.java | 4 +- .../be/components/utils/ConsumptionUtilsTest.java | 24 +++- .../sdc/be/tosca/GroupExportParserImplTest.java | 38 ++++-- .../sdc/be/tosca/model/ToscaMetadataTest.java | 66 ++++++++++- 15 files changed, 461 insertions(+), 249 deletions(-) (limited to 'catalog-be/src/test/java/org') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditingManagerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditingManagerTest.java index e672ced134..5cfa64ea49 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditingManagerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/AuditingManagerTest.java @@ -19,22 +19,23 @@ */ package org.openecomp.sdc.be.auditing.impl; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.auditing.api.AuditEventFactory; +import org.openecomp.sdc.be.config.Configuration; import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; +import org.openecomp.sdc.common.log.wrappers.LoggerSdcAudit; import org.openecomp.sdc.test.utils.TestConfigurationProvider; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class AuditingManagerTest { private static final String MSG = "msg"; @@ -47,21 +48,39 @@ public class AuditingManagerTest { private AuditCassandraDao cassandraDao; @Mock private AuditEventFactory eventFactory; - - @Before - public void setUp() throws Exception { + @Mock + private ConfigurationProvider config; + @Test + public void testShouldAuditEvent() { auditingManager = new AuditingManager(cassandraDao, new TestConfigurationProvider()); Mockito.when(eventFactory.getLogMessage()).thenReturn(msg); Mockito.when(eventFactory.getDbEvent()).thenReturn(auditEvent); Mockito.when(cassandraDao.saveRecord(auditEvent)).thenReturn(CassandraOperationStatus.OK); - } - - @Test - public void testShouldAuditEvent() { String result = auditingManager.auditEvent(eventFactory); - assertThat(result, is(msg)); + assertEquals(msg, result); Mockito.verify(cassandraDao).saveRecord(auditEvent); } + @Test + public void testShouldNotAuditEvent() { + Configuration testConfig = new Configuration(); + testConfig.setDisableAudit(true); + Mockito.when(config.getConfiguration()).thenReturn(testConfig); + + AuditingManager auditingManager2 = new AuditingManager(cassandraDao, config); + assertNull(auditingManager2.auditEvent(eventFactory)); + Mockito.verify(config, Mockito.times(1)).getConfiguration(); + } + @Test + public void testShouldAuditEventWithLog() { + auditingManager = new AuditingManager(cassandraDao, new TestConfigurationProvider()); + Mockito.when(eventFactory.getLogMessage()).thenReturn(msg); + Mockito.when(eventFactory.getDbEvent()).thenReturn(auditEvent); + Mockito.when(cassandraDao.saveRecord(auditEvent)).thenReturn(CassandraOperationStatus.OK); + LoggerSdcAudit logger = Mockito.mock(LoggerSdcAudit.class); + String result = auditingManager.auditEvent(eventFactory, logger); + assertEquals(msg, result); + Mockito.verify(cassandraDao).saveRecord(auditEvent); + } } \ No newline at end of file diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/category/AuditGetCategoryHierarchyEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/category/AuditGetCategoryHierarchyEventFactoryTest.java index 554d8efdc2..1ab5faee15 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/category/AuditGetCategoryHierarchyEventFactoryTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/category/AuditGetCategoryHierarchyEventFactoryTest.java @@ -20,38 +20,29 @@ package org.openecomp.sdc.be.auditing.impl.category; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder; -public class AuditGetCategoryHierarchyEventFactoryTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; - private AuditGetCategoryHierarchyEventFactory createTestSubject() { - Builder newBuilder = CommonAuditData.newBuilder(); - CommonAuditData build = newBuilder.build(); - return new AuditGetCategoryHierarchyEventFactory( build, - new User(), ""); - } +public class AuditGetCategoryHierarchyEventFactoryTest { + private Builder newBuilder = CommonAuditData.newBuilder(); + private CommonAuditData build = newBuilder.build(); @Test public void testGetLogMessage() throws Exception { - AuditGetCategoryHierarchyEventFactory testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getLogMessage(); + AuditGetCategoryHierarchyEventFactory testSubject = new AuditGetCategoryHierarchyEventFactory( build, + "user", "", ""); + assertEquals("ACTION = \"GetCategoryHierarchy\" MODIFIER = \"user\" DETAILS = \"\" STATUS = \"\" DESC = \"\"", testSubject.getLogMessage()); } @Test public void testGetDbEvent() throws Exception { - AuditGetCategoryHierarchyEventFactory testSubject; - AuditingGenericEvent result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDbEvent(); + AuditGetCategoryHierarchyEventFactory testSubject = new AuditGetCategoryHierarchyEventFactory( build, new User(), ""); + assertNotNull(testSubject.getDbEvent()); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditGetUsersListEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditGetUsersListEventFactoryTest.java index 8e6785a9b1..46b746f5ae 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditGetUsersListEventFactoryTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditGetUsersListEventFactoryTest.java @@ -20,36 +20,26 @@ package org.openecomp.sdc.be.auditing.impl.usersadmin; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData; -public class AuditGetUsersListEventFactoryTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; - private AuditGetUsersListEventFactory createTestSubject() { - org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder(); - CommonAuditData commonAuData = newBuilder.build(); - return new AuditGetUsersListEventFactory(commonAuData, new User(), ""); - } +public class AuditGetUsersListEventFactoryTest { + private org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder(); + private CommonAuditData commonAuData = newBuilder.build(); @Test public void testGetLogMessage() throws Exception { - AuditGetUsersListEventFactory testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getLogMessage(); + AuditGetUsersListEventFactory testSubject = new AuditGetUsersListEventFactory(commonAuData, "user", "", ""); + assertEquals("ACTION = \"GetUsersList\" MODIFIER = \"user\" DETAILS = \"\" STATUS = \"\" DESC = \"\"", testSubject.getLogMessage()); } @Test public void testGetDbEvent() throws Exception { - AuditGetUsersListEventFactory testSubject; - AuditingGenericEvent result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDbEvent(); + AuditGetUsersListEventFactory testSubject = new AuditGetUsersListEventFactory(commonAuData, new User(), ""); + assertNotNull(testSubject.getDbEvent()); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditUserAccessEventFactoryTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditUserAccessEventFactoryTest.java index 13448a9c8f..4fe8fe7733 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditUserAccessEventFactoryTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/auditing/impl/usersadmin/AuditUserAccessEventFactoryTest.java @@ -20,36 +20,27 @@ package org.openecomp.sdc.be.auditing.impl.usersadmin; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.model.User; -import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent; import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData; -public class AuditUserAccessEventFactoryTest { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; - private AuditUserAccessEventFactory createTestSubject() { - org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder(); - CommonAuditData commonAuData = newBuilder.build(); - return new AuditUserAccessEventFactory(commonAuData, new User()); - } +public class AuditUserAccessEventFactoryTest { + private org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData.Builder newBuilder = CommonAuditData.newBuilder(); + private CommonAuditData commonAuData = newBuilder.build(); @Test public void testGetLogMessage() throws Exception { - AuditUserAccessEventFactory testSubject; - String result; + AuditUserAccessEventFactory testSubject = new AuditUserAccessEventFactory(commonAuData, new User()); + assertEquals("ACTION = \"Access\" USER = \"\" STATUS = \"\" DESC = \"\"", testSubject.getLogMessage()); - // default test - testSubject = createTestSubject(); - result = testSubject.getLogMessage(); } @Test public void testGetDbEvent() throws Exception { - AuditUserAccessEventFactory testSubject; - AuditingGenericEvent result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getDbEvent(); + AuditUserAccessEventFactory testSubject = new AuditUserAccessEventFactory(commonAuData, "user", ""); + assertNotNull(testSubject.getDbEvent()); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java index f3f0ab5628..fddb79afb6 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java @@ -20,12 +20,12 @@ package org.openecomp.sdc.be.components.csar; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.config.NonManoArtifactType; @@ -54,9 +54,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class CsarInfoTest { private CsarInfo csarInfo; @@ -72,7 +73,7 @@ public class CsarInfoTest { private static final String NODE_TYPE = "tosca.nodes.Compute"; private static final String DELIVER_FOR = "tosca.nodes.Root"; - @Before + @BeforeEach public void setup() throws ZipException, URISyntaxException { // given csarInfo = createCsarInfo(PAYLOAD_NAME, MAIN_TEMPLATE_NAME); @@ -115,6 +116,16 @@ public class CsarInfoTest { csarInfo.addNodeToQueue(NEW_NODE_NAME); } + @Test + public void setUpdateTest() { + + csarInfo.setUpdate(true); + assertTrue(csarInfo.isUpdate()); + + csarInfo.setUpdate(false); + assertFalse(csarInfo.isUpdate()); + } + @Test public void csarCheckNodeTypesInfoTest() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java index 6b5d41d5ae..d8da908e0d 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstanceInputPropertyDeclaratorTest.java @@ -17,14 +17,13 @@ package org.openecomp.sdc.be.components.property; import fj.data.Either; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.utils.AnnotationBuilder; import org.openecomp.sdc.be.components.utils.InputsBuilder; @@ -51,15 +50,17 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.openecomp.sdc.be.MockGenerator.mockComponentUtils; import static org.openecomp.sdc.be.MockGenerator.mockExceptionUtils; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclaratorTestBase { @@ -82,7 +83,7 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar private Annotation annotation2; @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); testInstance = new ComponentInstanceInputPropertyDeclarator(mockComponentUtils(), propertyOperation, @@ -110,9 +111,9 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar when(toscaOperationFacade.getToscaElement(eq(ORIGIN_INSTANCE_ID), inputsFilterCaptor.capture())).thenReturn(Either.left(originInstanceNodeType)); Either, StorageOperationStatus> createdInputs = testInstance.declarePropertiesAsInputs(resource, "inst1", propsToDeclare); List inputs = createdInputs.left().value(); - assertThat(inputs).hasSize(1); + assertEquals(1, inputs.size()); verifyInputAnnotations(inputs.get(0)); - assertThat(inputsFilterCaptor.getValue().isIgnoreInputs()).isFalse(); + assertFalse(inputsFilterCaptor.getValue().isIgnoreInputs()); } @Test @@ -120,13 +121,15 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar List properties = Collections.singletonList(prop1); List propsToDeclare = createInstancePropInputList(properties); when(toscaOperationFacade.getToscaElement(eq(ORIGIN_INSTANCE_ID), inputsFilterCaptor.capture())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); - assertThatExceptionOfType(StorageException.class).isThrownBy(() -> testInstance.declarePropertiesAsInputs(resource, "inst1", propsToDeclare)); + assertThrows(StorageException.class, () -> { + testInstance.declarePropertiesAsInputs(resource, "inst1", propsToDeclare); + }); } @Test public void testCreateDeclaredProperty() { ComponentInstanceInput declaredProperty = testInstance.createDeclaredProperty(prop1); - assertThat(declaredProperty.getUniqueId()).isEqualTo(prop1.getUniqueId()); + assertEquals(prop1.getUniqueId(), declaredProperty.getUniqueId()); } @Test @@ -141,18 +144,18 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar Either>, StorageOperationStatus> updateEither = (Either>, StorageOperationStatus>) testInstance.updatePropertiesValues(resource, resource.getUniqueId(), expectedProperties); - assertThat(updateEither.isLeft()); + assertTrue(updateEither.isLeft()); Map> actualProperties = updateEither.left().value(); - assertThat(actualProperties.values().size()).isEqualTo(expectedProperties.size()); - assertThat(actualProperties.values().iterator().next()).isEqualTo(expectedProperties); + assertEquals(expectedProperties.size(), actualProperties.values().size()); + assertEquals(expectedProperties, actualProperties.values().iterator().next()); } @Test public void testResolvePropertiesOwner() { Optional componentInstance = testInstance.resolvePropertiesOwner(resource, INSTANCE_ID); - assertThat(componentInstance.isPresent()); - assertThat(componentInstance.get().getUniqueId()).isEqualTo(INSTANCE_ID); + assertTrue(componentInstance.isPresent()); + assertEquals(INSTANCE_ID, componentInstance.get().getUniqueId()); } @Test @@ -189,7 +192,7 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar when(toscaOperationFacade.updateComponentInstanceInputs(eq(component), eq(ciProp.getComponentInstanceId()), eq(ciPropList))).thenReturn(StorageOperationStatus.OK); StorageOperationStatus storageOperationStatus = testInstance.unDeclarePropertiesAsListInputs(component, inputToDelete); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); } @Test @@ -201,13 +204,13 @@ public class ComponentInstanceInputPropertyDeclaratorTest extends PropertyDeclar List resList = new ArrayList<>(); when(componentInstanceBusinessLogic.getComponentInstanceInputsByInputId(eq(resource), eq(INPUT_ID))).thenReturn(resList); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.OK); + assertEquals(status, StorageOperationStatus.OK); } private void verifyInputAnnotations(InputDefinition inputDefinition) { List annotations = inputDefinition.getAnnotations(); - assertThat(annotations) - .containsExactlyInAnyOrder(annotation1, annotation2); + assertTrue(annotations.contains(annotation1)); + assertTrue(annotations.contains(annotation2)); } private Component createComponentWithInputAndAnnotation(String inputName) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java index 07deb6a2de..bcbd07db31 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentInstancePropertyDeclaratorTest.java @@ -17,14 +17,14 @@ package org.openecomp.sdc.be.components.property; import fj.data.Either; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic; import org.openecomp.sdc.be.components.utils.InputsBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; @@ -57,7 +57,7 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verifyZeroInteractions; @@ -66,7 +66,7 @@ import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.creat import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createProperties; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorTestBase { @InjectMocks @@ -90,7 +90,7 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT public void declarePropertiesAsInputs_componentInstanceNotExist() { Component cmpt = new Resource(); Either, StorageOperationStatus> createdInputs = testInstance.declarePropertiesAsInputs(cmpt, "someCmptInstId", Collections.emptyList()); - assertThat(createdInputs.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND); + assertEquals(StorageOperationStatus.NOT_FOUND, createdInputs.right().value()); verifyZeroInteractions(toscaOperationFacade); } @@ -128,7 +128,7 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT Either, StorageOperationStatus> createdInputs = testInstance .declarePropertiesAsInputs(resource, "inst1", propsToDeclare); - Assert.assertTrue(createdInputs.isLeft()); + assertTrue(createdInputs.isLeft()); } @Test @@ -161,7 +161,7 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT any(ComponentInstanceProperty.class), any(CapabilityDefinition.class))).thenReturn(StorageOperationStatus.OK); StorageOperationStatus result = testInstance.unDeclarePropertiesAsInputs(component, input); - Assert.assertEquals(StorageOperationStatus.OK, result); + assertEquals(StorageOperationStatus.OK, result); } @Test @@ -207,8 +207,8 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT PropertyDefinition propertyDefinition = getPropertyForDeclaration(); ComponentInstanceProperty declaredProperty = testInstance.createDeclaredProperty(propertyDefinition); - assertThat(declaredProperty).isNotNull(); - assertThat(declaredProperty.getUniqueId()).isEqualTo(propertyDefinition.getUniqueId()); + assertNotNull(declaredProperty); + assertEquals(propertyDefinition.getUniqueId(), declaredProperty.getUniqueId()); } @Test @@ -237,7 +237,7 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT StorageOperationStatus undeclareStatus = testInstance.unDeclarePropertiesAsInputs(service, inputToDelete); - assertThat(undeclareStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, undeclareStatus); } private List getGetInputListForDeclaration() { @@ -271,16 +271,16 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT when(toscaOperationFacade.addComponentInstancePropertiesToComponent(eq(resource), instancePropertiesCaptor.capture())).thenReturn(Either.left(Collections.emptyMap())); Either result = testInstance.declarePropertiesAsListInput(resource, "inst1", propsToDeclare, input); // validate result - assertThat(result.isLeft()).isTrue(); + assertTrue(result.isLeft()); List capturedInstanceProperties = instancePropertiesCaptor.getValue().get(INSTANCE_ID); - assertThat(capturedInstanceProperties.size()).isEqualTo(2); + assertEquals(2, capturedInstanceProperties.size()); Map propertiesMap = properties.stream().collect(Collectors.toMap(PropertyDataDefinition::getName, e->e)); for(ComponentInstanceProperty instanceProperty: capturedInstanceProperties) { - assertThat(propertiesMap.containsKey(instanceProperty.getName())).isTrue(); + assertTrue(propertiesMap.containsKey(instanceProperty.getName())); PropertyDataDefinition property = propertiesMap.get(instanceProperty.getName()); - assertThat(instanceProperty.getType()).isEqualTo(property.getType()); - assertThat(instanceProperty.isGetInputProperty()).isTrue(); + assertEquals(property.getType(), instanceProperty.getType()); + assertTrue(instanceProperty.isGetInputProperty()); } } @@ -297,8 +297,8 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT .build()); Either result = testInstance.declarePropertiesAsListInput(resource, "inst2", propsToDeclare, input); // validate result - assertThat(result.isRight()).isTrue(); - assertThat(result.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND); + assertTrue(result.isRight()); + assertEquals(StorageOperationStatus.NOT_FOUND, result.right().value()); } @Test @@ -335,7 +335,7 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT when(toscaOperationFacade.updateComponentInstanceProperties(eq(component), eq(ciProp.getComponentInstanceId()), eq(ciPropList))).thenReturn(StorageOperationStatus.OK); StorageOperationStatus storageOperationStatus = testInstance.unDeclarePropertiesAsListInputs(component, inputToDelete); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); } @Test @@ -347,29 +347,29 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT List resList = new ArrayList<>(); when(componentInstanceBusinessLogic.getComponentInstancePropertiesByInputId(eq(resource), eq(INPUT_ID))).thenReturn(resList); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.OK); + assertEquals(status, StorageOperationStatus.OK); } private void verifyUpdatedProperties(List properties, List capturedInstanceProperties, List inputs) { - assertThat(capturedInstanceProperties).hasSize(properties.size()); + assertEquals(properties.size(), capturedInstanceProperties.size()); Map updatedPropertiesByName = MapUtil.toMap(capturedInstanceProperties, ComponentInstanceProperty::getName); properties.forEach(prop -> verifyUpdatedInstanceProperty(prop, updatedPropertiesByName.get(prop.getName()), inputs)); } private void verifyUpdatedComplexProperty(List capturedInstanceProperties, List inputs) { - assertThat(capturedInstanceProperties).hasSize(1); + assertEquals(1, capturedInstanceProperties.size()); verifyUpdatedInstanceComplexProperty(capturedInstanceProperties.get(0), inputs); } private void verifyCreatedInputs(List originalPropsToDeclare, List capturedUpdatedProperties, List inputs) { - assertThat(inputs).hasSize(originalPropsToDeclare.size()); + assertEquals(originalPropsToDeclare.size(), inputs.size()); Map propertyIdToCreatedInput = MapUtil.toMap(inputs, InputDefinition::getPropertyId); originalPropsToDeclare.forEach(propToDeclare -> verifyCreatedInput(propToDeclare, propertyIdToCreatedInput.get(propToDeclare.getUniqueId()))); capturedUpdatedProperties.forEach(updatedProperty -> verifyInputPropertiesList(updatedProperty, propertyIdToCreatedInput.get(updatedProperty.getUniqueId()))); } private void verifyCreatedInputsFromComplexProperty(List propsToDeclare, List capturedInstanceProperties, List inputs) { - assertThat(inputs).hasSize(propsToDeclare.size()); + assertEquals(propsToDeclare.size(), inputs.size()); Map inputsByName = MapUtil.toMap(inputs, InputDefinition::getName); propsToDeclare.forEach(propToDeclare -> verifyCreatedInputFromComplexProperty(propToDeclare, inputsByName)); Map> propertyIdToCreatedInput = MapUtil.groupListBy(inputs, InputDefinition::getPropertyId); @@ -384,18 +384,17 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT PropertyDefinition innerProperty = parentProperty.getInput(); String expectedInputName = generateExpectedInputName(parentProperty, innerProperty); InputDefinition input = inputsByName.get(expectedInputName); - assertThat(input.getType()).isEqualTo(innerProperty.getType()); - assertThat(input.getValue()).isEqualTo(innerProperty.getValue()); + assertEquals(innerProperty.getType(), input.getType()); + assertEquals(innerProperty.getValue(), input.getValue()); // assertThat(input.getDefaultValue()).isEqualTo(innerProperty.getValue());//bug - assertThat(input.getUniqueId()).isEqualTo(UniqueIdBuilder.buildPropertyUniqueId(RESOURCE_ID, input.getName())); - assertThat(input.getPropertyId()).isEqualTo(parentProperty.getUniqueId()); - assertThat(input.getInstanceUniqueId()).isEqualTo(INSTANCE_ID); + assertEquals(UniqueIdBuilder.buildPropertyUniqueId(RESOURCE_ID, input.getName()), input.getUniqueId()); + assertEquals(INSTANCE_ID, input.getInstanceUniqueId()); } private void verifyInputPropertiesList(ComponentInstanceProperty updatedProperty, InputDefinition input) { - assertThat(input.getProperties()).hasSize(1); - assertThat(updatedProperty).isEqualTo(input.getProperties().get(0)); + assertEquals(1, input.getProperties().size()); + assertEquals(input.getProperties().get(0), updatedProperty); } @@ -411,17 +410,17 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT } private void verifyUpdatedInstanceProperty(PropertyDataDefinition originalProperty, ComponentInstanceProperty updatedProperty, List inputs) { - assertThat(updatedProperty.getValue()).isEqualTo(generateGetInputValue(generateExpectedInputName(originalProperty))); - assertThat(updatedProperty.isGetInputProperty()).isTrue(); - assertThat(updatedProperty.getName()).isEqualTo(originalProperty.getName()); + assertEquals(generateGetInputValue(generateExpectedInputName(originalProperty)), updatedProperty.getValue()); + assertTrue(updatedProperty.isGetInputProperty()); + assertEquals(originalProperty.getName(), updatedProperty.getName()); List getInputValues = updatedProperty.getGetInputValues(); verifyGetInputValues(getInputValues, inputs); } private void verifyUpdatedInstanceComplexProperty(ComponentInstanceProperty updatedComplexProperty, List inputs) { - assertThat(updatedComplexProperty.getValue()).isEqualTo(generateComplexGetInputValue(inputs)); - assertThat(updatedComplexProperty.isGetInputProperty()).isTrue(); - assertThat(updatedComplexProperty.getName()).isEqualTo(complexProperty.getName()); + assertEquals(generateComplexGetInputValue(inputs), updatedComplexProperty.getValue()); + assertTrue(updatedComplexProperty.isGetInputProperty()); + assertEquals(complexProperty.getName(), updatedComplexProperty.getName()); List getInputValues = updatedComplexProperty.getGetInputValues(); verifyGetInputValues(getInputValues, inputs); } @@ -430,7 +429,7 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT Map inputsByName = MapUtil.toMap(inputs, InputDefinition::getName); getInputValues.forEach(getInputVal -> { InputDefinition input = inputsByName.get(getInputVal.getInputName()); - assertThat(input.getUniqueId()).isEqualTo(getInputVal.getInputId()); + assertEquals(getInputVal.getInputId(), input.getUniqueId()); }); } @@ -447,13 +446,13 @@ public class ComponentInstancePropertyDeclaratorTest extends PropertyDeclaratorT } private void verifyCreatedInput(PropertyDataDefinition property, InputDefinition input) { - assertThat(input.getType()).isEqualTo(property.getType()); - assertThat(input.getName()).isEqualTo(generateExpectedInputName(property)); - assertThat(input.getValue()).isEqualTo(property.getValue()); - assertThat(input.getDefaultValue()).isEqualTo(property.getValue()); - assertThat(input.getUniqueId()).isEqualTo(UniqueIdBuilder.buildPropertyUniqueId(RESOURCE_ID, input.getName())); - assertThat(input.getPropertyId()).isEqualTo(property.getUniqueId()); - assertThat(input.getInstanceUniqueId()).isEqualTo(INSTANCE_ID); + assertEquals(property.getType(), input.getType()); + assertEquals(generateExpectedInputName(property), input.getName()); + assertEquals(property.getValue(), input.getValue()); + assertEquals(property.getValue(), input.getDefaultValue()); + assertEquals(UniqueIdBuilder.buildPropertyUniqueId(RESOURCE_ID, input.getName()), input.getUniqueId()); + assertEquals(property.getUniqueId(), input.getPropertyId()); + assertEquals(INSTANCE_ID, input.getInstanceUniqueId()); } private Component createComponentWithListInput(String inputName, String propName) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java index 057c4fba42..62d1d76c5c 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyDeclaratorTest.java @@ -22,12 +22,12 @@ package org.openecomp.sdc.be.components.property; import fj.data.Either; import org.apache.commons.collections.CollectionUtils; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic; import org.openecomp.sdc.be.components.utils.InputsBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; @@ -55,7 +55,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase { @InjectMocks @@ -71,11 +71,25 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase private static final String SERVICE_UID = "serviceUid"; private Service service; - @Before + @BeforeEach public void init() { service = new ServiceBuilder().setUniqueId(SERVICE_UID).build(); } + @Test + public void unDeclarePropertiesAsInputsTest_whenPropertyUsedByOperation() { + InputDefinition input = new InputDefinition(); + input.setUniqueId(INPUT_ID); + input.setName(INPUT_ID); + input.setValue("value"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(input); + + when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), eq(propertyDefinition))).thenReturn(true); + StorageOperationStatus status = testInstance.unDeclarePropertiesAsInputs(resource, input); + Assert.assertEquals(StorageOperationStatus.DECLARED_INPUT_USED_BY_OPERATION, status); + } + @Test public void unDeclarePropertiesAsListInputsTest_whenPropertyUsedByOperation() { InputDefinition input = new InputDefinition(); @@ -87,7 +101,22 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), eq(propertyDefinition))).thenReturn(true); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.DECLARED_INPUT_USED_BY_OPERATION); + Assert.assertEquals(StorageOperationStatus.DECLARED_INPUT_USED_BY_OPERATION, status); + } + + @Test + public void unDeclarePropertiesAsInputsTest_whenNotPresentPropertyToUpdateCandidate() { + InputDefinition input = new InputDefinition(); + input.setUniqueId(INPUT_ID); + input.setName(INPUT_ID); + input.setValue("value"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(); + resource.setProperties(Collections.singletonList(propertyDefinition)); + + when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any(PropertyDefinition.class))).thenReturn(false); + StorageOperationStatus status = testInstance.unDeclarePropertiesAsInputs(resource, input); + Assert.assertEquals(StorageOperationStatus.OK, status); } @Test @@ -102,7 +131,21 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any(PropertyDefinition.class))).thenReturn(false); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.OK); + Assert.assertEquals(StorageOperationStatus.OK, status); + } + + @Test + public void unDeclarePropertiesAsInputsTest_whenPropertiesEmpty() { + InputDefinition input = new InputDefinition(); + input.setUniqueId(INPUT_ID); + input.setName(INPUT_ID); + input.setValue("value"); + + resource.setProperties(new ArrayList<>()); + + when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any(PropertyDefinition.class))).thenReturn(false); + StorageOperationStatus status = testInstance.unDeclarePropertiesAsInputs(resource, input); + Assert.assertEquals(StorageOperationStatus.OK, status); } @Test @@ -116,7 +159,22 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any(PropertyDefinition.class))).thenReturn(false); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.OK); + Assert.assertEquals(StorageOperationStatus.OK, status); + } + + @Test + public void unDeclarePropertiesAsInputsTest_whenPropertiesToUpdateIsEmpty() { + InputDefinition input = new InputDefinition(); + input.setUniqueId(INPUT_ID); + input.setName(INPUT_ID); + input.setValue("value"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(input); + resource.setProperties(Collections.singletonList(propertyDefinition)); + + when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), eq(propertyDefinition))).thenReturn(false); + StorageOperationStatus status = testInstance.unDeclarePropertiesAsInputs(resource, input); + Assert.assertEquals(StorageOperationStatus.OK, status); } @Test @@ -131,7 +189,32 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), eq(propertyDefinition))).thenReturn(false); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.OK); + Assert.assertEquals(StorageOperationStatus.OK, status); + } + + @Test + public void unDeclarePropertiesAsInputsTest_singleProperty() { + InputDefinition input = new InputDefinition(); + input.setUniqueId(INPUT_ID); + input.setName(INPUT_ID); + input.setValue("value"); + input.setDefaultValue("default value"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(input); + List getInputValueList = new ArrayList<>(); + getInputValueList.add(buildGetInputValue(INPUT_ID)); + getInputValueList.add(buildGetInputValue("otherInputId")); + propertyDefinition.setGetInputValues(getInputValueList); + propertyDefinition.setUniqueId("propertyId"); + propertyDefinition.setDefaultValue("default value"); + propertyDefinition.setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName")); + resource.setProperties(Collections.singletonList(propertyDefinition)); + + when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any())).thenReturn(false); + when(propertyOperation.findDefaultValueFromSecondPosition(eq(Collections.emptyList()), eq(propertyDefinition.getUniqueId()), eq(propertyDefinition.getDefaultValue()))).thenReturn(Either.left(propertyDefinition.getDefaultValue())); + when(toscaOperationFacade.updatePropertyOfComponent(eq(resource), any())).thenReturn(Either.left(propertyDefinition)); + StorageOperationStatus status = testInstance.unDeclarePropertiesAsInputs(resource, input); + Assert.assertEquals(StorageOperationStatus.OK, status); } @Test @@ -156,7 +239,32 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase when(propertyOperation.findDefaultValueFromSecondPosition(eq(Collections.emptyList()), eq(propertyDefinition.getUniqueId()), eq(propertyDefinition.getDefaultValue()))).thenReturn(Either.left(propertyDefinition.getDefaultValue())); when(toscaOperationFacade.updatePropertyOfComponent(eq(resource), any())).thenReturn(Either.left(propertyDefinition)); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.OK); + Assert.assertEquals(StorageOperationStatus.OK, status); + } + + @Test + public void unDeclarePropertiesAsInputsTest_UnDeclareInputFail() { + InputDefinition input = new InputDefinition(); + input.setUniqueId(INPUT_ID); + input.setName(INPUT_ID); + input.setValue("value"); + input.setDefaultValue("default value"); + + PropertyDefinition propertyDefinition = new PropertyDefinition(input); + List getInputValueList = new ArrayList<>(); + getInputValueList.add(buildGetInputValue(INPUT_ID)); + getInputValueList.add(buildGetInputValue("otherInputId")); + propertyDefinition.setGetInputValues(getInputValueList); + propertyDefinition.setUniqueId("propertyId"); + propertyDefinition.setDefaultValue("default value"); + propertyDefinition.setValue(generateGetInputValueAsListInput(INPUT_ID, "innerPropName")); + resource.setProperties(Collections.singletonList(propertyDefinition)); + + when(propertyBusinessLogic.isPropertyUsedByOperation(eq(resource), any())).thenReturn(false); + when(propertyOperation.findDefaultValueFromSecondPosition(eq(Collections.emptyList()), eq(propertyDefinition.getUniqueId()), eq(propertyDefinition.getDefaultValue()))).thenReturn(Either.left(propertyDefinition.getDefaultValue())); + when(toscaOperationFacade.updatePropertyOfComponent(eq(resource), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); + StorageOperationStatus status = testInstance.unDeclarePropertiesAsInputs(resource, input); + Assert.assertEquals(StorageOperationStatus.NOT_FOUND, status); } @Test @@ -181,7 +289,7 @@ public class ComponentPropertyDeclaratorTest extends PropertyDeclaratorTestBase when(propertyOperation.findDefaultValueFromSecondPosition(eq(Collections.emptyList()), eq(propertyDefinition.getUniqueId()), eq(propertyDefinition.getDefaultValue()))).thenReturn(Either.left(propertyDefinition.getDefaultValue())); when(toscaOperationFacade.updatePropertyOfComponent(eq(resource), any())).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); StorageOperationStatus status = testInstance.unDeclarePropertiesAsListInputs(resource, input); - Assert.assertEquals(status, StorageOperationStatus.NOT_FOUND); + Assert.assertEquals(StorageOperationStatus.NOT_FOUND, status); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java index 96ba42d7b2..02d809d75c 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/ComponentPropertyToPolicyDeclaratorTest.java @@ -22,15 +22,15 @@ package org.openecomp.sdc.be.components.property; import fj.data.Either; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentPropertyToPolicyDeclarator; import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition; import org.openecomp.sdc.be.model.PolicyDefinition; @@ -43,10 +43,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ComponentPropertyToPolicyDeclaratorTest extends PropertyDeclaratorTestBase { @InjectMocks @@ -72,7 +74,7 @@ public class ComponentPropertyToPolicyDeclaratorTest extends PropertyDeclaratorT Either, StorageOperationStatus> declareEither = declarator.declarePropertiesAsPolicies( service, OWNER_ID, createInstancePropInputList(Collections.singletonList(prop1))); - Assert.assertTrue(declareEither.isLeft()); + assertTrue(declareEither.isLeft()); } @Test @@ -92,8 +94,8 @@ public class ComponentPropertyToPolicyDeclaratorTest extends PropertyDeclaratorT PropertyDefinition actualProperty = propertyCaptor.getValue(); - Assert.assertEquals(storageOperationStatus, storageOperationStatus.OK); - Assert.assertEquals(expectedProperty, actualProperty); + assertEquals(storageOperationStatus.OK, storageOperationStatus); + assertEquals(expectedProperty, actualProperty); } @@ -111,7 +113,7 @@ public class ComponentPropertyToPolicyDeclaratorTest extends PropertyDeclaratorT Either, StorageOperationStatus> declareEither = declarator.declarePropertiesAsPolicies( service, OWNER_ID, createInstancePropInputList(Collections.singletonList(prop1))); - Assert.assertTrue(declareEither.isLeft()); + assertTrue(declareEither.isLeft()); PolicyDefinition policyDefinition = createPolicyDefinition(prop1.getUniqueId()); StorageOperationStatus storageOperationStatus = @@ -119,9 +121,9 @@ public class ComponentPropertyToPolicyDeclaratorTest extends PropertyDeclaratorT List actualProperties = propertyCaptor.getAllValues(); - Assert.assertEquals(storageOperationStatus, storageOperationStatus.OK); - Assert.assertEquals(actualProperties.size(), 2); - Assert.assertEquals(prop1.getValue(), actualProperties.get(1).getValue()); + assertEquals(storageOperationStatus.OK, storageOperationStatus); + assertEquals(2, actualProperties.size()); + assertEquals(prop1.getValue(), actualProperties.get(1).getValue()); } private PropertyDefinition createPropertyWithDeclaredPolicy(String policyId) { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java index 1619e550d6..616e0babfa 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/GroupPropertyDeclaratorTest.java @@ -21,14 +21,14 @@ package org.openecomp.sdc.be.components.property; import fj.data.Either; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; import org.openecomp.sdc.be.components.utils.ResourceBuilder; @@ -48,12 +48,14 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { @@ -70,7 +72,7 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { private InputDefinition input; @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); resource = createResourceWithGroup(); @@ -83,7 +85,7 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { @Test public void testDeclarePropertiesAsInputs_groupNotExist() { Either, StorageOperationStatus> declareResult = groupPropertyDeclarator.declarePropertiesAsInputs(resource, "nonExistingGroup", Collections.emptyList()); - assertThat(declareResult.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND); + assertEquals(StorageOperationStatus.NOT_FOUND, declareResult.right().value()); verifyZeroInteractions(groupOperation); } @@ -91,7 +93,7 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { public void testDeclarePropertiesAsInputs_failedToUpdateProperties() { when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR); Either, StorageOperationStatus> declareResult = groupPropertyDeclarator.declarePropertiesAsInputs(resource, GROUP_ID, Collections.emptyList()); - assertThat(declareResult.right().value()).isEqualTo(StorageOperationStatus.GENERAL_ERROR); + assertEquals(StorageOperationStatus.GENERAL_ERROR, declareResult.right().value()); } @Test @@ -101,7 +103,7 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK); Either, StorageOperationStatus> createdInputs = groupPropertyDeclarator.declarePropertiesAsInputs(resource, GROUP_ID, propsToDeclare); List inputs = createdInputs.left().value(); - assertThat(inputs).hasSize(2); + assertEquals(2, inputs.size()); verifyInputPropertiesList(inputs, updatedPropsCapture.getValue()); //creation of inputs values is part of the DefaultPropertyDeclarator and is tested in the ComponentInstancePropertyDeclaratorTest class } @@ -110,14 +112,14 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { public void testUnDeclareProperties_whenComponentHasNoGroups_returnOk() { Resource resource = new Resource(); StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(groupOperation); } @Test public void testUnDeclareProperties_whenNoPropertiesFromGroupMatchInputId_returnOk() { StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsInputs(createResourceWithGroup(), input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(groupOperation); } @@ -125,13 +127,13 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { public void whenFailingToUpdateDeclaredProperties_returnErrorStatus() { Resource resource = createResourceWithGroups(GROUP_ID); Optional groupDefinition = resource.getGroupById(GROUP_ID); - assertThat(groupDefinition.isPresent()).isTrue(); + assertTrue(groupDefinition.isPresent()); PropertyDataDefinition getInputPropForInput = buildGetInputProperty(INPUT_ID); groupDefinition.get().setProperties(Collections.singletonList(getInputPropForInput)); when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue())); when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR); StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.GENERAL_ERROR); + assertEquals(StorageOperationStatus.GENERAL_ERROR, storageOperationStatus); } @Test @@ -146,28 +148,28 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK); StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); List updatedProperties = updatedPropsCapture.getValue(); - assertThat(updatedProperties).hasSize(1); + assertEquals(1, updatedProperties.size()); PropertyDataDefinition updatedProperty = updatedProperties.get(0); - assertThat(updatedProperty.isGetInputProperty()).isFalse(); - assertThat(updatedProperty.getValue()).isEmpty(); - assertThat(updatedProperty.getDefaultValue()).isEqualTo(getInputPropForInput.getDefaultValue()); - assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId()); + assertFalse(updatedProperty.isGetInputProperty()); + assertTrue(updatedProperty.getValue().isEmpty()); + assertEquals(getInputPropForInput.getDefaultValue(), updatedProperty.getDefaultValue()); + assertEquals(getInputPropForInput.getUniqueId(), updatedProperty.getUniqueId()); } @Test public void testUnDeclarePropertiesAsListInputs_whenComponentHasNoGroups_returnOk() { Resource resource = new Resource(); StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(groupOperation); } @Test public void testUnDeclarePropertiesAsListInputs_whenNoPropertiesFromGroupMatchInputId_returnOk() { StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(createResourceWithGroup(), input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(groupOperation); } @@ -175,13 +177,13 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { public void whenFailingToUpdateDeclaredPropertiesAsListInputs_returnErrorStatus() { Resource resource = createResourceWithGroups(GROUP_ID); Optional groupDefinition = resource.getGroupById(GROUP_ID); - assertThat(groupDefinition.isPresent()).isTrue(); + assertTrue(groupDefinition.isPresent()); PropertyDataDefinition getInputPropForInput = buildGetInputProperty(INPUT_ID); groupDefinition.get().setProperties(Collections.singletonList(getInputPropForInput)); when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue())); when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR); StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.GENERAL_ERROR); + assertEquals(StorageOperationStatus.GENERAL_ERROR, storageOperationStatus); } @Test @@ -196,14 +198,14 @@ public class GroupPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(groupOperation.updateGroupProperties(eq(resource), eq(GROUP_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK); StorageOperationStatus storageOperationStatus = groupPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); List updatedProperties = updatedPropsCapture.getValue(); - assertThat(updatedProperties).hasSize(1); + assertEquals(1, updatedProperties.size()); PropertyDataDefinition updatedProperty = updatedProperties.get(0); - assertThat(updatedProperty.isGetInputProperty()).isFalse(); - assertThat(updatedProperty.getValue()).isEmpty(); - assertThat(updatedProperty.getDefaultValue()).isEqualTo(getInputPropForInput.getDefaultValue()); - assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId()); + assertFalse(updatedProperty.isGetInputProperty()); + assertTrue(updatedProperty.getValue().isEmpty()); + assertEquals(getInputPropForInput.getDefaultValue(), updatedProperty.getDefaultValue()); + assertEquals(getInputPropForInput.getUniqueId(), updatedProperty.getUniqueId()); } private Resource createResourceWithGroup() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java index 0cbc957a14..c0b176a571 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PolicyPropertyDeclaratorTest.java @@ -21,14 +21,14 @@ package org.openecomp.sdc.be.components.property; import fj.data.Either; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.utils.PolicyDefinitionBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; import org.openecomp.sdc.be.components.utils.ResourceBuilder; @@ -47,12 +47,12 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) //note that testing for most of the common logic is under the ComponentInstancePropertyDeclaratorTest public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { @@ -69,7 +69,7 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { private InputDefinition input; @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); resource = createResourceWithPolicy(); @@ -82,7 +82,7 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { @Test public void testDeclarePropertiesAsInputs_policyNotExist() { Either, StorageOperationStatus> declareResult = policyPropertyDeclarator.declarePropertiesAsInputs(resource, "nonExistingPolicy", Collections.emptyList()); - assertThat(declareResult.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND); + assertEquals(StorageOperationStatus.NOT_FOUND, declareResult.right().value()); verifyZeroInteractions(policyOperation); } @@ -90,7 +90,7 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { public void testDeclarePropertiesAsInputs_failedToUpdateProperties() { when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR); Either, StorageOperationStatus> declareResult = policyPropertyDeclarator.declarePropertiesAsInputs(resource, POLICY_ID, Collections.emptyList()); - assertThat(declareResult.right().value()).isEqualTo(StorageOperationStatus.GENERAL_ERROR); + assertEquals(StorageOperationStatus.GENERAL_ERROR, declareResult.right().value()); } @Test @@ -100,7 +100,7 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK); Either, StorageOperationStatus> createdInputs = policyPropertyDeclarator.declarePropertiesAsInputs(resource, POLICY_ID, propsToDeclare); List inputs = createdInputs.left().value(); - assertThat(inputs).hasSize(2); + assertEquals(2, inputs.size()); verifyInputPropertiesList(inputs, updatedPropsCapture.getValue()); //creation of inputs values is part of the DefaultPropertyDeclarator and is tested in the ComponentInstancePropertyDeclaratorTest class } @@ -109,14 +109,14 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { public void testUnDeclareProperties_whenComponentHasNoPolicies_returnOk() { Resource resource = new Resource(); StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(policyOperation); } @Test public void testUnDeclareProperties_whenNoPropertiesFromPolicyMatchInputId_returnOk() { StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsInputs(createResourceWithPolicy(), input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(policyOperation); } @@ -129,7 +129,7 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue())); when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR); StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.GENERAL_ERROR); + assertEquals(StorageOperationStatus.GENERAL_ERROR, storageOperationStatus); } @Test @@ -144,28 +144,28 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK); StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); List updatedProperties = updatedPropsCapture.getValue(); - assertThat(updatedProperties).hasSize(1); + assertEquals(1, updatedProperties.size()); PropertyDataDefinition updatedProperty = updatedProperties.get(0); - assertThat(updatedProperty.isGetInputProperty()).isFalse(); - assertThat(updatedProperty.getValue()).isEmpty(); - assertThat(updatedProperty.getDefaultValue()).isEqualTo(getInputPropForInput.getDefaultValue()); - assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId()); + assertFalse(updatedProperty.isGetInputProperty()); + assertTrue(updatedProperty.getValue().isEmpty()); + assertEquals(getInputPropForInput.getDefaultValue(), updatedProperty.getDefaultValue()); + assertEquals(getInputPropForInput.getUniqueId(), updatedProperty.getUniqueId()); } @Test public void testUnDeclarePropertiesAsListInputs_whenComponentHasNoPolicies_returnOk() { Resource resource = new Resource(); StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(policyOperation); } @Test public void testUnDeclarePropertiesAsListInputs_whenNoPropertiesFromPolicyMatchInputId_returnOk() { StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(createResourceWithPolicy(), input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); verifyZeroInteractions(policyOperation); } @@ -178,7 +178,7 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(propertyOperation.findDefaultValueFromSecondPosition(Collections.emptyList(), getInputPropForInput.getUniqueId(), getInputPropForInput.getDefaultValue())).thenReturn(Either.left(getInputPropForInput.getDefaultValue())); when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.GENERAL_ERROR); StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.GENERAL_ERROR); + assertEquals(StorageOperationStatus.GENERAL_ERROR, storageOperationStatus); } @Test @@ -193,14 +193,14 @@ public class PolicyPropertyDeclaratorTest extends PropertyDeclaratorTestBase { when(policyOperation.updatePolicyProperties(eq(resource), eq(POLICY_ID), updatedPropsCapture.capture())).thenReturn(StorageOperationStatus.OK); StorageOperationStatus storageOperationStatus = policyPropertyDeclarator.unDeclarePropertiesAsListInputs(resource, input); - assertThat(storageOperationStatus).isEqualTo(StorageOperationStatus.OK); + assertEquals(StorageOperationStatus.OK, storageOperationStatus); List updatedProperties = updatedPropsCapture.getValue(); - assertThat(updatedProperties).hasSize(1); + assertEquals(1, updatedProperties.size()); PropertyDataDefinition updatedProperty = updatedProperties.get(0); - assertThat(updatedProperty.isGetInputProperty()).isFalse(); - assertThat(updatedProperty.getValue()).isEmpty(); - assertThat(updatedProperty.getDefaultValue()).isEqualTo(getInputPropForInput.getDefaultValue()); - assertThat(updatedProperty.getUniqueId()).isEqualTo(getInputPropForInput.getUniqueId()); + assertFalse(updatedProperty.isGetInputProperty()); + assertTrue(updatedProperty.getValue().isEmpty()); + assertEquals(getInputPropForInput.getDefaultValue(), updatedProperty.getDefaultValue()); + assertEquals(getInputPropForInput.getUniqueId(), updatedProperty.getUniqueId()); } private Resource createResourceWithPolicy() { diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java index 88878438c0..d69e58f5f4 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/property/PropertyDeclaratorTestBase.java @@ -20,7 +20,7 @@ package org.openecomp.sdc.be.components.property; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.openecomp.sdc.be.components.utils.ComponentInstanceBuilder; import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder; import org.openecomp.sdc.be.components.utils.ResourceBuilder; @@ -50,7 +50,7 @@ public class PropertyDeclaratorTestBase { PropertyDataDefinition prop1, prop2, complexProperty; Resource resource; - @Before + @BeforeEach public void setUp() throws Exception { prop1 = new PropertyDataDefinitionBuilder() .setUniqueId("prop1") diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ConsumptionUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ConsumptionUtilsTest.java index b78c013211..c240d0d479 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ConsumptionUtilsTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/utils/ConsumptionUtilsTest.java @@ -18,13 +18,15 @@ package org.openecomp.sdc.be.components.utils; import fj.data.Either; -import org.junit.Assert; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; +import org.openecomp.sdc.be.datatypes.elements.OperationOutputDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.ComponentInstanceProperty; import org.openecomp.sdc.be.model.Operation; +import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.types.ServiceConsumptionData; import org.openecomp.sdc.exception.ResponseFormat; @@ -34,6 +36,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createCapabilityDefinition; import static org.openecomp.sdc.be.components.property.CapabilityTestUtils.createProperties; @@ -71,6 +75,20 @@ public class ConsumptionUtilsTest { .handleConsumptionInputMappedToCapabilityProperty(operation, operationInputDefinition, serviceConsumptionData, capabilityMap, "componentName"); - Assert.assertTrue(operationResponseFormatEither.isLeft()); + assertTrue(operationResponseFormatEither.isLeft()); + } + + @Test + public void testIsAssignedValueFromValidType() { + assertTrue(ConsumptionUtils.isAssignedValueFromValidType("string", "testString")); + assertFalse(ConsumptionUtils.isAssignedValueFromValidType("string", true)); + + PropertyDefinition propertyDef = new PropertyDefinition(); + propertyDef.setType("propertyType"); + assertTrue(ConsumptionUtils.isAssignedValueFromValidType("PROPERTYTYPE", propertyDef)); + + OperationOutputDefinition opOutputDef = new OperationOutputDefinition(); + opOutputDef.setType("opOutputDef"); + assertTrue(ConsumptionUtils.isAssignedValueFromValidType("OPOUTPUTDEF", opOutputDef)); } } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/GroupExportParserImplTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/GroupExportParserImplTest.java index b55f7d8514..b8f60fe5b7 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/GroupExportParserImplTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/GroupExportParserImplTest.java @@ -22,19 +22,17 @@ package org.openecomp.sdc.be.tosca; import fj.data.Either; import org.apache.commons.lang3.tuple.Pair; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.openecomp.sdc.be.components.impl.exceptions.SdcResourceNotFoundException; import org.openecomp.sdc.be.components.utils.GroupDefinitionBuilder; import org.openecomp.sdc.be.components.utils.ResourceBuilder; -import org.openecomp.sdc.be.model.CapabilityDefinition; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentInstanceProperty; -import org.openecomp.sdc.be.model.GroupDefinition; -import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.*; import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.tosca.model.ToscaGroupTemplate; import org.openecomp.sdc.be.tosca.model.ToscaTemplateCapability; @@ -48,9 +46,11 @@ import java.util.stream.Stream; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GroupExportParserImplTest { private static final String GROUP_DEFINITION_NAME = "groupDefinitionName"; @@ -73,7 +73,7 @@ public class GroupExportParserImplTest { @Mock private PropertyConvertor propertyConvertor; - @Before + @BeforeEach public void setUp() throws Exception { initGroupExportParser(); } @@ -97,6 +97,22 @@ public class GroupExportParserImplTest { assertThat(groups).isNull(); } + @Test + public void testGetToscaGroupTemplate() { + GroupInstance groupInstance = new GroupInstance(); + groupInstance.setName("name"); + groupInstance.setGroupUUID("groupUUID"); + groupInstance.setInvariantUUID("invariantUUID"); + groupInstance.setVersion("version"); + groupInstance.setType("type"); + groupInstance.setCustomizationUUID("customizationUUID"); + ToscaGroupTemplate toscaGroupTemplate = groupExportParser.getToscaGroupTemplate(groupInstance, "invariantName"); + + assertEquals("type", toscaGroupTemplate.getType()); + assertNotNull(toscaGroupTemplate); + + } + @Test public void oneGroupInComponent() { when(component.getGroups()).thenReturn(genOneGroup()); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaMetadataTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaMetadataTest.java index 8f1923ec79..36c3fae376 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaMetadataTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/model/ToscaMetadataTest.java @@ -20,7 +20,9 @@ package org.openecomp.sdc.be.tosca.model; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ToscaMetadataTest { @@ -29,7 +31,67 @@ public class ToscaMetadataTest { return new ToscaMetadata(); } - + + @Test + public void testServiceFunction() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setServiceFunction("testServiceFunction"); + assertEquals("testServiceFunction", testSubject.getServiceFunction()); + } + + @Test + public void testInstantiationType() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setInstantiationType("testInstantiationType"); + assertEquals("testInstantiationType", testSubject.getInstantiationType()); + } + + @Test + public void testEcompGeneratedNaming() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setEcompGeneratedNaming(null); + assertEquals(false, testSubject.isEcompGeneratedNaming()); + testSubject.setEcompGeneratedNaming(true); + assertEquals(true, testSubject.isEcompGeneratedNaming()); + } + + @Test + public void testServiceEcompNaming() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setServiceEcompNaming(null); + assertEquals(false, testSubject.getServiceEcompNaming()); + testSubject.setServiceEcompNaming(false); + assertEquals(false, testSubject.getServiceEcompNaming()); + } + + @Test + public void testSourceModelInvariant() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setSourceModelInvariant("sourceModelInvariant"); + assertEquals("sourceModelInvariant", testSubject.getSourceModelInvariant()); + } + + @Test + public void testSourceModelName() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setSourceModelName("sourceModelName"); + assertEquals("sourceModelName", testSubject.getSourceModelName()); + } + + @Test + public void testSourceModelUuid() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setSourceModelUuid("sourceModelUuid"); + assertEquals("sourceModelUuid", testSubject.getSourceModelUuid()); + } + + @Test + public void testEnvironmentContext() { + ToscaMetadata testSubject = createTestSubject(); + testSubject.setEnvironmentContext("environmentContext"); + assertEquals("environmentContext", testSubject.getEnvironmentContext()); + } + @Test public void testGetName() throws Exception { ToscaMetadata testSubject; -- cgit 1.2.3-korg