aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java
blob: 00836176f0dd764befc896c8be5de2f340c67aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * 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.onap.so.client.sdnc.mapper;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
import org.onap.so.bpmn.servicedecomposition.generalobjects.License;
import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
import org.onap.so.client.sdnc.beans.SDNCSvcAction;
import org.onap.so.client.sdnc.beans.SDNCSvcOperation;

@RunWith(MockitoJUnitRunner.class)
public class VnfTopologyOperationRequestMapperTest {

    @Spy
    private GeneralTopologyObjectMapper generalTopologyObjectMapper;

    @InjectMocks
    private VnfTopologyOperationRequestMapper mapper = new VnfTopologyOperationRequestMapper();

    @Test
    public void reqMapperTest() throws Exception {
        // prepare and set service instance
        ServiceInstance serviceInstance = new ServiceInstance();
        ModelInfoServiceInstance modelInfoServiceInstance = new ModelInfoServiceInstance();
        modelInfoServiceInstance.setModelInvariantUuid("modelInvariantUuid");
        modelInfoServiceInstance.setModelName("modelName");
        modelInfoServiceInstance.setModelUuid("modelUuid");
        modelInfoServiceInstance.setModelVersion("modelVersion");
        serviceInstance.setModelInfoServiceInstance(modelInfoServiceInstance);

        // prepare VNF
        ModelInfoGenericVnf genericVnf = new ModelInfoGenericVnf();
        genericVnf.setModelInvariantUuid("vnfModelInvariantUUID");
        genericVnf.setModelVersion("vnfModelVersion");
        genericVnf.setModelName("vnfModelName");
        genericVnf.setModelUuid("vnfModelUUID");
        genericVnf.setModelCustomizationUuid("vnfModelCustomizationUUID");

        ModelInfoInstanceGroup modelL3Network = new ModelInfoInstanceGroup();
        modelL3Network.setType("L3-NETWORK");

        InstanceGroup instanceGroup1 = new InstanceGroup();
        instanceGroup1.setId("l3-network-ig-111");
        instanceGroup1.setModelInfoInstanceGroup(modelL3Network);

        InstanceGroup instanceGroup2 = new InstanceGroup();
        instanceGroup2.setId("l3-network-ig-222");
        instanceGroup2.setModelInfoInstanceGroup(modelL3Network);

        GenericVnf vnf = new GenericVnf();
        vnf.setModelInfoGenericVnf(genericVnf);
        vnf.setVnfId("vnfId");
        vnf.setVnfType("vnfType");
        vnf.getInstanceGroups().add(instanceGroup1);
        vnf.getInstanceGroups().add(instanceGroup2);
        License license = new License();
        List<String> entitlementPoolUuids = new ArrayList<>();
        entitlementPoolUuids.add("entitlementPoolUuid");
        List<String> licenseKeyGroupUuids = new ArrayList<>();
        licenseKeyGroupUuids.add("licenseKeyGroupUuid");
        license.setEntitlementPoolUuids(entitlementPoolUuids);
        license.setLicenseKeyGroupUuids(licenseKeyGroupUuids);
        vnf.setLicense(license);

        // prepare Customer object
        Customer customer = new Customer();
        customer.setGlobalCustomerId("globalCustomerId");

        ServiceSubscription serviceSubscription = new ServiceSubscription();
        serviceSubscription.setServiceType("productFamilyId");
        customer.setServiceSubscription(serviceSubscription);

        // set Customer on service instance
        customer.getServiceSubscription().getServiceInstances().add(serviceInstance);


        // prepare RequestContext
        RequestContext requestContext = new RequestContext();
        Map<String, Object> userParams = new HashMap<>();
        userParams.put("key1", "value1");
        requestContext.setUserParams(userParams);
        requestContext.setProductFamilyId("productFamilyId");
        requestContext.setMsoRequestId("MsoRequestId");

        CloudRegion cloudRegion = new CloudRegion();

        GenericResourceApiVnfOperationInformation vnfOpInformation =
                mapper.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
                        GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer,
                        cloudRegion, requestContext, true, new URI("http://localhost:8080"));
        GenericResourceApiVnfOperationInformation vnfOpInformationNullReqContext =
                mapper.reqMapper(SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,
                        GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer,
                        cloudRegion, null, true, new URI("http://localhost:8080"));

        assertNull(vnfOpInformation.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid());
        assertEquals("vnfModelCustomizationUUID",
                vnfOpInformation.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid());
        assertEquals(2, vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().size());
        assertEquals("l3-network-ig-111", vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().get(0)
                .getVnfNetworkInstanceGroupId());
        assertEquals("l3-network-ig-222", vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().get(1)
                .getVnfNetworkInstanceGroupId());
        assertEquals("entitlementPoolUuid",
                vnfOpInformation.getVnfRequestInput().getVnfInputParameters().getParam().get(1).getValue());
        assertEquals("licenseKeyGroupUuid",
                vnfOpInformation.getVnfRequestInput().getVnfInputParameters().getParam().get(2).getValue());
        assertEquals("MsoRequestId", vnfOpInformation.getRequestInformation().getRequestId());
        assertNotNull(vnfOpInformationNullReqContext.getRequestInformation().getRequestId());
    }
}