From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../dao/ServiceModelDaoFactoryTest.java | 226 ++++++++++++++++-- .../TxtInformationArtifactGeneratorImplTest.java | 252 +++++++++++++++++++++ .../src/test/resources/logback.xml | 13 ++ 3 files changed, 472 insertions(+), 19 deletions(-) create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java create mode 100644 openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml (limited to 'openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test') diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java index 2c8ffb1ded..5cfe33ba90 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java @@ -1,18 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.openecomp.sdc.vendorsoftwareproduct.dao; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; +import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; +import com.amdocs.zusammen.datatypes.Id; +import com.amdocs.zusammen.datatypes.SessionContext; +import com.amdocs.zusammen.datatypes.UserInfo; +import com.amdocs.zusammen.datatypes.item.ElementContext; +import com.amdocs.zusammen.datatypes.item.Info; +import com.amdocs.zusammen.datatypes.item.Item; +import com.amdocs.zusammen.datatypes.item.ItemVersion; +import com.amdocs.zusammen.datatypes.item.ItemVersionData; +import com.amdocs.zusammen.datatypes.itemversion.Tag; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.yaml.YamlUtil; +import org.openecomp.core.zusammen.api.ZusammenAdaptor; +import org.openecomp.sdc.model.impl.zusammen.ServiceModelDaoZusammenImpl; +import org.openecomp.sdc.model.impl.zusammen.StructureElement; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; - import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.core.model.dao.ServiceModelDaoFactory; -import org.openecomp.core.model.types.ServiceArtifact; -import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.core.utilities.file.FileContentHandler; import org.testng.Assert; import org.testng.annotations.Test; +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Optional; public class ServiceModelDaoFactoryTest { @@ -22,19 +60,64 @@ public class ServiceModelDaoFactoryTest { private static String artifact001; -// @Test + @Test public void storeServiceModelTest() { + ItemVersion itemVersionmock = new ItemVersion(); + itemVersionmock.setId(new Id()); + ZusammenAdaptorMock zusammenAdaptor = new ZusammenAdaptorMock(); + ServiceModelDaoZusammenImpl serviceModelDaoZusammen = new ServiceModelDaoZusammenImpl( + zusammenAdaptor); + + zusammenAdaptor.setItemVersion(itemVersionmock); ToscaServiceModel model = getToscaServiceModel(); - ServiceModelDaoFactory.getInstance().createInterface().storeServiceModel(vspId, version, model); + serviceModelDaoZusammen.storeServiceModel(vspId, version, model); + } + + private SessionContext getSessionContext() { + SessionContext context = new SessionContext(); + context.setUser(new UserInfo("USER_A")); + context.setTenant("asdc"); + return context; } -// @Test(dependsOnMethods = "storeServiceModelTest") + @Test public void getServiceModelTest() { + + ItemVersion itemVersionmock = new ItemVersion(); + itemVersionmock.setId(new Id()); + + ElementInfo elementInfo = new ElementInfo(); + Info info = new Info(); + info.addProperty("base","baseElement"); + elementInfo.setInfo(info); + + ElementInfo artifactElementInfo = new ElementInfo(); + artifactElementInfo.setInfo(info); + ElementInfo templateElementInfo = new ElementInfo(); + artifactElementInfo.setInfo(info); + + ZusammenElement element = new ZusammenElement(); + ServiceTemplate serviceTemplate = new ServiceTemplate(); + YamlUtil yamlUtil = new YamlUtil(); + element.setData(new ByteArrayInputStream(yamlUtil.objectToYaml(serviceTemplate).getBytes())); + info = new Info(); + info.setName("dataFileName"); + element.setInfo(info); + ZusammenAdaptorMock zusammenAdaptor = new ZusammenAdaptorMock(); + ServiceModelDaoZusammenImpl serviceModelDaoZusammen = new ServiceModelDaoZusammenImpl( + zusammenAdaptor); + + zusammenAdaptor.setItemVersion(itemVersionmock); + zusammenAdaptor.addElementInfo("null"+StructureElement.ServiceModel.name(),elementInfo); + zusammenAdaptor.addElementInfo("null"+StructureElement.Artifacts.name(),artifactElementInfo); + zusammenAdaptor.addElementInfo("null"+StructureElement.Templates.name(),templateElementInfo); + zusammenAdaptor.addElement(element); + Object model = - ServiceModelDaoFactory.getInstance().createInterface().getServiceModel(vspId, version); + serviceModelDaoZusammen.getServiceModel(vspId, version); Assert.assertNotNull(model); Assert.assertTrue(model instanceof ToscaServiceModel); if (model instanceof ToscaServiceModel) { @@ -44,16 +127,6 @@ public class ServiceModelDaoFactoryTest { } } -// @Test(dependsOnMethods = "getServiceModelTest") - public void getServiceModelInfoTest() { - Object info = ServiceModelDaoFactory.getInstance().createInterface() - .getServiceModelInfo(vspId, version, artifact001); - Assert.assertNotNull(info); - Assert.assertTrue(info instanceof ServiceArtifact); - if (info instanceof ServiceArtifact) { - Assert.assertEquals(((ServiceArtifact) info).getName(), artifact001); - } - } private ToscaServiceModel getToscaServiceModel() { @@ -94,4 +167,119 @@ public class ServiceModelDaoFactoryTest { serviceTemplate.setDescription(CommonMethods.nextUuId()); return serviceTemplate; } + + private class ZusammenAdaptorMock implements ZusammenAdaptor + { + + private ItemVersion itemVersion; + private Map elementInfoMap = new HashMap(); + private Collection elements = new ArrayList<>(); + + public void setItemVersion(ItemVersion itemVersion){ + this.itemVersion = itemVersion; + } + + public void addElementInfo(String key,ElementInfo elementInfo){ + elementInfoMap.put(key,elementInfo); + } + public void addElement(Element element){ + elements.add(element); + } + @Override + public Optional getFirstVersion(SessionContext context, Id itemId) { + + return Optional.ofNullable(itemVersion); + } + + @Override + public Optional getElement(SessionContext context, ElementContext elementContext, + String elementId) { + return null; + } + + @Override + public Optional getElementByName(SessionContext context, + ElementContext elementContext, + Id parentElementId, String elementName) { + return null; + } + + @Override + public Collection listElements(SessionContext context, + ElementContext elementContext, + Id parentElementId) { + return null; + } + + @Override + public Collection listElementData(SessionContext context, + ElementContext elementContext, + Id parentElementId) { + return elements; + } + + @Override + public Collection listElementsByName(SessionContext context, + ElementContext elementContext, + Id parentElementId, String elementName) { + return null; + } + + @Override + public Optional getElementInfoByName(SessionContext context, + ElementContext elementContext, + Id parentElementId, String elementName) { + return Optional.ofNullable(elementInfoMap.get(parentElementId+elementName)); + } + + @Override + public Optional saveElement(SessionContext context, ElementContext elementContext, + ZusammenElement element, String message) { + return null; + } + + @Override + public Id createItem(SessionContext context, Info info) { + return null; + } + + @Override + public void updateItem(SessionContext context, Id itemId, Info info) { + + } + + @Override + public Id createVersion(SessionContext context, Id itemId, Id baseVersionId, + ItemVersionData itemVersionData) { + return null; + } + + @Override + public void updateVersion(SessionContext context, Id itemId, Id versionId, + ItemVersionData itemVersionData) { + + } + + @Override + public void tagVersion(SessionContext context, Id itemId, Id versionId, Tag tag) { + + } + + @Override + public void resetVersionHistory(SessionContext context, Id itemId, Id versionId, String changeRef) { + + } + + @Override + public Optional getElementInfo(SessionContext context, + ElementContext elementContext, + Id elementId) { + return null; + } + + @Override + public Collection listItems(SessionContext context) { + return null; + } + } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java new file mode 100644 index 0000000000..6652c271ac --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/informationArtifact/impl/TxtInformationArtifactGeneratorImplTest.java @@ -0,0 +1,252 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl; + + +import org.junit.Assert; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactData; +import org.openecomp.sdc.vendorsoftwareproduct.questionnaire.QuestionnaireDataService; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.ComponentQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.Compute; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.GuestOS; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.compute.NumOfVMs; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Hypervisor; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.Recovery; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.network.NetworkCapacity; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.storage.Backup; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.storage.Storage; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.IpConfiguration; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.Network; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.NicQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.nic.Protocols; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.VspQuestionnaire; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.Availability; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.General; +import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.vsp.general.StorageDataReplication; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import javax.annotation.processing.SupportedAnnotationTypes; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.HEADER; +import static org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.impl.TxtInformationArtifactConstants.VFC_COMPUTE_CPU_OVER_SUBSCRIPTION; + + +/** + * @author KATYR + * @since December 07, 2016 + */ + +public class TxtInformationArtifactGeneratorImplTest { + + private static final String NETWORK_DESC = "\"network desc\""; + private static final String HYPERVIZOR_NAME = "\"hyper hyper hypervizor\""; + private static final String TOOLS ="all tools possible" ; + @Mock + QuestionnaireDataService questionnaireDataServiceMock; + @InjectMocks + TxtInformationArtifactGeneratorImpl informationArtifactGenerator; + + @BeforeMethod(alwaysRun = true) + public void injectDoubles() { + MockitoAnnotations.initMocks(this); + +// InformationArtifactData returnedQuestionnaire = new InformationArtifactData(); +// Mockito.when(questionnaireDataServiceMock.generateQuestionnaireDataForInformationArtifact +// (anyString(), anyObject())) +// .thenReturn(returnedQuestionnaire); +// + + } + + @Test + public void testRoundVersion(){ + Version version = new Version(2,1); + String rounded = TxtInformationArtifactGeneratorImpl.roundVersionAsNeeded(version); + Assert.assertEquals("3.0",rounded); + + version = Version.valueOf("2.0"); + rounded = TxtInformationArtifactGeneratorImpl.roundVersionAsNeeded(version); + Assert.assertEquals("2.0",rounded); + + } + + @Test + public void testArtifactCreation() throws IOException { + InformationArtifactData informationArtifactData = initArtifactData(); + Mockito.when(questionnaireDataServiceMock.generateQuestionnaireDataForInformationArtifact + (anyString(), anyObject())) + .thenReturn(informationArtifactData); + + + String result = informationArtifactGenerator.generate("vsp", new Version(0, 1)); + System.out.println("result = \n" + result); + + Assert.assertTrue(result.contains(HYPERVIZOR_NAME)); + Assert.assertTrue(result.contains(HEADER)); + Assert.assertTrue(result.contains(VFC_COMPUTE_CPU_OVER_SUBSCRIPTION)); + Assert.assertTrue(result.contains(TOOLS)); + Assert.assertTrue(result.contains(TxtInformationArtifactConstants.LICENSE_AGREEMENT_NAME)); + Assert.assertTrue(result.contains(TxtInformationArtifactConstants.LIST_OF_FEATURE_GROUPS)); + + } + + private InformationArtifactData initArtifactData() { + InformationArtifactData informationArtifactData = new InformationArtifactData(); + + informationArtifactData.setVspDetails(initVspDetails()); + + informationArtifactData.setVspQuestionnaire(initVspQuestionnaire()); + informationArtifactData.setComponentQuestionnaires(initComponentQuestionnaires()); + informationArtifactData.setNicQuestionnaires(initNicQuestionnaires()); + return informationArtifactData; + } + + private List initNicQuestionnaires() { + List nicQuestionnaires = new ArrayList<>(); + NicQuestionnaire nic1 = new NicQuestionnaire(); + NicQuestionnaire nic2 = new NicQuestionnaire(); + nic1 = initNicQuestionnaire(); + nic2 = initNicQuestionnaire(); + nicQuestionnaires.add(nic1); + nicQuestionnaires.add(nic2); + return nicQuestionnaires; + + } + + private NicQuestionnaire initNicQuestionnaire() { + NicQuestionnaire nic = new NicQuestionnaire(); + Network network = new Network(); + network.setNetworkDescription(NETWORK_DESC); + nic.setNetwork(network); + + IpConfiguration ipconfig = new IpConfiguration(); + ipconfig.setIpv4Required(true); + ipconfig.setIpv6Required(false); + + nic.setIpConfiguration(ipconfig); + + Protocols protocols = new Protocols(); + List protocolsList = new ArrayList<>(); + protocolsList.add("45"); + protocolsList.add("55"); + protocolsList.add("HTTP"); + protocols.setProtocols(protocolsList); + + nic.setProtocols(protocols); + + return nic; + } + + private List initComponentQuestionnaires() { + List componentQuestionnaires = new ArrayList<>(); + ComponentQuestionnaire componentQuestionnaire1 = new ComponentQuestionnaire(); + ComponentQuestionnaire componentQuestionnaire2 = new ComponentQuestionnaire(); + + componentQuestionnaire1 = initComponent(); + componentQuestionnaire2 = initComponent(); + + componentQuestionnaires.add(componentQuestionnaire1); + componentQuestionnaires.add(componentQuestionnaire2); + + return componentQuestionnaires; + } + + private ComponentQuestionnaire initComponent() { + ComponentQuestionnaire componentQuestionnaire = new ComponentQuestionnaire(); + org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.General general = + new org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.general.General(); + Hypervisor hypervisor = new Hypervisor(); + hypervisor.setDrivers("driving drivers"); + hypervisor.setHypervisor(HYPERVIZOR_NAME); + general.setHypervisor(hypervisor); + Recovery recovery = new Recovery(); + recovery.setPointObjective(22); + recovery.setTimeObjective(33); + general.setRecovery(recovery); + componentQuestionnaire.setGeneral( + general); + org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.network.Network net = + new org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.network.Network(); + net.setNetworkCapacity(new NetworkCapacity()); + componentQuestionnaire.setNetwork(net); + Compute compute = new Compute(); + GuestOS guestOS = new GuestOS(); + guestOS.setBitSize(32); + guestOS.setTools(TOOLS); + guestOS.setName("Ubuntu"); + compute.setGuestOS(guestOS); + NumOfVMs numOfVMs = new NumOfVMs(); + numOfVMs.setMaximum(256); + numOfVMs.setMinimum(2); + compute.setNumOfVMs(numOfVMs); + componentQuestionnaire.setCompute(compute); + + return componentQuestionnaire; + } + + private VspQuestionnaire initVspQuestionnaire() { + VspQuestionnaire vspQuestionnaire = new VspQuestionnaire(); + Availability availability = new Availability(); + availability.setUseAvailabilityZonesForHighAvailability(true); + General general = new General(); + general.setAvailability(availability); + + StorageDataReplication storageDataReplication = new StorageDataReplication(); + storageDataReplication.setStorageReplicationAcrossRegion(true); + storageDataReplication.setStorageReplicationDestination("in a galaxy far, far away"); + storageDataReplication.setStorageReplicationFrequency(6); + storageDataReplication.setStorageReplicationSize(128); + storageDataReplication.setStorageReplicationSource("here below"); + general.setStorageDataReplication(storageDataReplication); + vspQuestionnaire.setGeneral(general); + return vspQuestionnaire; + } + + private VspDetails initVspDetails() { + VspDetails vspDetails = new VspDetails(); + vspDetails.setCategory("vspCategory"); + vspDetails.setDescription("described"); + vspDetails.setName("vsp named Alice"); + vspDetails.setVendorName("Fortigate"); + vspDetails.setVersion(new Version(0, 79)); + vspDetails.setVlmVersion(new Version(0, 1)); + vspDetails.setLicenseAgreement("the usual license agreement"); + List featureGroups = new ArrayList<>(); + featureGroups.add("first feature group"); + featureGroups.add("one too many feature group"); + featureGroups.add("the very last feature group"); + vspDetails.setFeatureGroups(featureGroups); + return vspDetails; + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml new file mode 100644 index 0000000000..03ce9d1243 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file -- cgit 1.2.3-korg