Specify a model while creating a VSP
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-software-product-lib / openecomp-sdc-vendor-software-product-core / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / dao / impl / zusammen / convertor / ElementToVSPGeneralConvertorTest.java
1 /*
2  * -
3  *  ============LICENSE_START=======================================================
4  *  Copyright (C) 2021 Nordix Foundation.
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertNotNull;
26 import static org.junit.jupiter.api.Assertions.assertNull;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
29 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.CATEGORY;
30 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.DESCRIPTION;
31 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.FEATURE_GROUPS;
32 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ICON;
33 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_AGREEMENT;
34 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_TYPE;
35 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.MODELS;
36 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.NAME;
37 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ON_BOARDING_METHOD;
38 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.SUB_CATEGORY;
39 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_ID;
40 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_NAME;
41 import static org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_VERSION;
42
43 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
44 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
45 import com.amdocs.zusammen.datatypes.Id;
46 import com.amdocs.zusammen.datatypes.item.Info;
47 import com.amdocs.zusammen.datatypes.item.Item;
48 import java.util.Arrays;
49 import java.util.List;
50 import java.util.Set;
51 import org.junit.jupiter.api.Test;
52 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName;
53 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
54
55 class ElementToVSPGeneralConvertorTest {
56
57     final ElementToVSPGeneralConvertor elementToVSPGeneralConvertor = new ElementToVSPGeneralConvertor();
58
59     @Test
60     void convertElementTest() {
61         VspDetails actualVspDetails = elementToVSPGeneralConvertor.convert((Element) null);
62         assertNull(actualVspDetails);
63         final Element elementMock = mock(Element.class);
64         final Info defaultInfo = createDefaultInfo();
65         when(elementMock.getInfo()).thenReturn(defaultInfo);
66         actualVspDetails = elementToVSPGeneralConvertor.convert(elementMock);
67         assertNotNull(actualVspDetails);
68         assertVspDetails(actualVspDetails, defaultInfo);
69     }
70
71     @Test
72     void convertElementInfoTest() {
73         VspDetails actualVspDetails = elementToVSPGeneralConvertor.convert((ElementInfo) null);
74         assertNull(actualVspDetails);
75         final ElementInfo elementInfoMock = mock(ElementInfo.class);
76         final Info defaultInfo = createDefaultInfo();
77         when(elementInfoMock.getInfo()).thenReturn(defaultInfo);
78         actualVspDetails = elementToVSPGeneralConvertor.convert(elementInfoMock);
79         assertNotNull(actualVspDetails);
80         assertVspDetails(actualVspDetails, defaultInfo);
81     }
82
83     @Test
84     void convertItemTest() {
85         VspDetails actualVspDetails = elementToVSPGeneralConvertor.convert((Item) null);
86         assertNull(actualVspDetails);
87         final Item elementInfoMock = mock(Item.class);
88         final Info defaultInfo = createDefaultInfo();
89         final var itemId = new Id();
90         final var id = "anId";
91         itemId.setValue(id);
92
93         when(elementInfoMock.getInfo()).thenReturn(defaultInfo);
94         when(elementInfoMock.getId()).thenReturn(itemId);
95         actualVspDetails = elementToVSPGeneralConvertor.convert(elementInfoMock);
96
97         assertNotNull(actualVspDetails);
98         assertEquals(actualVspDetails.getId(), id);
99         assertVspDetails(actualVspDetails, defaultInfo);
100     }
101
102     private void assertVspDetails(final VspDetails vspDetails, final Info info) {
103         assertEquals(vspDetails.getName(), info.getProperty(NAME.getValue()));
104         assertEquals(vspDetails.getDescription(), info.getProperty(DESCRIPTION.getValue()));
105         assertEquals(vspDetails.getIcon(), info.getProperty(ICON.getValue()));
106         assertEquals(vspDetails.getCategory(), info.getProperty(CATEGORY.getValue()));
107         assertEquals(vspDetails.getSubCategory(), info.getProperty(SUB_CATEGORY.getValue()));
108         assertEquals(vspDetails.getVendorId(), info.getProperty(VENDOR_ID.getValue()));
109         assertEquals(vspDetails.getVendorName(), info.getProperty(VENDOR_NAME.getValue()));
110         assertEquals(vspDetails.getVlmVersion().getId(), info.getProperty(VENDOR_VERSION.getValue()));
111         assertEquals(vspDetails.getLicenseType(), info.getProperty(LICENSE_TYPE.getValue()));
112         assertEquals(vspDetails.getLicenseAgreement(), info.getProperty(LICENSE_AGREEMENT.getValue()));
113         assertEquals(vspDetails.getFeatureGroups(), info.getProperty(FEATURE_GROUPS.getValue()));
114         assertEquals(vspDetails.getOnboardingMethod(), info.getProperty(ON_BOARDING_METHOD.getValue()));
115         assertEquals(vspDetails.getModelIdList(), info.getProperty(MODELS.getValue()));
116     }
117
118     private Info createDefaultInfo() {
119         var info = new Info();
120         final Set<InfoPropertyName> collectionProperties = Set.of(FEATURE_GROUPS, MODELS);
121         Arrays.stream(InfoPropertyName.values()).filter(propertyName -> !collectionProperties.contains(propertyName))
122             .forEach(propertyName -> info.addProperty(propertyName.getValue(), propertyName.getValue()));
123         info.addProperty(FEATURE_GROUPS.getValue(), List.of("group1", "group2"));
124         info.addProperty(MODELS.getValue(), List.of("model1", "model2"));
125         return info;
126     }
127 }