a7a997b2d1b6ff3958f75b19182626c762c31a98
[usecase-ui/intent-analysis.git] /
1 /*
2  * Copyright (C) 2022 CMCC, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule;
18
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;
40
41 import java.util.ArrayList;
42 import java.util.List;
43
44 import static org.junit.jupiter.api.Assertions.*;
45 import static org.mockito.ArgumentMatchers.any;
46 import static org.mockito.ArgumentMatchers.anyString;
47
48 @SpringBootTest(classes = IntentAnalysisApplicationTests.class)
49 @RunWith(SpringRunner.class)
50 public class CLLBusinessDecisionModuleTest {
51     @InjectMocks
52     CLLBusinessDecisionModule cllBusinessDecisionModule;
53
54     @Mock
55     private ImfRegInfoService imfRegInfoService;
56     @Mock
57     private ApplicationContext applicationContext;
58     @Mock
59     private IntentContextService intentContextService;
60     IntentGoalBean intentGoalBean = new IntentGoalBean();
61     Intent intent = new Intent();
62
63     @Before
64     public void before() throws Exception {
65         intent.setIntentName("cllIntent");
66         intent.setIntentId("12345");
67         List<Expectation> expectationList = new ArrayList<>();
68
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);
78
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);
88
89         intent.setIntentExpectations(expectationList);
90         intent.setIntentExpectations(expectationList);
91         intent.setIntentExpectations(expectationList);
92         intentGoalBean.setIntent(intent);
93         intentGoalBean.setIntentGoalType(IntentGoalType.CREATE);
94     }
95
96     @Test
97     public void testNeedDecompostion() {
98 //        IntentManagementFunctionRegInfo imfRegInfo = new IntentManagementFunctionRegInfo();
99 //
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);
109     }
110
111     @Test
112     public void testIntentDecomposition() {
113         cllBusinessDecisionModule.intentDecomposition(intentGoalBean);
114         Assert.assertTrue(true);
115     }
116
117     @Test
118     public void testIntentOrchestration() {
119         List<IntentGoalBean> intentGoalBeanList = new ArrayList<>();
120         IntentGoalBean delivery = new IntentGoalBean();
121
122         Intent deliveryIntent = new Intent();
123         deliveryIntent.setIntentName("delivery");
124
125         delivery.setIntentGoalType(IntentGoalType.CREATE);
126         delivery.setIntent(deliveryIntent);
127         intentGoalBeanList.add(delivery);
128
129         IntentGoalBean assurance = new IntentGoalBean();
130
131         Intent assuranceIntent = new Intent();
132         deliveryIntent.setIntentName("assurance");
133
134         assurance.setIntentGoalType(IntentGoalType.CREATE);
135         assurance.setIntent(assuranceIntent);
136         intentGoalBeanList.add(assurance);
137
138         cllBusinessDecisionModule.intentOrchestration(intentGoalBeanList);
139         Assert.assertTrue(true);
140     }
141
142     @Test
143     public void testInvestigationCreateProcess() {
144
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);
150     }
151
152     @Test
153     public void testInvestigationUpdateProcess() {
154         Expectation deliveryExpectation = new Expectation();
155         deliveryExpectation.setExpectationName("CLL Delivery Expectation");
156
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);
162
163
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);
170
171         Intent assuranceIntent = new Intent();
172         assuranceIntent.setIntentName("CLL Assurance intent");
173         subIntentList.add(assuranceIntent);
174
175         Mockito.when(intentContextService.getSubIntentInfoFromContext(any())).thenReturn(subIntentList);
176
177         Mockito.doNothing().when(intentContextService).deleteSubIntentContext(any(), any());
178         cllBusinessDecisionModule.investigationUpdateProcess(originIntentGoal);
179         Assert.assertTrue(true);
180     }
181
182     @Test
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);
189
190         Mockito.when(intentContextService.getSubIntentInfoFromContext(any())).thenReturn(subIntentList);
191
192         CLLDeliveryIntentManagementFunction cllDeliveryImf = new CLLDeliveryIntentManagementFunction();
193         Mockito.when(intentContextService.getHandlerInfo(any())).thenReturn(cllDeliveryImf);
194         cllBusinessDecisionModule.investigationDeleteProcess(intentGoalBean);
195     }
196 }