ea6c6ef71a21100a4bf46b98dfdf17442809d687
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Nokia.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.svnfm.simulator.services;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
29 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
30 import org.onap.svnfm.simulator.config.ApplicationConfig;
31 import org.onap.svnfm.simulator.model.VnfOperation;
32 import org.onap.svnfm.simulator.model.Vnfds;
33 import org.onap.svnfm.simulator.model.Vnfds.Vnfc;
34 import org.onap.svnfm.simulator.model.Vnfds.Vnfd;
35
36 public class InstantiateOperatorProgressorTest {
37
38     private static final String VNF_ID = "vnfTestId";
39     private static final String CALLBACK_URI = "/lcn/uritest";
40     private static final String VNFC_TYPE = "COMPUTE";
41     private static final String RESOURCE_TEMPLATE_ID = "resTempIdTest";
42     private static final String VDU_ID = "vduIdTest";
43
44     private InstantiateOperationProgressor testedObject;
45
46     @Before
47     public void setup() {
48         testedObject = new InstantiateOperationProgressor(new VnfOperation(), new SvnfmService(), null,
49                 new ApplicationConfig(), createVnfds(), createSubscriptionService());
50     }
51
52     @Test
53     public void getAddResources_vnfIdFound() {
54         List<GrantsAddResources> result = testedObject.getAddResources(VNF_ID);
55         assertThat(result).hasSize(1);
56         GrantsAddResources grantsAddResourceResult = result.get(0);
57         assertThat(grantsAddResourceResult.getType()).hasToString(VNFC_TYPE);
58         assertThat(grantsAddResourceResult.getResourceTemplateId()).isEqualTo(RESOURCE_TEMPLATE_ID);
59         assertThat(grantsAddResourceResult.getVduId()).isEqualTo(VDU_ID);
60     }
61
62     @Test
63     public void getAddResources_vnfIdNotFound() {
64         List<GrantsAddResources> result = testedObject.getAddResources("otherVnfId");
65         assertThat(result).isEmpty();
66     }
67
68     private Vnfds createVnfds() {
69         Vnfd vnfd = new Vnfd();
70         vnfd.setVnfdId(VNF_ID);
71         List<Vnfc> vnfcList = new ArrayList<>();
72         vnfcList.add(createVnfc());
73         vnfd.setVnfcList(vnfcList);
74
75         List<Vnfd> vnfdList = new ArrayList<>();
76         vnfdList.add(vnfd);
77
78         Vnfds vnfds = new Vnfds();
79         vnfds.setVnfdList(vnfdList);
80         return vnfds;
81     }
82
83     private Vnfc createVnfc() {
84         Vnfc vnfc = new Vnfc();
85         vnfc.setType(VNFC_TYPE);
86         vnfc.setResourceTemplateId(RESOURCE_TEMPLATE_ID);
87         vnfc.setVduId(VDU_ID);
88         return vnfc;
89     }
90
91     private SubscriptionService createSubscriptionService() {
92         SubscriptionService subscriptionService = new SubscriptionService();
93         LccnSubscriptionRequest lccnSubscriptionRequest = new LccnSubscriptionRequest();
94         lccnSubscriptionRequest.setCallbackUri(CALLBACK_URI);
95         subscriptionService.registerSubscription(lccnSubscriptionRequest);
96         return subscriptionService;
97     }
98
99 }