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