2 * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule;
19 import org.apache.ibatis.annotations.Many;
20 import org.junit.Assert;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.onap.usecaseui.intentanalysis.IntentAnalysisApplicationTests;
28 import org.onap.usecaseui.intentanalysis.bean.enums.ExpectationType;
29 import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
30 import org.onap.usecaseui.intentanalysis.bean.enums.ObjectType;
31 import org.onap.usecaseui.intentanalysis.bean.models.*;
32 import org.onap.usecaseui.intentanalysis.cllassuranceIntentmgt.CLLAssuranceIntentManagementFunction;
33 import org.onap.usecaseui.intentanalysis.clldeliveryIntentmgt.CLLDeliveryIntentManagementFunction;
34 import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction;
35 import org.onap.usecaseui.intentanalysis.intentBaseService.contextService.IntentContextService;
36 import org.onap.usecaseui.intentanalysis.service.ImfRegInfoService;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.context.ApplicationContext;
39 import org.springframework.test.context.junit4.SpringRunner;
41 import java.util.ArrayList;
42 import java.util.List;
44 import static org.junit.jupiter.api.Assertions.*;
45 import static org.mockito.ArgumentMatchers.any;
46 import static org.mockito.ArgumentMatchers.anyString;
48 @SpringBootTest(classes = IntentAnalysisApplicationTests.class)
49 @RunWith(SpringRunner.class)
50 public class CLLBusinessDecisionModuleTest {
52 CLLBusinessDecisionModule cllBusinessDecisionModule;
55 private ImfRegInfoService imfRegInfoService;
57 private ApplicationContext applicationContext;
59 private IntentContextService intentContextService;
60 IntentGoalBean intentGoalBean = new IntentGoalBean();
61 Intent intent = new Intent();
64 public void before() throws Exception {
65 intent.setIntentName("cllIntent");
66 intent.setIntentId("12345");
67 List<Expectation> expectationList = new ArrayList<>();
69 Expectation delivery = new Expectation();
70 delivery.setExpectationId("12345-delivery");
71 delivery.setExpectationName("deliveryExpectation");
72 delivery.setExpectationType(ExpectationType.DELIVERY);
73 ExpectationObject expectationObject = new ExpectationObject();
74 expectationObject.setObjectType(ObjectType.SLICING);
75 //expetationTarget Context FulfilmentInfo is empty
76 delivery.setExpectationObject(expectationObject);
77 expectationList.add(delivery);
79 Expectation assurance = new Expectation();
80 assurance.setExpectationId("12345-assurance");
81 assurance.setExpectationName("assuranceExpectation");
82 assurance.setExpectationType(ExpectationType.ASSURANCE);
83 ExpectationObject expectationObject1 = new ExpectationObject();
84 expectationObject1.setObjectType(ObjectType.CCVPN);
85 //expetationTarget Context FulfilmentInfo is empty
86 assurance.setExpectationObject(expectationObject1);
87 expectationList.add(assurance);
89 intent.setIntentExpectations(expectationList);
90 intent.setIntentExpectations(expectationList);
91 intent.setIntentExpectations(expectationList);
92 intentGoalBean.setIntent(intent);
93 intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
97 public void testNeedDecompostion() {
98 // IntentManagementFunctionRegInfo imfRegInfo = new IntentManagementFunctionRegInfo();
100 // imfRegInfo.setSupportArea("cll");
101 // imfRegInfo.setSupportInterfaces("CREATE");
102 // imfRegInfo.setHandleName("aaa");
103 // // Mockito.when(imfRegInfoService.getImfRegInfo(intentGoalBean)).thenReturn(imfRegInfo).thenReturn(imfRegInfo);
104 // Mockito.when(cllBusinessDecisionModule.exploreIntentHandlers(intentGoalBean)).thenReturn(new IntentManagementFunction());
105 // Mockito.when(applicationContext.getBean("CLLDeliveryIntentManagementFunction")).thenReturn(new CLLDeliveryIntentManagementFunction());
106 // cllBusinessDecisionModule.findHandler(intentGoalBean);
107 cllBusinessDecisionModule.needDecompostion(intentGoalBean);
108 Assert.assertTrue(true);
112 public void testIntentDecomposition() {
113 cllBusinessDecisionModule.intentDecomposition(intentGoalBean);
114 Assert.assertTrue(true);
118 public void testIntentOrchestration() {
119 List<IntentGoalBean> intentGoalBeanList = new ArrayList<>();
120 IntentGoalBean delivery = new IntentGoalBean();
122 Intent deliveryIntent = new Intent();
123 deliveryIntent.setIntentName("delivery");
125 delivery.setIntentGoalType(IntentGoalType.CREATE);
126 delivery.setIntent(deliveryIntent);
127 intentGoalBeanList.add(delivery);
129 IntentGoalBean assurance = new IntentGoalBean();
131 Intent assuranceIntent = new Intent();
132 deliveryIntent.setIntentName("assurance");
134 assurance.setIntentGoalType(IntentGoalType.CREATE);
135 assurance.setIntent(assuranceIntent);
136 intentGoalBeanList.add(assurance);
138 cllBusinessDecisionModule.intentOrchestration(intentGoalBeanList);
139 Assert.assertTrue(true);
143 public void testInvestigationCreateProcess() {
145 IntentManagementFunctionRegInfo imfInfo = new IntentManagementFunctionRegInfo();
146 imfInfo.setHandleName("CLLBusinessIntentManagementFunction");
147 Mockito.when(imfRegInfoService.getImfRegInfo(any())).thenReturn(imfInfo);
148 cllBusinessDecisionModule.investigationCreateProcess(intentGoalBean);
149 Assert.assertTrue(true);
153 public void testInvestigationUpdateProcess() {
154 Expectation deliveryExpectation = new Expectation();
155 deliveryExpectation.setExpectationName("CLL Delivery Expectation");
157 List<Expectation> expectationList = new ArrayList<>();
158 expectationList.add(deliveryExpectation);
159 Intent originalIntent = new Intent();
160 originalIntent.setIntentExpectations(expectationList);
161 IntentGoalBean originIntentGoal = new IntentGoalBean(originalIntent, IntentGoalType.UPDATE);
164 CLLDeliveryIntentManagementFunction cllDeliveryImf = new CLLDeliveryIntentManagementFunction();
165 Mockito.when(intentContextService.getHandlerInfo(any())).thenReturn(cllDeliveryImf);
166 List<Intent> subIntentList = new ArrayList<>();
167 Intent deliveryIntent = new Intent();
168 deliveryIntent.setIntentName("CLL Delivery intent");
169 subIntentList.add(deliveryIntent);
171 Intent assuranceIntent = new Intent();
172 assuranceIntent.setIntentName("CLL Assurance intent");
173 subIntentList.add(assuranceIntent);
175 Mockito.when(intentContextService.getSubIntentInfoFromContext(any())).thenReturn(subIntentList);
177 Mockito.doNothing().when(intentContextService).deleteSubIntentContext(any(), any());
178 cllBusinessDecisionModule.investigationUpdateProcess(originIntentGoal);
179 Assert.assertTrue(true);
183 public void testInvestigationDeleteProcess() {
184 IntentGoalBean intentGoalBean = new IntentGoalBean(new Intent(),IntentGoalType.DELETE);
185 List<Intent> subIntentList = new ArrayList<>();
186 Intent deliveryIntent = new Intent();
187 deliveryIntent.setIntentName("CLL Delivery intent");
188 subIntentList.add(deliveryIntent);
190 Mockito.when(intentContextService.getSubIntentInfoFromContext(any())).thenReturn(subIntentList);
192 CLLDeliveryIntentManagementFunction cllDeliveryImf = new CLLDeliveryIntentManagementFunction();
193 Mockito.when(intentContextService.getHandlerInfo(any())).thenReturn(cllDeliveryImf);
194 cllBusinessDecisionModule.investigationDeleteProcess(intentGoalBean);