2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.svnfm.simulator.services;
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;
36 public class InstantiateOperatorProgressorTest {
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";
44 private InstantiateOperationProgressor testedObject;
48 testedObject = new InstantiateOperationProgressor(new VnfOperation(), new SvnfmService(), null,
49 new ApplicationConfig(), createVnfds(), createSubscriptionService());
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);
63 public void getAddResources_vnfIdNotFound() {
64 List<GrantsAddResources> result = testedObject.getAddResources("otherVnfId");
65 assertThat(result).isEmpty();
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);
75 List<Vnfd> vnfdList = new ArrayList<>();
78 Vnfds vnfds = new Vnfds();
79 vnfds.setVnfdList(vnfdList);
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);
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;