diff options
Diffstat (limited to 'catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java | 176 |
1 files changed, 150 insertions, 26 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java index ab4c662d35..edf561b717 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogicTest.java @@ -32,6 +32,8 @@ import com.google.gson.JsonElement; import fj.data.Either; import mockit.Deencapsulation; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.Assert; import org.junit.Before; @@ -117,8 +119,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -148,6 +151,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ private static final String RESOURCE_CATEGORY1 = "Network Layer 2-3"; private static final String RESOURCE_SUBCATEGORY = "Router"; public static final String RESOURCE_CATEGORY = "Network Layer 2-3/Router"; + private static final String ARTIFACT_PLACEHOLDER_FILE_EXTENSION = "fileExtension"; public static final Resource resource = Mockito.mock(Resource.class); @InjectMocks @@ -666,10 +670,10 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ .getConfiguration().getResourceDeploymentArtifacts(); Map<String, ArtifactTypeConfig> componentInstanceDeploymentArtifacts = ConfigurationManager .getConfigurationManager().getConfiguration().getResourceInstanceDeploymentArtifacts(); - assertTrue(componentDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_POLL.getType())); - assertTrue(componentDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_TRAP.getType())); - assertTrue(componentInstanceDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_POLL.getType())); - assertTrue(componentInstanceDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_TRAP.getType())); + assertThat(componentDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_POLL.getType())).isTrue(); + assertThat(componentDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_TRAP.getType())).isTrue(); + assertThat(componentInstanceDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_POLL.getType())).isTrue(); + assertThat(componentInstanceDeploymentArtifacts.containsKey(ArtifactTypeEnum.SNMP_TRAP.getType())).isTrue(); } @Test @@ -708,8 +712,8 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ when(toscaOperationFacade.getBySystemName(ComponentTypeEnum.SERVICE, serviceName)).thenReturn(getServiceRes); byte[] downloadServiceArtifactByNamesRes = artifactBL .downloadServiceArtifactByNames(serviceName, serviceVersion, artifactName); - assertTrue(downloadServiceArtifactByNamesRes != null - && downloadServiceArtifactByNamesRes.length == payload.length); + assertThat(downloadServiceArtifactByNamesRes != null + && downloadServiceArtifactByNamesRes.length == payload.length).isTrue(); } @Test @@ -1521,6 +1525,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ result = Deencapsulation.invoke(testSubject, "validateUserRole", new Object[]{user, auditingAction, componentId, artifactId, componentType, operation}); + assertNull(result); } @Test @@ -1535,8 +1540,23 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ testSubject = createTestSubject(); result = Deencapsulation.invoke(testSubject, "detectAuditingType", new Object[]{operation, origMd5}); + assertNotNull(result); } + @Test + public void testDetectNoAuditingType() throws Exception { + ArtifactsBusinessLogic testSubject; + ArtifactsBusinessLogic arb = getTestSubject(); + ArtifactOperationInfo operation = arb.new ArtifactOperationInfo(false, false, ArtifactOperationEnum.LINK); + String origMd5 = ""; + AuditingActionEnum result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "detectAuditingType", + new Object[]{operation, origMd5}); + assertNull(result); + } @Test public void testCreateEsArtifactData() throws Exception { @@ -1548,11 +1568,25 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ // default test testSubject = createTestSubject(); result = testSubject.createEsArtifactData(artifactInfo, artifactPayload); + assertNotNull(result); } @Test - public void testIsArtifactMetadataUpdate() throws Exception { + public void testIsArtifactMetadataUpdateTrue() throws Exception { + ArtifactsBusinessLogic testSubject; + AuditingActionEnum auditingActionEnum = AuditingActionEnum.ARTIFACT_METADATA_UPDATE; + boolean result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "isArtifactMetadataUpdate", + new Object[]{auditingActionEnum}); + assertThat(result).isTrue(); + } + + @Test + public void testIsArtifactMetadataUpdateFalse() throws Exception { ArtifactsBusinessLogic testSubject; AuditingActionEnum auditingActionEnum = AuditingActionEnum.ACTIVATE_SERVICE_BY_API; boolean result; @@ -1561,24 +1595,38 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ testSubject = createTestSubject(); result = Deencapsulation.invoke(testSubject, "isArtifactMetadataUpdate", new Object[]{auditingActionEnum}); + assertThat(result).isFalse(); } @Test - public void testIsDeploymentArtifact() throws Exception { + public void testIsDeploymentArtifactTrue() throws Exception { ArtifactsBusinessLogic testSubject; ArtifactDefinition artifactInfo = buildArtifactPayload(); + artifactInfo.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT); boolean result; // default test testSubject = createTestSubject(); result = Deencapsulation.invoke(testSubject, "isDeploymentArtifact", new Object[]{artifactInfo}); + assertThat(result).isTrue(); } + @Test + public void testIsDeploymentArtifactFalse() throws Exception { + ArtifactsBusinessLogic testSubject; + ArtifactDefinition artifactInfo = buildArtifactPayload(); // artifactGroupType == ArtifactGroupTypeEnum.TOSCA + boolean result; + + // default test + testSubject = createTestSubject(); + result = Deencapsulation.invoke(testSubject, "isDeploymentArtifact", new Object[]{artifactInfo}); + assertThat(result).isFalse(); + } @Test public void testSetArtifactPlaceholderCommonFields() throws Exception { ArtifactsBusinessLogic testSubject; - String resourceId = ""; + String resourceId = ES_ARTIFACT_ID; ArtifactDefinition artifactInfo = buildArtifactPayload(); @@ -1586,7 +1634,8 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ testSubject = createTestSubject(); Deencapsulation.invoke(testSubject, "setArtifactPlaceholderCommonFields", resourceId, user, artifactInfo); - + assertEquals(resourceId + "." +ARTIFACT_LABEL, artifactInfo.getUniqueId()); + assertEquals(user.getFullName(), artifactInfo.getCreatorFullName()); } @@ -1601,6 +1650,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ testSubject = createTestSubject(); result = Deencapsulation.invoke(testSubject, "createEsHeatEnvArtifactDataFromString", new Object[]{artifactDefinition, payloadStr}); + assertThat(result.isLeft()).isTrue(); } @Test @@ -1615,7 +1665,8 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ // test 1 testSubject = createTestSubject(); - testSubject.updateArtifactOnGroupInstance(component, instanceId, prevUUID, artifactInfo, artifactInfo); + result = testSubject.updateArtifactOnGroupInstance(component, instanceId, prevUUID, artifactInfo, artifactInfo); + assertThat(result.isLeft()).isTrue(); } @Test @@ -1628,6 +1679,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ testSubject = createTestSubject(); result = Deencapsulation.invoke(testSubject, "generateHeatEnvPayload", new Object[]{artifactDefinition}); + assertThat(result.isEmpty()).isFalse(); } @@ -1642,6 +1694,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ // default test testSubject = createTestSubject(); result = testSubject.buildJsonForUpdateArtifact(artifactInfo, artifactGroupType, updatedRequiredArtifacts); + assertThat(MapUtils.isNotEmpty(result)).isTrue(); } @Test @@ -1664,11 +1717,12 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ artifactId = ""; result = testSubject.buildJsonForUpdateArtifact(artifactId, artifactName, artifactType, artifactGroupType, label, displayName, description, artifactContent, updatedRequiredArtifacts, heatParameters); + assertThat(MapUtils.isNotEmpty(result)).isTrue(); } @Test - public void testReplaceCurrHeatValueWithUpdatedValue() throws Exception { + public void testNotReplaceCurrHeatValueWithUpdatedValue() throws Exception { ArtifactsBusinessLogic testSubject; List<HeatParameterDefinition> currentHeatEnvParams = new ArrayList<>(); List<HeatParameterDefinition> updatedHeatEnvParams = new ArrayList<>(); @@ -1676,7 +1730,33 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ // default test testSubject = createTestSubject(); - Deencapsulation.invoke(testSubject, "replaceCurrHeatValueWithUpdatedValue", new Object[]{currentHeatEnvParams, updatedHeatEnvParams}); + boolean result = Deencapsulation.invoke(testSubject, "replaceCurrHeatValueWithUpdatedValue", new Object[]{currentHeatEnvParams, updatedHeatEnvParams}); + assertThat(result).isFalse(); + } + + + @Test + public void testReplaceCurrHeatValueWithUpdatedValue() throws Exception { + ArtifactsBusinessLogic testSubject; + HeatParameterDefinition hpdOrig = new HeatParameterDefinition(); + hpdOrig.setName("param1"); + hpdOrig.setCurrentValue("value1"); + + HeatParameterDefinition hpdUpd = new HeatParameterDefinition(); + hpdUpd.setName("param1"); + hpdUpd.setCurrentValue("value2"); + + List<HeatParameterDefinition> currentHeatEnvParams = new ArrayList<>(); + currentHeatEnvParams.add(hpdOrig); + + List<HeatParameterDefinition> updatedHeatEnvParams = new ArrayList<>(); + updatedHeatEnvParams.add(hpdUpd); + + // default test + testSubject = createTestSubject(); + boolean result = Deencapsulation.invoke(testSubject, "replaceCurrHeatValueWithUpdatedValue", new Object[]{currentHeatEnvParams, updatedHeatEnvParams}); + assertThat(result).isTrue(); + assertEquals(hpdUpd.getCurrentValue(), hpdOrig.getCurrentValue()); } @@ -1690,44 +1770,85 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ // default test testSubject = createTestSubject(); result = testSubject.extractArtifactDefinition(eitherArtifact); + assertNotNull(result); + assertEquals(artifactDefinition, result); } @Test public void testSetHeatCurrentValuesOnHeatEnvDefaultValues() throws Exception { ArtifactsBusinessLogic testSubject; - ArtifactDefinition artifact = null; - ArtifactDefinition artifactInfo = buildArtifactPayload(); + ArtifactDefinition artifact = buildArtifactPayload(); + ArtifactDefinition artifactInfo = new ArtifactDefinition(); + + HeatParameterDefinition hpdOrig = new HeatParameterDefinition(); + hpdOrig.setName("param1"); + hpdOrig.setCurrentValue("value1"); + List<HeatParameterDefinition> currentHeatEnvParams = new ArrayList<>(); + currentHeatEnvParams.add(hpdOrig); + artifact.setListHeatParameters(currentHeatEnvParams); // default test testSubject = createTestSubject(); Deencapsulation.invoke(testSubject, "setHeatCurrentValuesOnHeatEnvDefaultValues", - artifactInfo, artifactInfo); + artifact, artifactInfo); + + assertNotEquals(artifact, artifactInfo); + assertEquals(1, artifact.getListHeatParameters().size()); + assertEquals(1, artifactInfo.getListHeatParameters().size()); + + String hpdOrigCurrValue = artifact.getListHeatParameters().get(0).getCurrentValue(); + String hpdNewDefaultValue = artifactInfo.getListHeatParameters().get(0).getDefaultValue(); + + assertEquals(hpdOrigCurrValue, hpdNewDefaultValue); } @Test - public void testBuildHeatEnvFileName() throws Exception { + public void testBuildHeatEnvFileNameArtifactNameNotNull() throws Exception { + String heatEnvExt = "zip"; ArtifactsBusinessLogic testSubject; - ArtifactDefinition heatArtifact = null; - ArtifactDefinition artifactInfo = buildArtifactPayload(); + ArtifactDefinition heatArtifact = buildArtifactPayload(); + ArtifactDefinition heatEnvArtifact = new ArtifactDefinition(); Map<String, Object> placeHolderData = new HashMap<>(); + placeHolderData.put(ARTIFACT_PLACEHOLDER_FILE_EXTENSION, heatEnvExt); + String artName = ARTIFACT_NAME.split("\\.")[0]; + + // default test + testSubject = createTestSubject(); + Deencapsulation.invoke(testSubject, "buildHeatEnvFileName", new Object[]{heatArtifact, heatEnvArtifact, placeHolderData}); + assertThat(heatEnvArtifact.getArtifactName().startsWith(artName)).isTrue(); + assertThat(heatEnvArtifact.getArtifactName().endsWith(heatEnvExt)).isTrue(); + } + @Test + public void testBuildHeatEnvFileNameArtifactNameIsNull() throws Exception { + String heatEnvExt = "zip"; + ArtifactsBusinessLogic testSubject; + ArtifactDefinition heatArtifact = buildArtifactPayload(); + heatArtifact.setArtifactName(null); + ArtifactDefinition heatEnvArtifact = new ArtifactDefinition(); + Map<String, Object> placeHolderData = new HashMap<>(); + placeHolderData.put(ARTIFACT_PLACEHOLDER_FILE_EXTENSION, heatEnvExt); // default test testSubject = createTestSubject(); - Deencapsulation.invoke(testSubject, "buildHeatEnvFileName", new Object[]{artifactInfo, artifactInfo, placeHolderData}); + Deencapsulation.invoke(testSubject, "buildHeatEnvFileName", new Object[]{heatArtifact, heatEnvArtifact, placeHolderData}); + assertThat(heatEnvArtifact.getArtifactName().startsWith(ARTIFACT_LABEL)).isTrue(); + assertThat(heatEnvArtifact.getArtifactName().endsWith(heatEnvExt)).isTrue(); } @Test public void testHandleEnvArtifactVersion() throws Exception { ArtifactsBusinessLogic testSubject; + String existingVersion = "1.0"; ArtifactDefinition artifactInfo = buildArtifactPayload(); Map<String, String> existingEnvVersions = new HashMap<>(); - + existingEnvVersions.put(artifactInfo.getArtifactName(), existingVersion); // test 1 testSubject = createTestSubject(); Deencapsulation.invoke(testSubject, "handleEnvArtifactVersion", artifactInfo, existingEnvVersions); + assertEquals(existingVersion, artifactInfo.getArtifactVersion()); } @Test @@ -1747,16 +1868,19 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ testSubject = createTestSubject(); result = testSubject.handleArtifactsForInnerVfcComponent(artifactsToHandle, component, user, vfcsNewCreatedArtifacts, operation, shouldLock, inTransaction); + + assertThat(CollectionUtils.isEmpty(result)).isTrue(); } @Test public void testSetNodeTemplateOperation() throws Exception { ArtifactsBusinessLogic testSubject; - NodeTemplateOperation nodeTemplateOperation = null; + NodeTemplateOperation nodeTemplateOperation = new NodeTemplateOperation(); // default test testSubject = createTestSubject(); - Deencapsulation.invoke(testSubject, "setNodeTemplateOperation", NodeTemplateOperation.class); + Deencapsulation.invoke(testSubject, "setNodeTemplateOperation", nodeTemplateOperation); + assertEquals(Deencapsulation.getField(testSubject, "nodeTemplateOperation"), nodeTemplateOperation); } @Test @@ -1841,7 +1965,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ , operationInfo, artifactDefinition.getUniqueId(), artifactDefinition, requestMd5, "data", "iuuid", null, componentId, "resources"); - assertTrue(result.isLeft()); + assertThat(result.isLeft()).isTrue(); ArtifactDefinition leftValue = result.left().value(); assertEquals(artifactDefinition.getArtifactName(), leftValue.getArtifactName()); } @@ -2020,7 +2144,7 @@ public class ArtifactsBusinessLogicTest extends BaseBusinessLogicMock{ componentInstance.setDeploymentArtifacts(deploymentArtifacts); List<ArtifactDefinition> result = artifactBL.getDeploymentArtifacts(resource, parentType, ciId); - Assert.assertTrue(result.size() == 1); + assertThat(result.size() == 1).isTrue(); Assert.assertEquals(artifactDefinition.getArtifactName(), result.get(0).getArtifactName()); } |